| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 3 * Copyright (C) 2011 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR | 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR |
| 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef HTMLElementStack_h | 27 #ifndef HTMLElementStack_h |
| 28 #define HTMLElementStack_h | 28 #define HTMLElementStack_h |
| 29 | 29 |
| 30 #include "core/html/parser/HTMLStackItem.h" | 30 #include "core/dom/Element.h" |
| 31 #include "wtf/Forward.h" | 31 #include "wtf/Forward.h" |
| 32 #include "wtf/Noncopyable.h" | 32 #include "wtf/Noncopyable.h" |
| 33 #include "wtf/OwnPtr.h" | 33 #include "wtf/OwnPtr.h" |
| 34 #include "wtf/PassOwnPtr.h" | 34 #include "wtf/PassOwnPtr.h" |
| 35 #include "wtf/RefPtr.h" | 35 #include "wtf/RefPtr.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 class ContainerNode; | 39 class ContainerNode; |
| 40 class DocumentFragment; | 40 class DocumentFragment; |
| 41 class Element; | 41 class Element; |
| 42 class QualifiedName; | 42 class QualifiedName; |
| 43 | 43 |
| 44 // NOTE: The HTML5 spec uses a backwards (grows downward) stack. We're using | 44 // NOTE: The HTML5 spec uses a backwards (grows downward) stack. We're using |
| 45 // more standard (grows upwards) stack terminology here. | 45 // more standard (grows upwards) stack terminology here. |
| 46 class HTMLElementStack { | 46 class HTMLElementStack { |
| 47 WTF_MAKE_NONCOPYABLE(HTMLElementStack); | 47 WTF_MAKE_NONCOPYABLE(HTMLElementStack); |
| 48 DISALLOW_ALLOCATION(); | 48 DISALLOW_ALLOCATION(); |
| 49 public: | 49 public: |
| 50 HTMLElementStack(); | 50 HTMLElementStack(); |
| 51 ~HTMLElementStack(); | 51 ~HTMLElementStack(); |
| 52 | 52 |
| 53 class ElementRecord FINAL : public NoBaseWillBeGarbageCollected<ElementRecor
d> { | 53 class ElementRecord { |
| 54 WTF_MAKE_NONCOPYABLE(ElementRecord); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REM
OVED; | 54 WTF_MAKE_NONCOPYABLE(ElementRecord); WTF_MAKE_FAST_ALLOCATED; |
| 55 public: | 55 public: |
| 56 #if !ENABLE(OILPAN) | 56 ElementRecord(PassRefPtr<ContainerNode>, PassOwnPtr<ElementRecord>); |
| 57 ~ElementRecord(); // Public for ~PassOwnPtr() | 57 ~ElementRecord(); |
| 58 #endif | |
| 59 | 58 |
| 60 Element* element() const { return m_item->element(); } | 59 Element* element() const { return toElement(m_node.get()); } |
| 61 ContainerNode* node() const { return m_item->node(); } | 60 ContainerNode* node() const { return m_node.get(); } |
| 62 PassRefPtrWillBeRawPtr<HTMLStackItem> stackItem() const { return m_item;
} | |
| 63 | 61 |
| 64 ElementRecord* next() const { return m_next.get(); } | 62 ElementRecord* next() const { return m_next.get(); } |
| 65 | 63 |
| 66 void trace(Visitor*); | 64 PassOwnPtr<ElementRecord> releaseNext() { return m_next.release(); } |
| 65 void setNext(PassOwnPtr<ElementRecord> next) { m_next = next; } |
| 66 |
| 67 private: | 67 private: |
| 68 friend class HTMLElementStack; | 68 RefPtr<ContainerNode> m_node; |
| 69 | 69 OwnPtr<ElementRecord> m_next; |
| 70 ElementRecord(PassRefPtrWillBeRawPtr<HTMLStackItem>, PassOwnPtrWillBeRaw
Ptr<ElementRecord>); | |
| 71 | |
| 72 PassOwnPtrWillBeRawPtr<ElementRecord> releaseNext() { return m_next.rele
ase(); } | |
| 73 void setNext(PassOwnPtrWillBeRawPtr<ElementRecord> next) { m_next = next
; } | |
| 74 | |
| 75 RefPtrWillBeMember<HTMLStackItem> m_item; | |
| 76 OwnPtrWillBeMember<ElementRecord> m_next; | |
| 77 }; | 70 }; |
| 78 | 71 |
| 79 unsigned stackDepth() const { return m_stackDepth; } | 72 unsigned stackDepth() const { return m_stackDepth; } |
| 80 | 73 |
| 81 // Inlining this function is a (small) performance win on the parsing | 74 // Inlining this function is a (small) performance win on the parsing |
| 82 // benchmark. | 75 // benchmark. |
| 83 Element* top() const | 76 Element* top() const |
| 84 { | 77 { |
| 85 ASSERT(m_top->element()); | 78 ASSERT(m_top->element()); |
| 86 return m_top->element(); | 79 return m_top->element(); |
| 87 } | 80 } |
| 88 | 81 |
| 89 ContainerNode* topNode() const | 82 ContainerNode* topNode() const |
| 90 { | 83 { |
| 91 ASSERT(m_top->node()); | 84 ASSERT(m_top->node()); |
| 92 return m_top->node(); | 85 return m_top->node(); |
| 93 } | 86 } |
| 94 | 87 |
| 95 HTMLStackItem* topStackItem() const | 88 ElementRecord* topRecord() const; |
| 96 { | |
| 97 ASSERT(m_top->stackItem()); | |
| 98 return m_top->stackItem().get(); | |
| 99 } | |
| 100 | 89 |
| 101 HTMLStackItem* oneBelowTop() const; | 90 void push(PassRefPtr<ContainerNode>); |
| 102 ElementRecord* topRecord() const; | 91 void pushRootNode(PassRefPtr<ContainerNode>); |
| 103 ElementRecord* find(Element*) const; | |
| 104 ElementRecord* topmost(const AtomicString& tagName) const; | |
| 105 | |
| 106 void insertAbove(PassRefPtrWillBeRawPtr<HTMLStackItem>, ElementRecord*); | |
| 107 | |
| 108 void push(PassRefPtrWillBeRawPtr<HTMLStackItem>); | |
| 109 void pushRootNode(PassRefPtrWillBeRawPtr<HTMLStackItem>); | |
| 110 | 92 |
| 111 void pop(); | 93 void pop(); |
| 112 void popUntil(const AtomicString& tagName); | |
| 113 void popUntil(Element*); | 94 void popUntil(Element*); |
| 114 void popUntilPopped(Element*); | 95 void popUntilPopped(Element*); |
| 115 void popAll(); | 96 void popAll(); |
| 116 | 97 |
| 117 void remove(Element*); | 98 void remove(Element*); |
| 118 | |
| 119 bool contains(Element*) const; | |
| 120 bool contains(const AtomicString& tagName) const; | |
| 121 | |
| 122 bool inScope(Element*) const; | |
| 123 | |
| 124 bool hasOnlyOneElement() const; | 99 bool hasOnlyOneElement() const; |
| 125 | 100 |
| 126 ContainerNode* rootNode() const; | 101 ContainerNode* rootNode() const; |
| 127 | 102 |
| 128 void trace(Visitor*); | |
| 129 | |
| 130 #ifndef NDEBUG | 103 #ifndef NDEBUG |
| 131 void show(); | 104 void show(); |
| 132 #endif | 105 #endif |
| 133 | 106 |
| 134 private: | 107 private: |
| 135 void pushCommon(PassRefPtrWillBeRawPtr<HTMLStackItem>); | 108 void pushCommon(PassRefPtr<ContainerNode>); |
| 136 void popCommon(); | 109 void popCommon(); |
| 137 void removeNonTopCommon(Element*); | 110 void removeNonTopCommon(Element*); |
| 138 | 111 |
| 139 OwnPtrWillBeMember<ElementRecord> m_top; | 112 OwnPtr<ElementRecord> m_top; |
| 140 | 113 |
| 141 // We remember the root node, <head> and <body> as they are pushed. Their | 114 ContainerNode* m_rootNode; |
| 142 // ElementRecords keep them alive. The root node is never popped. | |
| 143 // FIXME: We don't currently require type-specific information about | |
| 144 // these elements so we haven't yet bothered to plumb the types all the | |
| 145 // way down through createElement, etc. | |
| 146 RawPtrWillBeMember<ContainerNode> m_rootNode; | |
| 147 unsigned m_stackDepth; | 115 unsigned m_stackDepth; |
| 148 }; | 116 }; |
| 149 | 117 |
| 150 } // namespace blink | 118 } // namespace blink |
| 151 | 119 |
| 152 #endif // HTMLElementStack_h | 120 #endif // HTMLElementStack_h |
| OLD | NEW |