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

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

Issue 1962953002: Storage of ComputedStyle separate from LayoutObject. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added TODOs to remove redundant ComputedStyle members 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-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
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,
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 virtual int maxCharacterOffset() const; 506 virtual int maxCharacterOffset() const;
507 507
508 // Whether or not a selection can be started in this object 508 // Whether or not a selection can be started in this object
509 virtual bool canStartSelection() const; 509 virtual bool canStartSelection() const;
510 510
511 // ------------------------------------------------------------------------- ---- 511 // ------------------------------------------------------------------------- ----
512 // Integration with layout tree 512 // Integration with layout tree
513 513
514 // As layoutObject() includes a branch you should avoid calling it repeatedl y in hot code paths. 514 // As layoutObject() includes a branch you should avoid calling it repeatedl y in hot code paths.
515 // Note that if a Node has a layoutObject, it's parentNode is guaranteed to have one as well. 515 // Note that if a Node has a layoutObject, it's parentNode is guaranteed to have one as well.
516 LayoutObject* layoutObject() const { return hasRareData() ? m_data.m_rareDat a->layoutObject() : m_data.m_layoutObject; } 516 LayoutObject* layoutObject() const
517 {
518 if (hasRareData())
519 return m_data.m_rareData->layoutObject();
520 return hasLayoutObject() ? m_data.m_layoutObject : nullptr;
521 }
517 void setLayoutObject(LayoutObject* layoutObject) 522 void setLayoutObject(LayoutObject* layoutObject)
518 { 523 {
519 if (hasRareData()) 524 if (hasRareData())
520 m_data.m_rareData->setLayoutObject(layoutObject); 525 m_data.m_rareData->setLayoutObject(layoutObject);
521 else 526 else
522 m_data.m_layoutObject = layoutObject; 527 m_data.m_layoutObject = layoutObject;
528 if (layoutObject)
529 setFlag(HasLayoutObjectFlag);
530 else
531 clearFlag(HasLayoutObjectFlag);
523 } 532 }
524 533
525 // Use these two methods with caution. 534 // Use these two methods with caution.
526 LayoutBox* layoutBox() const; 535 LayoutBox* layoutBox() const;
527 LayoutBoxModelObject* layoutBoxModelObject() const; 536 LayoutBoxModelObject* layoutBoxModelObject() const;
528 537
529 struct AttachContext { 538 struct AttachContext {
530 STACK_ALLOCATED(); 539 STACK_ALLOCATED();
531 ComputedStyle* resolvedStyle = nullptr; 540 ComputedStyle* resolvedStyle = nullptr;
532 bool performingReattach = false; 541 bool performingReattach = false;
(...skipping 13 matching lines...) Expand all
546 555
547 void reattach(const AttachContext& = AttachContext()); 556 void reattach(const AttachContext& = AttachContext());
548 void lazyReattachIfAttached(); 557 void lazyReattachIfAttached();
549 558
550 // Returns true if recalcStyle should be called on the object, if there is s uch a method (on Document and Element). 559 // Returns true if recalcStyle should be called on the object, if there is s uch a method (on Document and Element).
551 bool shouldCallRecalcStyle(StyleRecalcChange); 560 bool shouldCallRecalcStyle(StyleRecalcChange);
552 561
553 // Wrapper for nodes that don't have a layoutObject, but still cache the sty le (like HTMLOptionElement). 562 // Wrapper for nodes that don't have a layoutObject, but still cache the sty le (like HTMLOptionElement).
554 ComputedStyle* mutableComputedStyle() const; 563 ComputedStyle* mutableComputedStyle() const;
555 const ComputedStyle* computedStyle() const; 564 const ComputedStyle* computedStyle() const;
565 void setComputedStyle(ComputedStyle*);
556 const ComputedStyle* parentComputedStyle() const; 566 const ComputedStyle* parentComputedStyle() const;
557 567
558 const ComputedStyle& computedStyleRef() const; 568 const ComputedStyle& computedStyleRef() const;
559 569
560 const ComputedStyle* ensureComputedStyle(PseudoId pseudoElementSpecifier = P seudoIdNone) { return virtualEnsureComputedStyle(pseudoElementSpecifier); } 570 const ComputedStyle* ensureComputedStyle(PseudoId pseudoElementSpecifier = P seudoIdNone) { return virtualEnsureComputedStyle(pseudoElementSpecifier); }
561 571
562 // ------------------------------------------------------------------------- ---- 572 // ------------------------------------------------------------------------- ----
563 // Notification of document structure changes (see ContainerNode.h for more notification methods) 573 // Notification of document structure changes (see ContainerNode.h for more notification methods)
564 // 574 //
565 // At first, WebKit notifies the node that it has been inserted into the doc ument. This is called during document parsing, and also 575 // At first, WebKit notifies the node that it has been inserted into the doc ument. This is called during document parsing, and also
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 690
681 DECLARE_VIRTUAL_TRACE_WRAPPERS(); 691 DECLARE_VIRTUAL_TRACE_WRAPPERS();
682 692
683 unsigned lengthOfContents() const; 693 unsigned lengthOfContents() const;
684 694
685 v8::Local<v8::Object> wrap(v8::Isolate*, v8::Local<v8::Object> creationConte xt) override; 695 v8::Local<v8::Object> wrap(v8::Isolate*, v8::Local<v8::Object> creationConte xt) override;
686 v8::Local<v8::Object> associateWithWrapper(v8::Isolate*, const WrapperTypeIn fo*, v8::Local<v8::Object> wrapper) override WARN_UNUSED_RETURN; 696 v8::Local<v8::Object> associateWithWrapper(v8::Isolate*, const WrapperTypeIn fo*, v8::Local<v8::Object> wrapper) override WARN_UNUSED_RETURN;
687 697
688 private: 698 private:
689 enum NodeFlags { 699 enum NodeFlags {
690 HasRareDataFlag = 1, 700 HasLayoutObjectFlag = 1,
701 HasRareDataFlag = 1 << 1,
691 702
692 // Node type flags. These never change once created. 703 // Node type flags. These never change once created.
693 IsTextFlag = 1 << 1, 704 IsTextFlag = 1 << 2,
694 IsContainerFlag = 1 << 2, 705 IsContainerFlag = 1 << 3,
695 IsElementFlag = 1 << 3, 706 IsElementFlag = 1 << 4,
696 IsHTMLFlag = 1 << 4, 707 IsHTMLFlag = 1 << 5,
697 IsSVGFlag = 1 << 5, 708 IsSVGFlag = 1 << 6,
698 IsDocumentFragmentFlag = 1 << 6, 709 IsDocumentFragmentFlag = 1 << 7,
699 IsInsertionPointFlag = 1 << 7, 710 IsInsertionPointFlag = 1 << 8,
700 711
701 // Changes based on if the element should be treated like a link, 712 // Changes based on if the element should be treated like a link,
702 // ex. When setting the href attribute on an <a>. 713 // ex. When setting the href attribute on an <a>.
703 IsLinkFlag = 1 << 8, 714 IsLinkFlag = 1 << 9,
704 715
705 // Changes based on :hover, :active and :focus state. 716 // Changes based on :hover, :active and :focus state.
706 IsUserActionElementFlag = 1 << 9, 717 IsUserActionElementFlag = 1 << 10,
707 718
708 // Tree state flags. These change when the element is added/removed 719 // Tree state flags. These change when the element is added/removed
709 // from a DOM tree. 720 // from a DOM tree.
710 InDocumentFlag = 1 << 10, 721 InDocumentFlag = 1 << 11,
711 IsInShadowTreeFlag = 1 << 11, 722 IsInShadowTreeFlag = 1 << 12,
712 723
713 // Set by the parser when the children are done parsing. 724 // Set by the parser when the children are done parsing.
714 IsFinishedParsingChildrenFlag = 1 << 12, 725 IsFinishedParsingChildrenFlag = 1 << 13,
715 726
716 // Flags related to recalcStyle. 727 // Flags related to recalcStyle.
717 SVGFilterNeedsLayerUpdateFlag = 1 << 13, 728 SVGFilterNeedsLayerUpdateFlag = 1 << 14,
718 HasCustomStyleCallbacksFlag = 1 << 14, 729 HasCustomStyleCallbacksFlag = 1 << 15,
719 ChildNeedsStyleInvalidationFlag = 1 << 15, 730 ChildNeedsStyleInvalidationFlag = 1 << 16,
720 NeedsStyleInvalidationFlag = 1 << 16, 731 NeedsStyleInvalidationFlag = 1 << 17,
721 ChildNeedsDistributionRecalcFlag = 1 << 17, 732 ChildNeedsDistributionRecalcFlag = 1 << 18,
722 ChildNeedsStyleRecalcFlag = 1 << 18, 733 ChildNeedsStyleRecalcFlag = 1 << 19,
723 StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1), 734 StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1),
724 735
725 CustomElementFlag = 1 << 21, 736 CustomElementFlag = 1 << 22,
726 CustomElementCustomFlag = 1 << 22, 737 CustomElementCustomFlag = 1 << 23,
727 738
728 HasNameOrIsEditingTextFlag = 1 << 23, 739 HasNameOrIsEditingTextFlag = 1 << 24,
729 HasWeakReferencesFlag = 1 << 24, 740 HasWeakReferencesFlag = 1 << 25,
730 V8CollectableDuringMinorGCFlag = 1 << 25, 741 V8CollectableDuringMinorGCFlag = 1 << 26,
731 HasEventTargetDataFlag = 1 << 26, 742 HasEventTargetDataFlag = 1 << 27,
732 AlreadySpellCheckedFlag = 1 << 27, 743 AlreadySpellCheckedFlag = 1 << 28,
733 744
734 V0CustomElementFlag = 1 << 28, 745 V0CustomElementFlag = 1 << 28,
Timothy Loh 2016/06/01 07:36:38 don't these need to change too?
735 V0CustomElementUpgradedFlag = 1 << 29, 746 V0CustomElementUpgradedFlag = 1 << 29,
736 747
737 DefaultNodeFlags = IsFinishedParsingChildrenFlag | NeedsReattachStyleCha nge 748 DefaultNodeFlags = IsFinishedParsingChildrenFlag | NeedsReattachStyleCha nge
738 }; 749 };
739 750
740 // 3 bits remaining. 751 // 3 bits remaining.
Timothy Loh 2016/06/01 07:36:38 needs to be updated?
741 752
742 bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; } 753 bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
743 void setFlag(bool f, NodeFlags mask) { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); } 754 void setFlag(bool f, NodeFlags mask) { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); }
744 void setFlag(NodeFlags mask) { m_nodeFlags |= mask; } 755 void setFlag(NodeFlags mask) { m_nodeFlags |= mask; }
745 void clearFlag(NodeFlags mask) { m_nodeFlags &= ~mask; } 756 void clearFlag(NodeFlags mask) { m_nodeFlags &= ~mask; }
746 757
747 protected: 758 protected:
748 enum ConstructionType { 759 enum ConstructionType {
749 CreateOther = DefaultNodeFlags, 760 CreateOther = DefaultNodeFlags,
750 CreateText = DefaultNodeFlags | IsTextFlag, 761 CreateText = DefaultNodeFlags | IsTextFlag,
(...skipping 11 matching lines...) Expand all
762 Node(TreeScope*, ConstructionType); 773 Node(TreeScope*, ConstructionType);
763 774
764 virtual void didMoveToNewDocument(Document& oldDocument); 775 virtual void didMoveToNewDocument(Document& oldDocument);
765 776
766 void addedEventListener(const AtomicString& eventType, RegisteredEventListen er&) override; 777 void addedEventListener(const AtomicString& eventType, RegisteredEventListen er&) override;
767 void removedEventListener(const AtomicString& eventType, const RegisteredEve ntListener&) override; 778 void removedEventListener(const AtomicString& eventType, const RegisteredEve ntListener&) override;
768 DispatchEventResult dispatchEventInternal(Event*) override; 779 DispatchEventResult dispatchEventInternal(Event*) override;
769 780
770 static void reattachWhitespaceSiblingsIfNeeded(Text* start); 781 static void reattachWhitespaceSiblingsIfNeeded(Text* start);
771 782
783 bool hasLayoutObject() const { return getFlag(HasLayoutObjectFlag); }
772 bool hasRareData() const { return getFlag(HasRareDataFlag); } 784 bool hasRareData() const { return getFlag(HasRareDataFlag); }
773 785
774 NodeRareData* rareData() const; 786 NodeRareData* rareData() const;
775 NodeRareData& ensureRareData(); 787 NodeRareData& ensureRareData();
776 788
777 void setHasCustomStyleCallbacks() { setFlag(true, HasCustomStyleCallbacksFla g); } 789 void setHasCustomStyleCallbacks() { setFlag(true, HasCustomStyleCallbacksFla g); }
778 790
779 void setTreeScope(TreeScope* scope) { m_treeScope = scope; } 791 void setTreeScope(TreeScope* scope) { m_treeScope = scope; }
780 792
781 // isTreeScopeInitialized() can be false 793 // isTreeScopeInitialized() can be false
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 HeapVector<Member<MutationObserverRegistration>>* mutationObserverRegistry() ; 831 HeapVector<Member<MutationObserverRegistration>>* mutationObserverRegistry() ;
820 HeapHashSet<Member<MutationObserverRegistration>>* transientMutationObserver Registry(); 832 HeapHashSet<Member<MutationObserverRegistration>>* transientMutationObserver Registry();
821 833
822 uint32_t m_nodeFlags; 834 uint32_t m_nodeFlags;
823 Member<ContainerNode> m_parentOrShadowHostNode; 835 Member<ContainerNode> m_parentOrShadowHostNode;
824 Member<TreeScope> m_treeScope; 836 Member<TreeScope> m_treeScope;
825 Member<Node> m_previous; 837 Member<Node> m_previous;
826 Member<Node> m_next; 838 Member<Node> m_next;
827 // When a node has rare data we move the layoutObject into the rare data. 839 // When a node has rare data we move the layoutObject into the rare data.
828 union DataUnion { 840 union DataUnion {
829 DataUnion() : m_layoutObject(nullptr) { } 841 DataUnion() : m_computedStyle(nullptr) { }
842 ComputedStyle* m_computedStyle;
830 // LayoutObjects are fully owned by their DOM node. See LayoutObject's 843 // LayoutObjects are fully owned by their DOM node. See LayoutObject's
831 // LIFETIME documentation section. 844 // LIFETIME documentation section.
832 LayoutObject* m_layoutObject; 845 LayoutObject* m_layoutObject;
833 NodeRareDataBase* m_rareData; 846 NodeRareDataBase* m_rareData;
834 } m_data; 847 } m_data;
835 }; 848 };
836 849
837 inline void Node::setParentOrShadowHostNode(ContainerNode* parent) 850 inline void Node::setParentOrShadowHostNode(ContainerNode* parent)
838 { 851 {
839 DCHECK(isMainThread()); 852 DCHECK(isMainThread());
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 } // namespace blink 927 } // namespace blink
915 928
916 #ifndef NDEBUG 929 #ifndef NDEBUG
917 // Outside the WebCore namespace for ease of invocation from gdb. 930 // Outside the WebCore namespace for ease of invocation from gdb.
918 void showNode(const blink::Node*); 931 void showNode(const blink::Node*);
919 void showTree(const blink::Node*); 932 void showTree(const blink::Node*);
920 void showNodePath(const blink::Node*); 933 void showNodePath(const blink::Node*);
921 #endif 934 #endif
922 935
923 #endif // Node_h 936 #endif // Node_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698