Changeset 142592 in webkit


Ignore:
Timestamp:
Feb 12, 2013 12:34:57 AM (11 years ago)
Author:
tkent@chromium.org
Message:

INPUT_MULTIPLE_FIELDS_UI: Mouse click not on sub-fields in multiple fields input should not move focus
https://bugs.webkit.org/show_bug.cgi?id=109544

Reviewed by Kentaro Hara.

Source/WebCore:

This is similar to Bug 108914, "Should not move focus if the element
already has focus." We fixed a focus() case in Bug 108914. However we
still have the problem in a case of focusing by mouse click.

The fix for Bug 108914 intercepted focus() function to change the
behavior. However focus-by-click doesn't call focus(), but calls
FocusController::setFocusedNode. To fix this problem, we introduce
oldFocusedNode argument to handleFocusEvent, and
BaseMultipleFieldsDateAndTimeInputType::handleFocusEvent restores the
focus to oldFocusedNode if oldFocusedNode is one of sub-fields.
handleFocusEvent is called whenever the focused node is changed.

We don't need InputType::willCancelFocus any more because the new code
in handleFocusEvent covers it.

Tests: Update fast/forms/time-multiple-fields/time-multiple-fields-focus.html.

  • html/HTMLTextFormControlElement.h:

(WebCore::HTMLTextFormControlElement::handleFocusEvent):
Add oldFocusedNode argument.

  • html/HTMLTextFormControlElement.cpp:

(WebCore::HTMLTextFormControlElement::dispatchFocusEvent):
Pass oldFocusedNode to handleFocusEvent.

  • html/HTMLInputElement.h:

(HTMLInputElement):

  • Add oldFocusedNode argument to handleFocusEvent.
  • Remove focus() override.
  • html/HTMLInputElement.cpp: Remove focus() override.

(WebCore::HTMLInputElement::handleFocusEvent):
Pass oldFocusedNode to InputType::handleFocusEvent.

  • html/InputType.cpp: Remove willCancelFocus.

(WebCore::InputType::handleFocusEvent):
Add oldFocusedNode argument.

  • html/InputType.h:

(InputType): Ditto.

  • html/PasswordInputType.cpp:

(WebCore::PasswordInputType::handleFocusEvent): Ditto.

  • html/PasswordInputType.h:

(PasswordInputType): Ditto.

  • html/BaseMultipleFieldsDateAndTimeInputType.h:

(BaseMultipleFieldsDateAndTimeInputType):
Remove willCancelFocus, and add oldFocusedNode argument to handleFocusEvent.

  • html/BaseMultipleFieldsDateAndTimeInputType.cpp:

(WebCore::BaseMultipleFieldsDateAndTimeInputType::handleFocusEvent):
Pass oldFocusedNode to DateTimeEditElement::focusByOwner if the
direction is FocusDirectionNone.

  • html/shadow/DateTimeEditElement.h:

(DateTimeEditElement): Add oldFocusedNode argument to focusByOwner.

  • html/shadow/DateTimeEditElement.cpp:

(WebCore::DateTimeEditElement::focusByOwner):
If oldFocusedNode is one of sub-fields, focus on it again.

LayoutTests:

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

Add test to click a delimiter.

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r142588 r142592  
     12013-02-12  Kent Tamura  <tkent@chromium.org>
     2
     3        INPUT_MULTIPLE_FIELDS_UI: Mouse click not on sub-fields in multiple fields input  should not move focus
     4        https://bugs.webkit.org/show_bug.cgi?id=109544
     5
     6        Reviewed by Kentaro Hara.
     7
     8        * fast/forms/time-multiple-fields/time-multiple-fields-focus-expected.txt:
     9        * fast/forms/time-multiple-fields/time-multiple-fields-focus.html:
     10        Add test to click a delimiter.
     11
    1122013-02-11  KwangYong Choi  <ky0.choi@samsung.com>
    213
  • trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-focus-expected.txt

    r141887 r142592  
    44
    55
    6 Move focus to the second sub-field, then press Up key:
     6Move focus to the second sub-field:
    77PASS document.activeElement is timeInput
    8 PASS timeInput.value is "01:02"
    9 Calls focus(), then press Up key:
    10 PASS timeInput.value is "01:03"
     8PASS pseudoOfFocused(timeInput) is "-webkit-datetime-edit-minute-field"
     9PASS timeInput.focus(); pseudoOfFocused(timeInput) is "-webkit-datetime-edit-minute-field"
     10Click on a delimiter between sub-fields, then check if focused element is not changed:
     11PASS pseudoOfFocused(timeInput) is "-webkit-datetime-edit-minute-field"
    1112PASS successfullyParsed is true
    1213
  • trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-focus.html

    r141887 r142592  
    22<body>
    33<script src="../../js/resources/js-test-pre.js"></script>
    4 <input id="timeInput" type="time" value="01:01" autofocus>
     4<input id="timeInput" type="time" value="01:01" style="font-size:20px" autofocus>
    55<script>
    66function dispatchKeyEventTo(type, key, target) {
     
    1010}
    1111
     12function pseudoOfFocused() {
     13    return internals.youngestShadowRoot(timeInput).activeElement.getAttribute("pseudo");
     14}
     15
    1216description('Check if focus() for focused input does not change focused sub-field.');
    13 debug('Move focus to the second sub-field, then press Up key:');
     17debug('Move focus to the second sub-field:');
    1418var timeInput = document.getElementById('timeInput');
    1519shouldBe('document.activeElement', 'timeInput');
    1620dispatchKeyEventTo('keydown', 'Right', timeInput);
    17 dispatchKeyEventTo('keydown', 'Up', timeInput);
    18 shouldBeEqualToString('timeInput.value', '01:02');
     21shouldBeEqualToString('pseudoOfFocused(timeInput)', '-webkit-datetime-edit-minute-field');
     22shouldBeEqualToString('timeInput.focus(); pseudoOfFocused(timeInput)', '-webkit-datetime-edit-minute-field');
    1923
    20 debug('Calls focus(), then press Up key:');
    21 timeInput.focus();
    22 dispatchKeyEventTo('keydown', 'Up', timeInput);
    23 shouldBeEqualToString('timeInput.value', '01:03');
     24debug('Click on a delimiter between sub-fields, then check if focused element is not changed:');
     25var focusedField = internals.youngestShadowRoot(timeInput).activeElement;
     26eventSender.mouseMoveTo(focusedField.offsetLeft + focusedField.offsetWidth + 10, focusedField.offsetTop + 10);
     27eventSender.mouseDown();
     28eventSender.mouseUp();
     29shouldBeEqualToString('pseudoOfFocused(timeInput)', '-webkit-datetime-edit-minute-field');
    2430</script>
    2531<script src="../../js/resources/js-test-post.js"></script>
  • trunk/Source/WebCore/ChangeLog

    r142591 r142592  
     12013-02-12  Kent Tamura  <tkent@chromium.org>
     2
     3        INPUT_MULTIPLE_FIELDS_UI: Mouse click not on sub-fields in multiple fields input  should not move focus
     4        https://bugs.webkit.org/show_bug.cgi?id=109544
     5
     6        Reviewed by Kentaro Hara.
     7
     8        This is similar to Bug 108914, "Should not move focus if the element
     9        already has focus." We fixed a focus() case in Bug 108914. However we
     10        still have the problem in a case of focusing by mouse click.
     11
     12        The fix for Bug 108914 intercepted focus() function to change the
     13        behavior. However focus-by-click doesn't call focus(), but calls
     14        FocusController::setFocusedNode. To fix this problem, we introduce
     15        oldFocusedNode argument to handleFocusEvent, and
     16        BaseMultipleFieldsDateAndTimeInputType::handleFocusEvent restores the
     17        focus to oldFocusedNode if oldFocusedNode is one of sub-fields.
     18        handleFocusEvent is called whenever the focused node is changed.
     19
     20        We don't need InputType::willCancelFocus any more because the new code
     21        in handleFocusEvent covers it.
     22
     23        Tests: Update fast/forms/time-multiple-fields/time-multiple-fields-focus.html.
     24
     25        * html/HTMLTextFormControlElement.h:
     26        (WebCore::HTMLTextFormControlElement::handleFocusEvent):
     27        Add oldFocusedNode argument.
     28        * html/HTMLTextFormControlElement.cpp:
     29        (WebCore::HTMLTextFormControlElement::dispatchFocusEvent):
     30        Pass oldFocusedNode to handleFocusEvent.
     31
     32        * html/HTMLInputElement.h:
     33        (HTMLInputElement):
     34         - Add oldFocusedNode argument to handleFocusEvent.
     35         - Remove focus() override.
     36        * html/HTMLInputElement.cpp: Remove focus() override.
     37        (WebCore::HTMLInputElement::handleFocusEvent):
     38        Pass oldFocusedNode to InputType::handleFocusEvent.
     39        * html/InputType.cpp: Remove willCancelFocus.
     40        (WebCore::InputType::handleFocusEvent):
     41        Add oldFocusedNode argument.
     42        * html/InputType.h:
     43        (InputType): Ditto.
     44        * html/PasswordInputType.cpp:
     45        (WebCore::PasswordInputType::handleFocusEvent): Ditto.
     46        * html/PasswordInputType.h:
     47        (PasswordInputType): Ditto.
     48
     49        * html/BaseMultipleFieldsDateAndTimeInputType.h:
     50        (BaseMultipleFieldsDateAndTimeInputType):
     51        Remove willCancelFocus, and add oldFocusedNode argument to handleFocusEvent.
     52        * html/BaseMultipleFieldsDateAndTimeInputType.cpp:
     53        (WebCore::BaseMultipleFieldsDateAndTimeInputType::handleFocusEvent):
     54        Pass oldFocusedNode to DateTimeEditElement::focusByOwner if the
     55        direction is FocusDirectionNone.
     56
     57        * html/shadow/DateTimeEditElement.h:
     58        (DateTimeEditElement): Add oldFocusedNode argument to focusByOwner.
     59        * html/shadow/DateTimeEditElement.cpp:
     60        (WebCore::DateTimeEditElement::focusByOwner):
     61        If oldFocusedNode is one of sub-fields, focus on it again.
     62
    1632013-02-12  Takashi Sakamoto  <tasak@google.com>
    264
  • trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp

    r141960 r142592  
    242242}
    243243
    244 bool BaseMultipleFieldsDateAndTimeInputType::willCancelFocus(bool restorePreviousSelection, FocusDirection direction)
    245 {
    246     return direction == FocusDirectionNone && m_dateTimeEditElement && m_dateTimeEditElement->hasFocusedField();
    247 }
    248 
    249 void BaseMultipleFieldsDateAndTimeInputType::handleFocusEvent(FocusDirection direction)
     244void BaseMultipleFieldsDateAndTimeInputType::handleFocusEvent(Node* oldFocusedNode, FocusDirection direction)
    250245{
    251246    if (!m_dateTimeEditElement)
     
    254249        if (element()->document()->page())
    255250            element()->document()->page()->focusController()->advanceFocus(direction, 0);
     251    } else if (direction == FocusDirectionNone) {
     252        m_dateTimeEditElement->focusByOwner(oldFocusedNode);
    256253    } else
    257254        m_dateTimeEditElement->focusByOwner();
  • trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.h

    r142248 r142592  
    8282    virtual void destroyShadowSubtree() OVERRIDE FINAL;
    8383    virtual void disabledAttributeChanged() OVERRIDE FINAL;
    84     virtual bool willCancelFocus(bool restorePreviousSelection, FocusDirection) OVERRIDE;
    8584    virtual void forwardEvent(Event*) OVERRIDE FINAL;
    86     virtual void handleFocusEvent(FocusDirection) OVERRIDE;
     85    virtual void handleFocusEvent(Node* oldFocusedNode, FocusDirection) OVERRIDE;
    8786    virtual void handleKeydownEvent(KeyboardEvent*) OVERRIDE FINAL;
    8887    virtual bool hasBadInput() const OVERRIDE;
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r141887 r142592  
    371371}
    372372
    373 void HTMLInputElement::focus(bool restorePreviousSelection, FocusDirection direction)
    374 {
    375     if (!m_inputType->willCancelFocus(restorePreviousSelection, direction))
    376         HTMLTextFormControlElement::focus(restorePreviousSelection, direction);
    377 }
    378 
    379373bool HTMLInputElement::hasCustomFocusLogic() const
    380374{
     
    434428}
    435429
    436 void HTMLInputElement::handleFocusEvent(FocusDirection direction)
    437 {
    438     m_inputType->handleFocusEvent(direction);
     430void HTMLInputElement::handleFocusEvent(Node* oldFocusedNode, FocusDirection direction)
     431{
     432    m_inputType->handleFocusEvent(oldFocusedNode, direction);
    439433}
    440434
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r141887 r142592  
    281281    virtual void blur() OVERRIDE;
    282282    void defaultBlur();
    283     virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone) OVERRIDE;
    284283
    285284    virtual const AtomicString& name() const OVERRIDE;
     
    379378    virtual bool isEmptyValue() const OVERRIDE { return innerTextValue().isEmpty(); }
    380379    virtual bool isEmptySuggestedValue() const { return suggestedValue().isEmpty(); }
    381     virtual void handleFocusEvent(FocusDirection) OVERRIDE;
     380    virtual void handleFocusEvent(Node* oldFocusedNode, FocusDirection) OVERRIDE;
    382381    virtual void handleBlurEvent();
    383382
  • trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp

    r142247 r142592  
    8989    if (supportsPlaceholder())
    9090        updatePlaceholderVisibility(false);
    91     handleFocusEvent(direction);
     91    handleFocusEvent(oldFocusedNode.get(), direction);
    9292    HTMLFormControlElementWithState::dispatchFocusEvent(oldFocusedNode, direction);
    9393}
  • trunk/Source/WebCore/html/HTMLTextFormControlElement.h

    r141738 r142592  
    128128    virtual bool isEmptySuggestedValue() const { return true; }
    129129    // Called in dispatchFocusEvent(), after placeholder process, before calling parent's dispatchFocusEvent().
    130     virtual void handleFocusEvent(FocusDirection) { }
     130    virtual void handleFocusEvent(Node* /* oldFocusedNode */, FocusDirection) { }
    131131    // Called in dispatchBlurEvent(), after placeholder process, before calling parent's dispatchBlurEvent().
    132132    virtual void handleBlurEvent() { }
  • trunk/Source/WebCore/html/InputType.cpp

    r142271 r142592  
    472472}
    473473
    474 bool InputType::willCancelFocus(bool, FocusDirection)
    475 {
    476     return false;
    477 }
    478 
    479474void InputType::createShadowSubtree()
    480475{
     
    564559}
    565560
    566 void InputType::handleFocusEvent(FocusDirection)
     561void InputType::handleFocusEvent(Node*, FocusDirection)
    567562{
    568563}
  • trunk/Source/WebCore/html/InputType.h

    r142290 r142592  
    205205    virtual bool isMouseFocusable() const;
    206206    virtual bool shouldUseInputMethod() const;
    207     virtual void handleFocusEvent(FocusDirection);
     207    virtual void handleFocusEvent(Node* oldFocusedNode, FocusDirection);
    208208    virtual void handleBlurEvent();
    209209    virtual void accessKeyAction(bool sendMouseEvents);
     
    215215
    216216    virtual void blur();
    217     virtual bool willCancelFocus(bool restorePreviousSelection, FocusDirection);
    218217
    219218    // Shadow tree handling
  • trunk/Source/WebCore/html/PasswordInputType.cpp

    r141835 r142592  
    9696}
    9797
    98 void PasswordInputType::handleFocusEvent(FocusDirection direction)
     98void PasswordInputType::handleFocusEvent(Node* oldFocusedNode, FocusDirection direction)
    9999{
    100     BaseTextInputType::handleFocusEvent(direction);
     100    BaseTextInputType::handleFocusEvent(oldFocusedNode, direction);
    101101    if (element()->document()->frame())
    102102        element()->document()->setUseSecureKeyboardEntryWhenActive(true);
  • trunk/Source/WebCore/html/PasswordInputType.h

    r141835 r142592  
    5151    virtual bool shouldRespectSpeechAttribute() OVERRIDE;
    5252    virtual bool isPasswordField() const OVERRIDE;
    53     virtual void handleFocusEvent(FocusDirection) OVERRIDE;
     53    virtual void handleFocusEvent(Node* oldFocusedNode, FocusDirection) OVERRIDE;
    5454    virtual void handleBlurEvent() OVERRIDE;
    5555};
  • trunk/Source/WebCore/html/shadow/DateTimeEditElement.cpp

    r141960 r142592  
    510510}
    511511
    512 void DateTimeEditElement::focusByOwner()
    513 {
     512void DateTimeEditElement::focusByOwner(Node* oldFocusedNode)
     513{
     514    if (oldFocusedNode && oldFocusedNode->isElementNode() && toElement(oldFocusedNode)->isDateTimeFieldElement()) {
     515        DateTimeFieldElement* oldFocusedField = static_cast<DateTimeFieldElement*>(oldFocusedNode);
     516        size_t index = fieldIndexOf(*oldFocusedField);
     517        if (index != invalidFieldIndex && oldFocusedField->isFocusable()) {
     518            oldFocusedField->focus();
     519            return;
     520        }
     521    }
    514522    focusOnNextFocusableField(0);
    515523}
  • trunk/Source/WebCore/html/shadow/DateTimeEditElement.h

    r141960 r142592  
    9090    Element* fieldsWrapperElement() const;
    9191    void focusIfNoFocus();
    92     void focusByOwner();
     92    // If oldFocusedNode is one of sub-fields, focus on it. Otherwise focus on
     93    // the first sub-field.
     94    void focusByOwner(Node* oldFocusedNode = 0);
    9395    bool hasFocusedField();
    9496    void readOnlyStateChanged();
Note: See TracChangeset for help on using the changeset viewer.