Changeset 12345 in webkit


Ignore:
Timestamp:
Jan 24, 2006 11:35:27 PM (18 years ago)
Author:
adele
Message:

LayoutTests:

Test for focus and blur for new text fields.

  • fast/forms/input-appearance-focus.html: Added.
  • fast/forms/input-appearance-focus-expected.txt: Added.
  • fast/forms/input-appearance-focus-expected.png: Added.
  • fast/forms/input-appearance-focus-expected.checksum: Added.

WebCore:

Reviewed by Hyatt.

This change will allow the new text field elements to get focus, and to respond to the focus and blur events.

Added: fast/forms/input-appearance-focus.html

  • khtml/html/HTMLElementImpl.cpp: (WebCore::HTMLElementImpl::isFocusable): Removed recently added code that allowed editable elements with no parent to be focusable. We don't need to do this now that we try to focus the input element, instead of the inner div.
  • khtml/html/HTMLGenericFormElementImpl.cpp: (WebCore::HTMLGenericFormElementImpl::isMouseFocusable): Added case to for text fields.
  • khtml/html/HTMLInputElementImpl.cpp: (WebCore::HTMLInputElementImpl::focus): Added. Selects contents of text field. (WebCore::HTMLInputElementImpl::setSelectionStart): Added break; in switch statement. (WebCore::HTMLInputElementImpl::setSelectionEnd): ditto. (WebCore::HTMLInputElementImpl::select): ditto. (WebCore::HTMLInputElementImpl::setSelectionRange): ditto.
  • khtml/html/HTMLInputElementImpl.h: Added focus()
  • khtml/xml/dom_elementimpl.h: Made focus() virtual.
  • page/Frame.cpp: (Frame::setFocusNodeIfNeeded): Walk up the Render Tree instead of the DOM tree when trying to find a node to focus. This will let us choose the input node instead of one of the nodes in the shadow tree.
  • page/FrameView.cpp: (FrameView::dispatchMouseEvent): ditto.
  • rendering/RenderContainer.cpp: (WebCore::RenderContainer::destroyLeftoverChildren): Corrected misspelling.
  • rendering/RenderTextField.cpp: (WebCore::RenderTextField::select): Implemented. Select contents of inner div.
  • rendering/RenderTextField.h: (WebCore::RenderTextField::renderName): Changed order. (WebCore::RenderTextField::removeLeftoverAnonymousBoxes): ditto.
Location:
trunk
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r12344 r12345  
     12006-01-24  Adele Peterson <adele@apple.com>
     2
     3        Test for focus and blur for new text fields.
     4
     5        * fast/forms/input-appearance-focus.html: Added.
     6        * fast/forms/input-appearance-focus-expected.txt: Added.
     7        * fast/forms/input-appearance-focus-expected.png: Added.
     8        * fast/forms/input-appearance-focus-expected.checksum: Added.
     9
    1102006-01-24  Darin Adler  <darin@apple.com>
    211
  • trunk/WebCore/ChangeLog

    r12343 r12345  
     12006-01-24  Adele Peterson  <adele@apple.com>
     2
     3        Reviewed by Hyatt.
     4
     5        This change will allow the new text field elements to get focus, and to respond to the focus and blur events.
     6
     7        Added: fast/forms/input-appearance-focus.html
     8
     9        * khtml/html/HTMLElementImpl.cpp: (WebCore::HTMLElementImpl::isFocusable):
     10          Removed recently added code that allowed editable elements with no parent to be focusable. 
     11          We don't need to do this now that we try to focus the input element, instead of the inner div.
     12        * khtml/html/HTMLGenericFormElementImpl.cpp: (WebCore::HTMLGenericFormElementImpl::isMouseFocusable): Added case to for text fields.
     13        * khtml/html/HTMLInputElementImpl.cpp:
     14        (WebCore::HTMLInputElementImpl::focus): Added. Selects contents of text field.
     15        (WebCore::HTMLInputElementImpl::setSelectionStart): Added break; in switch statement.
     16        (WebCore::HTMLInputElementImpl::setSelectionEnd): ditto.
     17        (WebCore::HTMLInputElementImpl::select): ditto.
     18        (WebCore::HTMLInputElementImpl::setSelectionRange): ditto.
     19        * khtml/html/HTMLInputElementImpl.h: Added focus()
     20        * khtml/xml/dom_elementimpl.h: Made focus() virtual.
     21        * page/Frame.cpp: (Frame::setFocusNodeIfNeeded):
     22          Walk up the Render Tree instead of the DOM tree when trying to find a node to focus. 
     23          This will let us choose the input node instead of one of the nodes in the shadow tree.
     24        * page/FrameView.cpp: (FrameView::dispatchMouseEvent): ditto.
     25        * rendering/RenderContainer.cpp: (WebCore::RenderContainer::destroyLeftoverChildren): Corrected misspelling.
     26        * rendering/RenderTextField.cpp:
     27        (WebCore::RenderTextField::select): Implemented.  Select contents of inner div.
     28        * rendering/RenderTextField.h:
     29        (WebCore::RenderTextField::renderName): Changed order.
     30        (WebCore::RenderTextField::removeLeftoverAnonymousBoxes): ditto.
     31
    1322006-01-24  Darin Adler  <darin@apple.com>
    233
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r12341 r12345  
    12461246                93E62D980985F41600E1B5E3 /* SystemTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SystemTime.cpp; path = platform/mac/SystemTime.cpp; sourceTree = "<group>"; };
    12471247                93E62D990985F41600E1B5E3 /* SystemTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SystemTime.h; path = platform/SystemTime.h; sourceTree = "<group>"; };
    1248                 93ECDB7E03ABE65B008635CE /* KWQColorData.gperf */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = text; path = KWQColorData.gperf; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    12491248                93F19B1908245E59001E9ABC /* Info.plist */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = text.xml; path = Info.plist; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    12501249                93F19B1A08245E5A001E9ABC /* WebCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = WebCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
  • trunk/WebCore/khtml/html/HTMLElementImpl.cpp

    r12329 r12345  
    451451bool HTMLElementImpl::isFocusable() const
    452452{
    453     // Added the check for !parent() so shadow elements, like those in engine-based textfields, can get focus.
    454     // We may reevaluate this when we resolve outstanding focus issues with these shadow elements.
    455     return isContentEditable() && ((parent() && !parent()->isContentEditable()) || !parent());
     453    return isContentEditable() && parent() && !parent()->isContentEditable();
    456454}
    457455
  • trunk/WebCore/khtml/html/HTMLGenericFormElementImpl.cpp

    r12330 r12345  
    218218{
    219219    if (isFocusable()) {
    220         if (renderer()->isWidget()) {
     220        if (renderer()->style()->appearance() == TextFieldAppearance)
     221            return true;
     222        else if (renderer()->isWidget()) {
    221223            return static_cast<RenderWidget*>(renderer())->widget() &&
    222224                (static_cast<RenderWidget*>(renderer())->widget()->focusPolicy() & QWidget::ClickFocus);
    223         }
     225        } 
    224226        // For <input type=image> and <button>, we will assume no mouse focusability.  This is
    225227        // consistent with OS X behavior for buttons.
  • trunk/WebCore/khtml/html/HTMLInputElementImpl.cpp

    r12330 r12345  
    3333
    3434#include "cssproperties.h"
     35#include "Frame.h"
    3536#include "render_form.h"
    3637#include "render_button.h"
     
    126127   
    127128    return true;
     129}
     130
     131void HTMLInputElementImpl::focus()
     132{
     133    if ((m_type == TEXT) || (m_type == PASSWORD) && renderer()->style()->appearance() == TextFieldAppearance) {
     134        DocumentImpl* doc = getDocument();
     135        if (doc) {
     136            doc->updateLayout();
     137            if (isFocusable()) {
     138                doc->setFocusNode(this);
     139                select();
     140                doc->frame()->revealSelection();
     141            }
     142        }
     143    } else
     144        HTMLGenericFormElementImpl::focus();
     145
    128146}
    129147
     
    324342        case PASSWORD:
    325343        case TEXT:
    326             if (renderer()->style()->appearance() == TextFieldAppearance)
     344            if (renderer()->style()->appearance() == TextFieldAppearance) {
    327345                 static_cast<RenderTextField *>(renderer())->setSelectionStart(start);
     346                 break;
     347            }
    328348            // Fall through for text fields that don't specify appearance
    329349        case SEARCH:
     
    343363        case PASSWORD:
    344364        case TEXT:
    345             if (renderer()->style()->appearance() == TextFieldAppearance)
     365            if (renderer()->style()->appearance() == TextFieldAppearance) {
    346366                 static_cast<RenderTextField *>(renderer())->setSelectionEnd(end);
     367                 break;
     368            }
    347369            // Fall through for text fields that don't specify appearance
    348370        case SEARCH:
     
    365387        case PASSWORD:
    366388        case TEXT:
    367             if (renderer()->style()->appearance() == TextFieldAppearance)
     389            if (renderer()->style()->appearance() == TextFieldAppearance) {
    368390                 static_cast<RenderTextField *>(renderer())->select();
     391                 break;
     392            }
    369393            // Fall through for text fields that don't specify appearance
    370394        case SEARCH:
     
    392416        case PASSWORD:
    393417        case TEXT:
    394             if (renderer()->style()->appearance() == TextFieldAppearance)
     418            if (renderer()->style()->appearance() == TextFieldAppearance) {
    395419                static_cast<RenderTextField *>(renderer())->setSelectionRange(start, end);
     420                break;
     421            }
    396422            // Fall through for text fields that don't specify appearance
    397423        case SEARCH:
  • trunk/WebCore/khtml/html/HTMLInputElementImpl.h

    r12330 r12345  
    7575    virtual bool isKeyboardFocusable() const;
    7676    virtual bool isEnumeratable() const { return inputType() != IMAGE; }
     77    virtual void focus();
    7778
    7879    virtual const AtomicString& name() const;
  • trunk/WebCore/khtml/xml/dom_elementimpl.h

    r12313 r12345  
    264264    virtual bool isURLAttribute(AttributeImpl *attr) const;
    265265       
    266     void focus();
     266    virtual void focus();
    267267    void blur();
    268268   
  • trunk/WebCore/page/Frame.cpp

    r12341 r12345  
    14481448   
    14491449    if (target) {
    1450         for ( ; target; target = target->parentNode()) {
     1450        RenderObject* renderer = target->renderer();
     1451
     1452        // Walk up the render tree to search for a node to focus.
     1453        // Walking up the DOM tree wouldn't work for shadow trees, like those behind the engine-based text fields.
     1454        while (renderer) {
    14511455            // We don't want to set focus on a subframe when selecting in a parent frame,
    14521456            // so add the !isFrameElement check here. There's probably a better way to make this
    14531457            // work in the long term, but this is the safest fix at this time.
    1454             if (target->isMouseFocusable() && !::isFrameElement(target)) {
     1458            if (target && target->isMouseFocusable() && !::isFrameElement(target)) {
    14551459                document()->setFocusNode(target);
    14561460                return;
    14571461            }
     1462            renderer = renderer->parent();
     1463            if (renderer)
     1464                target = renderer->element();
    14581465        }
    14591466        document()->setFocusNode(0);
  • trunk/WebCore/page/FrameView.cpp

    r12268 r12345  
    10871087        // from form fields before the button click is processed.
    10881088        NodeImpl* node = targetNode;
    1089         for ( ; node && !node->isFocusable(); node = node->parentNode());
     1089        RenderObject* renderer = node->renderer();
     1090               
     1091        // Walk up the render tree to search for a node to focus.
     1092        // Walking up the DOM tree wouldn't work for shadow trees, like those behind the engine-based text fields.
     1093        while (renderer) {
     1094            node = renderer->element();
     1095            if (node && node->isFocusable())
     1096                break;
     1097            renderer = renderer->parent();
     1098        }
    10901099        // If focus shift is blocked, we eat the event.  Note we should never clear swallowEvent
    10911100        // if the page already set it (e.g., by canceling default behavior).
  • trunk/WebCore/rendering/RenderContainer.cpp

    r12263 r12345  
    6666            m_first->remove();  // List markers are owned by their enclosing list and so don't get destroyed by this container.
    6767        else {
    68         // Destroy any anonymous children remaining in the render tree, as well as implicit (shadow) DOM elements like those used in the engine-based textfields.
     68        // Destroy any anonymous children remaining in the render tree, as well as implicit (shadow) DOM elements like those used in the engine-based text fields.
    6969            if (m_first->element())
    7070                m_first->element()->setRenderer(0);
  • trunk/WebCore/rendering/RenderTextField.cpp

    r12236 r12345  
    2020
    2121#include "config.h"
     22#include "RenderTextField.h"
     23
    2224#include "DocumentImpl.h"
    23 #include "RenderTextField.h"
     25#include "Frame.h"
    2426#include "RenderText.h"
    2527#include "htmlnames.h"
    2628#include "HTMLInputElementImpl.h"
    2729
    28 using namespace DOM;
     30namespace WebCore {
     31
    2932using namespace HTMLNames;
    30 
    31 namespace WebCore {
    3233
    3334RenderTextField::RenderTextField(NodeImpl* node)
     
    148149void RenderTextField::select()
    149150{
    150     // FIXME: Implement this.
     151    DocumentImpl* doc = document();
     152    if (doc && m_div)
     153        doc->frame()->selectContentsOfNode(m_div.get());
    151154}
    152155
  • trunk/WebCore/rendering/RenderTextField.h

    r12236 r12345  
    3030{
    3131public:
    32     RenderTextField(DOM::NodeImpl* node);
     32    RenderTextField(NodeImpl* node);
    3333    virtual ~RenderTextField();
    3434
     35    virtual const char *renderName() const { return "RenderTextField"; }
    3536    virtual void removeLeftoverAnonymousBoxes() {};
     37    virtual void setStyle(RenderStyle* style);
     38    virtual void updateFromElement();
     39   
     40    RenderStyle* createDivStyle(RenderStyle* startStyle);
    3641
    37     virtual void setStyle(RenderStyle* style);
    38     RenderStyle* createDivStyle(RenderStyle* startStyle);
    39     virtual void updateFromElement();
    40 
    41     virtual const char *renderName() const { return "RenderTextField"; }
    42    
    4342    int selectionStart();
    4443    int selectionEnd();
    4544    void setSelectionStart(int);
    46     void setSelectionEnd(int);
    47    
     45    void setSelectionEnd(int);   
    4846    void select();
    4947    void setSelectionRange(int, int);
Note: See TracChangeset for help on using the changeset viewer.