Changeset 76566 in webkit


Ignore:
Timestamp:
Jan 24, 2011 8:36:26 PM (13 years ago)
Author:
tkent@chromium.org
Message:

2011-01-24 Kent Tamura <tkent@chromium.org>

Reviewed by Dimitri Glazkov.

Some bugs of search cancel button and spin button about state change in
an event handler.
https://bugs.webkit.org/show_bug.cgi?id=46950

  • fast/forms/input-number-change-type-on-focus-expected.txt: Added.
  • fast/forms/input-number-change-type-on-focus.html: Added.
  • fast/forms/search-hide-cancel-on-cancel-expected.txt: Added.
  • fast/forms/search-hide-cancel-on-cancel.html: Added.

2011-01-24 Kent Tamura <tkent@chromium.org>

Reviewed by Dimitri Glazkov.

Some bugs of search cancel button and spin button about state change in
an event handler.
https://bugs.webkit.org/show_bug.cgi?id=46950

Fix the following problems:

  • Type=search field didn't release event capturing
  • Assertion failure when an input field with spin buttons was changed to another type on focus event.
  • A input field with spin button didn't release event capturing when it was changed to another type on focus event.

Tests: fast/forms/input-number-change-type-on-focus.html

fast/forms/search-hide-cancel-on-cancel.html

  • rendering/TextControlInnerElements.cpp: (WebCore::SearchFieldCancelButtonElement::defaultEventHandler):
    • Make the variable 'input' RefPtr. It makes the code simpler.
    • Remove visibility check on mouseup event. We should release capturing anyway because the cancel button may be invisible if JavaScript code called by the focus event removes the input value.

(WebCore::SpinButtonElement::detach):

  • Release capturing on detach because it is possible that a spin button node is detached while it is capturing events.

(WebCore::SpinButtonElement::defaultEventHandler):

Take a reference to this and check renderer() after some functions which
may run JavaScript code.

(WebCore::InputFieldSpeechButtonElement::defaultEventHandler):

Make the variable 'input' RefPtr to align other functions in this file.

(WebCore::InputFieldSpeechButtonElement::setRecognitionResult): ditto.

  • rendering/TextControlInnerElements.h: Declare SpinButtonElement::detach().
Location:
trunk
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r76565 r76566  
     12011-01-24  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Some bugs of search cancel button and spin button about state change in
     6        an event handler.
     7        https://bugs.webkit.org/show_bug.cgi?id=46950
     8
     9        * fast/forms/input-number-change-type-on-focus-expected.txt: Added.
     10        * fast/forms/input-number-change-type-on-focus.html: Added.
     11        * fast/forms/search-hide-cancel-on-cancel-expected.txt: Added.
     12        * fast/forms/search-hide-cancel-on-cancel.html: Added.
     13
    1142011-01-24  Ryosuke Niwa  <rniwa@webkit.org>
    215
  • trunk/Source/WebCore/ChangeLog

    r76565 r76566  
     12011-01-24  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Some bugs of search cancel button and spin button about state change in
     6        an event handler.
     7        https://bugs.webkit.org/show_bug.cgi?id=46950
     8
     9        Fix the following problems:
     10         * Type=search field didn't release event capturing
     11         * Assertion failure when an input field with spin buttons was changed
     12           to another type on focus event.
     13         * A input field with spin button didn't release event capturing when it
     14           was changed to another type on focus event.
     15
     16        Tests: fast/forms/input-number-change-type-on-focus.html
     17               fast/forms/search-hide-cancel-on-cancel.html
     18
     19        * rendering/TextControlInnerElements.cpp:
     20        (WebCore::SearchFieldCancelButtonElement::defaultEventHandler):
     21         - Make the variable 'input' RefPtr.  It makes the code simpler.
     22         - Remove visibility check on mouseup event. We should release capturing
     23           anyway because the cancel button may be invisible if JavaScript code
     24           called by the focus event removes the input value.
     25        (WebCore::SpinButtonElement::detach):
     26         - Release capturing on detach because it is possible that a spin button
     27           node is detached while it is capturing events.
     28        (WebCore::SpinButtonElement::defaultEventHandler):
     29          Take a reference to this and check renderer() after some functions which
     30          may run JavaScript code.
     31        (WebCore::InputFieldSpeechButtonElement::defaultEventHandler):
     32          Make the variable 'input' RefPtr to align other functions in this file.
     33        (WebCore::InputFieldSpeechButtonElement::setRecognitionResult): ditto.
     34        * rendering/TextControlInnerElements.h: Declare SpinButtonElement::detach().
     35
    1362011-01-24  Ryosuke Niwa  <rniwa@webkit.org>
    237
  • trunk/Source/WebCore/rendering/TextControlInnerElements.cpp

    r76494 r76566  
    220220{
    221221    // If the element is visible, on mouseup, clear the value, and set selection
    222     HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
     222    RefPtr<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowAncestorNode()));
    223223    if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
    224224        if (renderer() && renderer()->visibleToHitTesting()) {
     
    233233    }
    234234    if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
    235         if (m_capturing && renderer() && renderer()->visibleToHitTesting()) {
     235        if (m_capturing) {
    236236            if (Frame* frame = document()->frame()) {
    237237                frame->eventHandler()->setCapturingMouseEventsNode(0);
     
    239239            }
    240240            if (hovered()) {
    241                 RefPtr<HTMLInputElement> protector(input);
    242241                String oldValue = input->value();
    243242                input->setValue("");
     
    272271}
    273272
     273void SpinButtonElement::detach()
     274{
     275    stopRepeatingTimer();
     276    if (m_capturing) {
     277        if (Frame* frame = document()->frame()) {
     278            frame->eventHandler()->setCapturingMouseEventsNode(0);
     279            m_capturing = false;
     280        }
     281    }
     282    TextControlInnerElement::detach();
     283}
     284
    274285void SpinButtonElement::defaultEventHandler(Event* event)
    275286{
     
    287298    }
    288299
    289     HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
     300    RefPtr<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowAncestorNode()));
    290301    if (input->disabled() || input->isReadOnlyFormControl()) {
    291302        if (!event->defaultHandled())
     
    298309    if (mouseEvent->type() == eventNames().mousedownEvent && mouseEvent->button() == LeftButton) {
    299310        if (box->borderBoxRect().contains(local)) {
    300             RefPtr<Node> protector(input);
     311            // The following functions of HTMLInputElement may run JavaScript
     312            // code which detaches this shadow node. We need to take a reference
     313            // and check renderer() after such function calls.
     314            RefPtr<Node> protector(this);
    301315            input->focus();
    302316            input->select();
    303             input->stepUpFromRenderer(m_upDownState == Up ? 1 : -1);
     317            if (renderer()) {
     318                input->stepUpFromRenderer(m_upDownState == Up ? 1 : -1);
     319                if (renderer())
     320                    startRepeatingTimer();
     321            }
    304322            event->setDefaultHandled();
    305             startRepeatingTimer();
    306323        }
    307324    } else if (mouseEvent->type() == eventNames().mouseupEvent && mouseEvent->button() == LeftButton)
     
    404421    }
    405422
     423    // The call to focus() below dispatches a focus event, and an event handler in the page might
     424    // remove the input element from DOM. To make sure it remains valid until we finish our work
     425    // here, we take a temporary reference.
     426    RefPtr<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowAncestorNode()));
     427
    406428    // On mouse down, select the text and set focus.
    407     HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
    408429    if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
    409430        if (renderer() && renderer()->visibleToHitTesting()) {
     
    413434            }
    414435        }
    415         // The call to focus() below dispatches a focus event, and an event handler in the page might
    416         // remove the input element from DOM. To make sure it remains valid until we finish our work
    417         // here, we take a temporary reference.
    418         RefPtr<HTMLInputElement> holdRef(input);
    419436        RefPtr<InputFieldSpeechButtonElement> holdRefButton(this);
    420437        input->focus();
     
    483500    m_results = results;
    484501
    485     HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
    486502    // The call to setValue() below dispatches an event, and an event handler in the page might
    487503    // remove the input element from DOM. To make sure it remains valid until we finish our work
    488504    // here, we take a temporary reference.
    489     RefPtr<HTMLInputElement> holdRef(input);
     505    RefPtr<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowAncestorNode()));
    490506    RefPtr<InputFieldSpeechButtonElement> holdRefButton(this);
    491507    input->setValue(results.isEmpty() ? "" : results[0]->utterance());
  • trunk/Source/WebCore/rendering/TextControlInnerElements.h

    r76494 r76566  
    100100    SpinButtonElement(HTMLElement*);
    101101
     102    virtual void detach();
    102103    virtual bool isSpinButtonElement() const { return true; }
    103104    // FIXME: shadowAncestorNode() should be const.
Note: See TracChangeset for help on using the changeset viewer.