Title: [231846] trunk/Source/WebCore
Revision
231846
Author
za...@apple.com
Date
2018-05-16 07:49:55 -0700 (Wed, 16 May 2018)

Log Message

[LFC] Make Display::Box box sizing aware
https://bugs.webkit.org/show_bug.cgi?id=185649

Reviewed by Antti Koivisto.

Display::Box::width() == Display::Box::contentBox().width() <= box-sizing: content-box; (initial and default value)
Display::Box::width() == Display::Box::borderBox().width() <= box-sizing: border-box;

* layout/LayoutContext.cpp:
(WebCore::Layout::LayoutContext::createDisplayBox):
* layout/displaytree/DisplayBox.cpp:
(WebCore::Display::Box::Box):
(WebCore::Display::Box::marginBox const):
(WebCore::Display::Box::borderBox const):
(WebCore::Display::Box::paddingBox const):
(WebCore::Display::Box::contentBox const):
* layout/displaytree/DisplayBox.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (231845 => 231846)


--- trunk/Source/WebCore/ChangeLog	2018-05-16 14:26:30 UTC (rev 231845)
+++ trunk/Source/WebCore/ChangeLog	2018-05-16 14:49:55 UTC (rev 231846)
@@ -1,3 +1,23 @@
+2018-05-16  Zalan Bujtas  <za...@apple.com>
+
+        [LFC] Make Display::Box box sizing aware
+        https://bugs.webkit.org/show_bug.cgi?id=185649
+
+        Reviewed by Antti Koivisto.
+
+        Display::Box::width() == Display::Box::contentBox().width() <= box-sizing: content-box; (initial and default value)
+        Display::Box::width() == Display::Box::borderBox().width() <= box-sizing: border-box;
+
+        * layout/LayoutContext.cpp:
+        (WebCore::Layout::LayoutContext::createDisplayBox):
+        * layout/displaytree/DisplayBox.cpp:
+        (WebCore::Display::Box::Box):
+        (WebCore::Display::Box::marginBox const):
+        (WebCore::Display::Box::borderBox const):
+        (WebCore::Display::Box::paddingBox const):
+        (WebCore::Display::Box::contentBox const):
+        * layout/displaytree/DisplayBox.h:
+
 2018-05-16  Antoine Quint  <grao...@apple.com>
 
         REGRESSION (r230574): Interrupted hardware transitions don't behave correctly

Modified: trunk/Source/WebCore/layout/LayoutContext.cpp (231845 => 231846)


--- trunk/Source/WebCore/layout/LayoutContext.cpp	2018-05-16 14:26:30 UTC (rev 231845)
+++ trunk/Source/WebCore/layout/LayoutContext.cpp	2018-05-16 14:49:55 UTC (rev 231846)
@@ -64,7 +64,7 @@
 
 Display::Box& LayoutContext::createDisplayBox(const Box& layoutBox)
 {
-    std::unique_ptr<Display::Box> displayBox(new Display::Box());
+    std::unique_ptr<Display::Box> displayBox(new Display::Box(layoutBox.style().boxSizing()));
     auto* displayBoxPtr = displayBox.get();
     m_layoutToDisplayBox.add(&layoutBox, WTFMove(displayBox));
     return *displayBoxPtr;

Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp (231845 => 231846)


--- trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp	2018-05-16 14:26:30 UTC (rev 231845)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp	2018-05-16 14:49:55 UTC (rev 231846)
@@ -35,7 +35,8 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(Box);
 
-Box::Box()
+Box::Box(EBoxSizing boxSizing)
+    : m_boxSizing(boxSizing)
 {
 }
 
@@ -46,18 +47,27 @@
 LayoutRect Box::marginBox() const
 {
     ASSERT(m_hasValidMargin);
-    auto marginBox = rect();
-    auto topLeftMargin = LayoutSize(m_marginLeft, m_marginTop);
-    marginBox.inflate(topLeftMargin);
+    auto marginBox = borderBox();
 
-    auto bottomRightMargin = LayoutSize(m_marginRight, m_marginBottom);
-    marginBox.expand(bottomRightMargin);
+    marginBox.shiftXEdgeTo(marginBox.x() + m_marginLeft);
+    marginBox.shiftYEdgeTo(marginBox.y() + m_marginTop);
+    marginBox.shiftMaxXEdgeTo(marginBox.maxX() - m_marginRight);
+    marginBox.shiftMaxYEdgeTo(marginBox.maxY() - m_marginBottom);
+
     return marginBox;
 }
 
 LayoutRect Box::borderBox() const
 {
-    return LayoutRect(LayoutPoint(0, 0), size());
+    if (m_boxSizing == BORDER_BOX)
+        return LayoutRect( { }, size());
+
+    // Width is content box.
+    ASSERT(m_hasValidBorder);
+    ASSERT(m_hasValidPadding);
+    auto borderBoxSize = size();
+    borderBoxSize.expand(borderLeft() + paddingLeft() + paddingRight() + borderRight() , borderTop() + paddingTop() + paddingBottom() + borderBottom());
+    return LayoutRect( { }, borderBoxSize);
 }
 
 LayoutRect Box::paddingBox() const
@@ -64,23 +74,29 @@
 {
     ASSERT(m_hasValidBorder);
     auto paddingBox = borderBox();
-    auto topLeftBorder = LayoutSize(m_borderLeft, m_borderTop);
-    paddingBox.inflate(-topLeftBorder);
 
-    auto bottomRightBorder = LayoutSize(m_borderRight, m_borderBottom);
-    paddingBox.expand(-bottomRightBorder);
+    paddingBox.shiftXEdgeTo(paddingBox.x() + m_borderLeft);
+    paddingBox.shiftYEdgeTo(paddingBox.y() + m_borderTop);
+    paddingBox.shiftMaxXEdgeTo(paddingBox.maxX() - m_borderRight);
+    paddingBox.shiftMaxYEdgeTo(paddingBox.maxY() - m_borderBottom);
+
     return paddingBox;
 }
 
 LayoutRect Box::contentBox() const
 {
+    if (m_boxSizing == CONTENT_BOX)
+        return LayoutRect(LayoutPoint(0, 0), size());
+
+    // Width is border box.
     ASSERT(m_hasValidPadding);
     auto contentBox = paddingBox();
-    auto topLeftPadding = LayoutSize(m_paddingLeft, m_paddingTop);
-    contentBox.inflate(-topLeftPadding);
-    
-    auto bottomRightPadding = LayoutSize(m_paddingRight, m_paddingBottom);
-    contentBox.expand(-bottomRightPadding);
+
+    contentBox.shiftXEdgeTo(contentBox.x() + m_paddingLeft);
+    contentBox.shiftYEdgeTo(contentBox.y() + m_paddingTop);
+    contentBox.shiftMaxXEdgeTo(contentBox.maxX() - m_paddingRight);
+    contentBox.shiftMaxYEdgeTo(contentBox.maxY() - m_paddingBottom);
+
     return contentBox;
 }
 

Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.h (231845 => 231846)


--- trunk/Source/WebCore/layout/displaytree/DisplayBox.h	2018-05-16 14:26:30 UTC (rev 231845)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.h	2018-05-16 14:49:55 UTC (rev 231846)
@@ -30,6 +30,7 @@
 #include "LayoutPoint.h"
 #include "LayoutRect.h"
 #include "LayoutUnit.h"
+#include "RenderStyleConstants.h"
 #include <wtf/IsoMalloc.h>
 
 namespace WebCore {
@@ -86,7 +87,7 @@
     LayoutRect contentBox() const;
 
 private:
-    Box();
+    Box(EBoxSizing);
 
     void setRect(const LayoutRect&);
     void setTopLeft(const LayoutPoint&);
@@ -141,6 +142,8 @@
     LayoutUnit m_paddingBottom;
     LayoutUnit m_paddingRight;
 
+    EBoxSizing m_boxSizing { CONTENT_BOX };
+
 #if !ASSERT_DISABLED
     bool m_hasValidTop { false };
     bool m_hasValidLeft { false };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to