[webkit-changes] cvs commit: WebCore/khtml/xml dom_docimpl.cpp dom_docimpl.h

Timothy thatcher at opensource.apple.com
Mon Nov 14 15:03:27 PST 2005


thatcher    05/11/14 15:03:26

  Modified:    .        Tag: Safari-2-0-branch ChangeLog
               khtml/html Tag: Safari-2-0-branch html_formimpl.cpp
               khtml/xml Tag: Safari-2-0-branch dom_docimpl.cpp
                        dom_docimpl.h
  Log:
          Applied fix for the Safari-2-0-branch
  
      2005-11-10  Adele Peterson  <adele at apple.com>
  
          Reviewed by Maciej.
  
          Fixed <rdar://problem/4228997> selecting a new radio button does not automatically clear the previous selected (outside <form> element)
  
          Moved the radio button checking code to the document, since we shouldn't need a form to keep track of grouped radio buttons.
  
          Added
          * fast/forms/radio_checked.html
  
          * khtml/xml/dom_docimpl.h: Added m_selectedRadioButtons (now a two level hash table to account for forms and group names),
          radioButtonChecked, checkedRadioButtonForGroup, and removeRadioButtonGroup
          * khtml/xml/dom_docimpl.cpp:
          (DocumentImpl::DocumentImpl): initialize m_selectedRadioButtons
          (DocumentImpl::~DocumentImpl): delete m_selectedRadioButtons, and any of the inner hashtables if necessary
          (DocumentImpl::radioButtonChecked): moved from HTMLFormElementImpl.
          (DocumentImpl::checkedRadioButtonForGroup): ditto.
          (DocumentImpl::removeRadioButtonGroup): ditto.
          * khtml/html/html_formimpl.cpp:
          (DOM::HTMLFormElementImpl::HTMLFormElementImpl): removed initialization of m_selectedRadioButtons.
          (DOM::HTMLFormElementImpl::~HTMLFormElementImpl): removed deletion of m_selectedRadioButtons.
          (DOM::HTMLFormElementImpl::removeFormElement): now calls document's radio button functions
          (DOM::HTMLInputElementImpl::isKeyboardFocusable): ditto.
          (DOM::HTMLInputElementImpl::setInputType): ditto.
          (DOM::HTMLInputElementImpl::parseMappedAttribute): ditto.
          (DOM::HTMLInputElementImpl::setChecked): ditto.
          (DOM::HTMLInputElementImpl::preDispatchEventHandler): ditto.
          * khtml/html/html_formimpl.h: removed m_selectedRadioButtons, radioButtonChecked, checkedRadioButtonForGroup, and removeRadioButtonGroup
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.61  +34 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.1.2.60
  retrieving revision 1.1.2.61
  diff -u -r1.1.2.60 -r1.1.2.61
  --- ChangeLog	13 Nov 2005 03:21:42 -0000	1.1.2.60
  +++ ChangeLog	14 Nov 2005 23:03:16 -0000	1.1.2.61
  @@ -1,3 +1,37 @@
  +2005-11-14  Timothy Hatcher  <timothy at apple.com>
  +
  +        Applied fix for the Safari-2-0-branch
  +
  +    2005-11-10  Adele Peterson  <adele at apple.com>
  +
  +        Reviewed by Maciej.
  +
  +        Fixed <rdar://problem/4228997> selecting a new radio button does not automatically clear the previous selected (outside <form> element)
  +
  +        Moved the radio button checking code to the document, since we shouldn't need a form to keep track of grouped radio buttons.
  +
  +        Added 
  +        * fast/forms/radio_checked.html
  +
  +        * khtml/xml/dom_docimpl.h: Added m_selectedRadioButtons (now a two level hash table to account for forms and group names),
  +        radioButtonChecked, checkedRadioButtonForGroup, and removeRadioButtonGroup
  +        * khtml/xml/dom_docimpl.cpp:
  +        (DocumentImpl::DocumentImpl): initialize m_selectedRadioButtons
  +        (DocumentImpl::~DocumentImpl): delete m_selectedRadioButtons, and any of the inner hashtables if necessary
  +        (DocumentImpl::radioButtonChecked): moved from HTMLFormElementImpl.
  +        (DocumentImpl::checkedRadioButtonForGroup): ditto.
  +        (DocumentImpl::removeRadioButtonGroup): ditto.
  +        * khtml/html/html_formimpl.cpp: 
  +        (DOM::HTMLFormElementImpl::HTMLFormElementImpl): removed initialization of m_selectedRadioButtons.
  +        (DOM::HTMLFormElementImpl::~HTMLFormElementImpl): removed deletion of m_selectedRadioButtons.
  +        (DOM::HTMLFormElementImpl::removeFormElement): now calls document's radio button functions
  +        (DOM::HTMLInputElementImpl::isKeyboardFocusable): ditto.
  +        (DOM::HTMLInputElementImpl::setInputType): ditto.
  +        (DOM::HTMLInputElementImpl::parseMappedAttribute): ditto.
  +        (DOM::HTMLInputElementImpl::setChecked): ditto.
  +        (DOM::HTMLInputElementImpl::preDispatchEventHandler): ditto.
  +        * khtml/html/html_formimpl.h: removed m_selectedRadioButtons, radioButtonChecked, checkedRadioButtonForGroup, and removeRadioButtonGroup
  +
   2005-11-12  Timothy Hatcher  <timothy at apple.com>
   
           Merged fix from Ti-2005-009-branch to Safari-2-0-branch
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.156.6.6 +29 -14    WebCore/khtml/html/html_formimpl.cpp
  
  Index: html_formimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_formimpl.cpp,v
  retrieving revision 1.156.6.5
  retrieving revision 1.156.6.6
  diff -u -r1.156.6.5 -r1.156.6.6
  --- html_formimpl.cpp	11 Nov 2005 06:39:30 -0000	1.156.6.5
  +++ html_formimpl.cpp	14 Nov 2005 23:03:22 -0000	1.156.6.6
  @@ -704,18 +704,6 @@
       }
   }
   
  -void HTMLFormElementImpl::radioClicked( HTMLGenericFormElementImpl *caller )
  -{
  -    for (unsigned i = 0; i < formElements.count(); ++i) {
  -        HTMLGenericFormElementImpl *current = formElements[i];
  -        if (current->id() == ID_INPUT &&
  -            static_cast<HTMLInputElementImpl*>(current)->inputType() == HTMLInputElementImpl::RADIO &&
  -            current != caller && current->form() == caller->form() && current->name() == caller->name()) {
  -            static_cast<HTMLInputElementImpl*>(current)->setChecked(false);
  -        }
  -    }
  -}
  -
   template<class T> static void appendToVector(QPtrVector<T> &vec, T *item)
   {
       unsigned size = vec.size();
  @@ -747,6 +735,11 @@
   
   void HTMLFormElementImpl::removeFormElement(HTMLGenericFormElementImpl *e)
   {
  +    if (!e->name().isEmpty()) {
  +        HTMLGenericFormElementImpl* currentCheckedRadio = getDocument()->checkedRadioButtonForGroup(e->name(), this);
  +        if (currentCheckedRadio == e)
  +            getDocument()->removeRadioButtonGroup(e->name(), this);
  +    }
       removeFromVector(formElements, e);
       removeFromVector(dormantFormElements, e);
   }
  @@ -1314,6 +1307,10 @@
               // Useful in case we were called from inside parseHTMLAttribute.
               setAttribute(ATTR_TYPE, type());
           } else {
  +            if (m_type == RADIO && !name().isEmpty()) {
  +                if (getDocument()->checkedRadioButtonForGroup(name(), m_form) == this)
  +                    getDocument()->removeRadioButtonGroup(name(), m_form);
  +            }
               bool wasAttached = m_attached;
               if (wasAttached)
                   detach();
  @@ -1329,6 +1326,11 @@
               }
               if (wasAttached)
                   attach();
  +                
  +            // If our type morphs into a radio button and we are checked, then go ahead
  +            // and signal this to the form.
  +            if (m_type == RADIO && checked())
  +                getDocument()->radioButtonChecked(this, m_form);
           }
       }
       m_haveType = true;
  @@ -1722,6 +1724,19 @@
           setChanged();
           break;
   #endif
  +    case ATTR_NAME:
  +        if (m_type == RADIO && checked()) {
  +            // Remove the radio from its old group.
  +            if (!name().isEmpty())
  +                getDocument()->removeRadioButtonGroup(name(), m_form);
  +            
  +            // Update our cached reference to the name.
  +            setName(attr->value());
  +            
  +            // Add it to its new group.
  +            getDocument()->radioButtonChecked(this, m_form);
  +        }
  +        break;
       default:
           HTMLGenericFormElementImpl::parseHTMLAttribute(attr);
       }
  @@ -2007,8 +2022,8 @@
   {
       if (checked() == _checked) return;
   
  -    if (m_form && m_type == RADIO && _checked && !name().isEmpty())
  -        m_form->radioClicked(this);
  +    if (m_type == RADIO && _checked)
  +        getDocument()->radioButtonChecked(this, m_form);
   
       m_useDefaultChecked = false;
       m_checked = _checked;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.211.6.11 +59 -0     WebCore/khtml/xml/dom_docimpl.cpp
  
  Index: dom_docimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_docimpl.cpp,v
  retrieving revision 1.211.6.10
  retrieving revision 1.211.6.11
  diff -u -r1.211.6.10 -r1.211.6.11
  --- dom_docimpl.cpp	12 Nov 2005 01:24:34 -0000	1.211.6.10
  +++ dom_docimpl.cpp	14 Nov 2005 23:03:24 -0000	1.211.6.11
  @@ -286,6 +286,7 @@
       , m_designMode(inherit)
       , m_hasDashboardRegions(false)
       , m_dashboardRegionsDirty(false)
  +    , m_selectedRadioButtons(0)
   #endif
   {
       document->doc = this;
  @@ -450,6 +451,16 @@
           delete m_jsEditor;
           m_jsEditor = 0;
       }
  +    
  +    if (m_selectedRadioButtons) {
  +        QPtrDictIterator< QDict<HTMLInputElementImpl> > iter ((*m_selectedRadioButtons));
  +        for (; iter.current(); ++iter) {
  +            QDict<HTMLInputElementImpl>* inputDict= iter.current();
  +            if (inputDict)
  +                delete inputDict;
  +        }
  +        delete m_selectedRadioButtons;
  +    }
   }
   
   void DocumentImpl::resetLinkColor()
  @@ -3535,4 +3546,52 @@
       return 0;
   }
   
  +void DocumentImpl::radioButtonChecked(HTMLInputElementImpl *caller, HTMLFormElementImpl *form)
  +{
  +    // Without a name, there is no group.
  +    if (caller->name().isEmpty())
  +        return;
  +
  +    // Uncheck the currently selected item
  +    if (!m_selectedRadioButtons)
  +        m_selectedRadioButtons = new QPtrDict< QDict<HTMLInputElementImpl> >;
  +    QDict<HTMLInputElementImpl>* formRadioButtons = m_selectedRadioButtons->find(form);
  +    if (!formRadioButtons) {
  +        formRadioButtons = new QDict<HTMLInputElementImpl>;
  +        m_selectedRadioButtons->insert(form, formRadioButtons);
  +    }
  +    
  +    HTMLInputElementImpl* currentCheckedRadio = formRadioButtons->find(caller->name().string());
  +   
  +    if (currentCheckedRadio && currentCheckedRadio != caller)
  +        currentCheckedRadio->setChecked(false);
  +
  +    formRadioButtons->replace(caller->name().string(), caller);
  +}
  +
  +HTMLInputElementImpl* DocumentImpl::checkedRadioButtonForGroup(DOMString name, HTMLFormElementImpl *form)
  +{
  +    if (!m_selectedRadioButtons)
  +        return 0;
  +    QDict<HTMLInputElementImpl>* formRadioButtons = m_selectedRadioButtons->find(form);
  +    if (!formRadioButtons)
  +        return 0;
  +    
  +    return formRadioButtons->find(name.string());
  +}
  +
  +void DocumentImpl::removeRadioButtonGroup(DOMString name, HTMLFormElementImpl *form)
  +{
  +    if (m_selectedRadioButtons) {
  +        QDict<HTMLInputElementImpl>* formRadioButtons = m_selectedRadioButtons->find(form);
  +        if (formRadioButtons) {
  +            formRadioButtons->remove(name.string());
  +            if (formRadioButtons->count() == 0) {
  +                m_selectedRadioButtons->remove(form);
  +                delete formRadioButtons;
  +            }
  +        }
  +    }
  +}
  +
   #include "dom_docimpl.moc"
  
  
  
  1.104.6.7 +9 -0      WebCore/khtml/xml/dom_docimpl.h
  
  Index: dom_docimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_docimpl.h,v
  retrieving revision 1.104.6.6
  retrieving revision 1.104.6.7
  diff -u -r1.104.6.6 -r1.104.6.7
  --- dom_docimpl.h	12 Nov 2005 01:24:35 -0000	1.104.6.6
  +++ dom_docimpl.h	14 Nov 2005 23:03:25 -0000	1.104.6.7
  @@ -93,6 +93,8 @@
       class GenericRONamedNodeMapImpl;
       class HTMLDocumentImpl;
       class HTMLElementImpl;
  +    class HTMLFormElementImpl;
  +    class HTMLInputElementImpl;
       class HTMLImageLoader;
       class HTMLMapElementImpl;
       class JSEditor;
  @@ -755,6 +757,10 @@
   
       void registerDisconnectedNodeWithEventListeners(NodeImpl *node);
       void unregisterDisconnectedNodeWithEventListeners(NodeImpl *node);
  +    
  +    void radioButtonChecked(HTMLInputElementImpl *caller, HTMLFormElementImpl *form);
  +    HTMLInputElementImpl* checkedRadioButtonForGroup(DOMString name, HTMLFormElementImpl *form);
  +    void removeRadioButtonGroup(DOMString name, HTMLFormElementImpl *form);
   
   private:
       void updateTitle();
  @@ -786,6 +792,9 @@
       QValueList<khtml::DashboardRegionValue> m_dashboardRegions;
       bool m_hasDashboardRegions;
       bool m_dashboardRegionsDirty;
  +    
  +    QPtrDict< QDict<HTMLInputElementImpl> > *m_selectedRadioButtons;
  +
   #endif
   };
   
  
  
  



More information about the webkit-changes mailing list