<commit_before>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "sky/engine/config.h"
#include "sky/engine/core/painting/LayoutRoot.h"

#include "sky/engine/core/dom/Document.h"
#include "sky/engine/core/dom/Element.h"
#include "sky/engine/core/frame/FrameView.h"
#include "sky/engine/core/frame/LocalFrame.h"
#include "sky/engine/core/frame/Settings.h"
#include "sky/engine/core/painting/PaintingTasks.h"
#include "sky/engine/platform/geometry/IntRect.h"
#include "third_party/skia/include/core/SkCanvas.h"

namespace blink {

PassRefPtr<LayoutRoot> LayoutRoot::create()
{
    return adoptRef(new LayoutRoot);
}

LayoutRoot::LayoutRoot()
    : m_minWidth(0)
    , m_maxWidth(0)
    , m_minHeight(0)
    , m_maxHeight(0)
{
    m_settings = Settings::create();
    m_settings->setDefaultFixedFontSize(13);
    m_settings->setDefaultFontSize(16);
    m_frameHost = FrameHost::createDummy(m_settings.get());
    m_frame = LocalFrame::create(nullptr, m_frameHost.get());
    m_frame->createView(IntSize(), Color::white, false);
}

LayoutRoot::~LayoutRoot()
{
}

Element* LayoutRoot::rootElement() const
{
    if (!m_document)
        return nullptr;
    return m_document->firstElementChild();
}

void LayoutRoot::setRootElement(Element* root)
{
    m_document = &root->document();
    m_frame->setDocument(m_document.get());
    m_document->setFrame(m_frame.get());

    m_document->attach();
    m_document->setChild(root, ASSERT_NO_EXCEPTION);

    m_document->setFrame(nullptr);
    m_frame->setDocument(nullptr);
}

void LayoutRoot::layout()
{
    m_frame->setDocument(m_document.get());
    m_document->setFrame(m_frame.get());

    LayoutUnit maxWidth = std::max(m_minWidth, m_maxWidth);
    LayoutUnit maxHeight = std::max(m_minHeight, m_maxHeight);
    IntSize maxSize(maxWidth, maxHeight);

    m_frame->view()->setFrameRect(IntRect(IntPoint(), maxSize));
    m_frame->view()->setLayoutSize(maxSize);

    m_document->updateLayout();

    m_document->setFrame(nullptr);
    m_frame->setDocument(nullptr);
}

void LayoutRoot::paint(Canvas* canvas)
{
    if (m_document)
        rootElement()->paint(canvas);
}

} // namespace blink
<commit_msg>Make SkyShell stop crashing on scroll in Stocks2.<commit_after>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "sky/engine/config.h"
#include "sky/engine/core/painting/LayoutRoot.h"

#include "sky/engine/core/dom/Document.h"
#include "sky/engine/core/dom/Element.h"
#include "sky/engine/core/frame/FrameView.h"
#include "sky/engine/core/frame/LocalFrame.h"
#include "sky/engine/core/frame/Settings.h"
#include "sky/engine/core/painting/PaintingTasks.h"
#include "sky/engine/platform/geometry/IntRect.h"
#include "third_party/skia/include/core/SkCanvas.h"

namespace blink {

PassRefPtr<LayoutRoot> LayoutRoot::create()
{
    return adoptRef(new LayoutRoot);
}

LayoutRoot::LayoutRoot()
    : m_minWidth(0)
    , m_maxWidth(0)
    , m_minHeight(0)
    , m_maxHeight(0)
{
    m_settings = Settings::create();
    m_settings->setDefaultFixedFontSize(13);
    m_settings->setDefaultFontSize(16);
    m_frameHost = FrameHost::createDummy(m_settings.get());
    m_frame = LocalFrame::create(nullptr, m_frameHost.get());
    m_frame->createView(IntSize(), Color::white, false);
}

LayoutRoot::~LayoutRoot()
{
    if (!m_document->needsAttach())
        m_document->detach();
}

Element* LayoutRoot::rootElement() const
{
    if (!m_document)
        return nullptr;
    return m_document->firstElementChild();
}

void LayoutRoot::setRootElement(Element* root)
{
    m_document = &root->document();
    m_frame->setDocument(m_document.get());
    m_document->setFrame(m_frame.get());

    m_document->attach();
    m_document->setChild(root, ASSERT_NO_EXCEPTION);

    m_document->setFrame(nullptr);
    m_frame->setDocument(nullptr);
}

void LayoutRoot::layout()
{
    m_frame->setDocument(m_document.get());
    m_document->setFrame(m_frame.get());

    LayoutUnit maxWidth = std::max(m_minWidth, m_maxWidth);
    LayoutUnit maxHeight = std::max(m_minHeight, m_maxHeight);
    IntSize maxSize(maxWidth, maxHeight);

    m_frame->view()->setFrameRect(IntRect(IntPoint(), maxSize));
    m_frame->view()->setLayoutSize(maxSize);

    m_document->updateLayout();

    m_document->setFrame(nullptr);
    m_frame->setDocument(nullptr);
}

void LayoutRoot::paint(Canvas* canvas)
{
    if (m_document)
        rootElement()->paint(canvas);
}

} // namespace blink

{'fraction_non_alphanumeric': 0.14810834049871024, 'fraction_numerical': 0.005374032674118658, 'mean_word_length': 4.688264058679707, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3939692', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1563, 'n_words': 256}