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

Side by Side Diff: Source/bindings/dart/DartCustomElementWrapper.cpp

Issue 24294002: Dartium changes for custom element lifecycle events. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
(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::toDart<DartHTMLElement>(element);
53 }
54
55 template<>
56 Dart_Handle createDartDirectWrapper<SVGElement>(SVGElement* element)
57 {
58 return DartDOMWrapper::toDart<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_Handle oldInstance = DartDOMWrapper::lookupWrapper<DartHTMLElement>(rei nterpret_cast<HTMLElement*>(element));
104 if (oldInstance) {
105 // Previous wrapper exists. Test for upgrade.
106 Dart_Handle oldType = Dart_InstanceGetType(oldInstance);
107 if (Dart_IdentityEquals(oldType, customType)) {
108 return oldInstance;
109 }
110
111 DartDOMWrapper::disassociateWrapper<DartHTMLElement>(reinterpret_cast<HT MLElement*>(element), oldInstance);
112 }
113 Dart_Handle newInstance = Dart_Allocate(customType);
114 ASSERT(!Dart_IsError(newInstance));
115
116 Dart_Handle result = Dart_SetNativeInstanceField(newInstance, 0, reinterpret _cast<intptr_t>(element));
117 UNUSED_PARAM(result);
118 ASSERT(!Dart_IsError(result));
119
120 Dart_Handle wrapper = DartDOMWrapper::associateWrapper<DartHTMLElement>(rein terpret_cast<HTMLElement*>(element), newInstance);
121 Dart_Invoke(wrapper, Dart_NewStringFromCString("created"), 0, 0);
122 return wrapper;
123 }
124
125 template<>
126 Dart_Handle DartCustomElementWrapper<SVGElement>::upgradeDartWrapper(SVGElement* element)
127 {
128 // TODO: support SVG elements.
129 ASSERT(FALSE);
130 return Dart_Handle();
131 }
132
133 template
134 class DartCustomElementWrapper<HTMLElement>;
135
136 template
137 class DartCustomElementWrapper<SVGElement>;
138
139 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698