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-2011, 2014 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004-2011, 2014 Apple Inc. All rights reserved. |
6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 class ComputedStyle; | 83 class ComputedStyle; |
84 class SVGQualifiedName; | 84 class SVGQualifiedName; |
85 class ShadowRoot; | 85 class ShadowRoot; |
86 template <typename NodeType> class StaticNodeTypeList; | 86 template <typename NodeType> class StaticNodeTypeList; |
87 using StaticNodeList = StaticNodeTypeList<Node>; | 87 using StaticNodeList = StaticNodeTypeList<Node>; |
88 class StyleChangeReasonForTracing; | 88 class StyleChangeReasonForTracing; |
89 class TagCollection; | 89 class TagCollection; |
90 class Text; | 90 class Text; |
91 class TouchEvent; | 91 class TouchEvent; |
92 | 92 |
93 const int nodeStyleChangeShift = 19; | 93 const int nodeStyleChangeShift = 20; |
94 | 94 |
95 enum StyleChangeType { | 95 enum StyleChangeType { |
96 NoStyleChange = 0, | 96 NoStyleChange = 0, |
97 LocalStyleChange = 1 << nodeStyleChangeShift, | 97 LocalStyleChange = 1 << nodeStyleChangeShift, |
98 SubtreeStyleChange = 2 << nodeStyleChangeShift, | 98 SubtreeStyleChange = 2 << nodeStyleChangeShift, |
99 NeedsReattachStyleChange = 3 << nodeStyleChangeShift, | 99 NeedsReattachStyleChange = 3 << nodeStyleChangeShift, |
100 }; | 100 }; |
101 | 101 |
102 enum class CustomElementState { | 102 enum class CustomElementState { |
103 Uncustomized = 0, | 103 Uncustomized = 0, |
104 Custom = 1, | 104 Custom = 1, |
105 Undefined = 2, | 105 Undefined = 2, |
106 }; | 106 }; |
107 | 107 |
108 CORE_EXPORT std::ostream& operator<<(std::ostream&, CustomElementState); | 108 CORE_EXPORT std::ostream& operator<<(std::ostream&, CustomElementState); |
109 | 109 |
110 class NodeRareDataBase { | 110 class NodeRareDataBase { |
111 public: | 111 public: |
112 LayoutObject* layoutObject() const { return m_layoutObject; } | 112 LayoutObject* layoutObject() const { return m_layoutObject; } |
113 void setLayoutObject(LayoutObject* layoutObject) { m_layoutObject = layoutOb ject; } | 113 void setLayoutObject(LayoutObject* layoutObject) { m_layoutObject = layoutOb ject; } |
114 ComputedStyle* computedStyle() const { return m_computedStyle; } | |
115 void setComputedStyle(ComputedStyle* computedStyle) { m_computedStyle = comp utedStyle; } | |
114 | 116 |
115 protected: | 117 protected: |
116 NodeRareDataBase(LayoutObject* layoutObject) | 118 NodeRareDataBase(LayoutObject* layoutObject) |
117 : m_layoutObject(layoutObject) | 119 : m_computedStyle(nullptr) |
120 , m_layoutObject(layoutObject) | |
118 { } | 121 { } |
119 | 122 |
120 protected: | 123 protected: |
124 ComputedStyle* m_computedStyle; | |
Timothy Loh
2016/05/26 07:06:37
This should be a RefPtr<ComputedStyle> and should
| |
121 // LayoutObjects are fully owned by their DOM node. See LayoutObject's | 125 // LayoutObjects are fully owned by their DOM node. See LayoutObject's |
122 // LIFETIME documentation section. | 126 // LIFETIME documentation section. |
123 LayoutObject* m_layoutObject; | 127 LayoutObject* m_layoutObject; |
124 }; | 128 }; |
125 | 129 |
126 class Node; | 130 class Node; |
127 WILL_NOT_BE_EAGERLY_TRACED_CLASS(Node); | 131 WILL_NOT_BE_EAGERLY_TRACED_CLASS(Node); |
128 | 132 |
129 // This class represents a DOM node in the DOM tree. | 133 // This class represents a DOM node in the DOM tree. |
130 // https://dom.spec.whatwg.org/#interface-node | 134 // https://dom.spec.whatwg.org/#interface-node |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 virtual int maxCharacterOffset() const; | 513 virtual int maxCharacterOffset() const; |
510 | 514 |
511 // Whether or not a selection can be started in this object | 515 // Whether or not a selection can be started in this object |
512 virtual bool canStartSelection() const; | 516 virtual bool canStartSelection() const; |
513 | 517 |
514 // ------------------------------------------------------------------------- ---- | 518 // ------------------------------------------------------------------------- ---- |
515 // Integration with layout tree | 519 // Integration with layout tree |
516 | 520 |
517 // As layoutObject() includes a branch you should avoid calling it repeatedl y in hot code paths. | 521 // As layoutObject() includes a branch you should avoid calling it repeatedl y in hot code paths. |
518 // Note that if a Node has a layoutObject, it's parentNode is guaranteed to have one as well. | 522 // Note that if a Node has a layoutObject, it's parentNode is guaranteed to have one as well. |
519 LayoutObject* layoutObject() const { return hasRareData() ? m_data.m_rareDat a->layoutObject() : m_data.m_layoutObject; } | 523 LayoutObject* layoutObject() const |
520 void setLayoutObject(LayoutObject* layoutObject) | |
521 { | 524 { |
522 if (hasRareData()) | 525 if (hasRareData()) |
523 m_data.m_rareData->setLayoutObject(layoutObject); | 526 return m_data.m_rareData->layoutObject(); |
524 else | 527 else |
525 m_data.m_layoutObject = layoutObject; | 528 return hasLayoutObject() ? m_data.m_layoutObject : nullptr; |
526 } | 529 } |
530 void setLayoutObject(LayoutObject*); | |
531 void clearStyleAndLayoutObject(); | |
527 | 532 |
528 // Use these two methods with caution. | 533 // Use these two methods with caution. |
529 LayoutBox* layoutBox() const; | 534 LayoutBox* layoutBox() const; |
530 LayoutBoxModelObject* layoutBoxModelObject() const; | 535 LayoutBoxModelObject* layoutBoxModelObject() const; |
531 | 536 |
532 struct AttachContext { | 537 struct AttachContext { |
533 STACK_ALLOCATED(); | 538 STACK_ALLOCATED(); |
534 ComputedStyle* resolvedStyle = nullptr; | 539 ComputedStyle* resolvedStyle = nullptr; |
535 bool performingReattach = false; | 540 bool performingReattach = false; |
536 bool clearInvalidation = false; | 541 bool clearInvalidation = false; |
(...skipping 12 matching lines...) Expand all Loading... | |
549 | 554 |
550 void reattach(const AttachContext& = AttachContext()); | 555 void reattach(const AttachContext& = AttachContext()); |
551 void lazyReattachIfAttached(); | 556 void lazyReattachIfAttached(); |
552 | 557 |
553 // Returns true if recalcStyle should be called on the object, if there is s uch a method (on Document and Element). | 558 // Returns true if recalcStyle should be called on the object, if there is s uch a method (on Document and Element). |
554 bool shouldCallRecalcStyle(StyleRecalcChange); | 559 bool shouldCallRecalcStyle(StyleRecalcChange); |
555 | 560 |
556 // Wrapper for nodes that don't have a layoutObject, but still cache the sty le (like HTMLOptionElement). | 561 // Wrapper for nodes that don't have a layoutObject, but still cache the sty le (like HTMLOptionElement). |
557 ComputedStyle* mutableComputedStyle() const; | 562 ComputedStyle* mutableComputedStyle() const; |
558 const ComputedStyle* computedStyle() const; | 563 const ComputedStyle* computedStyle() const; |
564 void setComputedStyle(ComputedStyle*); | |
559 const ComputedStyle* parentComputedStyle() const; | 565 const ComputedStyle* parentComputedStyle() const; |
560 | 566 |
561 const ComputedStyle& computedStyleRef() const; | 567 const ComputedStyle& computedStyleRef() const; |
562 | 568 |
563 const ComputedStyle* ensureComputedStyle(PseudoId pseudoElementSpecifier = P seudoIdNone) { return virtualEnsureComputedStyle(pseudoElementSpecifier); } | 569 const ComputedStyle* ensureComputedStyle(PseudoId pseudoElementSpecifier = P seudoIdNone) { return virtualEnsureComputedStyle(pseudoElementSpecifier); } |
564 | 570 |
565 // ------------------------------------------------------------------------- ---- | 571 // ------------------------------------------------------------------------- ---- |
566 // Notification of document structure changes (see ContainerNode.h for more notification methods) | 572 // Notification of document structure changes (see ContainerNode.h for more notification methods) |
567 // | 573 // |
568 // At first, WebKit notifies the node that it has been inserted into the doc ument. This is called during document parsing, and also | 574 // At first, WebKit notifies the node that it has been inserted into the doc ument. This is called during document parsing, and also |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 | 688 |
683 DECLARE_VIRTUAL_TRACE_WRAPPERS(); | 689 DECLARE_VIRTUAL_TRACE_WRAPPERS(); |
684 | 690 |
685 unsigned lengthOfContents() const; | 691 unsigned lengthOfContents() const; |
686 | 692 |
687 v8::Local<v8::Object> wrap(v8::Isolate*, v8::Local<v8::Object> creationConte xt) override; | 693 v8::Local<v8::Object> wrap(v8::Isolate*, v8::Local<v8::Object> creationConte xt) override; |
688 v8::Local<v8::Object> associateWithWrapper(v8::Isolate*, const WrapperTypeIn fo*, v8::Local<v8::Object> wrapper) override WARN_UNUSED_RETURN; | 694 v8::Local<v8::Object> associateWithWrapper(v8::Isolate*, const WrapperTypeIn fo*, v8::Local<v8::Object> wrapper) override WARN_UNUSED_RETURN; |
689 | 695 |
690 private: | 696 private: |
691 enum NodeFlags { | 697 enum NodeFlags { |
692 HasRareDataFlag = 1, | 698 HasLayoutObjectFlag = 1, |
699 HasRareDataFlag = 1 << 1, | |
693 | 700 |
694 // Node type flags. These never change once created. | 701 // Node type flags. These never change once created. |
695 IsTextFlag = 1 << 1, | 702 IsTextFlag = 1 << 2, |
696 IsContainerFlag = 1 << 2, | 703 IsContainerFlag = 1 << 3, |
697 IsElementFlag = 1 << 3, | 704 IsElementFlag = 1 << 4, |
698 IsHTMLFlag = 1 << 4, | 705 IsHTMLFlag = 1 << 5, |
699 IsSVGFlag = 1 << 5, | 706 IsSVGFlag = 1 << 6, |
700 IsDocumentFragmentFlag = 1 << 6, | 707 IsDocumentFragmentFlag = 1 << 7, |
701 IsInsertionPointFlag = 1 << 7, | 708 IsInsertionPointFlag = 1 << 8, |
702 | 709 |
703 // Changes based on if the element should be treated like a link, | 710 // Changes based on if the element should be treated like a link, |
704 // ex. When setting the href attribute on an <a>. | 711 // ex. When setting the href attribute on an <a>. |
705 IsLinkFlag = 1 << 8, | 712 IsLinkFlag = 1 << 9, |
706 | 713 |
707 // Changes based on :hover, :active and :focus state. | 714 // Changes based on :hover, :active and :focus state. |
708 IsUserActionElementFlag = 1 << 9, | 715 IsUserActionElementFlag = 1 << 10, |
709 | 716 |
710 // Tree state flags. These change when the element is added/removed | 717 // Tree state flags. These change when the element is added/removed |
711 // from a DOM tree. | 718 // from a DOM tree. |
712 InDocumentFlag = 1 << 10, | 719 InDocumentFlag = 1 << 11, |
713 IsInShadowTreeFlag = 1 << 11, | 720 IsInShadowTreeFlag = 1 << 12, |
714 | 721 |
715 // Set by the parser when the children are done parsing. | 722 // Set by the parser when the children are done parsing. |
716 IsFinishedParsingChildrenFlag = 1 << 12, | 723 IsFinishedParsingChildrenFlag = 1 << 13, |
717 | 724 |
718 // Flags related to recalcStyle. | 725 // Flags related to recalcStyle. |
719 SVGFilterNeedsLayerUpdateFlag = 1 << 13, | 726 SVGFilterNeedsLayerUpdateFlag = 1 << 14, |
720 HasCustomStyleCallbacksFlag = 1 << 14, | 727 HasCustomStyleCallbacksFlag = 1 << 15, |
721 ChildNeedsStyleInvalidationFlag = 1 << 15, | 728 ChildNeedsStyleInvalidationFlag = 1 << 16, |
722 NeedsStyleInvalidationFlag = 1 << 16, | 729 NeedsStyleInvalidationFlag = 1 << 17, |
723 ChildNeedsDistributionRecalcFlag = 1 << 17, | 730 ChildNeedsDistributionRecalcFlag = 1 << 18, |
724 ChildNeedsStyleRecalcFlag = 1 << 18, | 731 ChildNeedsStyleRecalcFlag = 1 << 19, |
725 StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1), | 732 StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1), |
726 | 733 |
727 CustomElementFlag = 1 << 21, | 734 CustomElementFlag = 1 << 22, |
728 CustomElementCustomFlag = 1 << 22, | 735 CustomElementCustomFlag = 1 << 23, |
729 | 736 |
730 HasNameOrIsEditingTextFlag = 1 << 23, | 737 HasNameOrIsEditingTextFlag = 1 << 24, |
731 HasWeakReferencesFlag = 1 << 24, | 738 HasWeakReferencesFlag = 1 << 25, |
732 V8CollectableDuringMinorGCFlag = 1 << 25, | 739 V8CollectableDuringMinorGCFlag = 1 << 26, |
733 HasEventTargetDataFlag = 1 << 26, | 740 HasEventTargetDataFlag = 1 << 27, |
734 AlreadySpellCheckedFlag = 1 << 27, | 741 AlreadySpellCheckedFlag = 1 << 28, |
735 | 742 |
736 V0CustomElementFlag = 1 << 28, | 743 V0CustomElementFlag = 1 << 28, |
737 V0CustomElementUpgradedFlag = 1 << 29, | 744 V0CustomElementUpgradedFlag = 1 << 29, |
738 | 745 |
739 DefaultNodeFlags = IsFinishedParsingChildrenFlag | NeedsReattachStyleCha nge | 746 DefaultNodeFlags = IsFinishedParsingChildrenFlag | NeedsReattachStyleCha nge |
740 }; | 747 }; |
741 | 748 |
742 // 3 bits remaining. | 749 // 3 bits remaining. |
743 | 750 |
744 bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; } | 751 bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; } |
(...skipping 19 matching lines...) Expand all Loading... | |
764 Node(TreeScope*, ConstructionType); | 771 Node(TreeScope*, ConstructionType); |
765 | 772 |
766 virtual void didMoveToNewDocument(Document& oldDocument); | 773 virtual void didMoveToNewDocument(Document& oldDocument); |
767 | 774 |
768 void addedEventListener(const AtomicString& eventType, RegisteredEventListen er&) override; | 775 void addedEventListener(const AtomicString& eventType, RegisteredEventListen er&) override; |
769 void removedEventListener(const AtomicString& eventType, const RegisteredEve ntListener&) override; | 776 void removedEventListener(const AtomicString& eventType, const RegisteredEve ntListener&) override; |
770 DispatchEventResult dispatchEventInternal(Event*) override; | 777 DispatchEventResult dispatchEventInternal(Event*) override; |
771 | 778 |
772 static void reattachWhitespaceSiblingsIfNeeded(Text* start); | 779 static void reattachWhitespaceSiblingsIfNeeded(Text* start); |
773 | 780 |
781 bool hasLayoutObject() const { return getFlag(HasLayoutObjectFlag); } | |
774 bool hasRareData() const { return getFlag(HasRareDataFlag); } | 782 bool hasRareData() const { return getFlag(HasRareDataFlag); } |
775 | 783 |
776 NodeRareData* rareData() const; | 784 NodeRareData* rareData() const; |
777 NodeRareData& ensureRareData(); | 785 NodeRareData& ensureRareData(); |
778 | 786 |
779 void setHasCustomStyleCallbacks() { setFlag(true, HasCustomStyleCallbacksFla g); } | 787 void setHasCustomStyleCallbacks() { setFlag(true, HasCustomStyleCallbacksFla g); } |
780 | 788 |
781 void setTreeScope(TreeScope* scope) { m_treeScope = scope; } | 789 void setTreeScope(TreeScope* scope) { m_treeScope = scope; } |
782 | 790 |
783 // isTreeScopeInitialized() can be false | 791 // isTreeScopeInitialized() can be false |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
819 HeapVector<Member<MutationObserverRegistration>>* mutationObserverRegistry() ; | 827 HeapVector<Member<MutationObserverRegistration>>* mutationObserverRegistry() ; |
820 HeapHashSet<Member<MutationObserverRegistration>>* transientMutationObserver Registry(); | 828 HeapHashSet<Member<MutationObserverRegistration>>* transientMutationObserver Registry(); |
821 | 829 |
822 uint32_t m_nodeFlags; | 830 uint32_t m_nodeFlags; |
823 Member<ContainerNode> m_parentOrShadowHostNode; | 831 Member<ContainerNode> m_parentOrShadowHostNode; |
824 Member<TreeScope> m_treeScope; | 832 Member<TreeScope> m_treeScope; |
825 Member<Node> m_previous; | 833 Member<Node> m_previous; |
826 Member<Node> m_next; | 834 Member<Node> m_next; |
827 // When a node has rare data we move the layoutObject into the rare data. | 835 // When a node has rare data we move the layoutObject into the rare data. |
828 union DataUnion { | 836 union DataUnion { |
829 DataUnion() : m_layoutObject(nullptr) { } | 837 DataUnion() : m_computedStyle(nullptr) { } |
838 ComputedStyle* m_computedStyle; | |
Timothy Loh
2016/05/26 07:06:37
This probably needs lifetime management (i.e. refs
| |
830 // LayoutObjects are fully owned by their DOM node. See LayoutObject's | 839 // LayoutObjects are fully owned by their DOM node. See LayoutObject's |
831 // LIFETIME documentation section. | 840 // LIFETIME documentation section. |
832 LayoutObject* m_layoutObject; | 841 LayoutObject* m_layoutObject; |
833 NodeRareDataBase* m_rareData; | 842 NodeRareDataBase* m_rareData; |
834 } m_data; | 843 } m_data; |
835 }; | 844 }; |
836 | 845 |
837 inline void Node::setParentOrShadowHostNode(ContainerNode* parent) | 846 inline void Node::setParentOrShadowHostNode(ContainerNode* parent) |
838 { | 847 { |
839 DCHECK(isMainThread()); | 848 DCHECK(isMainThread()); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 } // namespace blink | 923 } // namespace blink |
915 | 924 |
916 #ifndef NDEBUG | 925 #ifndef NDEBUG |
917 // Outside the WebCore namespace for ease of invocation from gdb. | 926 // Outside the WebCore namespace for ease of invocation from gdb. |
918 void showNode(const blink::Node*); | 927 void showNode(const blink::Node*); |
919 void showTree(const blink::Node*); | 928 void showTree(const blink::Node*); |
920 void showNodePath(const blink::Node*); | 929 void showNodePath(const blink::Node*); |
921 #endif | 930 #endif |
922 | 931 |
923 #endif // Node_h | 932 #endif // Node_h |
OLD | NEW |