Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(956)

Unified Diff: sky/engine/core/painting/LayoutRoot.cpp

Issue 1148253003: Add LayoutRoot (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Updated Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/engine/core/painting/LayoutRoot.cpp
diff --git a/sky/engine/core/painting/LayoutRoot.cpp b/sky/engine/core/painting/LayoutRoot.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..aa86874e1617643bec3d66f550f6389445757f48
--- /dev/null
+++ b/sky/engine/core/painting/LayoutRoot.cpp
@@ -0,0 +1,80 @@
+// 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);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698