Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: third_party/WebKit/Source/core/dom/Node.cpp

Issue 1995203002: Rewrite Shadow DOM distribution engine to support partial synchronous distribution for v1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean up Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "core/dom/StaticNodeList.h" 52 #include "core/dom/StaticNodeList.h"
53 #include "core/dom/StyleEngine.h" 53 #include "core/dom/StyleEngine.h"
54 #include "core/dom/TemplateContentDocumentFragment.h" 54 #include "core/dom/TemplateContentDocumentFragment.h"
55 #include "core/dom/Text.h" 55 #include "core/dom/Text.h"
56 #include "core/dom/TreeScopeAdopter.h" 56 #include "core/dom/TreeScopeAdopter.h"
57 #include "core/dom/UserActionElementSet.h" 57 #include "core/dom/UserActionElementSet.h"
58 #include "core/dom/shadow/ElementShadow.h" 58 #include "core/dom/shadow/ElementShadow.h"
59 #include "core/dom/shadow/FlatTreeTraversal.h" 59 #include "core/dom/shadow/FlatTreeTraversal.h"
60 #include "core/dom/shadow/InsertionPoint.h" 60 #include "core/dom/shadow/InsertionPoint.h"
61 #include "core/dom/shadow/ShadowRoot.h" 61 #include "core/dom/shadow/ShadowRoot.h"
62 #include "core/dom/shadow/SlotAssignment.h"
62 #include "core/editing/EditingUtilities.h" 63 #include "core/editing/EditingUtilities.h"
63 #include "core/editing/markers/DocumentMarkerController.h" 64 #include "core/editing/markers/DocumentMarkerController.h"
64 #include "core/events/Event.h" 65 #include "core/events/Event.h"
65 #include "core/events/EventDispatchMediator.h" 66 #include "core/events/EventDispatchMediator.h"
66 #include "core/events/EventDispatcher.h" 67 #include "core/events/EventDispatcher.h"
67 #include "core/events/EventListener.h" 68 #include "core/events/EventListener.h"
68 #include "core/events/GestureEvent.h" 69 #include "core/events/GestureEvent.h"
69 #include "core/events/InputEvent.h" 70 #include "core/events/InputEvent.h"
70 #include "core/events/KeyboardEvent.h" 71 #include "core/events/KeyboardEvent.h"
71 #include "core/events/MouseEvent.h" 72 #include "core/events/MouseEvent.h"
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 return document(); 629 return document();
629 Node* root = const_cast<Node*>(this); 630 Node* root = const_cast<Node*>(this);
630 while (Node* host = root->shadowHost()) 631 while (Node* host = root->shadowHost())
631 root = host; 632 root = host;
632 while (Node* ancestor = root->parentNode()) 633 while (Node* ancestor = root->parentNode())
633 root = ancestor; 634 root = ancestor;
634 DCHECK(!root->shadowHost()); 635 DCHECK(!root->shadowHost());
635 return *root; 636 return *root;
636 } 637 }
637 638
638 #if DCHECK_IS_ON()
639 bool Node::needsDistributionRecalc() const 639 bool Node::needsDistributionRecalc() const
640 { 640 {
641 return shadowIncludingRoot().childNeedsDistributionRecalc(); 641 return shadowIncludingRoot().childNeedsDistributionRecalc();
642 } 642 }
643 #endif
644 643
645 void Node::updateDistribution() 644 void Node::updateDistribution()
646 { 645 {
647 // Extra early out to avoid spamming traces. 646 // Extra early out to avoid spamming traces.
648 if (inShadowIncludingDocument() && !document().childNeedsDistributionRecalc( )) 647 if (inShadowIncludingDocument() && !document().childNeedsDistributionRecalc( ))
649 return; 648 return;
650 TRACE_EVENT0("blink", "Node::updateDistribution"); 649 TRACE_EVENT0("blink", "Node::updateDistribution");
651 ScriptForbiddenScope forbidScript; 650 ScriptForbiddenScope forbidScript;
652 Node& root = shadowIncludingRoot(); 651 Node& root = shadowIncludingRoot();
653 if (root.childNeedsDistributionRecalc()) 652 if (root.childNeedsDistributionRecalc())
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 { 692 {
694 ScriptForbiddenScope forbidScriptDuringRawIteration; 693 ScriptForbiddenScope forbidScriptDuringRawIteration;
695 for (Node* node = parentOrShadowHostNode(); node && !node->childNeedsStyleIn validation(); node = node->parentOrShadowHostNode()) 694 for (Node* node = parentOrShadowHostNode(); node && !node->childNeedsStyleIn validation(); node = node->parentOrShadowHostNode())
696 node->setChildNeedsStyleInvalidation(); 695 node->setChildNeedsStyleInvalidation();
697 document().scheduleLayoutTreeUpdateIfNeeded(); 696 document().scheduleLayoutTreeUpdateIfNeeded();
698 } 697 }
699 698
700 void Node::markAncestorsWithChildNeedsDistributionRecalc() 699 void Node::markAncestorsWithChildNeedsDistributionRecalc()
701 { 700 {
702 ScriptForbiddenScope forbidScriptDuringRawIteration; 701 ScriptForbiddenScope forbidScriptDuringRawIteration;
703 if (RuntimeEnabledFeatures::shadowDOMV1Enabled() && inShadowIncludingDocumen t() && !document().childNeedsDistributionRecalc()) {
704 // TODO(hayato): Support a non-document composed tree.
705 // TODO(hayato): Enqueue a task only if a 'slotchange' event listner is registered in the document composed tree.
706 Microtask::enqueueMicrotask(WTF::bind(&Document::updateDistribution, &do cument()));
707 }
708 for (Node* node = this; node && !node->childNeedsDistributionRecalc(); node = node->parentOrShadowHostNode()) 702 for (Node* node = this; node && !node->childNeedsDistributionRecalc(); node = node->parentOrShadowHostNode())
709 node->setChildNeedsDistributionRecalc(); 703 node->setChildNeedsDistributionRecalc();
710 document().scheduleLayoutTreeUpdateIfNeeded(); 704 document().scheduleLayoutTreeUpdateIfNeeded();
711 } 705 }
712 706
713 inline void Node::setStyleChange(StyleChangeType changeType) 707 inline void Node::setStyleChange(StyleChangeType changeType)
714 { 708 {
715 m_nodeFlags = (m_nodeFlags & ~StyleChangeMask) | changeType; 709 m_nodeFlags = (m_nodeFlags & ~StyleChangeMask) | changeType;
716 } 710 }
717 711
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 return !isShadowRoot() && !isSlotOrActiveInsertionPoint(); 981 return !isShadowRoot() && !isSlotOrActiveInsertionPoint();
988 } 982 }
989 983
990 bool Node::isSlotOrActiveInsertionPoint() const 984 bool Node::isSlotOrActiveInsertionPoint() const
991 { 985 {
992 return isHTMLSlotElement(*this) || isActiveInsertionPoint(*this); 986 return isHTMLSlotElement(*this) || isActiveInsertionPoint(*this);
993 } 987 }
994 988
995 AtomicString Node::slotName() const 989 AtomicString Node::slotName() const
996 { 990 {
997 DCHECK(slottable()); 991 DCHECK(isSlotable());
998 if (isElementNode()) 992 if (isElementNode())
999 return normalizeSlotName(toElement(*this).fastGetAttribute(HTMLNames::sl otAttr)); 993 return HTMLSlotElement::normalizeSlotName(toElement(*this).fastGetAttrib ute(HTMLNames::slotAttr));
1000 DCHECK(isTextNode()); 994 DCHECK(isTextNode());
1001 return emptyAtom; 995 return emptyAtom;
1002 } 996 }
1003 997
1004 // static
1005 AtomicString Node::normalizeSlotName(const AtomicString& name)
1006 {
1007 return (name.isNull() || name.isEmpty()) ? emptyAtom : name;
1008 }
1009
1010 bool Node::isInV1ShadowTree() const 998 bool Node::isInV1ShadowTree() const
1011 { 999 {
1012 ShadowRoot* shadowRoot = containingShadowRoot(); 1000 ShadowRoot* shadowRoot = containingShadowRoot();
1013 return shadowRoot && shadowRoot->isV1(); 1001 return shadowRoot && shadowRoot->isV1();
1014 } 1002 }
1015 1003
1016 bool Node::isInV0ShadowTree() const 1004 bool Node::isInV0ShadowTree() const
1017 { 1005 {
1018 ShadowRoot* shadowRoot = containingShadowRoot(); 1006 ShadowRoot* shadowRoot = containingShadowRoot();
1019 return shadowRoot && !shadowRoot->isV1(); 1007 return shadowRoot && !shadowRoot->isV1();
(...skipping 10 matching lines...) Expand all
1030 ElementShadow* parentShadow = parentElementShadow(); 1018 ElementShadow* parentShadow = parentElementShadow();
1031 return parentShadow && parentShadow->isV1(); 1019 return parentShadow && parentShadow->isV1();
1032 } 1020 }
1033 1021
1034 bool Node::isChildOfV0ShadowHost() const 1022 bool Node::isChildOfV0ShadowHost() const
1035 { 1023 {
1036 ElementShadow* parentShadow = parentElementShadow(); 1024 ElementShadow* parentShadow = parentElementShadow();
1037 return parentShadow && !parentShadow->isV1(); 1025 return parentShadow && !parentShadow->isV1();
1038 } 1026 }
1039 1027
1028 ShadowRoot* Node::v1ShadowRootOfParent() const
1029 {
1030 if (Element* parent = parentElement())
1031 return parent->shadowRootIfV1();
1032 return nullptr;
1033 }
1034
1040 Element* Node::shadowHost() const 1035 Element* Node::shadowHost() const
1041 { 1036 {
1042 if (ShadowRoot* root = containingShadowRoot()) 1037 if (ShadowRoot* root = containingShadowRoot())
1043 return root->host(); 1038 return root->host();
1044 return nullptr; 1039 return nullptr;
1045 } 1040 }
1046 1041
1047 ShadowRoot* Node::containingShadowRoot() const 1042 ShadowRoot* Node::containingShadowRoot() const
1048 { 1043 {
1049 Node& root = treeScope().rootNode(); 1044 Node& root = treeScope().rootNode();
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2240 DCHECK(insertionPoint->containingShadowRoot()); 2235 DCHECK(insertionPoint->containingShadowRoot());
2241 if (!insertionPoint->containingShadowRoot()->isOpenOrV0()) 2236 if (!insertionPoint->containingShadowRoot()->isOpenOrV0())
2242 break; 2237 break;
2243 filteredInsertionPoints.append(insertionPoint); 2238 filteredInsertionPoints.append(insertionPoint);
2244 } 2239 }
2245 return StaticNodeList::adopt(filteredInsertionPoints); 2240 return StaticNodeList::adopt(filteredInsertionPoints);
2246 } 2241 }
2247 2242
2248 HTMLSlotElement* Node::assignedSlot() const 2243 HTMLSlotElement* Node::assignedSlot() const
2249 { 2244 {
2250 Element* parent = parentElement(); 2245 if (ShadowRoot* root = v1ShadowRootOfParent())
2251 ShadowRoot* root = parent ? parent->youngestShadowRoot() : nullptr; 2246 return root->ensureSlotAssignment().findSlot(*this);
2252 if (root && root->isV1())
2253 return root->assignedSlotFor(*this);
2254 return nullptr; 2247 return nullptr;
2255 } 2248 }
2256 2249
2257 HTMLSlotElement* Node::assignedSlotForBinding() 2250 HTMLSlotElement* Node::assignedSlotForBinding()
2258 { 2251 {
2259 updateDistribution(); 2252 updateDistribution();
2260 Element* parent = parentElement(); 2253 if (ShadowRoot* root = v1ShadowRootOfParent()) {
2261 ShadowRoot* root = parent ? parent->youngestShadowRoot() : nullptr; 2254 if (root->type() == ShadowRootType::Open)
2262 if (root && root->type() == ShadowRootType::Open) 2255 return root->ensureSlotAssignment().findSlot(*this);
2263 return root->assignedSlotFor(*this); 2256 }
2264 return nullptr; 2257 return nullptr;
2265 } 2258 }
2266 2259
2267 void Node::setFocus(bool flag) 2260 void Node::setFocus(bool flag)
2268 { 2261 {
2269 document().userActionElements().setFocused(this, flag); 2262 document().userActionElements().setFocused(this, flag);
2270 } 2263 }
2271 2264
2272 void Node::setActive(bool flag) 2265 void Node::setActive(bool flag)
2273 { 2266 {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 2365
2373 DCHECK(isHTMLElement() || isSVGElement()); 2366 DCHECK(isHTMLElement() || isSVGElement());
2374 DCHECK(CustomElementState::Custom != getCustomElementState()); 2367 DCHECK(CustomElementState::Custom != getCustomElementState());
2375 setFlag(V0CustomElementFlag); 2368 setFlag(V0CustomElementFlag);
2376 setFlag(newState == V0Upgraded, V0CustomElementUpgradedFlag); 2369 setFlag(newState == V0Upgraded, V0CustomElementUpgradedFlag);
2377 2370
2378 if (oldState == V0NotCustomElement || newState == V0Upgraded) 2371 if (oldState == V0NotCustomElement || newState == V0Upgraded)
2379 toElement(this)->pseudoStateChanged(CSSSelector::PseudoUnresolved); 2372 toElement(this)->pseudoStateChanged(CSSSelector::PseudoUnresolved);
2380 } 2373 }
2381 2374
2382 void Node::updateAssignmentForInsertedInto(ContainerNode* insertionPoint) 2375 void Node::checkSlotChange()
2383 { 2376 {
2384 if (isShadowHost(insertionPoint)) { 2377 // Common check logic is used in both cases, "after inserted" and "before re moved".
2385 ShadowRoot* root = insertionPoint->youngestShadowRoot(); 2378 if (!isSlotable())
2386 if (root && root->isV1()) 2379 return;
2387 root->assignV1(); 2380 if (ShadowRoot* root = v1ShadowRootOfParent()) {
2381 // Relevant DOM Standard:
2382 // https://dom.spec.whatwg.org/#concept-node-insert
2383 // - 6.1.2: If parent is a shadow host and node is a slotable, then assi gn a slot for node.
2384 // https://dom.spec.whatwg.org/#concept-node-remove
2385 // - 10. If node is assigned, then run assign slotables for node’s assig ned slot.
2386
2387 // Although DOM Standard requires "assign a slot for node / run assign s lotables" at this timing,
2388 // we skip it as an optimization.
2389 if (HTMLSlotElement* slot = root->ensureSlotAssignment().findSlot(*this) )
2390 slot->enqueueSlotChangeEvent();
2391 } else {
2392 // Relevant DOM Standard:
2393 // https://dom.spec.whatwg.org/#concept-node-insert
2394 // - 6.1.3: If parent is a slot whose assigned nodes is the empty list, then run signal a slot change for parent.
2395 // https://dom.spec.whatwg.org/#concept-node-remove
2396 // - 11. If parent is a slot whose assigned nodes is the empty list, the n run signal a slot change for parent.
2397 Element* parent = parentElement();
2398 if (parent && isHTMLSlotElement(parent)) {
2399 HTMLSlotElement& parentSlot = toHTMLSlotElement(*parent);
2400 if (ShadowRoot* root = containingShadowRoot()) {
2401 if (root && root->isV1() && !parentSlot.hasAssignedNodesSlow())
2402 parentSlot.enqueueSlotChangeEvent();
2403 }
2404 }
2388 } 2405 }
2389 } 2406 }
2390 2407
2391 DEFINE_TRACE(Node) 2408 DEFINE_TRACE(Node)
2392 { 2409 {
2393 visitor->trace(m_parentOrShadowHostNode); 2410 visitor->trace(m_parentOrShadowHostNode);
2394 visitor->trace(m_previous); 2411 visitor->trace(m_previous);
2395 visitor->trace(m_next); 2412 visitor->trace(m_next);
2396 // rareData() and m_data.m_layoutObject share their storage. We have to trac e 2413 // rareData() and m_data.m_layoutObject share their storage. We have to trac e
2397 // only one of them. 2414 // only one of them.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2474 2491
2475 void showNodePath(const blink::Node* node) 2492 void showNodePath(const blink::Node* node)
2476 { 2493 {
2477 if (node) 2494 if (node)
2478 node->showNodePathForThis(); 2495 node->showNodePathForThis();
2479 else 2496 else
2480 fprintf(stderr, "Cannot showNodePath for (nil)\n"); 2497 fprintf(stderr, "Cannot showNodePath for (nil)\n");
2481 } 2498 }
2482 2499
2483 #endif 2500 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698