| Index: Source/bindings/dart/DartCustomElementWrapper.cpp
|
| diff --git a/Source/bindings/dart/DartCustomElementWrapper.cpp b/Source/bindings/dart/DartCustomElementWrapper.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8a0be71a8aaa0283c422c5fdf80b8e8fb271b31d
|
| --- /dev/null
|
| +++ b/Source/bindings/dart/DartCustomElementWrapper.cpp
|
| @@ -0,0 +1,133 @@
|
| +/*
|
| + * Copyright (C) 2012 Google Inc. All rights reserved.
|
| + *
|
| + * Redistribution and use in source and binary forms, with or without
|
| + * modification, are permitted provided that the following conditions are
|
| + * met:
|
| + *
|
| + * * Redistributions of source code must retain the above copyright
|
| + * notice, this list of conditions and the following disclaimer.
|
| + * * Redistributions in binary form must reproduce the above
|
| + * copyright notice, this list of conditions and the following disclaimer
|
| + * in the documentation and/or other materials provided with the
|
| + * distribution.
|
| + * * Neither the name of Google Inc. nor the names of its
|
| + * contributors may be used to endorse or promote products derived from
|
| + * this software without specific prior written permission.
|
| + *
|
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + */
|
| +
|
| +#include "config.h"
|
| +#include "bindings/dart/DartCustomElementWrapper.h"
|
| +
|
| +#include "DartHTMLElement.h"
|
| +#include "DartHTMLElementWrapperFactory.h"
|
| +#include "DartSVGElement.h"
|
| +#include "DartSVGElementWrapperFactory.h"
|
| +#include "bindings/dart/DartCustomElementLifecycleCallbacks.h"
|
| +#include "core/dom/CustomElement.h"
|
| +#include "core/html/HTMLElement.h"
|
| +#include "core/html/HTMLUnknownElement.h"
|
| +#include "core/svg/SVGElement.h"
|
| +
|
| +namespace WebCore {
|
| +
|
| +template<typename ElementType>
|
| +Dart_Handle createDartDirectWrapper(ElementType*);
|
| +
|
| +template<>
|
| +Dart_Handle createDartDirectWrapper<HTMLElement>(HTMLElement* element)
|
| +{
|
| + return DartDOMWrapper::createWrapper<DartHTMLElement>(element);
|
| +}
|
| +
|
| +template<>
|
| +Dart_Handle createDartDirectWrapper<SVGElement>(SVGElement* element)
|
| +{
|
| + return DartDOMWrapper::createWrapper<DartSVGElement>(element);
|
| +}
|
| +
|
| +template<typename ElementType>
|
| +Dart_Handle createDartFallbackWrapper(ElementType*);
|
| +
|
| +template<>
|
| +Dart_Handle createDartFallbackWrapper<HTMLElement>(HTMLElement* element)
|
| +{
|
| + return createDartHTMLFallbackWrapper(toHTMLUnknownElement(element));
|
| +}
|
| +
|
| +template<>
|
| +Dart_Handle createDartFallbackWrapper<SVGElement>(SVGElement* element)
|
| +{
|
| + return createDartSVGFallbackWrapper(element);
|
| +}
|
| +
|
| +template<typename ElementType>
|
| +Dart_Handle createUpgradeCandidateWrapper(ElementType* element, Dart_Handle (*createSpecificWrapper)(ElementType* element))
|
| +{
|
| + if (CustomElement::isValidName(element->localName()))
|
| + return createDartDirectWrapper(element);
|
| + if (createSpecificWrapper)
|
| + return createSpecificWrapper(element);
|
| + return createDartFallbackWrapper(element);
|
| +}
|
| +
|
| +template<typename ElementType>
|
| +Dart_Handle DartCustomElementWrapper<ElementType>::wrap(PassRefPtr<ElementType> element, Dart_Handle (*createSpecificWrapper)(ElementType* element))
|
| +{
|
| + if (!element->isUpgradedCustomElement())
|
| + return createUpgradeCandidateWrapper(element.get(), createSpecificWrapper);
|
| +
|
| + return upgradeDartWrapper(element.get());
|
| +}
|
| +
|
| +template<>
|
| +Dart_Handle DartCustomElementWrapper<HTMLElement>::upgradeDartWrapper(HTMLElement* element)
|
| +{
|
| + DartDOMData* domData = DartDOMData::current();
|
| + DartCustomElementBinding* binding = domData->customElementBinding(CustomElement::definitionFor(element));
|
| + Dart_Handle customType = binding->customType();
|
| + ASSERT(!Dart_IsError(customType));
|
| +
|
| + Dart_WeakPersistentHandle oldInstance = DartDOMWrapper::lookupWrapper(DartHTMLElement::isNode, reinterpret_cast<HTMLElement*>(element));
|
| + if (oldInstance)
|
| + DartDOMWrapper::disassociateWrapper<DartHTMLElement>(reinterpret_cast<HTMLElement*>(element), Dart_HandleFromWeakPersistent(oldInstance));
|
| +
|
| + Dart_Handle newInstance = Dart_Allocate(customType);
|
| + ASSERT(!Dart_IsError(newInstance));
|
| +
|
| + Dart_Handle result = Dart_SetNativeInstanceField(newInstance, 0, reinterpret_cast<intptr_t>(element));
|
| + UNUSED_PARAM(result);
|
| + ASSERT(!Dart_IsError(result));
|
| +
|
| + DartDOMWrapper::associateWrapper<DartHTMLElement>(reinterpret_cast<HTMLElement*>(element), newInstance);
|
| + Dart_Invoke(newInstance, Dart_NewStringFromCString("created"), 0, 0);
|
| + return newInstance;
|
| +}
|
| +
|
| +template<>
|
| +Dart_Handle DartCustomElementWrapper<SVGElement>::upgradeDartWrapper(SVGElement* element)
|
| +{
|
| + // TODO: support SVG elements.
|
| + ASSERT(FALSE);
|
| + return Dart_Handle();
|
| +}
|
| +
|
| +template
|
| +class DartCustomElementWrapper<HTMLElement>;
|
| +
|
| +template
|
| +class DartCustomElementWrapper<SVGElement>;
|
| +
|
| +} // namespace WebCore
|
|
|