Title: [133441] trunk/Source/WebCore
Revision
133441
Author
tk...@chromium.org
Date
2012-11-05 00:22:02 -0800 (Mon, 05 Nov 2012)

Log Message

BaseChooserOnlyDateAndTimeInputType should implement DateTimeChooserClient
https://bugs.webkit.org/show_bug.cgi?id=101038

Reviewed by Hajime Morita.

Add DateTimeChooserClient behavior to BaseChooserOnlyDateAndTimeInputType.
It means that date/time input elements without
ENABLE_INPUT_MULTIPLE_FIELDS_UI can open date/time choosers by
DOMActivate event.

This patch doesn't change behavior yet because Chromimum-Android port
intercepts user events and doesn't deliver them to date/time input
elements. <http://crbug.com/159381>

* html/BaseChooserOnlyDateAndTimeInputType.cpp:
Add DateTimeChooserClient behavior. The code is similar to
PickerIndicatorElement.
(WebCore::BaseChooserOnlyDateAndTimeInputType::~BaseChooserOnlyDateAndTimeInputType):
Closes DateTimeChooser.
(WebCore::BaseChooserOnlyDateAndTimeInputType::handleDOMActivateEvent):
Open DateTimeChooser if
 - The element is not disabled,
 - The element is not read-only,
 - The element has a renderer,
 - This event is created by a user gesture, and
 - The element has no DateTimeChooser.
(WebCore::BaseChooserOnlyDateAndTimeInputType::detach):
Closes DateTimeChooser.
(WebCore::BaseChooserOnlyDateAndTimeInputType::didChooseValue):
Set a string value coming from a chooser to the input element.
(WebCore::BaseChooserOnlyDateAndTimeInputType::didEndChooser):
Clear m_dateTimeChooser when the chooser was closed.
(WebCore::BaseChooserOnlyDateAndTimeInputType::closeDateTimeChooser):
Requests to close the chooser.
* html/BaseChooserOnlyDateAndTimeInputType.h:
(BaseChooserOnlyDateAndTimeInputType):
 - Implement DateTimeChooserClient
 - Add closeDateTimeChooser helper function.
 - Add detach override.
 - Add m_dateTimeChooser.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::setupDateTimeChooserParameters):
Added. The code is moved from PickerIndicatorElement.cpp in order to
share it with BaseChooserOnlyDateAndTimeInputType.
* html/HTMLInputElement.h:
(HTMLInputElement): Declare setupDateTimeChooserParameters.
* html/shadow/PickerIndicatorElement.cpp:
(WebCore::PickerIndicatorElement::openPopup):
Move some code to HTMLInputElement::setupDateTimeChooserParameters.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (133440 => 133441)


--- trunk/Source/WebCore/ChangeLog	2012-11-05 08:04:04 UTC (rev 133440)
+++ trunk/Source/WebCore/ChangeLog	2012-11-05 08:22:02 UTC (rev 133441)
@@ -1,3 +1,55 @@
+2012-11-05  Kent Tamura  <tk...@chromium.org>
+
+        BaseChooserOnlyDateAndTimeInputType should implement DateTimeChooserClient
+        https://bugs.webkit.org/show_bug.cgi?id=101038
+
+        Reviewed by Hajime Morita.
+
+        Add DateTimeChooserClient behavior to BaseChooserOnlyDateAndTimeInputType.
+        It means that date/time input elements without
+        ENABLE_INPUT_MULTIPLE_FIELDS_UI can open date/time choosers by
+        DOMActivate event.
+
+        This patch doesn't change behavior yet because Chromimum-Android port
+        intercepts user events and doesn't deliver them to date/time input
+        elements. <http://crbug.com/159381>
+
+        * html/BaseChooserOnlyDateAndTimeInputType.cpp:
+        Add DateTimeChooserClient behavior. The code is similar to
+        PickerIndicatorElement.
+        (WebCore::BaseChooserOnlyDateAndTimeInputType::~BaseChooserOnlyDateAndTimeInputType):
+        Closes DateTimeChooser.
+        (WebCore::BaseChooserOnlyDateAndTimeInputType::handleDOMActivateEvent):
+        Open DateTimeChooser if
+         - The element is not disabled,
+         - The element is not read-only,
+         - The element has a renderer,
+         - This event is created by a user gesture, and
+         - The element has no DateTimeChooser.
+        (WebCore::BaseChooserOnlyDateAndTimeInputType::detach):
+        Closes DateTimeChooser.
+        (WebCore::BaseChooserOnlyDateAndTimeInputType::didChooseValue):
+        Set a string value coming from a chooser to the input element.
+        (WebCore::BaseChooserOnlyDateAndTimeInputType::didEndChooser):
+        Clear m_dateTimeChooser when the chooser was closed.
+        (WebCore::BaseChooserOnlyDateAndTimeInputType::closeDateTimeChooser):
+        Requests to close the chooser.
+        * html/BaseChooserOnlyDateAndTimeInputType.h:
+        (BaseChooserOnlyDateAndTimeInputType):
+         - Implement DateTimeChooserClient
+         - Add closeDateTimeChooser helper function.
+         - Add detach override.
+         - Add m_dateTimeChooser.
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::setupDateTimeChooserParameters):
+        Added. The code is moved from PickerIndicatorElement.cpp in order to
+        share it with BaseChooserOnlyDateAndTimeInputType.
+        * html/HTMLInputElement.h:
+        (HTMLInputElement): Declare setupDateTimeChooserParameters.
+        * html/shadow/PickerIndicatorElement.cpp:
+        (WebCore::PickerIndicatorElement::openPopup):
+        Move some code to HTMLInputElement::setupDateTimeChooserParameters.
+
 2012-11-04  Julien Chaffraix  <jchaffr...@webkit.org>
 
         Fix the collapsing border code to handle mixed directionality at the row level

Modified: trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp (133440 => 133441)


--- trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp	2012-11-05 08:04:04 UTC (rev 133440)
+++ trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp	2012-11-05 08:22:02 UTC (rev 133441)
@@ -27,17 +27,58 @@
 #if ENABLE(DATE_AND_TIME_INPUT_TYPES) && !ENABLE(INPUT_MULTIPLE_FIELDS_UI)
 #include "BaseChooserOnlyDateAndTimeInputType.h"
 
+#include "Chrome.h"
+#include "ChromeClient.h"
+#include "HTMLInputElement.h"
+#include "Page.h"
+#include "ScriptController.h"
+
 namespace WebCore {
 
 BaseChooserOnlyDateAndTimeInputType::~BaseChooserOnlyDateAndTimeInputType()
 {
+    closeDateTimeChooser();
 }
 
 void BaseChooserOnlyDateAndTimeInputType::handleDOMActivateEvent(Event*)
 {
-    // FIXME: start date-time chooser. webkit.org/b/101038.
+    if (element()->disabled() || element()->readOnly() || !element()->renderer() || !ScriptController::processingUserGesture())
+        return;
+
+    if (m_dateTimeChooser)
+        return;
+    if (!element()->document()->page())
+        return;
+    Chrome* chrome = element()->document()->page()->chrome();
+    if (!chrome)
+        return;
+    DateTimeChooserParameters parameters;
+    if (!element()->setupDateTimeChooserParameters(parameters))
+        return;
+    m_dateTimeChooser = chrome->client()->openDateTimeChooser(this, parameters);
 }
 
+void BaseChooserOnlyDateAndTimeInputType::detach()
+{
+    closeDateTimeChooser();
+}
+
+void BaseChooserOnlyDateAndTimeInputType::didChooseValue(const String& value)
+{
+    element()->setValue(value, DispatchChangeEvent);
+}
+
+void BaseChooserOnlyDateAndTimeInputType::didEndChooser()
+{
+    m_dateTimeChooser.clear();
+}
+
+void BaseChooserOnlyDateAndTimeInputType::closeDateTimeChooser()
+{
+    if (m_dateTimeChooser)
+        m_dateTimeChooser->endChooser();
+}
+
 void BaseChooserOnlyDateAndTimeInputType::handleKeydownEvent(KeyboardEvent* event)
 {
     BaseClickableWithKeyInputType::handleKeydownEvent(element(), event);

Modified: trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.h (133440 => 133441)


--- trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.h	2012-11-05 08:04:04 UTC (rev 133440)
+++ trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.h	2012-11-05 08:22:02 UTC (rev 133441)
@@ -29,22 +29,32 @@
 #if ENABLE(DATE_AND_TIME_INPUT_TYPES) && !ENABLE(INPUT_MULTIPLE_FIELDS_UI)
 #include "BaseClickableWithKeyInputType.h"
 #include "BaseDateAndTimeInputType.h"
+#include "DateTimeChooser.h"
+#include "DateTimeChooserClient.h"
 
 namespace WebCore {
 
-// FIXME: This class should implement DateTimeChooserClient. webkit.org/b/101038.
-class BaseChooserOnlyDateAndTimeInputType : public BaseDateAndTimeInputType {
+class BaseChooserOnlyDateAndTimeInputType : public BaseDateAndTimeInputType, public DateTimeChooserClient {
 protected:
     BaseChooserOnlyDateAndTimeInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
     virtual ~BaseChooserOnlyDateAndTimeInputType();
 
 private:
+    void closeDateTimeChooser();
+
     // InputType functions:
+    virtual void detach() OVERRIDE;
     virtual void handleDOMActivateEvent(Event*) OVERRIDE;
     virtual void handleKeydownEvent(KeyboardEvent*) OVERRIDE;
     virtual void handleKeypressEvent(KeyboardEvent*) OVERRIDE;
     virtual void handleKeyupEvent(KeyboardEvent*) OVERRIDE;
     virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE;
+
+    // DateTimeChooserClient functions:
+    virtual void didChooseValue(const String&) OVERRIDE;
+    virtual void didEndChooser() OVERRIDE;
+
+    RefPtr<DateTimeChooser> m_dateTimeChooser;
 };
 
 }

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (133440 => 133441)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2012-11-05 08:04:04 UTC (rev 133440)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2012-11-05 08:22:02 UTC (rev 133441)
@@ -33,6 +33,7 @@
 #include "BeforeTextInsertedEvent.h"
 #include "CSSPropertyNames.h"
 #include "CSSValueKeywords.h"
+#include "DateTimeChooser.h"
 #include "Document.h"
 #include "EventNames.h"
 #include "ExceptionCode.h"
@@ -40,6 +41,7 @@
 #include "FileList.h"
 #include "FormController.h"
 #include "Frame.h"
+#include "FrameView.h"
 #include "HTMLCollection.h"
 #include "HTMLDataListElement.h"
 #include "HTMLFormElement.h"
@@ -1901,6 +1903,45 @@
     HTMLTextFormControlElement::setRangeText(replacement, start, end, selectionMode, ec);
 }
 
+#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
+bool HTMLInputElement::setupDateTimeChooserParameters(DateTimeChooserParameters& parameters)
+{
+    if (!document()->view())
+        return false;
+
+    parameters.type = type();
+    parameters.minimum = minimum();
+    parameters.maximum = maximum();
+    parameters.required = required();
+
+    StepRange stepRange = createStepRange(RejectAny);
+    if (stepRange.hasStep()) {
+        parameters.step = stepRange.step().toDouble();
+        parameters.stepBase = stepRange.stepBase().toDouble();
+    } else {
+        parameters.step = 1.0;
+        parameters.stepBase = 0;
+    }
+
+    parameters.anchorRectInRootView = document()->view()->contentsToRootView(pixelSnappedBoundingBox());
+    parameters.currentValue = value();
+    parameters.isAnchorElementRTL = computedStyle()->direction() == RTL;
+#if ENABLE(DATALIST_ELEMENT)
+    if (HTMLDataListElement* dataList = this->dataList()) {
+        RefPtr<HTMLCollection> options = dataList->options();
+        for (unsigned i = 0; HTMLOptionElement* option = toHTMLOptionElement(options->item(i)); ++i) {
+            if (!isValidValue(option->value()))
+                continue;
+            parameters.suggestionValues.append(sanitizeValue(option->value()));
+            parameters.localizedSuggestionValues.append(localizeValue(option->value()));
+            parameters.suggestionLabels.append(option->value() == option->label() ? String() : option->label());
+        }
+    }
+#endif
+    return true;
+}
+#endif
+
 void HTMLInputElement::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
 {
     MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (133440 => 133441)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2012-11-05 08:04:04 UTC (rev 133440)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2012-11-05 08:22:02 UTC (rev 133441)
@@ -41,6 +41,7 @@
 class InputType;
 class KURL;
 class ListAttributeTargetObserver;
+struct DateTimeChooserParameters;
 
 class HTMLInputElement : public HTMLTextFormControlElement, public ImageLoaderClientBase<HTMLInputElement> {
 public:
@@ -291,6 +292,9 @@
     virtual void setRangeText(const String& replacement, ExceptionCode&) OVERRIDE;
     virtual void setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionCode&) OVERRIDE;
 
+#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
+    bool setupDateTimeChooserParameters(DateTimeChooserParameters&);
+#endif
     virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
 
 protected:

Modified: trunk/Source/WebCore/html/shadow/PickerIndicatorElement.cpp (133440 => 133441)


--- trunk/Source/WebCore/html/shadow/PickerIndicatorElement.cpp	2012-11-05 08:04:04 UTC (rev 133440)
+++ trunk/Source/WebCore/html/shadow/PickerIndicatorElement.cpp	2012-11-05 08:22:02 UTC (rev 133441)
@@ -35,10 +35,7 @@
 #include "Chrome.h"
 #include "ChromeClient.h"
 #include "Event.h"
-#include "FrameView.h"
-#include "HTMLDataListElement.h"
 #include "HTMLInputElement.h"
-#include "HTMLOptionElement.h"
 #include "Page.h"
 #include "RenderDetailsMarker.h"
 
@@ -124,38 +121,9 @@
     Chrome* chrome = document()->page()->chrome();
     if (!chrome)
         return;
-    if (!document()->view())
-        return;
-
-    HTMLInputElement* input = hostInput();
     DateTimeChooserParameters parameters;
-    parameters.type = input->type();
-    parameters.minimum = input->minimum();
-    parameters.maximum = input->maximum();
-    parameters.required = input->required();
-
-    StepRange stepRange = input->createStepRange(RejectAny);
-    if (stepRange.hasStep()) {
-        parameters.step = stepRange.step().toDouble();
-        parameters.stepBase = stepRange.stepBase().toDouble();
-    } else {
-        parameters.step = 1.0;
-        parameters.stepBase = 0;
-    }
-
-    parameters.anchorRectInRootView = document()->view()->contentsToRootView(hostInput()->pixelSnappedBoundingBox());
-    parameters.currentValue = input->value();
-    parameters.isAnchorElementRTL = input->computedStyle()->direction() == RTL;
-    if (HTMLDataListElement* dataList = input->dataList()) {
-        RefPtr<HTMLCollection> options = dataList->options();
-        for (unsigned i = 0; HTMLOptionElement* option = toHTMLOptionElement(options->item(i)); ++i) {
-            if (!input->isValidValue(option->value()))
-                continue;
-            parameters.suggestionValues.append(input->sanitizeValue(option->value()));
-            parameters.localizedSuggestionValues.append(input->localizeValue(option->value()));
-            parameters.suggestionLabels.append(option->value() == option->label() ? String() : option->label());
-        }
-    }
+    if (!hostInput()->setupDateTimeChooserParameters(parameters))
+        return;
     m_chooser = chrome->client()->openDateTimeChooser(this, parameters);
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to