Commit 37baf0b2 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Move RebuildLayoutTree/RecalcStyle to StyleEngine.

In preparation for starting those operations from a different root node
than the document root, make them separate methods on StyleEngine.

Bug: 868810
Change-Id: Ic3c1308835aef9a4e7887822ad7744ae76a7dcbd
Reviewed-on: https://chromium-review.googlesource.com/1206910Reviewed-by: default avatarAnders Ruud <andruud@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589476}
parent 9dc2f03d
...@@ -1545,6 +1545,21 @@ DocumentStyleEnvironmentVariables& StyleEngine::EnsureEnvironmentVariables() { ...@@ -1545,6 +1545,21 @@ DocumentStyleEnvironmentVariables& StyleEngine::EnsureEnvironmentVariables() {
return *environment_variables_.get(); return *environment_variables_.get();
} }
void StyleEngine::RecalcStyle(StyleRecalcChange change) {
DCHECK(GetDocument().documentElement());
DCHECK(GetDocument().ChildNeedsStyleRecalc() || change == kForce);
GetDocument().documentElement()->RecalcStyle(change);
}
void StyleEngine::RebuildLayoutTree() {
DCHECK(GetDocument().documentElement());
DCHECK(GetDocument().ChildNeedsReattachLayoutTree());
WhitespaceAttacher whitespace_attacher;
GetDocument().documentElement()->RebuildLayoutTree(whitespace_attacher);
}
void StyleEngine::Trace(blink::Visitor* visitor) { void StyleEngine::Trace(blink::Visitor* visitor) {
visitor->Trace(document_); visitor->Trace(document_);
visitor->Trace(injected_user_style_sheets_); visitor->Trace(injected_user_style_sheets_);
......
...@@ -319,6 +319,9 @@ class CORE_EXPORT StyleEngine final ...@@ -319,6 +319,9 @@ class CORE_EXPORT StyleEngine final
DocumentStyleEnvironmentVariables& EnsureEnvironmentVariables(); DocumentStyleEnvironmentVariables& EnsureEnvironmentVariables();
void RecalcStyle(StyleRecalcChange change);
void RebuildLayoutTree();
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
const char* NameInHeapSnapshot() const override { return "StyleEngine"; } const char* NameInHeapSnapshot() const override { return "StyleEngine"; }
......
...@@ -848,14 +848,12 @@ TEST_F(StyleEngineTest, HasViewportDependentMediaQueries) { ...@@ -848,14 +848,12 @@ TEST_F(StyleEngineTest, HasViewportDependentMediaQueries) {
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
} }
EXPECT_TRUE( EXPECT_TRUE(GetStyleEngine().HasViewportDependentMediaQueries());
GetDocument().GetStyleEngine().HasViewportDependentMediaQueries());
GetDocument().body()->RemoveChild(style_element); GetDocument().body()->RemoveChild(style_element);
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
EXPECT_FALSE( EXPECT_FALSE(GetStyleEngine().HasViewportDependentMediaQueries());
GetDocument().GetStyleEngine().HasViewportDependentMediaQueries());
} }
TEST_F(StyleEngineTest, StyleMediaAttributeStyleChange) { TEST_F(StyleEngineTest, StyleMediaAttributeStyleChange) {
...@@ -1482,7 +1480,7 @@ TEST_F(StyleEngineTest, RejectSelectorForPseudoElement) { ...@@ -1482,7 +1480,7 @@ TEST_F(StyleEngineTest, RejectSelectorForPseudoElement) {
)HTML"); )HTML");
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
StyleEngine& engine = GetDocument().GetStyleEngine(); StyleEngine& engine = GetStyleEngine();
engine.SetStatsEnabled(true); engine.SetStatsEnabled(true);
StyleResolverStats* stats = engine.Stats(); StyleResolverStats* stats = engine.Stats();
...@@ -1493,7 +1491,7 @@ TEST_F(StyleEngineTest, RejectSelectorForPseudoElement) { ...@@ -1493,7 +1491,7 @@ TEST_F(StyleEngineTest, RejectSelectorForPseudoElement) {
div->SetInlineStyleProperty(CSSPropertyColor, "green"); div->SetInlineStyleProperty(CSSPropertyColor, "green");
GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc); GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc);
GetDocument().documentElement()->RecalcStyle(kNoChange); GetStyleEngine().RecalcStyle(kNoChange);
// Should fast reject ".not-in-filter div::before {}" for both the div and its // Should fast reject ".not-in-filter div::before {}" for both the div and its
// ::before pseudo element. // ::before pseudo element.
...@@ -1514,35 +1512,35 @@ TEST_F(StyleEngineTest, MarkForWhitespaceReattachment) { ...@@ -1514,35 +1512,35 @@ TEST_F(StyleEngineTest, MarkForWhitespaceReattachment) {
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
d1->firstChild()->remove(); d1->firstChild()->remove();
EXPECT_TRUE(GetDocument().GetStyleEngine().NeedsWhitespaceReattachment(d1)); EXPECT_TRUE(GetStyleEngine().NeedsWhitespaceReattachment(d1));
EXPECT_FALSE(GetDocument().ChildNeedsStyleInvalidation()); EXPECT_FALSE(GetDocument().ChildNeedsStyleInvalidation());
EXPECT_FALSE(GetDocument().ChildNeedsStyleRecalc()); EXPECT_FALSE(GetDocument().ChildNeedsStyleRecalc());
EXPECT_FALSE(GetDocument().ChildNeedsReattachLayoutTree()); EXPECT_FALSE(GetDocument().ChildNeedsReattachLayoutTree());
GetDocument().GetStyleEngine().MarkForWhitespaceReattachment(); GetStyleEngine().MarkForWhitespaceReattachment();
EXPECT_FALSE(GetDocument().ChildNeedsReattachLayoutTree()); EXPECT_FALSE(GetDocument().ChildNeedsReattachLayoutTree());
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
d2->firstChild()->remove(); d2->firstChild()->remove();
d2->firstChild()->remove(); d2->firstChild()->remove();
EXPECT_TRUE(GetDocument().GetStyleEngine().NeedsWhitespaceReattachment(d2)); EXPECT_TRUE(GetStyleEngine().NeedsWhitespaceReattachment(d2));
EXPECT_FALSE(GetDocument().ChildNeedsStyleInvalidation()); EXPECT_FALSE(GetDocument().ChildNeedsStyleInvalidation());
EXPECT_FALSE(GetDocument().ChildNeedsStyleRecalc()); EXPECT_FALSE(GetDocument().ChildNeedsStyleRecalc());
EXPECT_FALSE(GetDocument().ChildNeedsReattachLayoutTree()); EXPECT_FALSE(GetDocument().ChildNeedsReattachLayoutTree());
GetDocument().GetStyleEngine().MarkForWhitespaceReattachment(); GetStyleEngine().MarkForWhitespaceReattachment();
EXPECT_FALSE(GetDocument().ChildNeedsReattachLayoutTree()); EXPECT_FALSE(GetDocument().ChildNeedsReattachLayoutTree());
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
d3->firstChild()->remove(); d3->firstChild()->remove();
EXPECT_TRUE(GetDocument().GetStyleEngine().NeedsWhitespaceReattachment(d3)); EXPECT_TRUE(GetStyleEngine().NeedsWhitespaceReattachment(d3));
EXPECT_FALSE(GetDocument().ChildNeedsStyleInvalidation()); EXPECT_FALSE(GetDocument().ChildNeedsStyleInvalidation());
EXPECT_FALSE(GetDocument().ChildNeedsStyleRecalc()); EXPECT_FALSE(GetDocument().ChildNeedsStyleRecalc());
EXPECT_FALSE(GetDocument().ChildNeedsReattachLayoutTree()); EXPECT_FALSE(GetDocument().ChildNeedsReattachLayoutTree());
GetDocument().GetStyleEngine().MarkForWhitespaceReattachment(); GetStyleEngine().MarkForWhitespaceReattachment();
EXPECT_TRUE(GetDocument().ChildNeedsReattachLayoutTree()); EXPECT_TRUE(GetDocument().ChildNeedsReattachLayoutTree());
} }
......
...@@ -2304,7 +2304,7 @@ void Document::UpdateStyle() { ...@@ -2304,7 +2304,7 @@ void Document::UpdateStyle() {
TRACE_EVENT0("blink,blink_style", "Document::recalcStyle"); TRACE_EVENT0("blink,blink_style", "Document::recalcStyle");
SCOPED_BLINK_UMA_HISTOGRAM_TIMER_HIGHRES("Style.RecalcTime"); SCOPED_BLINK_UMA_HISTOGRAM_TIMER_HIGHRES("Style.RecalcTime");
Element* viewport_defining = ViewportDefiningElement(); Element* viewport_defining = ViewportDefiningElement();
document_element->RecalcStyle(change); GetStyleEngine().RecalcStyle(change);
if (viewport_defining != ViewportDefiningElement()) if (viewport_defining != ViewportDefiningElement())
ViewportDefiningElementDidChange(); ViewportDefiningElementDidChange();
} }
...@@ -2315,8 +2315,7 @@ void Document::UpdateStyle() { ...@@ -2315,8 +2315,7 @@ void Document::UpdateStyle() {
TRACE_EVENT0("blink,blink_style", "Document::rebuildLayoutTree"); TRACE_EVENT0("blink,blink_style", "Document::rebuildLayoutTree");
SCOPED_BLINK_UMA_HISTOGRAM_TIMER_HIGHRES("Style.RebuildLayoutTreeTime"); SCOPED_BLINK_UMA_HISTOGRAM_TIMER_HIGHRES("Style.RebuildLayoutTreeTime");
ReattachLegacyLayoutObjectList legacy_layout_objects(*this); ReattachLegacyLayoutObjectList legacy_layout_objects(*this);
WhitespaceAttacher whitespace_attacher; GetStyleEngine().RebuildLayoutTree();
document_element->RebuildLayoutTree(whitespace_attacher);
legacy_layout_objects.ForceLegacyLayoutIfNeeded(); legacy_layout_objects.ForceLegacyLayoutIfNeeded();
} }
} }
......
...@@ -298,10 +298,8 @@ void ReattachLegacyLayoutObjectList::ForceLegacyLayoutIfNeeded() { ...@@ -298,10 +298,8 @@ void ReattachLegacyLayoutObjectList::ForceLegacyLayoutIfNeeded() {
for (const LayoutObject* block : blocks_) for (const LayoutObject* block : blocks_)
ToElement(*block->GetNode()).LazyReattachIfAttached(); ToElement(*block->GetNode()).LazyReattachIfAttached();
state_ = State::kForcingLegacyLayout; state_ = State::kForcingLegacyLayout;
Element& document_element = *document_->documentElement(); document_->GetStyleEngine().RecalcStyle(kNoChange);
document_element.RecalcStyle(kNoChange); document_->GetStyleEngine().RebuildLayoutTree();
WhitespaceAttacher whitespace_attacher;
document_element.RebuildLayoutTree(whitespace_attacher);
state_ = State::kClosed; state_ = State::kClosed;
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h" #include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/dom/comment.h" #include "third_party/blink/renderer/core/dom/comment.h"
#include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/flat_tree_traversal.h" #include "third_party/blink/renderer/core/dom/flat_tree_traversal.h"
...@@ -37,7 +38,7 @@ class NodeTest : public EditingTestBase { ...@@ -37,7 +38,7 @@ class NodeTest : public EditingTestBase {
LayoutObject* ReattachLayoutTreeForNode(Node& node) { LayoutObject* ReattachLayoutTreeForNode(Node& node) {
node.LazyReattachIfAttached(); node.LazyReattachIfAttached();
GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc); GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc);
GetDocument().documentElement()->RecalcStyle(kNoChange); GetDocument().GetStyleEngine().RecalcStyle(kNoChange);
PushSelectorFilterAncestors( PushSelectorFilterAncestors(
GetDocument().EnsureStyleResolver().GetSelectorFilter(), node); GetDocument().EnsureStyleResolver().GetSelectorFilter(), node);
ReattachLegacyLayoutObjectList legacy_objects(GetDocument()); ReattachLegacyLayoutObjectList legacy_objects(GetDocument());
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/html/html_content_element.h" #include "third_party/blink/renderer/core/html/html_content_element.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h" #include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h" #include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
...@@ -38,7 +39,7 @@ TEST_F(HTMLContentElementTest, FallbackRecalcForReattach) { ...@@ -38,7 +39,7 @@ TEST_F(HTMLContentElementTest, FallbackRecalcForReattach) {
GetDocument().UpdateDistributionForLegacyDistributedNodes(); GetDocument().UpdateDistributionForLegacyDistributedNodes();
GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc); GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc);
GetDocument().documentElement()->RecalcStyle(kNoChange); GetDocument().GetStyleEngine().RecalcStyle(kNoChange);
EXPECT_TRUE(fallback->GetNonAttachedStyle()); EXPECT_TRUE(fallback->GetNonAttachedStyle());
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/html/html_object_element.h" #include "third_party/blink/renderer/core/html/html_object_element.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h" #include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h" #include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
...@@ -38,7 +39,7 @@ TEST_F(HTMLObjectElementTest, FallbackRecalcForReattach) { ...@@ -38,7 +39,7 @@ TEST_F(HTMLObjectElementTest, FallbackRecalcForReattach) {
object->RenderFallbackContent(); object->RenderFallbackContent();
GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc); GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc);
GetDocument().documentElement()->RecalcStyle(kForce); GetDocument().GetStyleEngine().RecalcStyle(kForce);
EXPECT_TRUE(IsHTMLSlotElement(slot)); EXPECT_TRUE(IsHTMLSlotElement(slot));
EXPECT_TRUE(object->UseFallbackContent()); EXPECT_TRUE(object->UseFallbackContent());
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <array> #include <array>
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h" #include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h" #include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
...@@ -161,7 +162,7 @@ TEST_F(HTMLSlotElementReattachTest, RecalcAssignedNodeStyleForReattach) { ...@@ -161,7 +162,7 @@ TEST_F(HTMLSlotElementReattachTest, RecalcAssignedNodeStyleForReattach) {
shadow_span.setAttribute(HTMLNames::styleAttr, "display:block"); shadow_span.setAttribute(HTMLNames::styleAttr, "display:block");
GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc); GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc);
GetDocument().documentElement()->RecalcStyle(kNoChange); GetDocument().GetStyleEngine().RecalcStyle(kNoChange);
EXPECT_TRUE(shadow_span.GetNonAttachedStyle()); EXPECT_TRUE(shadow_span.GetNonAttachedStyle());
EXPECT_TRUE(span.GetNonAttachedStyle()); EXPECT_TRUE(span.GetNonAttachedStyle());
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/html/shadow/progress_shadow_element.h" #include "third_party/blink/renderer/core/html/shadow/progress_shadow_element.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h" #include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h" #include "third_party/blink/renderer/core/dom/shadow_root.h"
...@@ -40,7 +41,7 @@ TEST_F(ProgressShadowElementTest, LayoutObjectIsNeeded) { ...@@ -40,7 +41,7 @@ TEST_F(ProgressShadowElementTest, LayoutObjectIsNeeded) {
progress->LazyReattachIfAttached(); progress->LazyReattachIfAttached();
GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc); GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc);
GetDocument().documentElement()->RecalcStyle(kForce); GetDocument().GetStyleEngine().RecalcStyle(kForce);
EXPECT_TRUE(shadow_element->GetNonAttachedStyle()); EXPECT_TRUE(shadow_element->GetNonAttachedStyle());
scoped_refptr<ComputedStyle> style = shadow_element->StyleForLayoutObject(); scoped_refptr<ComputedStyle> style = shadow_element->StyleForLayoutObject();
......
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