| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright (C) 2012 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. |
| 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 #include "config.h" |
| 32 #include "bindings/dart/DartCustomElementWrapper.h" |
| 33 |
| 34 #include "DartHTMLElement.h" |
| 35 #include "DartHTMLElementWrapperFactory.h" |
| 36 #include "DartSVGElement.h" |
| 37 #include "DartSVGElementWrapperFactory.h" |
| 38 #include "bindings/dart/DartCustomElementLifecycleCallbacks.h" |
| 39 #include "core/dom/CustomElement.h" |
| 40 #include "core/html/HTMLElement.h" |
| 41 #include "core/html/HTMLUnknownElement.h" |
| 42 #include "core/svg/SVGElement.h" |
| 43 |
| 44 namespace WebCore { |
| 45 |
| 46 template<typename ElementType> |
| 47 Dart_Handle createDartDirectWrapper(ElementType*); |
| 48 |
| 49 template<> |
| 50 Dart_Handle createDartDirectWrapper<HTMLElement>(HTMLElement* element) |
| 51 { |
| 52 return DartDOMWrapper::createWrapper<DartHTMLElement>(element); |
| 53 } |
| 54 |
| 55 template<> |
| 56 Dart_Handle createDartDirectWrapper<SVGElement>(SVGElement* element) |
| 57 { |
| 58 return DartDOMWrapper::createWrapper<DartSVGElement>(element); |
| 59 } |
| 60 |
| 61 template<typename ElementType> |
| 62 Dart_Handle createDartFallbackWrapper(ElementType*); |
| 63 |
| 64 template<> |
| 65 Dart_Handle createDartFallbackWrapper<HTMLElement>(HTMLElement* element) |
| 66 { |
| 67 return createDartHTMLFallbackWrapper(toHTMLUnknownElement(element)); |
| 68 } |
| 69 |
| 70 template<> |
| 71 Dart_Handle createDartFallbackWrapper<SVGElement>(SVGElement* element) |
| 72 { |
| 73 return createDartSVGFallbackWrapper(element); |
| 74 } |
| 75 |
| 76 template<typename ElementType> |
| 77 Dart_Handle createUpgradeCandidateWrapper(ElementType* element, Dart_Handle (*cr
eateSpecificWrapper)(ElementType* element)) |
| 78 { |
| 79 if (CustomElement::isValidName(element->localName())) |
| 80 return createDartDirectWrapper(element); |
| 81 if (createSpecificWrapper) |
| 82 return createSpecificWrapper(element); |
| 83 return createDartFallbackWrapper(element); |
| 84 } |
| 85 |
| 86 template<typename ElementType> |
| 87 Dart_Handle DartCustomElementWrapper<ElementType>::wrap(PassRefPtr<ElementType>
element, Dart_Handle (*createSpecificWrapper)(ElementType* element)) |
| 88 { |
| 89 if (!element->isUpgradedCustomElement()) |
| 90 return createUpgradeCandidateWrapper(element.get(), createSpecificWrappe
r); |
| 91 |
| 92 return upgradeDartWrapper(element.get()); |
| 93 } |
| 94 |
| 95 template<> |
| 96 Dart_Handle DartCustomElementWrapper<HTMLElement>::upgradeDartWrapper(HTMLElemen
t* element) |
| 97 { |
| 98 DartDOMData* domData = DartDOMData::current(); |
| 99 DartCustomElementBinding* binding = domData->customElementBinding(CustomElem
ent::definitionFor(element)); |
| 100 Dart_Handle customType = binding->customType(); |
| 101 ASSERT(!Dart_IsError(customType)); |
| 102 |
| 103 Dart_WeakPersistentHandle oldInstance = DartDOMWrapper::lookupWrapper(DartHT
MLElement::isNode, reinterpret_cast<HTMLElement*>(element)); |
| 104 if (oldInstance) |
| 105 DartDOMWrapper::disassociateWrapper<DartHTMLElement>(reinterpret_cast<HT
MLElement*>(element), Dart_HandleFromWeakPersistent(oldInstance)); |
| 106 |
| 107 Dart_Handle newInstance = Dart_Allocate(customType); |
| 108 ASSERT(!Dart_IsError(newInstance)); |
| 109 |
| 110 Dart_Handle result = Dart_SetNativeInstanceField(newInstance, 0, reinterpret
_cast<intptr_t>(element)); |
| 111 UNUSED_PARAM(result); |
| 112 ASSERT(!Dart_IsError(result)); |
| 113 |
| 114 DartDOMWrapper::associateWrapper<DartHTMLElement>(reinterpret_cast<HTMLEleme
nt*>(element), newInstance); |
| 115 Dart_Invoke(newInstance, Dart_NewStringFromCString("created"), 0, 0); |
| 116 return newInstance; |
| 117 } |
| 118 |
| 119 template<> |
| 120 Dart_Handle DartCustomElementWrapper<SVGElement>::upgradeDartWrapper(SVGElement*
element) |
| 121 { |
| 122 // TODO: support SVG elements. |
| 123 ASSERT(FALSE); |
| 124 return Dart_Handle(); |
| 125 } |
| 126 |
| 127 template |
| 128 class DartCustomElementWrapper<HTMLElement>; |
| 129 |
| 130 template |
| 131 class DartCustomElementWrapper<SVGElement>; |
| 132 |
| 133 } // namespace WebCore |
| OLD | NEW |