[LFC] Add showLayoutTree() that does not require LayoutContext.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Aug 2018 14:35:24 +0000 (14:35 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Aug 2018 14:35:24 +0000 (14:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188631

Reviewed by Antti Koivisto.

* layout/layouttree/LayoutBox.cpp:
(WebCore::Layout::Box::formattingContextRoot const):
(WebCore::Layout::Box::initialContainingBlock const):
* layout/layouttree/LayoutBox.h:
* layout/layouttree/LayoutTreeBuilder.cpp:
(WebCore::Layout::outputLayoutTree):
(WebCore::Layout::showLayoutTree):
(WebCore::Layout::TreeBuilder::showLayoutTree): Deleted.
* layout/layouttree/LayoutTreeBuilder.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234924 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/layout/Verification.cpp
Source/WebCore/layout/layouttree/LayoutBox.cpp
Source/WebCore/layout/layouttree/LayoutBox.h
Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
Source/WebCore/layout/layouttree/LayoutTreeBuilder.h

index 82ae3b0..3771800 100644 (file)
@@ -1,5 +1,22 @@
 2018-08-16  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC] Add showLayoutTree() that does not require LayoutContext.
+        https://bugs.webkit.org/show_bug.cgi?id=188631
+
+        Reviewed by Antti Koivisto.
+
+        * layout/layouttree/LayoutBox.cpp:
+        (WebCore::Layout::Box::formattingContextRoot const):
+        (WebCore::Layout::Box::initialContainingBlock const):
+        * layout/layouttree/LayoutBox.h:
+        * layout/layouttree/LayoutTreeBuilder.cpp:
+        (WebCore::Layout::outputLayoutTree):
+        (WebCore::Layout::showLayoutTree):
+        (WebCore::Layout::TreeBuilder::showLayoutTree): Deleted.
+        * layout/layouttree/LayoutTreeBuilder.h:
+
+2018-08-16  Zalan Bujtas  <zalan@apple.com>
+
         [LFC] Tree builder should construct block and inline containers based on the display type.
         https://bugs.webkit.org/show_bug.cgi?id=188632
 
index 0b7d0ac..ef11025 100644 (file)
@@ -201,7 +201,7 @@ void LayoutContext::verifyAndOutputMismatchingLayoutTree(const RenderView& rende
         return;
 #if ENABLE(TREE_DEBUGGING)
     showRenderTree(&renderView);
-    TreeBuilder::showLayoutTree(*this, *m_root.get());
+    showLayoutTree(*m_root.get(), this);
 #endif
     WTFLogAlways("%s", stream.release().utf8().data());
 }
index f8f447c..e1d26fa 100644 (file)
@@ -162,9 +162,21 @@ const Container& Box::formattingContextRoot() const
     // Initial containing block always establishes a formatting context.
     if (isInitialContainingBlock())
         return downcast<Container>(*this);
+
     RELEASE_ASSERT_NOT_REACHED();
 }
 
+const Container& Box::initialContainingBlock() const
+{
+    if (isInitialContainingBlock())
+        return downcast<Container>(*this);
+
+    auto* parent = this->parent();
+    for (; parent->parent(); parent = parent->parent()) { }
+
+    return *parent;
+}
+
 bool Box::isDescendantOf(const Container& container) const
 { 
     for (auto* ancestor = containingBlock(); ancestor; ancestor = ancestor->containingBlock()) {
index bcfc086..0d1831b 100644 (file)
@@ -68,6 +68,8 @@ public:
 
     const Container* containingBlock() const;
     const Container& formattingContextRoot() const;
+    const Container& initialContainingBlock() const;
+
     bool isDescendantOf(const Container&) const;
 
     bool isAnonymous() const { return !m_elementAttributes; }
index a6c8738..e8a0ee2 100644 (file)
@@ -152,23 +152,30 @@ static void outputLayoutBox(TextStream& stream, const Box& layoutBox, const Disp
     stream.nextLine();
 }
 
-static void outputLayoutTree(const LayoutContext& layoutContext, TextStream& stream, const Container& rootContainer, unsigned depth)
+static void outputLayoutTree(const LayoutContext* layoutContext, TextStream& stream, const Container& rootContainer, unsigned depth)
 {
     for (auto& child : childrenOfType<Box>(rootContainer)) {
-        outputLayoutBox(stream, child, layoutContext.displayBoxForLayoutBox(child), depth);
+        outputLayoutBox(stream, child, layoutContext ? layoutContext->displayBoxForLayoutBox(child) : nullptr, depth);
         if (is<Container>(child))
             outputLayoutTree(layoutContext, stream, downcast<Container>(child), depth + 1);
     }
 }
 
-void TreeBuilder::showLayoutTree(const LayoutContext& layoutContext, const Container& layoutBox)
+void showLayoutTree(const Box& layoutBox, const LayoutContext* layoutContext)
 {
     TextStream stream(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect);
-    outputLayoutBox(stream, layoutBox, layoutContext.displayBoxForLayoutBox(layoutBox), 0);
-    outputLayoutTree(layoutContext, stream, layoutBox, 1);
+
+    auto& initialContainingBlock = layoutBox.initialContainingBlock();
+    outputLayoutBox(stream, initialContainingBlock, layoutContext ? layoutContext->displayBoxForLayoutBox(initialContainingBlock) : nullptr, 0);
+    outputLayoutTree(layoutContext, stream, initialContainingBlock, 1);
     WTFLogAlways("%s", stream.release().utf8().data());
 }
 
+void showLayoutTree(const Box& layoutBox)
+{
+    showLayoutTree(layoutBox, nullptr);
+}
+
 void printLayoutTreeForLiveDocuments()
 {
     for (const auto* document : Document::allDocuments()) {
index a8b1cfd..92d3365 100644 (file)
@@ -34,19 +34,21 @@ class RenderView;
 
 namespace Layout {
 
+class Box;
 class Container;
 class LayoutContext;
 
 class TreeBuilder {
 public:
     static std::unique_ptr<Container> createLayoutTree(const RenderView&);
-    static void showLayoutTree(const LayoutContext&, const Container&);
 
 private:
     static void createSubTree(const RenderElement& rootRenderer, Container& rootContainer);
 };
 
 #if ENABLE(TREE_DEBUGGING)
+void showLayoutTree(const Box&, const LayoutContext*);
+void showLayoutTree(const Box&);
 void printLayoutTreeForLiveDocuments();
 #endif