Changeset 87371 in webkit


Ignore:
Timestamp:
May 26, 2011 2:10:51 AM (13 years ago)
Author:
tkent@chromium.org
Message:

2011-05-26 Kent Tamura <tkent@chromium.org>

Reviewed by Dimitri Glazkov.

Fix a bug that <input type="number"> dispatches two blurs when tabbing
from an invalid number
https://bugs.webkit.org/show_bug.cgi?id=59071

  • fast/forms/input-number-blur-twice-expected.txt: Added.
  • fast/forms/input-number-blur-twice.html: Added.

2011-05-26 Kent Tamura <tkent@chromium.org>

Reviewed by Dimitri Glazkov.

Fix a bug that <input type="number"> dispatches two blurs when tabbing
from an invalid number
https://bugs.webkit.org/show_bug.cgi?id=59071

NumberInputType::handleBlurEvent() dispatched an extra focus event
and an extra blur event because
SelectionController::textWillBeReplaced() called by
RenderTextControlSingleLine::updateFromElement() focuses a node
with the selection.

In order to avoid this problem,

  • Introduce Node::willBlur() It is called before any state changes by a blur event.
  • Call RenderTextControlSingleLine::updateFromElement() in willBlur() It avoids extra focus/blur events because Document::m_focusedNode is still the number input during willBlur().

Test: fast/forms/input-number-blur-twice.html

  • dom/Document.cpp: (WebCore::Document::setFocusedNode): Calls Node::beforeBlueEvent().
  • dom/Node.cpp: (WebCore::Node::willBlur): Default empty implementation of willBlur().
  • dom/Node.h: Declare willBlur().
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::willBlur): Added. It just calls InputType::willBlur(). (WebCore::HTMLInputElement::handleBlurEvent): Removed InputType::handleBlurEvent() call.
  • html/HTMLInputElement.h: Declare willBlur().
  • html/InputType.cpp: (WebCore::InputType::willBlur): Default empty implementation. (WebCore::InputType::handleBlurEvent): Removed.
  • html/InputType.h: Declare willBlur(), remove handleBlurEvent().
  • html/NumberInputType.cpp: (WebCore::NumberInputType::willBlur): Move the code in handleBlurEvent() here.
  • html/NumberInputType.h: Declare willBlur().
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r87368 r87371  
     12011-05-26  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Fix a bug that <input type="number"> dispatches two blurs when tabbing
     6        from an invalid number
     7        https://bugs.webkit.org/show_bug.cgi?id=59071
     8
     9        * fast/forms/input-number-blur-twice-expected.txt: Added.
     10        * fast/forms/input-number-blur-twice.html: Added.
     11
    1122011-05-26  Shane Stephens  <shanestephens@google.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r87370 r87371  
     12011-05-26  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Fix a bug that <input type="number"> dispatches two blurs when tabbing
     6        from an invalid number
     7        https://bugs.webkit.org/show_bug.cgi?id=59071
     8
     9        NumberInputType::handleBlurEvent() dispatched an extra focus event
     10        and an extra blur event because
     11        SelectionController::textWillBeReplaced() called by
     12        RenderTextControlSingleLine::updateFromElement() focuses a node
     13        with the selection.
     14
     15        In order to avoid this problem,
     16         - Introduce Node::willBlur()
     17           It is called before any state changes by a blur event.
     18         - Call RenderTextControlSingleLine::updateFromElement() in willBlur()
     19           It avoids extra focus/blur events because Document::m_focusedNode is
     20           still the number input during willBlur().
     21
     22        Test: fast/forms/input-number-blur-twice.html
     23
     24        * dom/Document.cpp:
     25        (WebCore::Document::setFocusedNode): Calls Node::beforeBlueEvent().
     26        * dom/Node.cpp:
     27        (WebCore::Node::willBlur):
     28          Default empty implementation of willBlur().
     29        * dom/Node.h: Declare willBlur().
     30        * html/HTMLInputElement.cpp:
     31        (WebCore::HTMLInputElement::willBlur):
     32          Added.  It just calls InputType::willBlur().
     33        (WebCore::HTMLInputElement::handleBlurEvent):
     34          Removed InputType::handleBlurEvent() call.
     35        * html/HTMLInputElement.h: Declare willBlur().
     36        * html/InputType.cpp:
     37        (WebCore::InputType::willBlur): Default empty implementation.
     38        (WebCore::InputType::handleBlurEvent): Removed.
     39        * html/InputType.h: Declare willBlur(), remove handleBlurEvent().
     40        * html/NumberInputType.cpp:
     41        (WebCore::NumberInputType::willBlur):
     42          Move the code in handleBlurEvent() here.
     43        * html/NumberInputType.h: Declare willBlur().
     44
    1452011-05-25  Hans Wennborg  <hans@chromium.org>
    246
  • trunk/Source/WebCore/dom/Document.cpp

    r87322 r87371  
    32213221    bool focusChangeBlocked = false;
    32223222    RefPtr<Node> oldFocusedNode = m_focusedNode;
    3223     m_focusedNode = 0;
    32243223
    32253224    // Remove focus from the existing focus node (if any)
    3226     if (oldFocusedNode && !oldFocusedNode->inDetach()) {
     3225    if (oldFocusedNode && !oldFocusedNode->inDetach()) {
     3226        // willBlur() should be called before any status changes.
     3227        oldFocusedNode->willBlur();
     3228        m_focusedNode = 0;
    32273229        if (oldFocusedNode->active())
    32283230            oldFocusedNode->setActive(false);
     
    32693271                view()->setFocus(false);
    32703272        }
    3271     }
     3273    } else
     3274        m_focusedNode = 0;
    32723275
    32733276    if (newFocusedNode) {
  • trunk/Source/WebCore/dom/Node.cpp

    r87227 r87371  
    27322732}
    27332733
     2734void Node::willBlur()
     2735{
     2736}
     2737
    27342738void Node::dispatchBlurEvent()
    27352739{
  • trunk/Source/WebCore/dom/Node.h

    r87227 r87371  
    556556
    557557    virtual void dispatchFocusEvent();
     558    virtual void willBlur();
    558559    virtual void dispatchBlurEvent();
    559560    virtual void dispatchChangeEvent();
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r87125 r87371  
    497497}
    498498
     499void HTMLInputElement::willBlur()
     500{
     501    m_inputType->willBlur();
     502    HTMLTextFormControlElement::willBlur();
     503}
     504
    499505void HTMLInputElement::handleBlurEvent()
    500506{
    501     m_inputType->handleBlurEvent();
    502 
    503507    if (!isTextField())
    504508        return;
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r87125 r87371  
    302302    virtual bool isEmptySuggestedValue() const { return suggestedValue().isEmpty(); }
    303303    virtual void handleFocusEvent();
     304    virtual void willBlur();
    304305    virtual void handleBlurEvent();
    305306    virtual int cachedSelectionStart() const { return m_cachedSelectionStart; }
  • trunk/Source/WebCore/html/InputType.cpp

    r87274 r87371  
    411411}
    412412
    413 void InputType::handleBlurEvent()
     413void InputType::willBlur()
    414414{
    415415}
  • trunk/Source/WebCore/html/InputType.h

    r87274 r87371  
    179179    virtual bool isKeyboardFocusable() const;
    180180    virtual bool shouldUseInputMethod() const;
    181     virtual void handleBlurEvent();
     181    virtual void willBlur();
    182182    virtual void accessKeyAction(bool sendToAnyElement);
    183183    virtual bool canBeSuccessfulSubmitButton();
  • trunk/Source/WebCore/html/NumberInputType.cpp

    r84695 r87371  
    212212}
    213213
    214 void NumberInputType::handleBlurEvent()
     214void NumberInputType::willBlur()
    215215{
    216216    // Reset the renderer value, which might be unmatched with the element value.
  • trunk/Source/WebCore/html/NumberInputType.h

    r84695 r87371  
    6464    virtual String serialize(double) const;
    6565    virtual double acceptableError(double) const;
    66     virtual void handleBlurEvent();
     66    virtual void willBlur();
    6767    virtual String visibleValue() const;
    6868    virtual String convertFromVisibleValue(const String&) const;
Note: See TracChangeset for help on using the changeset viewer.