Fix RenderBlock::percentHeightDescendants()

RenderBlock::percentHeightDescendants() is used to schedule layout of
descencents of a block when the logical height of the block changes.
It should contain descendants having percent height whose real height
calculation depends on the height of the block.

Previously
- the set doesn't contain direct children;
- skipped containing blocks for percent height calculation unnecessarily
  have the set.

Let the set contain all necessary objects. This doesn't fix any
functional breakage for now, but later layout optimization may depend
on the correct behavior of the function.

BUG=327815
TEST=WebFrameTest.RenderBlockPercentHeightDescendants

Review URL: https://codereview.chromium.org/201153008

git-svn-id: svn://svn.chromium.org/blink/trunk@169588 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent bbab58ab
...@@ -120,12 +120,18 @@ public: ...@@ -120,12 +120,18 @@ public:
void addPercentHeightDescendant(RenderBox*); void addPercentHeightDescendant(RenderBox*);
static void removePercentHeightDescendant(RenderBox*); static void removePercentHeightDescendant(RenderBox*);
TrackedRendererListHashSet* percentHeightDescendants() const;
static bool hasPercentHeightContainerMap(); static bool hasPercentHeightContainerMap();
static bool hasPercentHeightDescendant(RenderBox*); static bool hasPercentHeightDescendant(RenderBox*);
static void clearPercentHeightDescendantsFrom(RenderBox*); static void clearPercentHeightDescendantsFrom(RenderBox*);
static void removePercentHeightDescendantIfNeeded(RenderBox*); static void removePercentHeightDescendantIfNeeded(RenderBox*);
TrackedRendererListHashSet* percentHeightDescendants() const;
bool hasPercentHeightDescendants() const
{
TrackedRendererListHashSet* descendants = percentHeightDescendants();
return descendants && !descendants->isEmpty();
}
void setHasMarkupTruncation(bool b) { m_hasMarkupTruncation = b; } void setHasMarkupTruncation(bool b) { m_hasMarkupTruncation = b; }
bool hasMarkupTruncation() const { return m_hasMarkupTruncation; } bool hasMarkupTruncation() const { return m_hasMarkupTruncation; }
......
...@@ -2692,8 +2692,8 @@ LayoutUnit RenderBox::computePercentageLogicalHeight(const Length& height) const ...@@ -2692,8 +2692,8 @@ LayoutUnit RenderBox::computePercentageLogicalHeight(const Length& height) const
skippedAutoHeightContainingBlock = true; skippedAutoHeightContainingBlock = true;
containingBlockChild = cb; containingBlockChild = cb;
cb = cb->containingBlock(); cb = cb->containingBlock();
cb->addPercentHeightDescendant(const_cast<RenderBox*>(this));
} }
cb->addPercentHeightDescendant(const_cast<RenderBox*>(this));
RenderStyle* cbstyle = cb->style(); RenderStyle* cbstyle = cb->style();
...@@ -2845,10 +2845,10 @@ LayoutUnit RenderBox::computeReplacedLogicalHeightUsing(Length logicalHeight) co ...@@ -2845,10 +2845,10 @@ LayoutUnit RenderBox::computeReplacedLogicalHeightUsing(Length logicalHeight) co
case Calculated: case Calculated:
{ {
RenderObject* cb = isOutOfFlowPositioned() ? container() : containingBlock(); RenderObject* cb = isOutOfFlowPositioned() ? container() : containingBlock();
while (cb->isAnonymous()) { while (cb->isAnonymous())
cb = cb->containingBlock(); cb = cb->containingBlock();
if (cb->isRenderBlock())
toRenderBlock(cb)->addPercentHeightDescendant(const_cast<RenderBox*>(this)); toRenderBlock(cb)->addPercentHeightDescendant(const_cast<RenderBox*>(this));
}
// FIXME: This calculation is not patched for block-flow yet. // FIXME: This calculation is not patched for block-flow yet.
// https://bugs.webkit.org/show_bug.cgi?id=46500 // https://bugs.webkit.org/show_bug.cgi?id=46500
......
...@@ -174,10 +174,9 @@ LayoutUnit RenderSVGRoot::computeReplacedLogicalHeight() const ...@@ -174,10 +174,9 @@ LayoutUnit RenderSVGRoot::computeReplacedLogicalHeight() const
if (height.isPercent()) { if (height.isPercent()) {
RenderBlock* cb = containingBlock(); RenderBlock* cb = containingBlock();
ASSERT(cb); ASSERT(cb);
while (cb->isAnonymous()) { while (cb->isAnonymous())
cb = cb->containingBlock(); cb = cb->containingBlock();
cb->addPercentHeightDescendant(const_cast<RenderSVGRoot*>(this)); cb->addPercentHeightDescendant(const_cast<RenderSVGRoot*>(this));
}
} else } else
RenderBlock::removePercentHeightDescendant(const_cast<RenderSVGRoot*>(this)); RenderBlock::removePercentHeightDescendant(const_cast<RenderSVGRoot*>(this));
......
...@@ -5334,4 +5334,33 @@ TEST_F(WebFrameTest, FullscreenLayerNonScrollable) ...@@ -5334,4 +5334,33 @@ TEST_F(WebFrameTest, FullscreenLayerNonScrollable)
ASSERT_TRUE(webScrollLayer->scrollable()); ASSERT_TRUE(webScrollLayer->scrollable());
} }
TEST_F(WebFrameTest, RenderBlockPercentHeightDescendants)
{
registerMockedHttpURLLoad("percent-height-descendants.html");
FrameTestHelpers::WebViewHelper webViewHelper;
webViewHelper.initializeAndLoad(m_baseURL + "percent-height-descendants.html");
WebView* webView = webViewHelper.webView();
webView->resize(WebSize(800, 800));
webView->layout();
Document* document = toWebFrameImpl(webView->mainFrame())->frame()->document();
WebCore::RenderBlock* container = WebCore::toRenderBlock(document->getElementById("container")->renderer());
WebCore::RenderBox* percentHeightInAnonymous = WebCore::toRenderBox(document->getElementById("percent-height-in-anonymous")->renderer());
WebCore::RenderBox* percentHeightDirectChild = WebCore::toRenderBox(document->getElementById("percent-height-direct-child")->renderer());
EXPECT_TRUE(WebCore::RenderBlock::hasPercentHeightDescendant(percentHeightInAnonymous));
EXPECT_TRUE(WebCore::RenderBlock::hasPercentHeightDescendant(percentHeightDirectChild));
ASSERT_TRUE(container->percentHeightDescendants());
ASSERT_TRUE(container->hasPercentHeightDescendants());
EXPECT_EQ(2U, container->percentHeightDescendants()->size());
EXPECT_TRUE(container->percentHeightDescendants()->contains(percentHeightInAnonymous));
EXPECT_TRUE(container->percentHeightDescendants()->contains(percentHeightDirectChild));
WebCore::RenderBlock* anonymousBlock = percentHeightInAnonymous->containingBlock();
EXPECT_TRUE(anonymousBlock->isAnonymous());
EXPECT_FALSE(anonymousBlock->hasPercentHeightDescendants());
}
} // namespace } // namespace
<!DOCTYPE html>
<div id="container" style="position: absolute; width: 500px; height: 500px; background-color: blue">
ABCD<img id="percent-height-in-anonymous" style="height: 20%; width: 50px;">
<div id="percent-height-direct-child" style="height: 20%; background-color: red"></div>
</div>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment