[LFC] Add BlockFormattingContext::computeStaticPosition
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 May 2018 20:00:31 +0000 (20:00 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 May 2018 20:00:31 +0000 (20:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185352

Reviewed by Antti Koivisto.

This is the core logic for positioning inflow boxes in a block formatting context (very naive though).

* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::computeStaticPosition const):
* layout/displaytree/DisplayBox.h:

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

Source/WebCore/ChangeLog
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/displaytree/DisplayBox.h

index 7a6d26c..9b48d83 100644 (file)
@@ -1,3 +1,16 @@
+2018-05-06  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Add BlockFormattingContext::computeStaticPosition
+        https://bugs.webkit.org/show_bug.cgi?id=185352
+
+        Reviewed by Antti Koivisto.
+
+        This is the core logic for positioning inflow boxes in a block formatting context (very naive though).
+
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::computeStaticPosition const):
+        * layout/displaytree/DisplayBox.h:
+
 2018-05-05  Sam Weinig  <sam@webkit.org>
 
         Cleanup XMLHttpRequestUpload a little
index 237b732..464c0b0 100644 (file)
@@ -124,8 +124,22 @@ Ref<FloatingState> BlockFormattingContext::createOrFindFloatingState() const
     return FloatingState::create();
 }
 
-void BlockFormattingContext::computeStaticPosition(const Box&, Display::Box&) const
+void BlockFormattingContext::computeStaticPosition(const Box& layoutBox, Display::Box& displayBox) const
 {
+    // https://www.w3.org/TR/CSS22/visuren.html#block-formatting
+    // In a block formatting context, boxes are laid out one after the other, vertically, beginning at the top of a containing block.
+    // The vertical distance between two sibling boxes is determined by the 'margin' properties.
+    // Vertical margins between adjacent block-level boxes in a block formatting context collapse.
+    // In a block formatting context, each box's left outer edge touches the left edge of the containing block (for right-to-left formatting, right edges touch).
+    auto containingBlockContentBox = layoutContext().displayBoxForLayoutBox(*layoutBox.containingBlock())->contentBox();
+    // Start from the top of the container's content box.
+    auto top = containingBlockContentBox.y();
+    auto left = containingBlockContentBox.x();
+    if (auto* previousInFlowSibling = layoutBox.previousInFlowSibling())
+        top = layoutContext().displayBoxForLayoutBox(*previousInFlowSibling)->bottom() + marginBottom(*previousInFlowSibling);
+    LayoutPoint topLeft = { top, left };
+    topLeft.moveBy({ marginLeft(layoutBox), marginTop(layoutBox) });
+    displayBox.setTopLeft(topLeft);
 }
 
 void BlockFormattingContext::computeInFlowWidth(const Box&, Display::Box&) const
index 73ea630..1b24e84 100644 (file)
@@ -36,6 +36,7 @@ namespace WebCore {
 
 namespace Layout {
 class LayoutContext;
+class BlockFormattingContext;
 }
 
 namespace Display {
@@ -44,6 +45,7 @@ class Box {
     WTF_MAKE_ISO_ALLOCATED(Box);
 public:
     friend class Layout::LayoutContext;
+    friend class Layout::BlockFormattingContext;
 
     ~Box();