 Chromium Code Reviews
 Chromium Code Reviews 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
    
  
    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| OLD | NEW | 
|---|---|
| 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 Loading... | |
| 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 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 { | 694 { | 
| 694 ScriptForbiddenScope forbidScriptDuringRawIteration; | 695 ScriptForbiddenScope forbidScriptDuringRawIteration; | 
| 695 for (Node* node = parentOrShadowHostNode(); node && !node->childNeedsStyleIn validation(); node = node->parentOrShadowHostNode()) | 696 for (Node* node = parentOrShadowHostNode(); node && !node->childNeedsStyleIn validation(); node = node->parentOrShadowHostNode()) | 
| 696 node->setChildNeedsStyleInvalidation(); | 697 node->setChildNeedsStyleInvalidation(); | 
| 697 document().scheduleLayoutTreeUpdateIfNeeded(); | 698 document().scheduleLayoutTreeUpdateIfNeeded(); | 
| 698 } | 699 } | 
| 699 | 700 | 
| 700 void Node::markAncestorsWithChildNeedsDistributionRecalc() | 701 void Node::markAncestorsWithChildNeedsDistributionRecalc() | 
| 701 { | 702 { | 
| 702 ScriptForbiddenScope forbidScriptDuringRawIteration; | 703 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()) | 704 for (Node* node = this; node && !node->childNeedsDistributionRecalc(); node = node->parentOrShadowHostNode()) | 
| 709 node->setChildNeedsDistributionRecalc(); | 705 node->setChildNeedsDistributionRecalc(); | 
| 710 document().scheduleLayoutTreeUpdateIfNeeded(); | 706 document().scheduleLayoutTreeUpdateIfNeeded(); | 
| 711 } | 707 } | 
| 712 | 708 | 
| 713 inline void Node::setStyleChange(StyleChangeType changeType) | 709 inline void Node::setStyleChange(StyleChangeType changeType) | 
| 714 { | 710 { | 
| 715 m_nodeFlags = (m_nodeFlags & ~StyleChangeMask) | changeType; | 711 m_nodeFlags = (m_nodeFlags & ~StyleChangeMask) | changeType; | 
| 716 } | 712 } | 
| 717 | 713 | 
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 987 return !isShadowRoot() && !isSlotOrActiveInsertionPoint(); | 983 return !isShadowRoot() && !isSlotOrActiveInsertionPoint(); | 
| 988 } | 984 } | 
| 989 | 985 | 
| 990 bool Node::isSlotOrActiveInsertionPoint() const | 986 bool Node::isSlotOrActiveInsertionPoint() const | 
| 991 { | 987 { | 
| 992 return isHTMLSlotElement(*this) || isActiveInsertionPoint(*this); | 988 return isHTMLSlotElement(*this) || isActiveInsertionPoint(*this); | 
| 993 } | 989 } | 
| 994 | 990 | 
| 995 AtomicString Node::slotName() const | 991 AtomicString Node::slotName() const | 
| 996 { | 992 { | 
| 997 DCHECK(slottable()); | 993 DCHECK(isSlotable()); | 
| 998 if (isElementNode()) | 994 if (isElementNode()) | 
| 999 return normalizeSlotName(toElement(*this).fastGetAttribute(HTMLNames::sl otAttr)); | 995 return HTMLSlotElement::normalizeSlotName(toElement(*this).fastGetAttrib ute(HTMLNames::slotAttr)); | 
| 1000 DCHECK(isTextNode()); | 996 DCHECK(isTextNode()); | 
| 1001 return emptyAtom; | 997 return emptyAtom; | 
| 1002 } | 998 } | 
| 1003 | 999 | 
| 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 | 1000 bool Node::isInV1ShadowTree() const | 
| 1011 { | 1001 { | 
| 1012 ShadowRoot* shadowRoot = containingShadowRoot(); | 1002 ShadowRoot* shadowRoot = containingShadowRoot(); | 
| 1013 return shadowRoot && shadowRoot->isV1(); | 1003 return shadowRoot && shadowRoot->isV1(); | 
| 1014 } | 1004 } | 
| 1015 | 1005 | 
| 1016 bool Node::isInV0ShadowTree() const | 1006 bool Node::isInV0ShadowTree() const | 
| 1017 { | 1007 { | 
| 1018 ShadowRoot* shadowRoot = containingShadowRoot(); | 1008 ShadowRoot* shadowRoot = containingShadowRoot(); | 
| 1019 return shadowRoot && !shadowRoot->isV1(); | 1009 return shadowRoot && !shadowRoot->isV1(); | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1030 ElementShadow* parentShadow = parentElementShadow(); | 1020 ElementShadow* parentShadow = parentElementShadow(); | 
| 1031 return parentShadow && parentShadow->isV1(); | 1021 return parentShadow && parentShadow->isV1(); | 
| 1032 } | 1022 } | 
| 1033 | 1023 | 
| 1034 bool Node::isChildOfV0ShadowHost() const | 1024 bool Node::isChildOfV0ShadowHost() const | 
| 1035 { | 1025 { | 
| 1036 ElementShadow* parentShadow = parentElementShadow(); | 1026 ElementShadow* parentShadow = parentElementShadow(); | 
| 1037 return parentShadow && !parentShadow->isV1(); | 1027 return parentShadow && !parentShadow->isV1(); | 
| 1038 } | 1028 } | 
| 1039 | 1029 | 
| 1030 ShadowRoot* Node::v1ShadowRootOfParent() const | |
| 1031 { | |
| 1032 if (Element* parent = parentElement()) | |
| 1033 return parent->shadowRootIfV1(); | |
| 1034 return nullptr; | |
| 1035 } | |
| 1036 | |
| 1040 Element* Node::shadowHost() const | 1037 Element* Node::shadowHost() const | 
| 1041 { | 1038 { | 
| 1042 if (ShadowRoot* root = containingShadowRoot()) | 1039 if (ShadowRoot* root = containingShadowRoot()) | 
| 1043 return root->host(); | 1040 return root->host(); | 
| 1044 return nullptr; | 1041 return nullptr; | 
| 1045 } | 1042 } | 
| 1046 | 1043 | 
| 1047 ShadowRoot* Node::containingShadowRoot() const | 1044 ShadowRoot* Node::containingShadowRoot() const | 
| 1048 { | 1045 { | 
| 1049 Node& root = treeScope().rootNode(); | 1046 Node& root = treeScope().rootNode(); | 
| (...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2240 DCHECK(insertionPoint->containingShadowRoot()); | 2237 DCHECK(insertionPoint->containingShadowRoot()); | 
| 2241 if (!insertionPoint->containingShadowRoot()->isOpenOrV0()) | 2238 if (!insertionPoint->containingShadowRoot()->isOpenOrV0()) | 
| 2242 break; | 2239 break; | 
| 2243 filteredInsertionPoints.append(insertionPoint); | 2240 filteredInsertionPoints.append(insertionPoint); | 
| 2244 } | 2241 } | 
| 2245 return StaticNodeList::adopt(filteredInsertionPoints); | 2242 return StaticNodeList::adopt(filteredInsertionPoints); | 
| 2246 } | 2243 } | 
| 2247 | 2244 | 
| 2248 HTMLSlotElement* Node::assignedSlot() const | 2245 HTMLSlotElement* Node::assignedSlot() const | 
| 2249 { | 2246 { | 
| 2250 Element* parent = parentElement(); | 2247 if (ShadowRoot* root = v1ShadowRootOfParent()) | 
| 2251 ShadowRoot* root = parent ? parent->youngestShadowRoot() : nullptr; | 2248 return root->ensureSlotAssignment().findSlot(*this); | 
| 2252 if (root && root->isV1()) | |
| 2253 return root->assignedSlotFor(*this); | |
| 2254 return nullptr; | 2249 return nullptr; | 
| 2255 } | 2250 } | 
| 2256 | 2251 | 
| 2257 HTMLSlotElement* Node::assignedSlotForBinding() | 2252 HTMLSlotElement* Node::assignedSlotForBinding() | 
| 2258 { | 2253 { | 
| 2259 updateDistribution(); | 2254 updateDistribution(); | 
| 2260 Element* parent = parentElement(); | 2255 if (ShadowRoot* root = v1ShadowRootOfParent()) { | 
| 2261 ShadowRoot* root = parent ? parent->youngestShadowRoot() : nullptr; | 2256 if (root->type() == ShadowRootType::Open) | 
| 2262 if (root && root->type() == ShadowRootType::Open) | 2257 return root->ensureSlotAssignment().findSlot(*this); | 
| 2263 return root->assignedSlotFor(*this); | 2258 } | 
| 2264 return nullptr; | 2259 return nullptr; | 
| 2265 } | 2260 } | 
| 2266 | 2261 | 
| 2267 void Node::setFocus(bool flag) | 2262 void Node::setFocus(bool flag) | 
| 2268 { | 2263 { | 
| 2269 document().userActionElements().setFocused(this, flag); | 2264 document().userActionElements().setFocused(this, flag); | 
| 2270 } | 2265 } | 
| 2271 | 2266 | 
| 2272 void Node::setActive(bool flag) | 2267 void Node::setActive(bool flag) | 
| 2273 { | 2268 { | 
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2372 | 2367 | 
| 2373 DCHECK(isHTMLElement() || isSVGElement()); | 2368 DCHECK(isHTMLElement() || isSVGElement()); | 
| 2374 DCHECK(CustomElementState::Custom != getCustomElementState()); | 2369 DCHECK(CustomElementState::Custom != getCustomElementState()); | 
| 2375 setFlag(V0CustomElementFlag); | 2370 setFlag(V0CustomElementFlag); | 
| 2376 setFlag(newState == V0Upgraded, V0CustomElementUpgradedFlag); | 2371 setFlag(newState == V0Upgraded, V0CustomElementUpgradedFlag); | 
| 2377 | 2372 | 
| 2378 if (oldState == V0NotCustomElement || newState == V0Upgraded) | 2373 if (oldState == V0NotCustomElement || newState == V0Upgraded) | 
| 2379 toElement(this)->pseudoStateChanged(CSSSelector::PseudoUnresolved); | 2374 toElement(this)->pseudoStateChanged(CSSSelector::PseudoUnresolved); | 
| 2380 } | 2375 } | 
| 2381 | 2376 | 
| 2382 void Node::updateAssignmentForInsertedInto(ContainerNode* insertionPoint) | 2377 void Node::checkSlotChange() | 
| 2383 { | 2378 { | 
| 2384 if (isShadowHost(insertionPoint)) { | 2379 // Common check logic is used in both cases, "after inserted" and "before re moved". | 
| 2385 ShadowRoot* root = insertionPoint->youngestShadowRoot(); | 2380 if (!isSlotable()) | 
| 2386 if (root && root->isV1()) | 2381 return; | 
| 2387 root->assignV1(); | 2382 if (ShadowRoot* root = v1ShadowRootOfParent()) { | 
| 2383 // Relevant DOM Standard: | |
| 2384 // https://dom.spec.whatwg.org/#concept-node-insert | |
| 2385 // - 6.1.2: If parent is a shadow host and node is a slotable, then assi gn a slot for node. | |
| 2386 // https://dom.spec.whatwg.org/#concept-node-remove | |
| 2387 // - 10. If node is assigned, then run assign slotables for node’s assig ned slot. | |
| 2388 | |
| 2389 // Although DOM Standard requires "assign a slot for node / run assing s lotables" at this timing, | |
| 
esprehn
2016/05/23 06:41:00
typo, assign? you probably want to spell check you
 | |
| 2390 // we skip it as an optimization. | |
| 2391 if (HTMLSlotElement* slot = root->ensureSlotAssignment().findSlot(*this) ) | |
| 2392 slot->enqueueSlotChangeEvent(); | |
| 2393 } else { | |
| 2394 // Relevant DOM Standard: | |
| 2395 // https://dom.spec.whatwg.org/#concept-node-insert | |
| 2396 // - 6.1.3: If parent is a slot whose assigned nodes is the empty list, then run signal a slot change for parent. | |
| 2397 // https://dom.spec.whatwg.org/#concept-node-remove | |
| 2398 // - 11. If parent is a slot whose assigned nodes is the empty list, the n run signal a slot change for parent. | |
| 2399 Element* parent = parentElement(); | |
| 2400 if (parent && isHTMLSlotElement(parent)) { | |
| 2401 HTMLSlotElement& parentSlot = toHTMLSlotElement(*parent); | |
| 2402 if (ShadowRoot* root = containingShadowRoot()) { | |
| 2403 if (root && root->isV1() && !parentSlot.hasAssignedNodesSynchron ously()) | |
| 2404 parentSlot.enqueueSlotChangeEvent(); | |
| 2405 } | |
| 2406 } | |
| 2388 } | 2407 } | 
| 2389 } | 2408 } | 
| 2390 | 2409 | 
| 2391 DEFINE_TRACE(Node) | 2410 DEFINE_TRACE(Node) | 
| 2392 { | 2411 { | 
| 2393 visitor->trace(m_parentOrShadowHostNode); | 2412 visitor->trace(m_parentOrShadowHostNode); | 
| 2394 visitor->trace(m_previous); | 2413 visitor->trace(m_previous); | 
| 2395 visitor->trace(m_next); | 2414 visitor->trace(m_next); | 
| 2396 // rareData() and m_data.m_layoutObject share their storage. We have to trac e | 2415 // rareData() and m_data.m_layoutObject share their storage. We have to trac e | 
| 2397 // only one of them. | 2416 // only one of them. | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2474 | 2493 | 
| 2475 void showNodePath(const blink::Node* node) | 2494 void showNodePath(const blink::Node* node) | 
| 2476 { | 2495 { | 
| 2477 if (node) | 2496 if (node) | 
| 2478 node->showNodePathForThis(); | 2497 node->showNodePathForThis(); | 
| 2479 else | 2498 else | 
| 2480 fprintf(stderr, "Cannot showNodePath for (nil)\n"); | 2499 fprintf(stderr, "Cannot showNodePath for (nil)\n"); | 
| 2481 } | 2500 } | 
| 2482 | 2501 | 
| 2483 #endif | 2502 #endif | 
| OLD | NEW |