| 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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2378 | 2371 |
| 2379 DCHECK(isHTMLElement() || isSVGElement()); | 2372 DCHECK(isHTMLElement() || isSVGElement()); |
| 2380 DCHECK(CustomElementState::Custom != getCustomElementState()); | 2373 DCHECK(CustomElementState::Custom != getCustomElementState()); |
| 2381 setFlag(V0CustomElementFlag); | 2374 setFlag(V0CustomElementFlag); |
| 2382 setFlag(newState == V0Upgraded, V0CustomElementUpgradedFlag); | 2375 setFlag(newState == V0Upgraded, V0CustomElementUpgradedFlag); |
| 2383 | 2376 |
| 2384 if (oldState == V0NotCustomElement || newState == V0Upgraded) | 2377 if (oldState == V0NotCustomElement || newState == V0Upgraded) |
| 2385 toElement(this)->pseudoStateChanged(CSSSelector::PseudoUnresolved); | 2378 toElement(this)->pseudoStateChanged(CSSSelector::PseudoUnresolved); |
| 2386 } | 2379 } |
| 2387 | 2380 |
| 2388 void Node::updateAssignmentForInsertedInto(ContainerNode* insertionPoint) | 2381 void Node::checkSlotChange() |
| 2389 { | 2382 { |
| 2390 if (isShadowHost(insertionPoint)) { | 2383 // Common check logic is used in both cases, "after inserted" and "before re
moved". |
| 2391 ShadowRoot* root = insertionPoint->youngestShadowRoot(); | 2384 if (!isSlotable()) |
| 2392 if (root && root->isV1()) | 2385 return; |
| 2393 root->assignV1(); | 2386 if (ShadowRoot* root = v1ShadowRootOfParent()) { |
| 2387 // Relevant DOM Standard: |
| 2388 // https://dom.spec.whatwg.org/#concept-node-insert |
| 2389 // - 6.1.2: If parent is a shadow host and node is a slotable, then assi
gn a slot for node. |
| 2390 // https://dom.spec.whatwg.org/#concept-node-remove |
| 2391 // - 10. If node is assigned, then run assign slotables for node’s assig
ned slot. |
| 2392 |
| 2393 // Although DOM Standard requires "assign a slot for node / run assign s
lotables" at this timing, |
| 2394 // we skip it as an optimization. |
| 2395 if (HTMLSlotElement* slot = root->ensureSlotAssignment().findSlot(*this)
) |
| 2396 slot->enqueueSlotChangeEvent(); |
| 2397 } else { |
| 2398 // Relevant DOM Standard: |
| 2399 // https://dom.spec.whatwg.org/#concept-node-insert |
| 2400 // - 6.1.3: If parent is a slot whose assigned nodes is the empty list,
then run signal a slot change for parent. |
| 2401 // https://dom.spec.whatwg.org/#concept-node-remove |
| 2402 // - 11. If parent is a slot whose assigned nodes is the empty list, the
n run signal a slot change for parent. |
| 2403 Element* parent = parentElement(); |
| 2404 if (parent && isHTMLSlotElement(parent)) { |
| 2405 HTMLSlotElement& parentSlot = toHTMLSlotElement(*parent); |
| 2406 if (ShadowRoot* root = containingShadowRoot()) { |
| 2407 if (root && root->isV1() && !parentSlot.hasAssignedNodesSlow()) |
| 2408 parentSlot.enqueueSlotChangeEvent(); |
| 2409 } |
| 2410 } |
| 2394 } | 2411 } |
| 2395 } | 2412 } |
| 2396 | 2413 |
| 2397 DEFINE_TRACE(Node) | 2414 DEFINE_TRACE(Node) |
| 2398 { | 2415 { |
| 2399 visitor->trace(m_parentOrShadowHostNode); | 2416 visitor->trace(m_parentOrShadowHostNode); |
| 2400 visitor->trace(m_previous); | 2417 visitor->trace(m_previous); |
| 2401 visitor->trace(m_next); | 2418 visitor->trace(m_next); |
| 2402 // rareData() and m_data.m_layoutObject share their storage. We have to trac
e | 2419 // rareData() and m_data.m_layoutObject share their storage. We have to trac
e |
| 2403 // only one of them. | 2420 // only one of them. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2480 | 2497 |
| 2481 void showNodePath(const blink::Node* node) | 2498 void showNodePath(const blink::Node* node) |
| 2482 { | 2499 { |
| 2483 if (node) | 2500 if (node) |
| 2484 node->showNodePathForThis(); | 2501 node->showNodePathForThis(); |
| 2485 else | 2502 else |
| 2486 fprintf(stderr, "Cannot showNodePath for (nil)\n"); | 2503 fprintf(stderr, "Cannot showNodePath for (nil)\n"); |
| 2487 } | 2504 } |
| 2488 | 2505 |
| 2489 #endif | 2506 #endif |
| OLD | NEW |