Skip to content
Permalink
Browse files
[LayoutReloaded] Should never need to go beyond the root container wh…
…en asking for the containing block.

https://bugs.webkit.org/show_bug.cgi?id=183691

Reviewed by Antti Koivisto.

While laying out the boxes in a block formatting context, if we happen to need
to get to the containing block of a box to compute geometry, it should always be a
descendant of the root container (or the root container itself).
Nothing outside of the formatting context should be able to impact the boxes inside.

* LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
(BlockFormattingContext.prototype._computeOutOfFlowPosition):
(BlockFormattingContext.prototype._toAbsolutePosition):
(BlockFormattingContext):
* LayoutReloaded/FormattingContext/BlockFormatting/BlockMarginCollapse.js:
(BlockMarginCollapse._isMarginTopCollapsedWithParent):
(BlockMarginCollapse._isMarginBottomCollapsedWithParent):
* LayoutReloaded/LayoutTree/Box.js:
(Layout.Box.prototype.isRootBox):
(Layout.Box.prototype.isRootElement): Deleted.
* LayoutReloaded/Utils.js:
(Utils.isDescendantOf):
(Utils.mapStaticToAbsolute): Deleted.
* LayoutReloaded/misc/headers/Box.h:

Canonical link: https://commits.webkit.org/199330@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229658 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbujtas committed Mar 16, 2018
1 parent e0792c4 commit 190d1df7039f40457984bb4b5c9845bee1f81113
@@ -1,3 +1,30 @@
2018-03-15 Zalan Bujtas <zalan@apple.com>

[LayoutReloaded] Should never need to go beyond the root container when asking for the containing block.
https://bugs.webkit.org/show_bug.cgi?id=183691

Reviewed by Antti Koivisto.

While laying out the boxes in a block formatting context, if we happen to need
to get to the containing block of a box to compute geometry, it should always be a
descendant of the root container (or the root container itself).
Nothing outside of the formatting context should be able to impact the boxes inside.

* LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
(BlockFormattingContext.prototype._computeOutOfFlowPosition):
(BlockFormattingContext.prototype._toAbsolutePosition):
(BlockFormattingContext):
* LayoutReloaded/FormattingContext/BlockFormatting/BlockMarginCollapse.js:
(BlockMarginCollapse._isMarginTopCollapsedWithParent):
(BlockMarginCollapse._isMarginBottomCollapsedWithParent):
* LayoutReloaded/LayoutTree/Box.js:
(Layout.Box.prototype.isRootBox):
(Layout.Box.prototype.isRootElement): Deleted.
* LayoutReloaded/Utils.js:
(Utils.isDescendantOf):
(Utils.mapStaticToAbsolute): Deleted.
* LayoutReloaded/misc/headers/Box.h:

2018-03-15 Wenson Hsieh <wenson_hsieh@apple.com>

[iOS WK2] Hit-testing fails when specifying a large top content inset
@@ -294,7 +294,7 @@ class BlockFormattingContext extends FormattingContext {
let top = Number.NaN;
if (Utils.isTopAuto(layoutBox) && Utils.isBottomAuto(layoutBox)) {
// Convert static position to absolute.
top = Utils.mapStaticToAbsolute(layoutBox).top();
top = this._toAbsolutePosition(layoutBox).top();
} else if (!Utils.isTopAuto(layoutBox))
top = Utils.top(layoutBox) + this.marginTop(layoutBox);
else if (!Utils.isBottomAuto(layoutBox))
@@ -305,7 +305,7 @@ class BlockFormattingContext extends FormattingContext {
let left = Number.NaN;
if (Utils.isLeftAuto(layoutBox) && Utils.isRightAuto(layoutBox)) {
// Convert static position to absolute.
left = Utils.mapStaticToAbsolute(layoutBox).left();
left = this._toAbsolutePosition(layoutBox).left();
} else if (!Utils.isLeftAuto(layoutBox))
left = Utils.left(layoutBox) + this.marginLeft(layoutBox);
else if (!Utils.isRightAuto(layoutBox))
@@ -327,5 +327,18 @@ class BlockFormattingContext extends FormattingContext {
}
return width;
}

_toAbsolutePosition(layoutBox) {
// We should never need to go beyond the root container.
let containingBlock = layoutBox.containingBlock();
ASSERT(containingBlock == this.rootContainer() || Utils.isDescendantOf(containingBlock, this.rootContainer()));
let topLeft = layoutBox.rect().topLeft();
let ascendant = layoutBox.parent();
while (ascendant && ascendant != containingBlock) {
topLeft.moveBy(ascendant.rect().topLeft());
ascendant = ascendant.parent();
}
return new LayoutRect(topLeft, layoutBox.rect().size());
}
}

@@ -94,7 +94,7 @@ class BlockMarginCollapse {
if (parent.establishesBlockFormattingContext())
return false;
// Margins of the root element's box do not collapse.
if (parent.isRootElement())
if (parent.isRootBox())
return false;
if (Utils.hasBorderTop(parent))
return false;
@@ -117,7 +117,7 @@ class BlockMarginCollapse {
if (parent.establishesBlockFormattingContext())
return false;
// Margins of the root element's box do not collapse.
if (parent.isRootElement())
if (parent.isRootBox())
return false;
if (Utils.hasBorderTop(parent))
return false;
@@ -213,7 +213,7 @@ Layout.Box = class Box {
return this.isFloatingPositioned() || this.isOutOfFlowPositioned();
}

isRootElement() {
isRootBox() {
// FIXME: This should just be a simple instanceof check, but we are in the mainframe while the test document is in an iframe
// Let's just return root for both the RenderView and the <html> element.
return !this.parent() || !this.parent().parent();
@@ -486,8 +486,12 @@ class Utils {
return new LayoutRect(topLeft, box.rect().size());
}

static mapStaticToAbsolute(box) {
return Utils.mapToContainer(box, box.containingBlock());
static isDescendantOf(layoutBox, container) {
ASSERT(container);
let ascendant = layoutBox.parent();
while (ascendant && ascendant != container)
ascendant = ascendant.parent();
return !!ascendant;
}

static collectOutOfFlowDescendants(containtBlock) {
@@ -54,7 +54,7 @@ class Box {

void setIsAnonymous(bool);
bool isAnonymous() const;
virtual bool isRootElement() const;
bool isRootBox() const;
virtual bool isContainer() const;

bool isBlockLevelBox() const;

0 comments on commit 190d1df

Please sign in to comment.