Create render tree lazily
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Dec 2013 14:44:23 +0000 (14:44 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Dec 2013 14:44:23 +0000 (14:44 +0000)
commit90f419be6b39f8c3345dc9f30be4e9241e25ee05
treec1e1c1b44b63ab286891ca1f4717b2cc3ab9d7c8
parent7e3aa3c9ec09f87ca036439eba272eafa748d55c
Create render tree lazily
https://bugs.webkit.org/show_bug.cgi?id=120685

Source/WebCore:

Reviewed by Andreas Kling.

We currently recompute style and construct renderer for each DOM node immediately after they are added to
the tree. This is often inefficient as the style may change immediately afterwards and the work needs to be
redone.

With this patch we always compute style and construct render tree lazily, either on style recalc timer or
synchronously when they are needed. It also removes the 'attached' bit. If document has render tree then
all nodes are conceptually "attached" even if this happens lazily.

The patch slightly changes behavior of implicit CSS transitions. A synchronous style change during parsing
may not trigger the animation anymore as laziness means we don't see anything changing. This matches Firefox
and Chrome in our test cases.

* WebCore.exp.in:
* bindings/js/JSNodeCustom.cpp:
(WebCore::JSNode::insertBefore):
(WebCore::JSNode::replaceChild):
(WebCore::JSNode::appendChild):

    All attaching is now lazy, remove AttachLazily.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::propertyValue):

    SVG renderers with !isValid() have empty display property value for some reason. Keep the behavior.

* dom/ContainerNode.cpp:
(WebCore::ContainerNode::insertBefore):
(WebCore::ContainerNode::parserInsertBefore):
(WebCore::ContainerNode::replaceChild):
(WebCore::ContainerNode::appendChild):
(WebCore::ContainerNode::parserAppendChild):
(WebCore::ContainerNode::updateTreeAfterInsertion):
* dom/ContainerNode.h:
* dom/Document.cpp:
(WebCore::Document::~Document):
(WebCore::Document::updateStyleIfNeeded):
(WebCore::Document::createRenderTree):
(WebCore::Document::destroyRenderTree):

    Remove attach bit maintenance.

(WebCore::Document::webkitDidExitFullScreenForElement):

    Do lazy render tree reconstruction after returning from full screen. That is the only reliable way
    to get the render tree back to decent shape.

* dom/Element.cpp:
(WebCore::Element::isFocusable):

    Remove pointless !renderer()->needsLayout() assert.

(WebCore::Element::addShadowRoot):
(WebCore::Element::childShouldCreateRenderer):
(WebCore::Element::resetComputedStyle):

    Take care to reset computed style in all descendants. attachRenderTree no longer does this.

* dom/Element.h:
* dom/Node.cpp:
(WebCore::Node::insertBefore):
(WebCore::Node::replaceChild):
(WebCore::Node::appendChild):
(WebCore::Node::setNeedsStyleRecalc):

    Propagate ReconstructRenderTree.

(WebCore::Node::attached):

    Emulate the behavior of old attached bit for now so existing code calling this mostly stays working.

* dom/Node.h:

    Add new ReconstructRenderTree value for StyleChangeType.

* dom/Range.cpp:
(WebCore::Range::isPointInRange):
(WebCore::Range::comparePoint):
(WebCore::Range::compareNode):
(WebCore::Range::intersectsNode):
* editing/AppendNodeCommand.cpp:
(WebCore::AppendNodeCommand::doApply):
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::canRebalance):
* editing/InsertNodeBeforeCommand.cpp:
(WebCore::InsertNodeBeforeCommand::doApply):
* html/HTMLDetailsElement.cpp:
(WebCore::HTMLDetailsElement::didAddUserAgentShadowRoot):
* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::activeElement):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::setInnerText):

    TextControlInnerTextElement always preserves newline even if it doesn't have style yet.

(WebCore::HTMLElement::supportsFocus):
* html/HTMLEmbedElement.cpp:
(WebCore::HTMLEmbedElement::parseAttribute):
* html/HTMLFormControlElement.cpp:
(WebCore::shouldAutofocus):

    Don't autofocus until we have renderer.

* html/HTMLFormControlElementWithState.cpp:
(WebCore::HTMLFormControlElementWithState::shouldSaveAndRestoreFormControlState):
* html/HTMLFrameElementBase.cpp:
(WebCore::HTMLFrameElementBase::didNotifySubtreeInsertions):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::updateType):

    Lazy render tree construction.

(WebCore::HTMLInputElement::parseAttribute):
(WebCore::HTMLInputElement::defaultEventHandler):
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::parseAttribute):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::parseAttribute):
* html/HTMLSummaryElement.cpp:
(WebCore::HTMLSummaryElement::didAddUserAgentShadowRoot):
* html/parser/HTMLConstructionSite.cpp:
(WebCore::executeTask):

    Don't attach renderer after construction.

* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::callTheAdoptionAgency):
* html/shadow/ContentDistributor.cpp:
(WebCore::ContentDistributor::invalidateDistribution):
* html/shadow/InsertionPoint.cpp:
(WebCore::InsertionPoint::willAttachRenderers):
(WebCore::InsertionPoint::willDetachRenderers):
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlTextTrackContainerElement::updateDisplay):
* html/shadow/MediaControls.cpp:
(WebCore::MediaControls::createTextTrackDisplay):
* html/shadow/MediaControlsApple.cpp:
(WebCore::MediaControlsApple::createControls):
* html/track/TextTrackCue.cpp:
(WebCore::TextTrackCue::getDisplayTree):
* loader/PlaceholderDocument.cpp:
(WebCore::PlaceholderDocument::createRenderTree):
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::preload):
* style/StyleResolveTree.cpp:
(WebCore::Style::attachTextRenderer):
(WebCore::Style::detachTextRenderer):

    Remove attached bit maintenance.

(WebCore::Style::attachChildren):
(WebCore::Style::attachShadowRoot):
(WebCore::Style::attachRenderTree):
(WebCore::Style::detachShadowRoot):
(WebCore::Style::detachRenderTree):
(WebCore::Style::resolveLocal):
* svg/SVGTests.cpp:
(WebCore::SVGTests::handleAttributeChange):

    Make lazy.

* testing/Internals.cpp:
(WebCore::Internals::attached):
(WebCore::Internals::elementRenderTreeAsText):
(WebCore::Internals::markerAt):
(WebCore::Internals::nodesFromRect):

LayoutTests:

Reviewed by Andreas Kling.

Most of these are non-visible render tree dump changes (they become simpler).

* editing/selection/click-on-head-margin-expected.txt:
* fast/css-generated-content/before-content-continuation-chain-expected.txt:
* fast/css/transition-color-unspecified.html:
* fast/dom/adopt-node-crash-2-expected.txt:
* fast/dom/modify-node-and-while-in-the-callback-too-crash-expected.txt:
* fast/forms/radio/radio_checked_dynamic-expected.txt:
* fast/frames/lots-of-iframes-expected.txt:
* fast/frames/sandboxed-iframe-autofocus-denied-expected.txt:
* fast/table/table-row-style-not-updated-with-after-content-expected.txt:
* fullscreen/full-screen-render-inline-expected.txt:
* fullscreen/parent-flow-inline-with-block-child-expected.txt:
* platform/mac/editing/inserting/break-blockquote-after-delete-expected.txt:
* platform/mac/fast/css-generated-content/table-row-group-to-inline-expected.txt:
* platform/mac/fast/dynamic/011-expected.txt:
* platform/mac/fast/forms/formmove3-expected.txt:
* platform/mac/fast/forms/preserveFormDuringResidualStyle-expected.txt:
* platform/mac/fast/invalid/001-expected.txt:
* platform/mac/fast/invalid/003-expected.txt:
* platform/mac/fast/invalid/004-expected.txt:
* platform/mac/fast/invalid/007-expected.txt:
* platform/mac/fast/invalid/019-expected.txt:
* platform/mac/fast/multicol/span/span-as-immediate-child-generated-content-expected.txt:
* platform/mac/fast/multicol/span/span-as-immediate-columns-child-dynamic-expected.txt:
* platform/mac/fast/multicol/span/span-as-nested-columns-child-dynamic-expected.txt:
* platform/mac/fast/ruby/ruby-base-merge-block-children-crash-expected.txt:
* platform/mac/tables/mozilla/bugs/bug113235-1-expected.txt:
* platform/mac/tables/mozilla/bugs/bug647-expected.txt:
* platform/mac/tables/mozilla/other/wa_table_tr_align-expected.txt:
* plugins/plugin-remove-readystatechange-expected.txt:
* svg/custom/system-language-crash-expected.txt:
* transitions/equivalent-background-image-no-transition.html:
* transitions/repeated-firing-background-color.html:
* transitions/transition-duration-cleared-in-transitionend-crash.html:

    Adopt a few transition test cases to new behavior.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@160908 268f45cc-cd09-0410-ab3c-d52691b4dbfc
75 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/selection/click-on-head-margin-expected.txt
LayoutTests/fast/css-generated-content/before-content-continuation-chain-expected.txt
LayoutTests/fast/css/transition-color-unspecified.html
LayoutTests/fast/dom/adopt-node-crash-2-expected.txt
LayoutTests/fast/dom/modify-node-and-while-in-the-callback-too-crash-expected.txt
LayoutTests/fast/forms/radio/radio_checked_dynamic-expected.txt
LayoutTests/fast/frames/lots-of-iframes-expected.txt
LayoutTests/fast/frames/sandboxed-iframe-autofocus-denied-expected.txt
LayoutTests/fast/table/table-row-style-not-updated-with-after-content-expected.txt
LayoutTests/fullscreen/full-screen-render-inline-expected.txt
LayoutTests/fullscreen/parent-flow-inline-with-block-child-expected.txt
LayoutTests/platform/mac/editing/inserting/break-blockquote-after-delete-expected.txt
LayoutTests/platform/mac/fast/css-generated-content/table-row-group-to-inline-expected.txt
LayoutTests/platform/mac/fast/dynamic/011-expected.txt
LayoutTests/platform/mac/fast/forms/formmove3-expected.txt
LayoutTests/platform/mac/fast/forms/preserveFormDuringResidualStyle-expected.txt
LayoutTests/platform/mac/fast/invalid/001-expected.txt
LayoutTests/platform/mac/fast/invalid/003-expected.txt
LayoutTests/platform/mac/fast/invalid/004-expected.txt
LayoutTests/platform/mac/fast/invalid/007-expected.txt
LayoutTests/platform/mac/fast/invalid/019-expected.txt
LayoutTests/platform/mac/fast/multicol/span/span-as-immediate-child-generated-content-expected.txt
LayoutTests/platform/mac/fast/multicol/span/span-as-immediate-columns-child-dynamic-expected.txt
LayoutTests/platform/mac/fast/multicol/span/span-as-nested-columns-child-dynamic-expected.txt
LayoutTests/platform/mac/fast/ruby/ruby-base-merge-block-children-crash-expected.txt
LayoutTests/platform/mac/tables/mozilla/bugs/bug113235-1-expected.txt
LayoutTests/platform/mac/tables/mozilla/bugs/bug647-expected.txt
LayoutTests/platform/mac/tables/mozilla/other/wa_table_tr_align-expected.txt
LayoutTests/plugins/plugin-remove-readystatechange-expected.txt
LayoutTests/svg/custom/system-language-crash-expected.txt
LayoutTests/transitions/equivalent-background-image-no-transition.html
LayoutTests/transitions/repeated-firing-background-color.html
LayoutTests/transitions/transition-duration-cleared-in-transitionend-crash.html
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/bindings/js/JSNodeCustom.cpp
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/ContainerNode.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/dom/Range.cpp
Source/WebCore/editing/AppendNodeCommand.cpp
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/InsertNodeBeforeCommand.cpp
Source/WebCore/html/HTMLDetailsElement.cpp
Source/WebCore/html/HTMLDocument.cpp
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLEmbedElement.cpp
Source/WebCore/html/HTMLFormControlElement.cpp
Source/WebCore/html/HTMLFormControlElementWithState.cpp
Source/WebCore/html/HTMLFrameElementBase.cpp
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLObjectElement.cpp
Source/WebCore/html/HTMLSummaryElement.cpp
Source/WebCore/html/parser/HTMLConstructionSite.cpp
Source/WebCore/html/parser/HTMLTreeBuilder.cpp
Source/WebCore/html/shadow/ContentDistributor.cpp
Source/WebCore/html/shadow/InsertionPoint.cpp
Source/WebCore/html/shadow/MediaControlElements.cpp
Source/WebCore/html/shadow/MediaControls.cpp
Source/WebCore/html/shadow/MediaControlsApple.cpp
Source/WebCore/html/track/TextTrackCue.cpp
Source/WebCore/loader/PlaceholderDocument.cpp
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/style/StyleResolveTree.cpp
Source/WebCore/svg/SVGTests.cpp
Source/WebCore/testing/Internals.cpp
Source/WebKit/mac/WebView/WebHTMLView.mm
Source/WebKit2/WebProcess/WebPage/WebPage.cpp