Custom Elements Refactoring: CustomElementConstructor API shouldn't bound to HTMLElement
authormorrita@google.com <morrita@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Mar 2013 06:32:27 +0000 (06:32 +0000)
committermorrita@google.com <morrita@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Mar 2013 06:32:27 +0000 (06:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=111678

Reviewed by Kentaro Hara.

The latest Custom Elements standard supports non-HTML custom elements. Even though current implementation
support only HTML, it'd be better off to make API generic enough to support them.

This change

- eliminates HTMLElement from the API signature by replacing it with Element, and
- rename V8HTMLCustomElement to V8CustomElement.

No new tests, just changing signatures and a class name.

* WebCore.gypi:
* bindings/v8/V8CustomElement.cpp: Renamed from Source/WebCore/bindings/v8/V8HTMLCustomElement.cpp.
(WebCore):
(WebCore::findWrapperTypeOf):
(WebCore::V8CustomElement::createWrapper):
* bindings/v8/V8CustomElement.h: Renamed from Source/WebCore/bindings/v8/V8HTMLCustomElement.h.
(WebCore):
(V8CustomElement):
(WebCore::V8CustomElement::toV8):
(WebCore::V8CustomElement::wrap):
(WebCore::HTMLCustomElement::wrap):
* bindings/v8/custom/V8CustomElementConstructorCustom.cpp:
(WebCore::V8CustomElementConstructor::callAsFunctionCallback):
* dom/CustomElementConstructor.cpp:
(WebCore::CustomElementConstructor::createElement):
* dom/CustomElementConstructor.h:
(WebCore):
(CustomElementConstructor):
* dom/CustomElementRegistry.cpp:
(WebCore::CustomElementRegistry::constructorOf):
(WebCore::CustomElementRegistry::createElement):
* dom/CustomElementRegistry.h:
(WebCore):
(CustomElementRegistry):
* dom/Document.cpp: Ensured that the document is an HTML.
(WebCore::Document::registerElement):
* dom/Document.idl:
* dom/make_names.pl:
(printWrapperFactoryCppFile):
* html/HTMLDocument.idl: Moved an API to Document.idl

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@145040 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/bindings/v8/V8CustomElement.cpp [moved from Source/WebCore/bindings/v8/V8HTMLCustomElement.cpp with 94% similarity]
Source/WebCore/bindings/v8/V8CustomElement.h [moved from Source/WebCore/bindings/v8/V8HTMLCustomElement.h with 64% similarity]
Source/WebCore/bindings/v8/custom/V8CustomElementConstructorCustom.cpp
Source/WebCore/dom/CustomElementConstructor.cpp
Source/WebCore/dom/CustomElementConstructor.h
Source/WebCore/dom/CustomElementRegistry.cpp
Source/WebCore/dom/CustomElementRegistry.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.idl
Source/WebCore/dom/make_names.pl
Source/WebCore/html/HTMLDocument.idl

index 6fa1f5d..978eed3 100644 (file)
@@ -1,3 +1,51 @@
+2013-03-06  Hajime Morrita  <morrita@google.com>
+
+        Custom Elements Refactoring: CustomElementConstructor API shouldn't bound to HTMLElement
+        https://bugs.webkit.org/show_bug.cgi?id=111678
+
+        Reviewed by Kentaro Hara.
+
+        The latest Custom Elements standard supports non-HTML custom elements. Even though current implementation
+        support only HTML, it'd be better off to make API generic enough to support them.
+
+        This change
+
+        - eliminates HTMLElement from the API signature by replacing it with Element, and
+        - rename V8HTMLCustomElement to V8CustomElement.
+
+        No new tests, just changing signatures and a class name.
+
+        * WebCore.gypi:
+        * bindings/v8/V8CustomElement.cpp: Renamed from Source/WebCore/bindings/v8/V8HTMLCustomElement.cpp.
+        (WebCore):
+        (WebCore::findWrapperTypeOf):
+        (WebCore::V8CustomElement::createWrapper):
+        * bindings/v8/V8CustomElement.h: Renamed from Source/WebCore/bindings/v8/V8HTMLCustomElement.h.
+        (WebCore):
+        (V8CustomElement):
+        (WebCore::V8CustomElement::toV8):
+        (WebCore::V8CustomElement::wrap):
+        (WebCore::HTMLCustomElement::wrap):
+        * bindings/v8/custom/V8CustomElementConstructorCustom.cpp:
+        (WebCore::V8CustomElementConstructor::callAsFunctionCallback):
+        * dom/CustomElementConstructor.cpp:
+        (WebCore::CustomElementConstructor::createElement):
+        * dom/CustomElementConstructor.h:
+        (WebCore):
+        (CustomElementConstructor):
+        * dom/CustomElementRegistry.cpp:
+        (WebCore::CustomElementRegistry::constructorOf):
+        (WebCore::CustomElementRegistry::createElement):
+        * dom/CustomElementRegistry.h:
+        (WebCore):
+        (CustomElementRegistry):
+        * dom/Document.cpp: Ensured that the document is an HTML.
+        (WebCore::Document::registerElement):
+        * dom/Document.idl:
+        * dom/make_names.pl:
+        (printWrapperFactoryCppFile):
+        * html/HTMLDocument.idl: Moved an API to Document.idl
+
 2013-03-06  Tim Horton  <timothy_horton@apple.com>
 
         TileCache debug minimap should fit inside the intersection of the visible rect and exposed rect
index 28ddbea..49d693c 100644 (file)
             'bindings/v8/V8Callback.h',
             'bindings/v8/V8Collection.cpp',
             'bindings/v8/V8Collection.h',
+            'bindings/v8/V8CustomElement.cpp',
+            'bindings/v8/V8CustomElement.h',
             'bindings/v8/V8DOMConfiguration.cpp',
             'bindings/v8/V8DOMConfiguration.h',
             'bindings/v8/V8DOMActivityLogger.h',
             'bindings/v8/V8GCController.h',
             'bindings/v8/V8GCForContextDispose.cpp',
             'bindings/v8/V8GCForContextDispose.h',
-            'bindings/v8/V8HTMLCustomElement.cpp',
-            'bindings/v8/V8HTMLCustomElement.h',
             'bindings/v8/V8HiddenPropertyName.cpp',
             'bindings/v8/V8HiddenPropertyName.h',
             'bindings/v8/V8Initializer.cpp',
 
 #if ENABLE(CUSTOM_ELEMENTS)
 
-#include "V8HTMLCustomElement.h"
+#include "V8CustomElement.h"
 
 #include "CustomElementHelpers.h"
 #include "CustomElementRegistry.h"
-#include "HTMLElement.h"
+#include "Element.h"
 #include "V8CustomElementConstructor.h"
 #include "V8HTMLUnknownElement.h"
 
@@ -54,13 +54,13 @@ static WrapperTypeInfo* findWrapperTypeOf(v8::Handle<v8::Value> chain)
     return 0;
 }
 
-v8::Handle<v8::Object> V8HTMLCustomElement::createWrapper(PassRefPtr<HTMLElement> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+v8::Handle<v8::Object> V8CustomElement::createWrapper(PassRefPtr<Element> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
 {
     ASSERT(impl);
 
     RefPtr<CustomElementConstructor> constructor = CustomElementRegistry::constructorOf(impl.get());
     if (!constructor) {
-        v8::Handle<v8::Value> wrapperValue = WebCore::toV8(toHTMLUnknownElement(impl.get()), creationContext, isolate);
+        v8::Handle<v8::Value> wrapperValue = WebCore::toV8(toHTMLUnknownElement(toHTMLElement(impl.get())), creationContext, isolate);
         if (!wrapperValue.IsEmpty() && wrapperValue->IsObject())
             return v8::Handle<v8::Object>::Cast(wrapperValue);
         return v8::Handle<v8::Object>();
@@ -28,8 +28,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef V8HTMLCustomElement_h
-#define V8HTMLCustomElement_h
+#ifndef V8CustomElement_h
+#define V8CustomElement_h
 
 #include "V8Binding.h"
 #include "V8DOMWrapper.h"
 
 namespace WebCore {
 
-class HTMLElement;
+class Element;
 
 #if ENABLE(CUSTOM_ELEMENTS)
 
-class V8HTMLCustomElement {
+class V8CustomElement {
 public:
-    static v8::Handle<v8::Value> toV8(HTMLElement*, v8::Handle<v8::Object> creationContext = v8::Handle<v8::Object>(), v8::Isolate* = 0);
-    static v8::Handle<v8::Object> wrap(HTMLElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
+    static v8::Handle<v8::Value> toV8(Element*, v8::Handle<v8::Object> creationContext = v8::Handle<v8::Object>(), v8::Isolate* = 0);
+    static v8::Handle<v8::Object> wrap(Element*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
 
 private:
-    static v8::Handle<v8::Object> createWrapper(PassRefPtr<HTMLElement>, v8::Handle<v8::Object>, v8::Isolate*);
+    static v8::Handle<v8::Object> createWrapper(PassRefPtr<Element>, v8::Handle<v8::Object>, v8::Isolate*);
 };
 
-inline v8::Handle<v8::Value> V8HTMLCustomElement::toV8(HTMLElement* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+inline v8::Handle<v8::Value> V8CustomElement::toV8(Element* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
 {
     if (UNLIKELY(!impl))
         return v8NullWithCheck(isolate);
     v8::Handle<v8::Object> wrapper = DOMDataStore::getWrapper(impl, isolate);
     if (!wrapper.IsEmpty())
         return wrapper;
-    return V8HTMLCustomElement::wrap(impl, creationContext, isolate);
+    return V8CustomElement::wrap(impl, creationContext, isolate);
 }
 
-inline v8::Handle<v8::Object> V8HTMLCustomElement::wrap(HTMLElement* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+inline v8::Handle<v8::Object> V8CustomElement::wrap(Element* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
 {
     ASSERT(impl);
     ASSERT(DOMDataStore::getWrapper(impl, isolate).IsEmpty());
-    return V8HTMLCustomElement::createWrapper(impl, creationContext, isolate);
+    return V8CustomElement::createWrapper(impl, creationContext, isolate);
 }
 
 #else // ENABLE(CUSTOM_ELEMENTS)
 
-class V8HTMLCustomElement {
+class V8CustomElement {
 public:
-    static v8::Handle<v8::Object> wrap(HTMLElement*, v8::Handle<v8::Object> creationContext = v8::Handle<v8::Object>(), v8::Isolate* = 0);
+    static v8::Handle<v8::Object> wrap(Element*, v8::Handle<v8::Object> creationContext = v8::Handle<v8::Object>(), v8::Isolate* = 0);
 };
 
-inline v8::Handle<v8::Object> HTMLCustomElement::wrap(HTMLElement* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+inline v8::Handle<v8::Object> HTMLCustomElement::wrap(Element* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
 {
     return wrap(toHTMLUnknownElement(impl), creationContext, isolate);
 }
@@ -85,4 +85,4 @@ inline v8::Handle<v8::Object> HTMLCustomElement::wrap(HTMLElement* impl, v8::Han
 
 } // namespace WebCore
 
-#endif // V8HTMLCustomElement_h
+#endif // V8CustomElement_h
index 34374f6..8ed79b8 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "CustomElementConstructor.h"
 #include "V8Binding.h"
-#include "V8HTMLCustomElement.h"
+#include "V8CustomElement.h"
 
 namespace WebCore {
 
@@ -45,10 +45,10 @@ v8::Handle<v8::Value> V8CustomElementConstructor::callAsFunctionCallback(const v
         return args.Holder();
 
     CustomElementConstructor* impl = toNative(args.Holder());
-    RefPtr<HTMLElement> element = impl->createElement();
+    RefPtr<Element> element = impl->createElement();
     if (!element)
         return v8Undefined();
-    return V8HTMLCustomElement::toV8(element.get(), args.Holder(), args.GetIsolate());
+    return V8CustomElement::toV8(element.get(), args.Holder(), args.GetIsolate());
 }
 
 } // namespace WebCore
index 198160f..c975d6c 100644 (file)
@@ -59,7 +59,7 @@ CustomElementConstructor::~CustomElementConstructor()
 {
 }
 
-PassRefPtr<HTMLElement> CustomElementConstructor::createElement() const
+PassRefPtr<Element> CustomElementConstructor::createElement() const
 {
     if (!document())
         return 0;
index 52b7cad..844e0e8 100644 (file)
@@ -44,7 +44,7 @@
 namespace WebCore {
 
 class Document;
-class HTMLElement;
+class Element;
 class ScriptState;
 class ScriptValue;
 
@@ -57,7 +57,7 @@ public:
     Document* document() const { return static_cast<Document*>(m_scriptExecutionContext); }
     const QualifiedName& name() const { return m_name; }
 
-    PassRefPtr<HTMLElement> createElement() const;
+    PassRefPtr<Element> createElement() const;
     
 private:
     CustomElementConstructor(Document*, const QualifiedName&);
index 5d9648b..d8b0cd9 100644 (file)
@@ -38,7 +38,7 @@
 #include "CustomElementHelpers.h"
 #include "Dictionary.h"
 #include "Document.h"
-#include "HTMLElement.h"
+#include "Element.h"
 #include "HTMLNames.h"
 #include "RuntimeEnabledFeatures.h"
 #include <wtf/ASCIICType.h>
@@ -62,7 +62,7 @@ CustomElementRegistry::~CustomElementRegistry()
 {
 }
 
-PassRefPtr<CustomElementConstructor> CustomElementRegistry::constructorOf(HTMLElement* element)
+PassRefPtr<CustomElementConstructor> CustomElementRegistry::constructorOf(Element* element)
 {
     RefPtr<CustomElementRegistry> self = element->document()->registry();
     if (!self)
@@ -155,7 +155,7 @@ PassRefPtr<CustomElementConstructor> CustomElementRegistry::find(const Qualified
     return (found != m_constructors.end()) ? found->value : 0;
 }
 
-PassRefPtr<HTMLElement> CustomElementRegistry::createElement(const QualifiedName& name) const
+PassRefPtr<Element> CustomElementRegistry::createElement(const QualifiedName& name) const
 {
     if (RefPtr<CustomElementConstructor> found = find(name))
         return found->createElement();
index 7b58c13..2082cd7 100644 (file)
@@ -48,7 +48,7 @@ namespace WebCore {
 class CustomElementConstructor;
 class Dictionary;
 class Document;
-class HTMLElement;
+class Element;
 class ScriptExecutionContext;
 class QualifiedName;
 
@@ -60,10 +60,10 @@ public:
 
     PassRefPtr<CustomElementConstructor> registerElement(WebCore::ScriptState*, const AtomicString& name, const Dictionary& options, ExceptionCode&);
     PassRefPtr<CustomElementConstructor> find(const QualifiedName&) const;
-    PassRefPtr<HTMLElement> createElement(const QualifiedName&) const;
+    PassRefPtr<Element> createElement(const QualifiedName&) const;
     Document* document() const;
 
-    static PassRefPtr<CustomElementConstructor> constructorOf(HTMLElement*);
+    static PassRefPtr<CustomElementConstructor> constructorOf(Element*);
     
 private:
     static bool isValidName(const AtomicString&);
index 0a7ecf6..348ec89 100644 (file)
@@ -840,6 +840,11 @@ PassRefPtr<CustomElementConstructor> Document::registerElement(WebCore::ScriptSt
 
 PassRefPtr<CustomElementConstructor> Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, const Dictionary& options, ExceptionCode& ec)
 {
+    if (!isHTMLDocument() && !isXHTMLDocument()) {
+        ec = NOT_SUPPORTED_ERR;
+        return 0;
+    }
+
     if (!m_registry)
         m_registry = adoptRef(new CustomElementRegistry(this));
     return m_registry->registerElement(state, name, options, ec);
index 4d4e9fb..0e06fc7 100644 (file)
         raises (DOMException);
 #endif
 
+#if defined(ENABLE_CUSTOM_ELEMENTS) && ENABLE_CUSTOM_ELEMENTS
+    [V8EnabledAtRuntime=customDOMElements, Conditional=CUSTOM_ELEMENTS, ImplementedAs=registerElement, CallWith=ScriptState]
+    CustomElementConstructor webkitRegister(in DOMString name, in [Optional] Dictionary options) raises(DOMException);
+#endif
+
 #if defined(LANGUAGE_CPP) && LANGUAGE_CPP
     // Extra WebCore methods exposed to allow compile-time casting in C++
     boolean isHTMLDocument();
index 341eac0..043a382 100755 (executable)
@@ -1172,7 +1172,7 @@ END
 ;
     } elsif ($wrapperFactoryType eq "V8") {
         print F <<END
-#include "V8HTMLCustomElement.h"
+#include "V8CustomElement.h"
 #include "V8$parameters{namespace}Element.h"
 
 #include <v8.h>
@@ -1277,7 +1277,7 @@ END
 ;
         } elsif ($parameters{namespace} eq "HTML") {
             print F <<END
-    return V8HTMLCustomElement::wrap(element, creationContext, isolate);
+    return V8CustomElement::wrap(element, creationContext, isolate);
 END
 ;
         } else {
index e1f57d2..07427cf 100644 (file)
     readonly attribute Element activeElement;
     boolean hasFocus();
 
-#if defined(ENABLE_CUSTOM_ELEMENTS) && ENABLE_CUSTOM_ELEMENTS
-    [V8EnabledAtRuntime=customDOMElements, Conditional=CUSTOM_ELEMENTS, ImplementedAs=registerElement, CallWith=ScriptState]
-    CustomElementConstructor webkitRegister(in DOMString name, in [Optional] Dictionary options) raises(DOMException);
-#endif
-
     // Deprecated attributes
              [TreatNullAs=NullString] attribute DOMString bgColor;
              [TreatNullAs=NullString] attribute DOMString fgColor;