提交 085b988e 编写于 作者: A Adam Barth

Make it possible for sky-element to register any tag name

... instead of hard-coding "example".

We do this by adding a custom constructor for Element that gets the |tagName|
property off the instance.

R=esprehn@chromium.org

Review URL: https://codereview.chromium.org/943153002
上级 16db84fd
......@@ -13,6 +13,7 @@ source_set("bindings") {
"builtin_natives.h",
"builtin_sky.cc",
"builtin_sky.h",
"custom/dart_element_custom.cc",
"dart_callback.cc",
"dart_callback.h",
"dart_event_listener.cc",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/config.h"
#include "sky/engine/core/dom/Element.h"
#include "dart/runtime/include/dart_api.h"
#include "sky/engine/core/script/dom_dart_state.h"
#include "sky/engine/tonic/dart_converter.h"
namespace blink {
namespace DartElementInternal {
void constructorCallback(Dart_NativeArguments args) {
Dart_Handle receiver = Dart_GetNativeArgument(args, 0);
DCHECK(!LogIfError(receiver));
Dart_Handle tag_name = Dart_GetField(receiver,
Dart_NewStringFromCString("tagName"));
if (!Dart_IsString(tag_name)) {
Dart_ThrowException(Dart_NewStringFromCString("tagName is not a string"));
return;
}
RefPtr<Element> element = Element::create(
QualifiedName(StringFromDart(tag_name)), DOMDartState::CurrentDocument());
// TODO(abarth): We should remove these states because elements are never
// waiting for upgrades.
element->setCustomElementState(Element::WaitingForUpgrade);
element->setCustomElementState(Element::Upgraded);
element->AssociateWithDartWrapper(args);
}
} // namespace DartElementInternal
} // namespace blink
......@@ -19,11 +19,11 @@ part of sky.core;
{%- endfor -%}
{%- endmacro -%}
{% if not constructors %}abstract {% endif -%}
{% if not constructors and not custom_constructors %}abstract {% endif -%}
class {{interface_name}} extends {{ parent_interface if parent_interface else 'NativeFieldWrapperClass2' }} {
// Constructors
{# TODO(eseidel): We only ever have one constructor. #}
{%- for constructor in constructors %}
{%- for constructor in constructors + custom_constructors %}
void _constructor(
{%- for arg in constructor.arguments -%}
{{ arg.dart_type }} {{ arg.name }}{% if not loop.last %}, {% endif %}
......
......@@ -87,17 +87,6 @@
namespace blink {
PassRefPtr<Element> Element::create(Document& document, const AtomicString& tagName)
{
DCHECK(DartState::Current()) << "This function should be used only by the bindings";
RefPtr<Element> element = create(QualifiedName(tagName), &document);
// TODO(abarth): We should remove these states because elements are never
// waiting for upgrades.
element->setCustomElementState(Element::WaitingForUpgrade);
element->setCustomElementState(Element::Upgraded);
return element.release();
}
PassRefPtr<Element> Element::create(const QualifiedName& tagName, Document* document)
{
return adoptRef(new Element(tagName, document, CreateElement));
......
......@@ -65,9 +65,6 @@ enum SpellcheckAttributeState {
class Element : public ContainerNode {
DEFINE_WRAPPERTYPEINFO();
public:
// Used for custom elements.
static PassRefPtr<Element> create(Document& document, const AtomicString& tagName);
static PassRefPtr<Element> create(const QualifiedName&, Document*);
virtual ~Element();
......
......@@ -3,8 +3,7 @@
// found in the LICENSE file.
[
Constructor(DOMString tagName),
ConstructorCallWith=Document,
CustomConstructor,
] interface Element : ParentNode {
readonly attribute DOMString tagName;
......
......@@ -34,9 +34,7 @@ abstract class SkyElement extends Element {
String get tagName => _getTagName(runtimeType);
// TODO(abarth): Rather than hard-coding "example" here, we should make the
// bindings read the |tagName| property of this object during construction.
SkyElement() : super("example") {
SkyElement() {
created();
// Invoke attributeChanged callback when element is first created too.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册