 Chromium Code Reviews
 Chromium Code Reviews Issue 2634493007:
  Introduce LayoutObject::AncestorSkipInfo.  (Closed)
    
  
    Issue 2634493007:
  Introduce LayoutObject::AncestorSkipInfo.  (Closed) 
  | Index: third_party/WebKit/Source/core/layout/LayoutObject.h | 
| diff --git a/third_party/WebKit/Source/core/layout/LayoutObject.h b/third_party/WebKit/Source/core/layout/LayoutObject.h | 
| index 3b28df12550cf8720dad571dd0bd6206e632dd34..518e6ed2f1d7c5a4b03675ea350b1ecbfa8c6c98 100644 | 
| --- a/third_party/WebKit/Source/core/layout/LayoutObject.h | 
| +++ b/third_party/WebKit/Source/core/layout/LayoutObject.h | 
| @@ -895,6 +895,34 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver, | 
| return isLayoutBlockFlow() || isLayoutButton(); | 
| } | 
| + // May be optionally passed to container() and various other similar methods | 
| + // that search the ancestry for some sort of containing block. | 
| + struct AncestorSkipInfo { | 
| + AncestorSkipInfo() {} | 
| 
Xianzhu
2017/01/15 23:05:05
Is the above constructor needed?
 
mstensho (USE GERRIT)
2017/01/16 09:34:04
Maybe it's not used at the moment, but it should b
 | 
| + AncestorSkipInfo(const LayoutObject* ancestor) : ancestor(ancestor) {} | 
| + | 
| + void resetOutput() { | 
| + ancestorSkipped = false; | 
| + filterSkipped = false; | 
| + } | 
| 
Xianzhu
2017/01/15 19:41:13
As we have default values for the fields, do we st
 
mstensho (USE GERRIT)
2017/01/15 21:09:25
There is a unit test that called container() twice
 
Xianzhu
2017/01/15 23:05:05
Agreed (about setAncestor() :) ).
 
mstensho (USE GERRIT)
2017/01/16 09:34:04
Done. Removed.
 | 
| + void setAncestor(const LayoutObject* ancestor) { | 
| + this->ancestor = ancestor; | 
| + resetOutput(); | 
| + } | 
| 
Xianzhu
2017/01/15 19:41:13
What's the purpose of this method?
 
mstensho (USE GERRIT)
2017/01/15 21:09:25
This will update this AncestorSkipInfo object base
 
Xianzhu
2017/01/15 23:05:05
I meant setAncestor() here. Sorry for the confusio
 | 
| + void update(const LayoutObject&); | 
| 
Xianzhu
2017/01/15 19:41:13
I'm a bit concerned about performance of this meth
 
mstensho (USE GERRIT)
2017/01/15 21:09:25
I was kind of assuming that it wasn't the common c
 
Xianzhu
2017/01/15 23:05:05
The difference is that pushing two pointers on the
 
mstensho (USE GERRIT)
2017/01/16 09:34:04
Done. Also made update() inline.
 
mstensho (USE GERRIT)
2017/01/16 14:39:02
This turned out to be tricky (see trybot failures
 | 
| + | 
| + // Input: A potential ancestor to look for. If we walk past this one while | 
| + // walking the ancestry in search of some containing block, ancestorSkipped | 
| + // will be set to true. | 
| + const LayoutObject* ancestor = nullptr; | 
| + // Output: Set to true if |ancestor| was walked past while walking the | 
| + // ancestry. | 
| + bool ancestorSkipped = false; | 
| + // Output: Set to true if we walked past a filter object. This will be set | 
| + // regardless of the value of |ancestor|. | 
| + bool filterSkipped = false; | 
| + }; | 
| + | 
| // This function returns the containing block of the object. | 
| // Due to CSS being inconsistent, a containing block can be a relatively | 
| // positioned inline, thus we can't return a LayoutBlock from this function. | 
| @@ -914,23 +942,12 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver, | 
| // walk the containing block chain. See e.g. markContainerChainForLayout. | 
| // It is also used for correctly sizing absolutely positioned elements | 
| // (point 3 above). | 
| - // | 
| - // If |ancestor| and |ancestorSkipped| are not null, on return | 
| - // *ancestorSkipped is true if the layoutObject returned is an ancestor of | 
| - // |ancestor|. | 
| - LayoutObject* container(const LayoutBoxModelObject* ancestor = nullptr, | 
| - bool* ancestorSkipped = nullptr, | 
| - bool* filterSkipped = nullptr) const; | 
| + LayoutObject* container(AncestorSkipInfo* = nullptr) const; | 
| // Finds the container as if this object is fixed-position. | 
| - LayoutBlock* containerForFixedPosition( | 
| - const LayoutBoxModelObject* ancestor = nullptr, | 
| - bool* ancestorSkipped = nullptr, | 
| - bool* filterSkipped = nullptr) const; | 
| + LayoutBlock* containerForFixedPosition(AncestorSkipInfo* = nullptr) const; | 
| // Finds the containing block as if this object is absolute-position. | 
| LayoutBlock* containingBlockForAbsolutePosition( | 
| - const LayoutBoxModelObject* ancestor = nullptr, | 
| - bool* ancestorSkipped = nullptr, | 
| - bool* filterSkipped = nullptr) const; | 
| + AncestorSkipInfo* = nullptr) const; | 
| virtual LayoutObject* hoverAncestor() const { return parent(); } | 
| @@ -1119,9 +1136,7 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver, | 
| // | 
| // See container() for the function that returns the containing block. | 
| // See LayoutBlock.h for some extra explanations on containing blocks. | 
| - LayoutBlock* containingBlock(const LayoutBoxModelObject* ancestor = nullptr, | 
| - bool* ancestorSkipped = nullptr, | 
| - bool* filterSkipped = nullptr) const; | 
| + LayoutBlock* containingBlock(AncestorSkipInfo* = nullptr) const; | 
| bool canContainAbsolutePositionObjects() const { | 
| return m_style->canContainAbsolutePositionObjects() || | 
| @@ -2035,10 +2050,7 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver, | 
| void invalidatePaintIncludingNonSelfPaintingLayerDescendantsInternal( | 
| const LayoutBoxModelObject& paintInvalidationContainer); | 
| - LayoutObject* containerForAbsolutePosition( | 
| - const LayoutBoxModelObject* ancestor = nullptr, | 
| - bool* ancestorSkipped = nullptr, | 
| - bool* filterSkipped = nullptr) const; | 
| + LayoutObject* containerForAbsolutePosition(AncestorSkipInfo* = nullptr) const; | 
| const LayoutBoxModelObject* enclosingCompositedContainer() const; |