Title: [141887] trunk
Revision
141887
Author
[email protected]
Date
2013-02-05 05:03:38 -0800 (Tue, 05 Feb 2013)

Log Message

INPUT_MULTIPLE_FIELDS_UI: Should not move focus if the element already has focus
https://bugs.webkit.org/show_bug.cgi?id=108914

Reviewed by Kentaro Hara.

Source/WebCore:

If timeInput.focus() is called when a sub-field of the time input
already has focus, we should not focus on the first sub-field of the
time input.

Test: fast/forms/time-multiple-fields/time-multiple-fields-focus.html

* html/BaseMultipleFieldsDateAndTimeInputType.cpp:
(WebCore::BaseMultipleFieldsDateAndTimeInputType::willCancelFocus): If
the input elment already has focused sub-field, we don't need to proceed
focus handling. FocusDirection check is required because we don't need
to do this in cases of sequential focus navigation.
* html/BaseMultipleFieldsDateAndTimeInputType.h:
(BaseMultipleFieldsDateAndTimeInputType): Override InputType::willCancelFocus.

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::focus):
Cancel focus if InputType::willCancelFocus returns true.
* html/HTMLInputElement.h:
(HTMLInputElement): Override focus.
* html/InputType.cpp:
(WebCore::InputType::willCancelFocus):
Add a default implementation. It returns false.
* html/InputType.h:
(InputType): Declare willCancelFocus.

LayoutTests:

* fast/forms/time-multiple-fields/time-multiple-fields-focus-expected.txt: Added.
* fast/forms/time-multiple-fields/time-multiple-fields-focus.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (141886 => 141887)


--- trunk/LayoutTests/ChangeLog	2013-02-05 12:57:01 UTC (rev 141886)
+++ trunk/LayoutTests/ChangeLog	2013-02-05 13:03:38 UTC (rev 141887)
@@ -1,3 +1,13 @@
+2013-02-05  Kent Tamura  <[email protected]>
+
+        INPUT_MULTIPLE_FIELDS_UI: Should not move focus if the element already has focus
+        https://bugs.webkit.org/show_bug.cgi?id=108914
+
+        Reviewed by Kentaro Hara.
+
+        * fast/forms/time-multiple-fields/time-multiple-fields-focus-expected.txt: Added.
+        * fast/forms/time-multiple-fields/time-multiple-fields-focus.html: Added.
+
 2013-02-05  Zan Dobersek  <[email protected]>
 
         Unreviewed GTK gardening.

Added: trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-focus-expected.txt (0 => 141887)


--- trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-focus-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-focus-expected.txt	2013-02-05 13:03:38 UTC (rev 141887)
@@ -0,0 +1,14 @@
+Check if focus() for focused input does not change focused sub-field.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Move focus to the second sub-field, then press Up key:
+PASS document.activeElement is timeInput
+PASS timeInput.value is "01:02"
+Calls focus(), then press Up key:
+PASS timeInput.value is "01:03"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-focus.html (0 => 141887)


--- trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-focus.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-focus.html	2013-02-05 13:03:38 UTC (rev 141887)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<body>
+<script src=""
+<input id="timeInput" type="time" value="01:01" autofocus>
+<script>
+function dispatchKeyEventTo(type, key, target) {
+    var event = document.createEvent('KeyboardEvent');
+    event.initKeyboardEvent(type, true, true, document.defaultView, key);
+    target.dispatchEvent(event);
+}
+
+description('Check if focus() for focused input does not change focused sub-field.');
+debug('Move focus to the second sub-field, then press Up key:');
+var timeInput = document.getElementById('timeInput');
+shouldBe('document.activeElement', 'timeInput');
+dispatchKeyEventTo('keydown', 'Right', timeInput);
+dispatchKeyEventTo('keydown', 'Up', timeInput);
+shouldBeEqualToString('timeInput.value', '01:02');
+
+debug('Calls focus(), then press Up key:');
+timeInput.focus();
+dispatchKeyEventTo('keydown', 'Up', timeInput);
+shouldBeEqualToString('timeInput.value', '01:03');
+</script>
+<script src=""
+</body>

Modified: trunk/Source/WebCore/ChangeLog (141886 => 141887)


--- trunk/Source/WebCore/ChangeLog	2013-02-05 12:57:01 UTC (rev 141886)
+++ trunk/Source/WebCore/ChangeLog	2013-02-05 13:03:38 UTC (rev 141887)
@@ -1,3 +1,35 @@
+2013-02-05  Kent Tamura  <[email protected]>
+
+        INPUT_MULTIPLE_FIELDS_UI: Should not move focus if the element already has focus
+        https://bugs.webkit.org/show_bug.cgi?id=108914
+
+        Reviewed by Kentaro Hara.
+
+        If timeInput.focus() is called when a sub-field of the time input
+        already has focus, we should not focus on the first sub-field of the
+        time input.
+
+        Test: fast/forms/time-multiple-fields/time-multiple-fields-focus.html
+
+        * html/BaseMultipleFieldsDateAndTimeInputType.cpp:
+        (WebCore::BaseMultipleFieldsDateAndTimeInputType::willCancelFocus): If
+        the input elment already has focused sub-field, we don't need to proceed
+        focus handling. FocusDirection check is required because we don't need
+        to do this in cases of sequential focus navigation.
+        * html/BaseMultipleFieldsDateAndTimeInputType.h:
+        (BaseMultipleFieldsDateAndTimeInputType): Override InputType::willCancelFocus.
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::focus):
+        Cancel focus if InputType::willCancelFocus returns true.
+        * html/HTMLInputElement.h:
+        (HTMLInputElement): Override focus.
+        * html/InputType.cpp:
+        (WebCore::InputType::willCancelFocus):
+        Add a default implementation. It returns false.
+        * html/InputType.h:
+        (InputType): Declare willCancelFocus.
+
 2013-02-05  Allan Sandfeld Jensen  <[email protected]>
 
         [Qt] RGB -> BGR is wrong on big endian

Modified: trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp (141886 => 141887)


--- trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp	2013-02-05 12:57:01 UTC (rev 141886)
+++ trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp	2013-02-05 13:03:38 UTC (rev 141887)
@@ -241,6 +241,11 @@
     BaseDateAndTimeInputType::destroyShadowSubtree();
 }
 
+bool BaseMultipleFieldsDateAndTimeInputType::willCancelFocus(bool restorePreviousSelection, FocusDirection direction)
+{
+    return direction == FocusDirectionNone && m_dateTimeEditElement && m_dateTimeEditElement->hasFocusedField();
+}
+
 void BaseMultipleFieldsDateAndTimeInputType::handleFocusEvent(FocusDirection direction)
 {
     if (!m_dateTimeEditElement)

Modified: trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.h (141886 => 141887)


--- trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.h	2013-02-05 12:57:01 UTC (rev 141886)
+++ trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.h	2013-02-05 13:03:38 UTC (rev 141887)
@@ -81,6 +81,7 @@
     virtual void createShadowSubtree() OVERRIDE FINAL;
     virtual void destroyShadowSubtree() OVERRIDE FINAL;
     virtual void disabledAttributeChanged() OVERRIDE FINAL;
+    virtual bool willCancelFocus(bool restorePreviousSelection, FocusDirection) OVERRIDE;
     virtual void forwardEvent(Event*) OVERRIDE FINAL;
     virtual void handleFocusEvent(FocusDirection) OVERRIDE;
     virtual void handleKeydownEvent(KeyboardEvent*) OVERRIDE FINAL;

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (141886 => 141887)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2013-02-05 12:57:01 UTC (rev 141886)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2013-02-05 13:03:38 UTC (rev 141887)
@@ -370,6 +370,12 @@
     HTMLTextFormControlElement::blur();
 }
 
+void HTMLInputElement::focus(bool restorePreviousSelection, FocusDirection direction)
+{
+    if (!m_inputType->willCancelFocus(restorePreviousSelection, direction))
+        HTMLTextFormControlElement::focus(restorePreviousSelection, direction);
+}
+
 bool HTMLInputElement::hasCustomFocusLogic() const
 {
     return m_inputType->hasCustomFocusLogic();

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (141886 => 141887)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2013-02-05 12:57:01 UTC (rev 141886)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2013-02-05 13:03:38 UTC (rev 141887)
@@ -280,6 +280,7 @@
 
     virtual void blur() OVERRIDE;
     void defaultBlur();
+    virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone) OVERRIDE;
 
     virtual const AtomicString& name() const OVERRIDE;
 

Modified: trunk/Source/WebCore/html/InputType.cpp (141886 => 141887)


--- trunk/Source/WebCore/html/InputType.cpp	2013-02-05 12:57:01 UTC (rev 141886)
+++ trunk/Source/WebCore/html/InputType.cpp	2013-02-05 13:03:38 UTC (rev 141887)
@@ -470,6 +470,11 @@
     element()->defaultBlur();
 }
 
+bool InputType::willCancelFocus(bool, FocusDirection)
+{
+    return false;
+}
+
 void InputType::createShadowSubtree()
 {
 }

Modified: trunk/Source/WebCore/html/InputType.h (141886 => 141887)


--- trunk/Source/WebCore/html/InputType.h	2013-02-05 12:57:01 UTC (rev 141886)
+++ trunk/Source/WebCore/html/InputType.h	2013-02-05 13:03:38 UTC (rev 141887)
@@ -214,6 +214,7 @@
 #endif
 
     virtual void blur();
+    virtual bool willCancelFocus(bool restorePreviousSelection, FocusDirection);
 
     // Shadow tree handling
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to