FeatureObserver: Input types are counted unexpectedly in a page with Modernizr
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2013 10:01:24 +0000 (10:01 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2013 10:01:24 +0000 (10:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108141

Reviewed by Kentaro Hara.

We don't want to record input type instantiation by Modernizr. Modernizr
creates input elements with these types, append it to document.body, and
render it with visibility:hidden. So, we record input types only when
they are attached without visibility:hidden.

No new tests. FeatureObserver is not testable by layout test.

* html/InputType.cpp:
(WebCore::InputType::create): Remove FeatureObserver::observe
callsites. They are moved to TextInputType::attach.
(WebCore::InputType::observeFeatureIfVisible):
Added. A helper for attach().
* html/InputType.h:
(InputType): Add observeFeatureIfVisible.

* html/ColorInputType.cpp:
(WebCore::ColorInputType::create):
Remove a FeatureObserver::observe callsite.
(WebCore::ColorInputType::attach):
Calls FetureObserver through InputType::observeFeatureIfVisible.
* html/ColorInputType.h:
(ColorInputType): Declare attach.
* html/DateInputType.cpp: Ditto.
* html/DateInputType.h: Ditto.
* html/DateTimeInputType.cpp: Ditto.
* html/DateTimeInputType.h: Ditto.
* html/DateTimeLocalInputType.cpp: Ditto.
* html/DateTimeLocalInputType.h: Ditto.
* html/MonthInputType.cpp: Ditto.
* html/MonthInputType.h: Ditto.
* html/RangeInputType.cpp: Ditt
* html/RangeInputType.h: Ditto.
* html/TimeInputType.cpp: Ditto.
* html/TimeInputType.h: Ditto.
* html/WeekInputType.cpp: Ditto.
* html/WeekInputType.h: Ditto.

* html/TextFieldInputType.h:
(TextFieldInputType):
Make attach protected in order that sub classes can call it.
* html/EmailInputType.cpp:
(WebCore::EmailInputType::create):
Remove a FeatureObserver::observe callsite.
(WebCore::EmailInputType::attach): Calls FetureObserver through
InputType::observeFeatureIfVisible after TextFieldInptuType::attach.
* html/EmailInputType.h:
(EmailInputType):Declare attach.
* html/NumberInputType.cpp: Ditto.
* html/NumberInputType.h: Ditto.
* html/SearchInputType.cpp: Ditto.
* html/SearchInputType.h: Ditto.
* html/TelephoneInputType.cpp: Ditto.
* html/TelephoneInputType.h: Ditto.
* html/URLInputType.cpp: Ditto.
* html/URLInputType.h: Ditto.

* html/TextInputType.cpp:
(WebCore::TextInputType::attach):
Move the code for type fallback from InputType::create.
* html/TextInputType.h:
(TextInputType): Declare attach.

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

32 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/ColorInputType.cpp
Source/WebCore/html/ColorInputType.h
Source/WebCore/html/DateInputType.cpp
Source/WebCore/html/DateInputType.h
Source/WebCore/html/DateTimeInputType.cpp
Source/WebCore/html/DateTimeInputType.h
Source/WebCore/html/DateTimeLocalInputType.cpp
Source/WebCore/html/DateTimeLocalInputType.h
Source/WebCore/html/EmailInputType.cpp
Source/WebCore/html/EmailInputType.h
Source/WebCore/html/InputType.cpp
Source/WebCore/html/InputType.h
Source/WebCore/html/MonthInputType.cpp
Source/WebCore/html/MonthInputType.h
Source/WebCore/html/NumberInputType.cpp
Source/WebCore/html/NumberInputType.h
Source/WebCore/html/RangeInputType.cpp
Source/WebCore/html/RangeInputType.h
Source/WebCore/html/SearchInputType.cpp
Source/WebCore/html/SearchInputType.h
Source/WebCore/html/TelephoneInputType.cpp
Source/WebCore/html/TelephoneInputType.h
Source/WebCore/html/TextFieldInputType.h
Source/WebCore/html/TextInputType.cpp
Source/WebCore/html/TextInputType.h
Source/WebCore/html/TimeInputType.cpp
Source/WebCore/html/TimeInputType.h
Source/WebCore/html/URLInputType.cpp
Source/WebCore/html/URLInputType.h
Source/WebCore/html/WeekInputType.cpp
Source/WebCore/html/WeekInputType.h

index 98a8156..6976724 100644 (file)
@@ -1,3 +1,72 @@
+2013-01-29  Kent Tamura  <tkent@chromium.org>
+
+        FeatureObserver: Input types are counted unexpectedly in a page with Modernizr
+        https://bugs.webkit.org/show_bug.cgi?id=108141
+
+        Reviewed by Kentaro Hara.
+
+        We don't want to record input type instantiation by Modernizr. Modernizr
+        creates input elements with these types, append it to document.body, and
+        render it with visibility:hidden. So, we record input types only when
+        they are attached without visibility:hidden.
+
+        No new tests. FeatureObserver is not testable by layout test.
+
+        * html/InputType.cpp:
+        (WebCore::InputType::create): Remove FeatureObserver::observe
+        callsites. They are moved to TextInputType::attach.
+        (WebCore::InputType::observeFeatureIfVisible):
+        Added. A helper for attach().
+        * html/InputType.h:
+        (InputType): Add observeFeatureIfVisible.
+
+        * html/ColorInputType.cpp:
+        (WebCore::ColorInputType::create):
+        Remove a FeatureObserver::observe callsite.
+        (WebCore::ColorInputType::attach):
+        Calls FetureObserver through InputType::observeFeatureIfVisible.
+        * html/ColorInputType.h:
+        (ColorInputType): Declare attach.
+        * html/DateInputType.cpp: Ditto.
+        * html/DateInputType.h: Ditto.
+        * html/DateTimeInputType.cpp: Ditto.
+        * html/DateTimeInputType.h: Ditto.
+        * html/DateTimeLocalInputType.cpp: Ditto.
+        * html/DateTimeLocalInputType.h: Ditto.
+        * html/MonthInputType.cpp: Ditto.
+        * html/MonthInputType.h: Ditto.
+        * html/RangeInputType.cpp: Ditt
+        * html/RangeInputType.h: Ditto.
+        * html/TimeInputType.cpp: Ditto.
+        * html/TimeInputType.h: Ditto.
+        * html/WeekInputType.cpp: Ditto.
+        * html/WeekInputType.h: Ditto.
+
+        * html/TextFieldInputType.h:
+        (TextFieldInputType):
+        Make attach protected in order that sub classes can call it.
+        * html/EmailInputType.cpp:
+        (WebCore::EmailInputType::create):
+        Remove a FeatureObserver::observe callsite.
+        (WebCore::EmailInputType::attach): Calls FetureObserver through
+        InputType::observeFeatureIfVisible after TextFieldInptuType::attach.
+        * html/EmailInputType.h:
+        (EmailInputType):Declare attach.
+        * html/NumberInputType.cpp: Ditto.
+        * html/NumberInputType.h: Ditto.
+        * html/SearchInputType.cpp: Ditto.
+        * html/SearchInputType.h: Ditto.
+        * html/TelephoneInputType.cpp: Ditto.
+        * html/TelephoneInputType.h: Ditto.
+        * html/URLInputType.cpp: Ditto.
+        * html/URLInputType.h: Ditto.
+
+        * html/TextInputType.cpp:
+        (WebCore::TextInputType::attach):
+        Move the code for type fallback from InputType::create.
+        * html/TextInputType.h:
+        (TextInputType): Declare attach.
+
 2013-01-29  Michael BrĂ¼ning  <michael.bruning@digia.com>
 
         [Qt][WK1] Reflect recursion limit and loop checks also for list conversions.
index 2898a1d..49063b3 100644 (file)
@@ -35,7 +35,6 @@
 #include "Chrome.h"
 #include "Color.h"
 #include "ElementShadow.h"
-#include "FeatureObserver.h"
 #include "HTMLDataListElement.h"
 #include "HTMLDivElement.h"
 #include "HTMLInputElement.h"
@@ -72,7 +71,6 @@ static bool isValidColorString(const String& value)
 
 PassOwnPtr<InputType> ColorInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeColor);
     return adoptPtr(new ColorInputType(element));
 }
 
@@ -81,6 +79,11 @@ ColorInputType::~ColorInputType()
     endColorChooser();
 }
 
+void ColorInputType::attach()
+{
+    observeFeatureIfVisible(FeatureObserver::InputTypeColor);
+}
+
 bool ColorInputType::isColorControl() const
 {
     return true;
index 1f08133..91ecdaa 100644 (file)
@@ -53,6 +53,7 @@ public:
 
 private:
     ColorInputType(HTMLInputElement* element) : BaseClickableWithKeyInputType(element) { }
+    virtual void attach() OVERRIDE;
     virtual bool isColorControl() const OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual bool supportsRequired() const OVERRIDE;
index 1fd5e0e..83a2f6f 100644 (file)
@@ -34,7 +34,6 @@
 #if ENABLE(INPUT_TYPE_DATE)
 #include "DateComponents.h"
 #include "DateTimeFieldsState.h"
-#include "FeatureObserver.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "InputTypeNames.h"
@@ -59,10 +58,14 @@ inline DateInputType::DateInputType(HTMLInputElement* element)
 
 PassOwnPtr<InputType> DateInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeDate);
     return adoptPtr(new DateInputType(element));
 }
 
+void DateInputType::attach()
+{
+    observeFeatureIfVisible(FeatureObserver::InputTypeDate);
+}
+
 const AtomicString& DateInputType::formControlType() const
 {
     return InputTypeNames::date();
index 19c136f..fd75f91 100644 (file)
@@ -52,6 +52,7 @@ public:
 
 private:
     DateInputType(HTMLInputElement*);
+    virtual void attach() OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual DateComponents::Type dateType() const OVERRIDE;
     virtual StepRange createStepRange(AnyStepHandling) const OVERRIDE;
index 0cb93d3..f900f04 100644 (file)
@@ -32,7 +32,6 @@
 #include "DateTimeInputType.h"
 
 #include "DateComponents.h"
-#include "FeatureObserver.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "InputTypeNames.h"
@@ -59,10 +58,14 @@ static const int dateTimeStepScaleFactor = 1000;
 
 PassOwnPtr<InputType> DateTimeInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeDateTime);
     return adoptPtr(new DateTimeInputType(element));
 }
 
+void DateTimeInputType::attach()
+{
+    observeFeatureIfVisible(FeatureObserver::InputTypeDateTime);
+}
+
 const AtomicString& DateTimeInputType::formControlType() const
 {
     return InputTypeNames::datetime();
index 8afc30f..4de95a5 100644 (file)
@@ -51,6 +51,7 @@ public:
 
 private:
     DateTimeInputType(HTMLInputElement* element) : BaseDateTimeInputType(element) { }
+    virtual void attach() OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual DateComponents::Type dateType() const OVERRIDE;
     virtual StepRange createStepRange(AnyStepHandling) const OVERRIDE;
index 916998b..e3fbd4a 100644 (file)
@@ -32,7 +32,6 @@
 #include "DateTimeLocalInputType.h"
 
 #include "DateComponents.h"
-#include "FeatureObserver.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "InputTypeNames.h"
@@ -58,10 +57,14 @@ static const int dateTimeLocalStepScaleFactor = 1000;
 
 PassOwnPtr<InputType> DateTimeLocalInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeDateTimeLocal);
     return adoptPtr(new DateTimeLocalInputType(element));
 }
 
+void DateTimeLocalInputType::attach()
+{
+    observeFeatureIfVisible(FeatureObserver::InputTypeDateTimeLocal);
+}
+
 const AtomicString& DateTimeLocalInputType::formControlType() const
 {
     return InputTypeNames::datetimelocal();
index c0e7d16..31eea4d 100644 (file)
@@ -49,6 +49,7 @@ public:
 
 private:
     DateTimeLocalInputType(HTMLInputElement* element) : BaseDateTimeLocalInputType(element) { }
+    virtual void attach() OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual DateComponents::Type dateType() const OVERRIDE;
     virtual double valueAsDate() const OVERRIDE;
index 27ed0cf..b51d0a7 100644 (file)
@@ -24,7 +24,6 @@
 #include "config.h"
 #include "EmailInputType.h"
 
-#include "FeatureObserver.h"
 #include "HTMLInputElement.h"
 #include "HTMLParserIdioms.h"
 #include "InputTypeNames.h"
@@ -56,10 +55,15 @@ static bool isValidEmailAddress(const String& address)
 
 PassOwnPtr<InputType> EmailInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeEmail);
     return adoptPtr(new EmailInputType(element));
 }
 
+void EmailInputType::attach()
+{
+    TextFieldInputType::attach();
+    observeFeatureIfVisible(FeatureObserver::InputTypeEmail);
+}
+
 const AtomicString& EmailInputType::formControlType() const
 {
     return InputTypeNames::email();
index 2d45347..0d7e3b4 100644 (file)
@@ -41,6 +41,7 @@ public:
 
 private:
     EmailInputType(HTMLInputElement* element) : BaseTextInputType(element) { }
+    virtual void attach() OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual bool typeMismatchFor(const String&) const OVERRIDE;
     virtual bool typeMismatch() const OVERRIDE;
index 1ab5ad1..098c1e1 100644 (file)
@@ -55,6 +55,7 @@
 #include "KeyboardEvent.h"
 #include "LocalizedStrings.h"
 #include "MonthInputType.h"
+#include "NodeRenderStyle.h"
 #include "NumberInputType.h"
 #include "Page.h"
 #include "PasswordInputType.h"
@@ -140,13 +141,8 @@ PassOwnPtr<InputType> InputType::create(HTMLInputElement* element, const AtomicS
 {
     static const InputTypeFactoryMap* factoryMap = createInputTypeFactoryMap().leakPtr();
     PassOwnPtr<InputType> (*factory)(HTMLInputElement*) = typeName.isEmpty() ? 0 : factoryMap->get(typeName);
-    if (!factory) {
+    if (!factory)
         factory = TextInputType::create;
-        if (typeName == InputTypeNames::datetime())
-            FeatureObserver::observe(element->document(), FeatureObserver::InputTypeDateTimeFallback);
-        else if (typeName == InputTypeNames::week())
-            FeatureObserver::observe(element->document(), FeatureObserver::InputTypeWeekFallback);
-    }
     return factory(element);
 }
 
@@ -1134,4 +1130,12 @@ void InputType::stepUpFromRenderer(int n)
     }
 }
 
+void InputType::observeFeatureIfVisible(FeatureObserver::Feature feature) const
+{
+    if (RenderStyle* style = element()->renderStyle()) {
+        if (style->visibility() != HIDDEN)
+            FeatureObserver::observe(element()->document(), feature);
+    }
+}
+
 } // namespace WebCore
index c6d14a9..38f2efe 100644 (file)
@@ -33,6 +33,7 @@
 #ifndef InputType_h
 #define InputType_h
 
+#include "FeatureObserver.h"
 #include "HTMLTextFormControlElement.h"
 #include "StepRange.h"
 #include <wtf/Forward.h>
@@ -313,6 +314,7 @@ protected:
     HTMLInputElement* element() const { return m_element; }
     Chrome* chrome() const;
     Decimal parseToNumberOrNaN(const String&) const;
+    void observeFeatureIfVisible(FeatureObserver::Feature) const;
 
 private:
     // Helper for stepUp()/stepDown(). Adds step value * count to the current value.
index 6bf4741..7b5b0d7 100644 (file)
@@ -32,7 +32,6 @@
 #include "MonthInputType.h"
 
 #include "DateComponents.h"
-#include "FeatureObserver.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "InputTypeNames.h"
@@ -60,10 +59,14 @@ static const int monthStepScaleFactor = 1;
 
 PassOwnPtr<InputType> MonthInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeMonth);
     return adoptPtr(new MonthInputType(element));
 }
 
+void MonthInputType::attach()
+{
+    observeFeatureIfVisible(FeatureObserver::InputTypeMonth);
+}
+
 const AtomicString& MonthInputType::formControlType() const
 {
     return InputTypeNames::month();
index 61488bc..7ed318b 100644 (file)
@@ -49,6 +49,7 @@ public:
 
 private:
     MonthInputType(HTMLInputElement* element) : BaseMonthInputType(element) { }
+    virtual void attach() OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual DateComponents::Type dateType() const OVERRIDE;
     virtual double valueAsDate() const OVERRIDE;
index 3017512..33ad02b 100644 (file)
@@ -34,7 +34,6 @@
 
 #include "BeforeTextInsertedEvent.h"
 #include "ExceptionCode.h"
-#include "FeatureObserver.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "HTMLParserIdioms.h"
@@ -99,10 +98,15 @@ static RealNumberRenderSize calculateRenderSize(const Decimal& value)
 
 PassOwnPtr<InputType> NumberInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeNumber);
     return adoptPtr(new NumberInputType(element));
 }
 
+void NumberInputType::attach()
+{
+    TextFieldInputType::attach();
+    observeFeatureIfVisible(FeatureObserver::InputTypeNumber);
+}
+
 const AtomicString& NumberInputType::formControlType() const
 {
     return InputTypeNames::number();
index 1efcdc1..10a6237 100644 (file)
@@ -41,6 +41,7 @@ public:
 
 private:
     NumberInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
+    virtual void attach() OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) OVERRIDE;
     virtual double valueAsDouble() const OVERRIDE;
index 529802b..beca7ad 100644 (file)
@@ -34,7 +34,6 @@
 
 #include "AXObjectCache.h"
 #include "ElementShadow.h"
-#include "FeatureObserver.h"
 #include "HTMLDivElement.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
@@ -82,7 +81,6 @@ static Decimal ensureMaximum(const Decimal& proposedValue, const Decimal& minimu
 
 PassOwnPtr<InputType> RangeInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeRange);
     return adoptPtr(new RangeInputType(element));
 }
 
@@ -94,6 +92,11 @@ RangeInputType::RangeInputType(HTMLInputElement* element)
 {
 }
 
+void RangeInputType::attach()
+{
+    observeFeatureIfVisible(FeatureObserver::InputTypeRange);
+}
+
 bool RangeInputType::isRangeControl() const
 {
     return true;
index b85442d..61fa3a2 100644 (file)
@@ -43,6 +43,7 @@ public:
 
 private:
     RangeInputType(HTMLInputElement*);
+    virtual void attach() OVERRIDE;
     virtual bool isRangeControl() const OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual double valueAsDouble() const OVERRIDE;
index 8a1eb02..fb96365 100644 (file)
@@ -31,7 +31,6 @@
 #include "config.h"
 #include "SearchInputType.h"
 
-#include "FeatureObserver.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "InputTypeNames.h"
@@ -55,10 +54,15 @@ inline SearchInputType::SearchInputType(HTMLInputElement* element)
 
 PassOwnPtr<InputType> SearchInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeSearch);
     return adoptPtr(new SearchInputType(element));
 }
 
+void SearchInputType::attach()
+{
+    TextFieldInputType::attach();
+    observeFeatureIfVisible(FeatureObserver::InputTypeSearch);
+}
+
 void SearchInputType::addSearchResult()
 {
     if (RenderObject* renderer = element()->renderer())
index 45bbd34..d749e6e 100644 (file)
@@ -47,6 +47,7 @@ public:
 
 private:
     SearchInputType(HTMLInputElement*);
+    virtual void attach() OVERRIDE;
     virtual void addSearchResult() OVERRIDE;
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
index 4964906..0adf654 100644 (file)
@@ -31,7 +31,6 @@
 #include "config.h"
 #include "TelephoneInputType.h"
 
-#include "FeatureObserver.h"
 #include "HTMLInputElement.h"
 #include "InputTypeNames.h"
 #include <wtf/PassOwnPtr.h>
@@ -40,10 +39,15 @@ namespace WebCore {
 
 PassOwnPtr<InputType> TelephoneInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeTel);
     return adoptPtr(new TelephoneInputType(element));
 }
 
+void TelephoneInputType::attach()
+{
+    TextFieldInputType::attach();
+    observeFeatureIfVisible(FeatureObserver::InputTypeTel);
+}
+
 const AtomicString& TelephoneInputType::formControlType() const
 {
     return InputTypeNames::telephone();
index 923fad6..18f8188 100644 (file)
@@ -41,6 +41,7 @@ public:
 
 private:
     TelephoneInputType(HTMLInputElement* element) : BaseTextInputType(element) { }
+    virtual void attach() OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual bool shouldRespectSpeechAttribute() OVERRIDE;
     virtual bool isTelephoneField() const OVERRIDE;
index a798871..fd73140 100644 (file)
@@ -58,6 +58,7 @@ protected:
 #endif
 
 protected:
+    virtual void attach() OVERRIDE;
     virtual bool needsContainer() const;
     virtual bool shouldHaveSpinButton() const;
     virtual void createShadowSubtree() OVERRIDE;
@@ -91,7 +92,6 @@ private:
     virtual HTMLElement* placeholderElement() const OVERRIDE;
     virtual void updatePlaceholderText() OVERRIDE;
     virtual bool appendFormData(FormDataList&, bool multipart) const OVERRIDE;
-    virtual void attach() OVERRIDE;
     virtual void subtreeHasChanged() OVERRIDE;
 
     // SpinButtonElement::SpinButtonOwner functions.
index 19bdca7..f7a9b58 100644 (file)
 #include "config.h"
 #include "TextInputType.h"
 
+#include "HTMLInputElement.h"
 #include "InputTypeNames.h"
 #include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
 
+using namespace HTMLNames;
+
 PassOwnPtr<InputType> TextInputType::create(HTMLInputElement* element)
 {
     return adoptPtr(new TextInputType(element));
 }
 
+void TextInputType::attach()
+{
+    TextFieldInputType::attach();
+    const AtomicString& type = element()->fastGetAttribute(typeAttr);
+    if (equalIgnoringCase(type, InputTypeNames::datetime()))
+        observeFeatureIfVisible(FeatureObserver::InputTypeDateTimeFallback);
+    else if (equalIgnoringCase(type, InputTypeNames::week()))
+        observeFeatureIfVisible(FeatureObserver::InputTypeWeekFallback);
+}
+
 const AtomicString& TextInputType::formControlType() const
 {
     return InputTypeNames::text();
index 421fe57..693ae06 100644 (file)
@@ -41,6 +41,7 @@ public:
 
 private:
     TextInputType(HTMLInputElement* element) : BaseTextInputType(element) { }
+    virtual void attach() OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual bool shouldRespectSpeechAttribute() OVERRIDE;
 };
index 8f3ef0c..ec595e7 100644 (file)
@@ -32,7 +32,6 @@
 #include "TimeInputType.h"
 
 #include "DateComponents.h"
-#include "FeatureObserver.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "InputTypeNames.h"
@@ -64,10 +63,14 @@ TimeInputType::TimeInputType(HTMLInputElement*  element)
 
 PassOwnPtr<InputType> TimeInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeTime);
     return adoptPtr(new TimeInputType(element));
 }
 
+void TimeInputType::attach()
+{
+    observeFeatureIfVisible(FeatureObserver::InputTypeTime);
+}
+
 const AtomicString& TimeInputType::formControlType() const
 {
     return InputTypeNames::time();
index c2ee279..32eab5e 100644 (file)
@@ -49,6 +49,7 @@ public:
 
 private:
     TimeInputType(HTMLInputElement*);
+    virtual void attach() OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual DateComponents::Type dateType() const OVERRIDE;
     virtual Decimal defaultValueForStepUp() const OVERRIDE;
index 65765b8..99dd089 100644 (file)
@@ -31,7 +31,6 @@
 #include "config.h"
 #include "URLInputType.h"
 
-#include "FeatureObserver.h"
 #include "HTMLInputElement.h"
 #include "InputTypeNames.h"
 #include "LocalizedStrings.h"
@@ -42,10 +41,15 @@ namespace WebCore {
 
 PassOwnPtr<InputType> URLInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeURL);
     return adoptPtr(new URLInputType(element));
 }
 
+void URLInputType::attach()
+{
+    TextFieldInputType::attach();
+    observeFeatureIfVisible(FeatureObserver::InputTypeURL);
+}
+
 const AtomicString& URLInputType::formControlType() const
 {
     return InputTypeNames::url();
index de68418..87c068d 100644 (file)
@@ -41,6 +41,7 @@ public:
 
 private:
     URLInputType(HTMLInputElement* element) : BaseTextInputType(element) { }
+    virtual void attach() OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual bool typeMismatchFor(const String&) const OVERRIDE;
     virtual bool typeMismatch() const OVERRIDE;
index 0c7133e..eae2e7e 100644 (file)
@@ -32,7 +32,6 @@
 #include "WeekInputType.h"
 
 #include "DateComponents.h"
-#include "FeatureObserver.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "InputTypeNames.h"
@@ -56,10 +55,14 @@ static const int weekStepScaleFactor = 604800000;
 
 PassOwnPtr<InputType> WeekInputType::create(HTMLInputElement* element)
 {
-    FeatureObserver::observe(element->document(), FeatureObserver::InputTypeWeek);
     return adoptPtr(new WeekInputType(element));
 }
 
+void WeekInputType::attach()
+{
+    observeFeatureIfVisible(FeatureObserver::InputTypeWeek);
+}
+
 const AtomicString& WeekInputType::formControlType() const
 {
     return InputTypeNames::week();
index a70b9a9..385bd6d 100644 (file)
@@ -49,6 +49,7 @@ public:
 
 private:
     WeekInputType(HTMLInputElement* element) : BaseWeekInputType(element) { }
+    virtual void attach() OVERRIDE;
     virtual const AtomicString& formControlType() const OVERRIDE;
     virtual DateComponents::Type dateType() const OVERRIDE;
     virtual StepRange createStepRange(AnyStepHandling) const OVERRIDE;