Changeset 231846 in webkit


Ignore:
Timestamp:
May 16, 2018 7:49:55 AM (6 years ago)
Author:
Alan Bujtas
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:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r231840 r231846  
     12018-05-16  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Make Display::Box box sizing aware
     4        https://bugs.webkit.org/show_bug.cgi?id=185649
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Display::Box::width() == Display::Box::contentBox().width() <= box-sizing: content-box; (initial and default value)
     9        Display::Box::width() == Display::Box::borderBox().width() <= box-sizing: border-box;
     10
     11        * layout/LayoutContext.cpp:
     12        (WebCore::Layout::LayoutContext::createDisplayBox):
     13        * layout/displaytree/DisplayBox.cpp:
     14        (WebCore::Display::Box::Box):
     15        (WebCore::Display::Box::marginBox const):
     16        (WebCore::Display::Box::borderBox const):
     17        (WebCore::Display::Box::paddingBox const):
     18        (WebCore::Display::Box::contentBox const):
     19        * layout/displaytree/DisplayBox.h:
     20
    1212018-05-16  Antoine Quint  <graouts@apple.com>
    222
  • trunk/Source/WebCore/layout/LayoutContext.cpp

    r231480 r231846  
    6565Display::Box& LayoutContext::createDisplayBox(const Box& layoutBox)
    6666{
    67     std::unique_ptr<Display::Box> displayBox(new Display::Box());
     67    std::unique_ptr<Display::Box> displayBox(new Display::Box(layoutBox.style().boxSizing()));
    6868    auto* displayBoxPtr = displayBox.get();
    6969    m_layoutToDisplayBox.add(&layoutBox, WTFMove(displayBox));
  • trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp

    r231401 r231846  
    3636WTF_MAKE_ISO_ALLOCATED_IMPL(Box);
    3737
    38 Box::Box()
     38Box::Box(EBoxSizing boxSizing)
     39    : m_boxSizing(boxSizing)
    3940{
    4041}
     
    4748{
    4849    ASSERT(m_hasValidMargin);
    49     auto marginBox = rect();
    50     auto topLeftMargin = LayoutSize(m_marginLeft, m_marginTop);
    51     marginBox.inflate(topLeftMargin);
     50    auto marginBox = borderBox();
    5251
    53     auto bottomRightMargin = LayoutSize(m_marginRight, m_marginBottom);
    54     marginBox.expand(bottomRightMargin);
     52    marginBox.shiftXEdgeTo(marginBox.x() + m_marginLeft);
     53    marginBox.shiftYEdgeTo(marginBox.y() + m_marginTop);
     54    marginBox.shiftMaxXEdgeTo(marginBox.maxX() - m_marginRight);
     55    marginBox.shiftMaxYEdgeTo(marginBox.maxY() - m_marginBottom);
     56
    5557    return marginBox;
    5658}
     
    5860LayoutRect Box::borderBox() const
    5961{
    60     return LayoutRect(LayoutPoint(0, 0), size());
     62    if (m_boxSizing == BORDER_BOX)
     63        return LayoutRect( { }, size());
     64
     65    // Width is content box.
     66    ASSERT(m_hasValidBorder);
     67    ASSERT(m_hasValidPadding);
     68    auto borderBoxSize = size();
     69    borderBoxSize.expand(borderLeft() + paddingLeft() + paddingRight() + borderRight() , borderTop() + paddingTop() + paddingBottom() + borderBottom());
     70    return LayoutRect( { }, borderBoxSize);
    6171}
    6272
     
    6575    ASSERT(m_hasValidBorder);
    6676    auto paddingBox = borderBox();
    67     auto topLeftBorder = LayoutSize(m_borderLeft, m_borderTop);
    68     paddingBox.inflate(-topLeftBorder);
    6977
    70     auto bottomRightBorder = LayoutSize(m_borderRight, m_borderBottom);
    71     paddingBox.expand(-bottomRightBorder);
     78    paddingBox.shiftXEdgeTo(paddingBox.x() + m_borderLeft);
     79    paddingBox.shiftYEdgeTo(paddingBox.y() + m_borderTop);
     80    paddingBox.shiftMaxXEdgeTo(paddingBox.maxX() - m_borderRight);
     81    paddingBox.shiftMaxYEdgeTo(paddingBox.maxY() - m_borderBottom);
     82
    7283    return paddingBox;
    7384}
     
    7586LayoutRect Box::contentBox() const
    7687{
     88    if (m_boxSizing == CONTENT_BOX)
     89        return LayoutRect(LayoutPoint(0, 0), size());
     90
     91    // Width is border box.
    7792    ASSERT(m_hasValidPadding);
    7893    auto contentBox = paddingBox();
    79     auto topLeftPadding = LayoutSize(m_paddingLeft, m_paddingTop);
    80     contentBox.inflate(-topLeftPadding);
    81    
    82     auto bottomRightPadding = LayoutSize(m_paddingRight, m_paddingBottom);
    83     contentBox.expand(-bottomRightPadding);
     94
     95    contentBox.shiftXEdgeTo(contentBox.x() + m_paddingLeft);
     96    contentBox.shiftYEdgeTo(contentBox.y() + m_paddingTop);
     97    contentBox.shiftMaxXEdgeTo(contentBox.maxX() - m_paddingRight);
     98    contentBox.shiftMaxYEdgeTo(contentBox.maxY() - m_paddingBottom);
     99
    84100    return contentBox;
    85101}
  • trunk/Source/WebCore/layout/displaytree/DisplayBox.h

    r231780 r231846  
    3131#include "LayoutRect.h"
    3232#include "LayoutUnit.h"
     33#include "RenderStyleConstants.h"
    3334#include <wtf/IsoMalloc.h>
    3435
     
    8788
    8889private:
    89     Box();
     90    Box(EBoxSizing);
    9091
    9192    void setRect(const LayoutRect&);
     
    142143    LayoutUnit m_paddingRight;
    143144
     145    EBoxSizing m_boxSizing { CONTENT_BOX };
     146
    144147#if !ASSERT_DISABLED
    145148    bool m_hasValidTop { false };
Note: See TracChangeset for help on using the changeset viewer.