Source/WebCore/ChangeLog

 12012-01-20 Shinya Kawanaka <shinyak@google.com>
 2
 3 Refactoring: Reconsider the attach order of light children when a shadow tree exists.
 4 https://bugs.webkit.org/show_bug.cgi?id=76611
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Children of an element having a shadow root were to be attached in Element::attach(),
 9 however it is natural that they were attached in a shadow tree
 10 because their show and no show is determined in a shadow tree.
 11 Since the children were attached in ContainerNode::attach(),
 12 a HTMLContentElement must detach them before attaching them.
 13
 14 This patch changes its behavior. An element having a shadow root does not attach their
 15 children. They should be attached in a shadow tree.
 16
 17 No new tests, no change in behavior.
 18
 19 * dom/ContainerNode.cpp:
 20 (WebCore::ContainerNode::attachWithoutChildren):
 21 Attaches only ContainerNode. Does not attach its children.
 22 (WebCore::ContainerNode::detachWithoutChildren):
 23 Detaches only ContainerNode. Does not detach its children.
 24 * dom/ContainerNode.h:
 25 * dom/Element.cpp:
 26 (WebCore::Element::attach):
 27 If Element has a shadow root, attaching children is due for the shadow root.
 28 (WebCore::Element::detach):
 29 If Element has a shadow root, detaching children is due for the shadow root.
 30 * dom/ShadowRoot.cpp:
 31 (WebCore::ShadowRoot::attach):
 32 Attaches shadow hosts children when they are not attached in shadow tree.
 33 Its children may be attached in HTMLContentElement.
 34 (WebCore::ShadowRoot::detach):
 35 Detaches shadow hosts children when they are not detached in shadow tree.
 36 Its children may be detached in HTMLContentElement.
 37 * dom/ShadowRoot.h:
 38 * html/shadow/HTMLContentElement.cpp:
 39 (WebCore::HTMLContentElement::attach):
 40 Does not need to attach included elements, because they are not attached in ContainerNode anymore.
 41 (WebCore::HTMLContentElement::detach):
 42 Needs to detach included elements, because they won't detached in ContainerNode anymore.
 43
1442012-01-20 Hayato Ito <hayato@chromium.org>
245
346 Add ShadowRoot.idl which is enabled by newly introduced SHADOW_DOM flag.

Source/WebCore/dom/ContainerNode.cpp

@@void ContainerNode::attach()
787787 Node::attach();
788788}
789789
 790void ContainerNode::attachWithoutChildren()
 791{
 792 Node::attach();
 793}
 794
790795void ContainerNode::detach()
791796{
792797 for (Node* child = m_firstChild; child; child = child->nextSibling())

@@void ContainerNode::detach()
795800 Node::detach();
796801}
797802
 803void ContainerNode::detachWithoutChildren()
 804{
 805 Node::detach();
 806}
 807
798808void ContainerNode::insertedIntoDocument()
799809{
800810 RefPtr<Node> protect(this);

Source/WebCore/dom/ContainerNode.h

@@public:
7373 bool dispatchBeforeLoadEvent(const String& sourceURL);
7474
7575 virtual void attach() OVERRIDE;
 76 void attachWithoutChildren();
7677 virtual void detach() OVERRIDE;
 78 void detachWithoutChildren();
7779 virtual void willRemove() OVERRIDE;
7880 virtual LayoutRect getRect() const OVERRIDE;
7981 virtual void setFocus(bool = true) OVERRIDE;

Source/WebCore/dom/Element.cpp

@@void Element::attach()
940940 RenderWidget::suspendWidgetHierarchyUpdates();
941941
942942 createRendererIfNeeded();
943 
944943 StyleSelectorParentPusher parentPusher(this);
945944
946  if (firstChild())
947  parentPusher.push();
948  ContainerNode::attach();
949 
 945 // When a shadow root exists, attaching all children is due for the shadow root.
950946 if (ShadowRoot* shadow = shadowRoot()) {
 947 ContainerNode::attachWithoutChildren();
951948 parentPusher.push();
952949 shadow->attach();
 950 } else {
 951 if (firstChild())
 952 parentPusher.push();
 953 ContainerNode::attach();
953954 }
954955
 956
955957 if (hasRareData()) {
956958 ElementRareData* data = rareData();
957959 if (data->needsFocusAppearanceUpdateSoonAfterAttach()) {

@@void Element::detach()
972974 cancelFocusAppearanceUpdate();
973975 if (hasRareData())
974976 rareData()->resetComputedStyle();
975  ContainerNode::detach();
976  if (ShadowRoot* shadow = shadowRoot())
 977
 978 if (ShadowRoot* shadow = shadowRoot()) {
 979 ContainerNode::detachWithoutChildren();
977980 shadow->detach();
 981 } else
 982 ContainerNode::detach();
978983
979984 RenderWidget::resumeWidgetHierarchyUpdates();
980985}

Source/WebCore/dom/ShadowRoot.cpp

@@void ShadowRoot::attach()
153153 TreeScope::attach();
154154 if (m_inclusions)
155155 m_inclusions->didSelect();
 156
 157 Element* host = shadowHost();
 158 for (Node* child = host->firstChild(); child; child = child->nextSibling()) {
 159 if (!child->attached())
 160 child->attach();
 161 }
 162}
 163
 164void ShadowRoot::detach()
 165{
 166 TreeScope::detach();
 167
 168 Element* host = shadowHost();
 169 for (Node* child = host->firstChild(); child; child = child->nextSibling()) {
 170 if (child->attached())
 171 child->detach();
 172 }
156173}
157174
158175ContentInclusionSelector* ShadowRoot::inclusions() const

Source/WebCore/dom/ShadowRoot.h

@@public:
4646 bool isInclusionSelectorActive() const;
4747
4848 virtual void attach();
 49 virtual void detach();
4950
5051 virtual bool applyAuthorSheets() const;
5152 void setApplyAuthorSheets(bool);

Source/WebCore/html/shadow/HTMLContentElement.cpp

@@void HTMLContentElement::attach()
6969
7070 if (root) {
7171 for (ShadowInclusion* inclusion = m_inclusions->first(); inclusion; inclusion = inclusion->next())
72  inclusion->content()->detach();
73  for (ShadowInclusion* inclusion = m_inclusions->first(); inclusion; inclusion = inclusion->next())
7472 inclusion->content()->attach();
7573 }
7674}

@@void HTMLContentElement::attach()
7876void HTMLContentElement::detach()
7977{
8078 if (ShadowRoot* root = toShadowRoot(shadowTreeRootNode())) {
 79 for (ShadowInclusion* inclusion = m_inclusions->first(); inclusion; inclusion = inclusion->next())
 80 inclusion->content()->detach();
 81
8182 if (ContentInclusionSelector* selector = root->inclusions())
8283 selector->unselect(m_inclusions.get());
8384 }