| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution.z | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #ifndef SKY_ENGINE_PUBLIC_WEB_WEBNODE_H_ | |
| 32 #define SKY_ENGINE_PUBLIC_WEB_WEBNODE_H_ | |
| 33 | |
| 34 #include "../platform/WebCommon.h" | |
| 35 #include "../platform/WebPrivatePtr.h" | |
| 36 #include "../platform/WebString.h" | |
| 37 #include "sky/engine/public/web/WebExceptionCode.h" | |
| 38 | |
| 39 namespace blink { | |
| 40 | |
| 41 class Node; | |
| 42 class WebDocument; | |
| 43 class WebElement; | |
| 44 | |
| 45 // Provides access to some properties of a DOM node. | |
| 46 // Note that the class design requires that neither this class nor any of its su
bclasses have any virtual | |
| 47 // methods (other than the destructor), so that it is possible to safely static_
cast an instance of one | |
| 48 // class to the appropriate subclass based on the actual type of the wrapped bli
nk::Node. For the same | |
| 49 // reason, subclasses must not add any additional data members. | |
| 50 class WebNode { | |
| 51 public: | |
| 52 virtual ~WebNode() { reset(); } | |
| 53 | |
| 54 WebNode() { } | |
| 55 WebNode(const WebNode& n) { assign(n); } | |
| 56 WebNode& operator=(const WebNode& n) | |
| 57 { | |
| 58 assign(n); | |
| 59 return *this; | |
| 60 } | |
| 61 | |
| 62 BLINK_EXPORT void reset(); | |
| 63 BLINK_EXPORT void assign(const WebNode&); | |
| 64 | |
| 65 BLINK_EXPORT bool equals(const WebNode&) const; | |
| 66 // Required for using WebNodes in std maps. Note the order used is | |
| 67 // arbitrary and should not be expected to have any specific meaning. | |
| 68 BLINK_EXPORT bool lessThan(const WebNode&) const; | |
| 69 | |
| 70 bool isNull() const { return m_private.isNull(); } | |
| 71 | |
| 72 enum NodeType { | |
| 73 ElementNode = 1, | |
| 74 TextNode = 3, | |
| 75 CDataSectionNode = 4, | |
| 76 // EntityReferenceNodes are impossible to create in Blink. | |
| 77 // EntityNodes are impossible to create in Blink. | |
| 78 ProcessingInstructionsNode = 7, | |
| 79 CommentNode = 8, | |
| 80 DocumentNode = 9, | |
| 81 DocumentTypeNode = 10, | |
| 82 DocumentFragmentNode = 11, | |
| 83 // NotationNodes are impossible to create in Blink. | |
| 84 // XPathNamespaceNodes are impossible to create in Blink. | |
| 85 ShadowRootNode = 14 | |
| 86 }; | |
| 87 | |
| 88 BLINK_EXPORT NodeType nodeType() const; | |
| 89 BLINK_EXPORT WebNode parentNode() const; | |
| 90 BLINK_EXPORT WebString nodeName() const; | |
| 91 BLINK_EXPORT WebDocument document() const; | |
| 92 BLINK_EXPORT WebNode firstChild() const; | |
| 93 BLINK_EXPORT WebNode lastChild() const; | |
| 94 BLINK_EXPORT WebNode previousSibling() const; | |
| 95 BLINK_EXPORT WebNode nextSibling() const; | |
| 96 BLINK_EXPORT bool hasChildNodes() const; | |
| 97 BLINK_EXPORT bool isLink() const; | |
| 98 BLINK_EXPORT bool isTextNode() const; | |
| 99 BLINK_EXPORT bool isFocusable() const; | |
| 100 BLINK_EXPORT bool isContentEditable() const; | |
| 101 BLINK_EXPORT bool isElementNode() const; | |
| 102 BLINK_EXPORT WebElement querySelector(const WebString&, WebExceptionCode&) c
onst; | |
| 103 BLINK_EXPORT WebElement rootEditableElement() const; | |
| 104 BLINK_EXPORT bool focused() const; | |
| 105 BLINK_EXPORT bool remove(); | |
| 106 | |
| 107 BLINK_EXPORT bool containsIncludingShadowDOM(const WebNode&) const; | |
| 108 BLINK_EXPORT WebElement shadowHost() const; | |
| 109 | |
| 110 template<typename T> T to() | |
| 111 { | |
| 112 T res; | |
| 113 res.WebNode::assign(*this); | |
| 114 return res; | |
| 115 } | |
| 116 | |
| 117 template<typename T> const T toConst() const | |
| 118 { | |
| 119 T res; | |
| 120 res.WebNode::assign(*this); | |
| 121 return res; | |
| 122 } | |
| 123 | |
| 124 #if BLINK_IMPLEMENTATION | |
| 125 WebNode(const PassRefPtr<Node>&); | |
| 126 WebNode& operator=(const PassRefPtr<Node>&); | |
| 127 operator PassRefPtr<Node>() const; | |
| 128 #endif | |
| 129 | |
| 130 #if BLINK_IMPLEMENTATION | |
| 131 template<typename T> T* unwrap() | |
| 132 { | |
| 133 return static_cast<T*>(m_private.get()); | |
| 134 } | |
| 135 | |
| 136 template<typename T> const T* constUnwrap() const | |
| 137 { | |
| 138 return static_cast<const T*>(m_private.get()); | |
| 139 } | |
| 140 #endif | |
| 141 | |
| 142 protected: | |
| 143 WebPrivatePtr<Node> m_private; | |
| 144 }; | |
| 145 | |
| 146 inline bool operator==(const WebNode& a, const WebNode& b) | |
| 147 { | |
| 148 return a.equals(b); | |
| 149 } | |
| 150 | |
| 151 inline bool operator!=(const WebNode& a, const WebNode& b) | |
| 152 { | |
| 153 return !(a == b); | |
| 154 } | |
| 155 | |
| 156 inline bool operator<(const WebNode& a, const WebNode& b) | |
| 157 { | |
| 158 return a.lessThan(b); | |
| 159 } | |
| 160 | |
| 161 } // namespace blink | |
| 162 | |
| 163 #endif // SKY_ENGINE_PUBLIC_WEB_WEBNODE_H_ | |
| OLD | NEW |