| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2011, Google Inc. |
| 2 // 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. |
| 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 #include "config.h" |
| 31 #include "bindings/core/dart/DartNode.h" |
| 32 |
| 33 #include "bindings/core/dart/DartAttr.h" |
| 34 #include "bindings/core/dart/DartCDATASection.h" |
| 35 #include "bindings/core/dart/DartComment.h" |
| 36 #include "bindings/core/dart/DartDOMWrapper.h" |
| 37 #include "bindings/core/dart/DartDocument.h" |
| 38 #include "bindings/core/dart/DartDocumentFragment.h" |
| 39 #include "bindings/core/dart/DartDocumentType.h" |
| 40 #include "bindings/core/dart/DartElement.h" |
| 41 #include "bindings/core/dart/DartProcessingInstruction.h" |
| 42 #include "bindings/core/dart/DartShadowRoot.h" |
| 43 #include "bindings/core/dart/DartText.h" |
| 44 #include "core/dom/custom/CustomElementCallbackDispatcher.h" |
| 45 |
| 46 namespace blink { |
| 47 |
| 48 namespace DartNodeInternal { |
| 49 |
| 50 // This function is customized to take advantage of the optional 4th argument: s
houldLazyAttach. |
| 51 void insertBeforeCallback(Dart_NativeArguments args) |
| 52 { |
| 53 Dart_Handle exception = 0; |
| 54 { |
| 55 Node* receiver = DartDOMWrapper::receiver<Node>(args); |
| 56 |
| 57 Node* newChild = DartNode::toNativeWithNullCheck(args, 1, exception); |
| 58 if (exception) |
| 59 goto fail; |
| 60 |
| 61 Node* refChild = DartNode::toNativeWithNullCheck(args, 2, exception); |
| 62 if (exception) |
| 63 goto fail; |
| 64 |
| 65 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
| 66 |
| 67 DartExceptionState es; |
| 68 receiver->insertBefore(newChild, refChild, es); |
| 69 if (es.hadException()) { |
| 70 exception = es.toDart(args); |
| 71 goto fail; |
| 72 } |
| 73 |
| 74 DartDOMWrapper::returnToDart<DartNode>(args, newChild); |
| 75 return; |
| 76 } |
| 77 |
| 78 fail: |
| 79 Dart_ThrowException(exception); |
| 80 ASSERT_NOT_REACHED(); |
| 81 } |
| 82 |
| 83 // This function is customized to take advantage of the optional 4th argument: s
houldLazyAttach. |
| 84 void replaceChildCallback(Dart_NativeArguments args) |
| 85 { |
| 86 Dart_Handle exception = 0; |
| 87 { |
| 88 Node* receiver = DartDOMWrapper::receiver<Node>(args); |
| 89 |
| 90 Node* newChild = DartNode::toNativeWithNullCheck(args, 1, exception); |
| 91 if (exception) |
| 92 goto fail; |
| 93 |
| 94 Node* oldChild = DartNode::toNativeWithNullCheck(args, 2, exception); |
| 95 if (exception) |
| 96 goto fail; |
| 97 |
| 98 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
| 99 |
| 100 DartExceptionState es; |
| 101 receiver->replaceChild(newChild, oldChild, es); |
| 102 if (es.hadException()) { |
| 103 exception = es.toDart(args); |
| 104 goto fail; |
| 105 } |
| 106 |
| 107 DartDOMWrapper::returnToDart<DartNode>(args, newChild); |
| 108 return; |
| 109 } |
| 110 |
| 111 fail: |
| 112 Dart_ThrowException(exception); |
| 113 ASSERT_NOT_REACHED(); |
| 114 } |
| 115 |
| 116 // Custom handling of the return value. |
| 117 void removeChildCallback(Dart_NativeArguments args) |
| 118 { |
| 119 Dart_Handle exception = 0; |
| 120 { |
| 121 Node* receiver = DartDOMWrapper::receiver<Node>(args); |
| 122 |
| 123 Node* child = DartNode::toNativeWithNullCheck(args, 1, exception); |
| 124 if (exception) |
| 125 goto fail; |
| 126 |
| 127 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
| 128 |
| 129 DartExceptionState es; |
| 130 receiver->removeChild(child, es); |
| 131 if (es.hadException()) { |
| 132 exception = es.toDart(args); |
| 133 goto fail; |
| 134 } |
| 135 |
| 136 DartDOMWrapper::returnToDart<DartNode>(args, child); |
| 137 return; |
| 138 } |
| 139 |
| 140 fail: |
| 141 Dart_ThrowException(exception); |
| 142 ASSERT_NOT_REACHED(); |
| 143 } |
| 144 |
| 145 // This function is customized to enable lazy attaching - see the last argument
to appendChild. |
| 146 void appendChildCallback(Dart_NativeArguments args) |
| 147 { |
| 148 Dart_Handle exception = 0; |
| 149 { |
| 150 Node* receiver = DartDOMWrapper::receiver<Node>(args); |
| 151 |
| 152 Node* child = DartNode::toNativeWithNullCheck(args, 1, exception); |
| 153 if (exception) |
| 154 goto fail; |
| 155 |
| 156 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
| 157 |
| 158 DartExceptionState es; |
| 159 receiver->appendChild(child, es); |
| 160 if (es.hadException()) { |
| 161 exception = es.toDart(args); |
| 162 goto fail; |
| 163 } |
| 164 |
| 165 DartDOMWrapper::returnToDart<DartNode>(args, child); |
| 166 return; |
| 167 } |
| 168 |
| 169 fail: |
| 170 Dart_ThrowException(exception); |
| 171 ASSERT_NOT_REACHED(); |
| 172 } |
| 173 |
| 174 void cloneNodeCallback(Dart_NativeArguments args) |
| 175 { |
| 176 Dart_Handle exception = 0; |
| 177 { |
| 178 Node* receiver = DartDOMWrapper::receiver< Node >(args); |
| 179 |
| 180 bool deep = DartUtilities::dartToBool(args, 1, exception); |
| 181 if (exception) |
| 182 goto fail; |
| 183 |
| 184 RefPtr<Node> result; |
| 185 { |
| 186 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope
; |
| 187 |
| 188 result = receiver->cloneNode(deep); |
| 189 } |
| 190 |
| 191 DartNode::returnToDart(args, result); |
| 192 return; |
| 193 } |
| 194 |
| 195 fail: |
| 196 Dart_ThrowException(exception); |
| 197 ASSERT_NOT_REACHED(); |
| 198 } |
| 199 |
| 200 } |
| 201 |
| 202 Dart_Handle DartNode::createWrapper(DartDOMData* domData, Node* node) |
| 203 { |
| 204 if (!node) |
| 205 return Dart_Null(); |
| 206 |
| 207 switch (node->nodeType()) { |
| 208 case Node::ELEMENT_NODE: |
| 209 return DartElement::createWrapper(domData, static_cast<Element*>(node)); |
| 210 case Node::ATTRIBUTE_NODE: |
| 211 return DartAttr::createWrapper(domData, static_cast<Attr*>(node)); |
| 212 case Node::TEXT_NODE: |
| 213 return DartText::createWrapper(domData, toText(node)); |
| 214 case Node::CDATA_SECTION_NODE: |
| 215 return DartCDATASection::createWrapper(domData, static_cast<CDATASection
*>(node)); |
| 216 case Node::PROCESSING_INSTRUCTION_NODE: |
| 217 return DartProcessingInstruction::createWrapper(domData, static_cast<Pro
cessingInstruction*>(node)); |
| 218 case Node::COMMENT_NODE: |
| 219 return DartComment::createWrapper(domData, static_cast<Comment*>(node)); |
| 220 case Node::DOCUMENT_NODE: |
| 221 return DartDocument::createWrapper(domData, static_cast<Document*>(node)
); |
| 222 case Node::DOCUMENT_TYPE_NODE: |
| 223 return DartDocumentType::createWrapper(domData, static_cast<DocumentType
*>(node)); |
| 224 case Node::DOCUMENT_FRAGMENT_NODE: |
| 225 if (node->isShadowRoot()) |
| 226 return DartShadowRoot::createWrapper(domData, static_cast<ShadowRoot
*>(node)); |
| 227 return DartDocumentFragment::createWrapper(domData, static_cast<Document
Fragment*>(node)); |
| 228 default: break; // XPATH_NAMESPACE_NODE |
| 229 } |
| 230 return DartDOMWrapper::createWrapper<DartNode>(domData, node); |
| 231 } |
| 232 |
| 233 } |
| OLD | NEW |