Changeset 232042 in webkit


Ignore:
Timestamp:
May 21, 2018 6:41:58 PM (6 years ago)
Author:
Alan Bujtas
Message:

[LFC] Add FormattingContext::validateGeometryConstraintsAfterLayout
https://bugs.webkit.org/show_bug.cgi?id=185811

Reviewed by Antti Koivisto.

Also implement LayoutDescendantIterator and fix LayoutIterator.

  • WebCore.xcodeproj/project.pbxproj:
  • layout/FormattingContext.cpp:

(WebCore::Layout::FormattingContext::validateGeometryConstraintsAfterLayout const):

  • layout/FormattingContext.h:
  • layout/blockformatting/BlockFormattingContext.cpp:

(WebCore::Layout::BlockFormattingContext::layout const):

  • layout/layouttree/LayoutDescendantIterator.h: Added.

(WebCore::Layout::LayoutDescendantIterator<T>::LayoutDescendantIterator):
(WebCore::Layout::LayoutDescendantIterator<T>::operator):
(WebCore::Layout::LayoutDescendantIteratorAdapter<T>::LayoutDescendantIteratorAdapter):
(WebCore::Layout::LayoutDescendantIteratorAdapter<T>::begin):
(WebCore::Layout::LayoutDescendantIteratorAdapter<T>::end):
(WebCore::Layout::LayoutDescendantIteratorAdapter<T>::at):
(WebCore::Layout::descendantsOfType):

  • layout/layouttree/LayoutIterator.h:

(WebCore::Layout::LayoutBoxTraversal::firstChild):
(WebCore::Layout::LayoutBoxTraversal::nextAncestorSibling):
(WebCore::Layout::LayoutBoxTraversal::next):
(WebCore::Layout::LayoutBoxTraversal::nextSkippingChildren):
(WebCore::Layout::Traversal::firstChild):
(WebCore::Layout::Traversal::nextSibling):
(WebCore::Layout::Traversal::previousSibling):
(WebCore::Layout::Traversal::findAncestorOfType):
(WebCore::Layout::Traversal::firstWithin):
(WebCore::Layout::Traversal::next):
(WebCore::Layout::LayoutIterator<T>::traversePreviousSibling):
(WebCore::Layout::LayoutIterator<T>::traverseAncestor):
(WebCore::Layout::Traversal::nextAncestorSibling): Deleted.
(WebCore::Layout::Traversal::nextWithin): Deleted.

Location:
trunk/Source/WebCore
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r232039 r232042  
     12018-05-21  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Add FormattingContext::validateGeometryConstraintsAfterLayout
     4        https://bugs.webkit.org/show_bug.cgi?id=185811
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Also implement LayoutDescendantIterator and fix LayoutIterator.
     9
     10        * WebCore.xcodeproj/project.pbxproj:
     11        * layout/FormattingContext.cpp:
     12        (WebCore::Layout::FormattingContext::validateGeometryConstraintsAfterLayout const):
     13        * layout/FormattingContext.h:
     14        * layout/blockformatting/BlockFormattingContext.cpp:
     15        (WebCore::Layout::BlockFormattingContext::layout const):
     16        * layout/layouttree/LayoutDescendantIterator.h: Added.
     17        (WebCore::Layout::LayoutDescendantIterator<T>::LayoutDescendantIterator):
     18        (WebCore::Layout::LayoutDescendantIterator<T>::operator):
     19        (WebCore::Layout::LayoutDescendantIteratorAdapter<T>::LayoutDescendantIteratorAdapter):
     20        (WebCore::Layout::LayoutDescendantIteratorAdapter<T>::begin):
     21        (WebCore::Layout::LayoutDescendantIteratorAdapter<T>::end):
     22        (WebCore::Layout::LayoutDescendantIteratorAdapter<T>::at):
     23        (WebCore::Layout::descendantsOfType):
     24        * layout/layouttree/LayoutIterator.h:
     25        (WebCore::Layout::LayoutBoxTraversal::firstChild):
     26        (WebCore::Layout::LayoutBoxTraversal::nextAncestorSibling):
     27        (WebCore::Layout::LayoutBoxTraversal::next):
     28        (WebCore::Layout::LayoutBoxTraversal::nextSkippingChildren):
     29        (WebCore::Layout::Traversal::firstChild):
     30        (WebCore::Layout::Traversal::nextSibling):
     31        (WebCore::Layout::Traversal::previousSibling):
     32        (WebCore::Layout::Traversal::findAncestorOfType):
     33        (WebCore::Layout::Traversal::firstWithin):
     34        (WebCore::Layout::Traversal::next):
     35        (WebCore::Layout::LayoutIterator<T>::traversePreviousSibling):
     36        (WebCore::Layout::LayoutIterator<T>::traverseAncestor):
     37        (WebCore::Layout::Traversal::nextAncestorSibling): Deleted.
     38        (WebCore::Layout::Traversal::nextWithin): Deleted.
     39
    1402018-05-21  Basuke Suzuki  <Basuke.Suzuki@sony.com>
    241
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r232032 r232042  
    57775777                1199FA59208E3C7F002358CC /* DisplayBox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayBox.h; sourceTree = "<group>"; };
    57785778                1199FA5A208E3C7F002358CC /* DisplayBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayBox.cpp; sourceTree = "<group>"; };
     5779                11B042FB20B0E21400828A6B /* LayoutDescendantIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutDescendantIterator.h; sourceTree = "<group>"; };
    57795780                11C5F1162003E7750001AE60 /* RenderTreeBuilderInline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeBuilderInline.cpp; sourceTree = "<group>"; };
    57805781                11C5F1182003E7760001AE60 /* RenderTreeBuilderInline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderInline.h; sourceTree = "<group>"; };
     
    1569815699                                1199FA45208E35A3002358CC /* LayoutContainer.cpp */,
    1569915700                                1199FA44208E35A3002358CC /* LayoutContainer.h */,
     15701                                11B042FB20B0E21400828A6B /* LayoutDescendantIterator.h */,
    1570015702                                1199FA52208E38D3002358CC /* LayoutInlineBox.cpp */,
    1570115703                                1199FA51208E38D3002358CC /* LayoutInlineBox.h */,
     
    2693226934                        buildActionMask = 2147483647;
    2693326935                        files = (
    26934                                 29A812490FBB9CA900510293 /* WebAccessibilityObjectWrapperBase.h in Headers */,
    26935                                 AA478A7F16CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.h in Headers */,
    2693626936                                7CD0E2B81F80A4820016A4CE /* AbortController.h in Headers */,
    2693726937                                7CD0E2BF1F80A56E0016A4CE /* AbortSignal.h in Headers */,
     
    3072630726                                FD7F299413D4C0CB00AD9535 /* WaveShaperNode.h in Headers */,
    3072730727                                FD7F299713D4C0CB00AD9535 /* WaveShaperProcessor.h in Headers */,
     30728                                29A812490FBB9CA900510293 /* WebAccessibilityObjectWrapperBase.h in Headers */,
    3072830729                                AAA728F716D1D8BC00D3BBC6 /* WebAccessibilityObjectWrapperIOS.h in Headers */,
     30730                                AA478A7F16CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.h in Headers */,
    3072930731                                2D3EF4481917915C00034184 /* WebActionDisablingCALayerDelegate.h in Headers */,
    3073030732                                71025ED31F99F0CE004A250C /* WebAnimation.h in Headers */,
  • trunk/Source/WebCore/layout/FormattingContext.cpp

    r231958 r232042  
    3333#include "LayoutContainer.h"
    3434#include "LayoutContext.h"
     35#include "LayoutDescendantIterator.h"
    3536#include <wtf/IsoMallocInlines.h>
    3637
     
    443444}
    444445
    445 }
     446#ifndef NDEBUG
     447void FormattingContext::validateGeometryConstraintsAfterLayout(const LayoutContext& layoutContext) const
     448{
     449    if (!is<Container>(root()))
     450        return;
     451    auto& formattingContextRoot = downcast<Container>(root());
     452    // FIXME: add a descendantsOfType<> flavor that stops at nested formatting contexts
     453    for (auto& layoutBox : descendantsOfType<Box>(formattingContextRoot)) {
     454        if (&layoutBox.formattingContextRoot() != &formattingContextRoot)
     455            continue;
     456        auto* containingBlock = layoutBox.containingBlock();
     457        ASSERT(containingBlock);
     458        auto containingBlockSize = layoutContext.displayBoxForLayoutBox(*containingBlock)->size();
     459        auto* displayBox = layoutContext.displayBoxForLayoutBox(layoutBox);
     460        ASSERT(displayBox);
     461
     462        // 10.3.3 Block-level, non-replaced elements in normal flow
     463        // 10.3.7 Absolutely positioned, non-replaced elements
     464        if ((layoutBox.isBlockLevelBox() || layoutBox.isOutOfFlowPositioned()) && !layoutBox.replaced()) {
     465            // margin-left + border-left-width + padding-left + width + padding-right + border-right-width + margin-right = width of containing block
     466            ASSERT(displayBox->marginLeft() + displayBox->borderLeft() + displayBox->paddingLeft() + displayBox->width()
     467                + displayBox->paddingRight() + displayBox->borderRight() + displayBox->marginRight() == containingBlockSize.width());
     468        }
     469
     470        // 10.6.4 Absolutely positioned, non-replaced elements
     471        if (layoutBox.isOutOfFlowPositioned() && !layoutBox.replaced()) {
     472            // top + margin-top + border-top-width + padding-top + height + padding-bottom + border-bottom-width + margin-bottom + bottom = height of containing block
     473            ASSERT(displayBox->top() + displayBox->marginTop() + displayBox->borderTop() + displayBox->paddingTop()
     474                + displayBox->paddingBottom() + displayBox->borderBottom() + displayBox->marginBottom() == containingBlockSize.height());
     475        }
     476    }
    446477}
    447478#endif
     479}
     480}
     481#endif
  • trunk/Source/WebCore/layout/FormattingContext.h

    r231958 r232042  
    9191    void computeReplacedWidth(LayoutContext&, const Box&, Display::Box&) const;
    9292
     93#ifndef NDEBUG
     94    virtual void validateGeometryConstraintsAfterLayout(const LayoutContext&) const;
     95#endif
     96
    9397private:
    9498    void computeOutOfFlowNonReplacedHeight(LayoutContext&, const Box&, Display::Box&) const;
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r231953 r232042  
    113113    // And take care of out-of-flow boxes as the final step.
    114114    layoutOutOfFlowDescendants(layoutContext);
     115#ifndef NDEBUG
     116    validateGeometryConstraintsAfterLayout(layoutContext);
     117#endif
    115118}
    116119
  • trunk/Source/WebCore/layout/layouttree/LayoutIterator.h

    r231093 r232042  
    5757inline bool isLayoutBoxOfType(const U& layoutBox) { return TypeCastTraits<const T, const U>::isOfType(layoutBox); }
    5858
    59 // Traversal helpers
    60 namespace Traversal {
    61 
    62 template <typename T, typename U>
    63 inline const T* firstChild(U& current)
    64 {
    65     auto* object = current.firstChild();
    66     while (object && !isLayoutBoxOfType<T>(*object))
    67         object = object->nextSibling();
    68     return static_cast<const T*>(object);
    69 }
    70 
    71 template <typename T, typename U>
    72 inline const T* lastChild(U& current)
    73 {
    74     auto* object = current.lastChild();
    75     while (object && !isLayoutBoxOfType<T>(*object))
    76         object = object->previousSibling();
    77     return static_cast<const T*>(object);
    78 }
    79 
    80 template <typename T, typename U>
    81 inline const T* nextSibling(U& current)
    82 {
    83     auto* object = current.nextSibling();
    84     while (object && !isLayoutBoxOfType<T>(*object))
    85         object = object->nextSibling();
    86     return static_cast<const T*>(object);
    87 }
    88 
    89 template <typename T, typename U>
    90 inline const T* previousSibling(U& current)
    91 {
    92     auto* object = current.previousSibling();
    93     while (object && !isLayoutBoxOfType<T>(*object))
    94         object = object->previousSibling();
    95     return static_cast<const T*>(object);
    96 }
    97 
    98 template <typename T>
    99 inline const T* findAncestorOfType(const Box& current)
    100 {
    101     for (auto* ancestor = current.parent(); ancestor; ancestor = ancestor->parent()) {
    102         if (isLayoutBoxOfType<T>(*ancestor))
    103             return static_cast<const T*>(ancestor);
    104     }
     59namespace LayoutBoxTraversal {
     60
     61template <typename U>
     62inline const Box* firstChild(U& object)
     63{
     64    return object.firstChild();
     65}
     66
     67inline const Box* firstChild(const Box&)
     68{
    10569    return nullptr;
    10670}
    10771
    108 template <typename T, typename U>
    109 inline const T* nextAncestorSibling(U& current, const Container* stayWithin)
     72inline const Box* nextAncestorSibling(const Box& current, const Container* stayWithin)
    11073{
    11174    for (auto* ancestor = current.parent(); ancestor; ancestor = ancestor->parent()) {
     
    11881}
    11982
    120 template <typename T, typename U>
    121 inline const T* nextWithin(U& current, const Container* stayWithin)
     83template <typename U>
     84inline const Box* next(const U& current, const Container* stayWithin)
    12285{
    12386    if (auto* child = firstChild(current))
     
    13396}
    13497
    135 template <typename T, typename U>
    136 inline const T* firstWithin(U& current)
    137 {
    138     auto* descendant = current.fistChild();
     98inline const Box* nextSkippingChildren(Box& current, const Container* stayWithin)
     99{
     100    if (&current == stayWithin)
     101        return nullptr;
     102
     103    if (auto* sibling = current.nextSibling())
     104        return sibling;
     105
     106    return nextAncestorSibling(current, stayWithin);
     107}
     108
     109}
     110// Traversal helpers
     111namespace Traversal {
     112
     113template <typename T, typename U>
     114inline const T* firstChild(U& current)
     115{
     116    auto* object = LayoutBoxTraversal::firstChild(current);
     117    while (object && !isLayoutBoxOfType<T>(*object))
     118        object = object->nextSibling();
     119    return static_cast<const T*>(object);
     120}
     121
     122template <typename T, typename U>
     123inline const T* lastChild(U& current)
     124{
     125    auto* object = current.lastChild();
     126    while (object && !isLayoutBoxOfType<T>(*object))
     127        object = object->previousSibling();
     128    return static_cast<const T*>(object);
     129}
     130
     131template <typename T>
     132inline const T* nextSibling(const T& current)
     133{
     134    auto* object = current.nextSibling();
     135    while (object && !isLayoutBoxOfType<T>(*object))
     136        object = object->nextSibling();
     137    return static_cast<const T*>(object);
     138}
     139
     140template <typename T, typename U>
     141inline const T* previousSibling(const T& current)
     142{
     143    auto* object = current.previousSibling();
     144    while (object && !isLayoutBoxOfType<T>(*object))
     145        object = object->previousSibling();
     146    return static_cast<const T*>(object);
     147}
     148
     149template <typename T, typename U>
     150inline const T* findAncestorOfType(const T& current)
     151{
     152    for (auto* ancestor = current.parent(); ancestor; ancestor = ancestor->parent()) {
     153        if (isLayoutBoxOfType<T>(*ancestor))
     154            return static_cast<const T*>(ancestor);
     155    }
     156    return nullptr;
     157}
     158
     159template <typename T, typename U>
     160inline const T* firstWithin(const U& stayWithin)
     161{
     162    auto* descendant = LayoutBoxTraversal::firstChild(stayWithin);
    139163    while (descendant && !isLayoutBoxOfType<T>(*descendant))
    140         descendant = nextWithin(*descendant, &current);
     164        descendant = LayoutBoxTraversal::next(*descendant, &stayWithin);
    141165    return static_cast<const T*>(descendant);
    142166}
    143167
    144168template <typename T, typename U>
    145 inline const T* next(U& current, const RenderObject* stayWithin)
    146 {
    147     auto* descendant = nextWithin(current, stayWithin);
     169inline const T* next(const U& current, const Container* stayWithin)
     170{
     171    auto* descendant = LayoutBoxTraversal::next(current, stayWithin);
    148172    while (descendant && !isLayoutBoxOfType<T>(*descendant))
    149         descendant = nextWithin(*descendant, stayWithin);
     173        descendant = LayoutBoxTraversal::next(*descendant, stayWithin);
    150174    return static_cast<const T*>(descendant);
    151175}
     
    189213{
    190214    ASSERT(m_current);
    191     m_current = Traversal::previousSibling<T>(m_current);
    192     return *this;
    193 }
    194 
     215    m_current = Traversal::previousSibling<T>(*m_current);
     216    return *this;
     217}
    195218
    196219template <typename T>
     
    199222    ASSERT(m_current);
    200223    ASSERT(m_current != m_root);
    201     m_current = Traversal::findAncestorOfType<const T>(*m_current);
     224    m_current = Traversal::findAncestorOfType<T>(*m_current);
    202225    return *this;
    203226}
Note: See TracChangeset for help on using the changeset viewer.