[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/4.0/kdelibs/khtml
From:       Maks Orlovich <maksim () kde ! org>
Date:       2008-03-25 16:31:48
Message-ID: 1206462708.907017.24772.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 789902 by orlovich:

Be more careful not to make a mistake when restoring form entries.
Still imperfect, but I am not sure what perfect means here..
CCBUG:56188


 M  +8 -5      html/html_formimpl.cpp  
 M  +2 -4      html/htmlparser.cpp  
 M  +40 -10    xml/dom_docimpl.cpp  
 M  +4 -1      xml/dom_docimpl.h  


--- branches/KDE/4.0/kdelibs/khtml/html/html_formimpl.cpp #789901:789902
@@ -348,7 +348,7 @@
                     form_data.append(hstr);
                     form_data.append(*it);
                     form_data.append("\r\n");
-                    
+
 		    // reset unsubmittedFormChange flag
                     if (current->id() == ID_INPUT &&
                         static_cast<HTMLInputElementImpl*>(current)->inputType() == \
HTMLInputElementImpl::TEXT) @@ -796,7 +796,7 @@
 
 void HTMLFormElementImpl::removeFormElement(HTMLGenericFormElementImpl *e)
 {
-    int i = formElements.indexOf(e); 
+    int i = formElements.indexOf(e);
     if (i != -1)
         formElements.removeAt(i);
 }
@@ -808,7 +808,7 @@
 
 void HTMLFormElementImpl::removeImgElement(HTMLImageElementImpl *e)
 {
-    int i = imgElements.indexOf(e); 
+    int i = imgElements.indexOf(e);
     if (i != -1)
         imgElements.removeAt(i);
 }
@@ -1390,6 +1390,9 @@
         m_value = DOMString(state.left(state.length()-1));
         setChanged();
         break;
+    case HIDDEN:
+        // Don't mess with those...
+        break;
     default:
         setValue(DOMString(state.left(state.length()-1)));
         m_unsubmittedFormChange = state.endsWith('M');
@@ -2702,10 +2705,10 @@
 /*
  The rules for storing the value are simple:
 
- If there is no renderer, either m_value or defaultValue() is definitive, 
+ If there is no renderer, either m_value or defaultValue() is definitive,
     depending on whether m_initialized is true or not.
  If there is a renderer, m_render->text() is definitive. During its construction,
-    m_value is initialized if needed,  so there is no longer any need to worry 
+    m_value is initialized if needed,  so there is no longer any need to worry
     about default values or not.
 */
 
--- branches/KDE/4.0/kdelibs/khtml/html/htmlparser.cpp #789901:789902
@@ -350,8 +350,7 @@
                 n->attach();
             if (n->maintainsState()) {
                 document->registerMaintainsState(n);
-                QString state(document->nextState());
-                if (!state.isNull()) n->restoreState(state);
+                document->attemptRestoreState(n);
             }
             n->close();
 #endif
@@ -1660,8 +1659,7 @@
     if((Elem->node != current)) {
         if (current->maintainsState() && document){
             document->registerMaintainsState(current);
-            QString state(document->nextState());
-            if (!state.isNull()) current->restoreState(state);
+            document->attemptRestoreState(current);
         }
         current->close();
     }
--- branches/KDE/4.0/kdelibs/khtml/xml/dom_docimpl.cpp #789901:789902
@@ -388,6 +388,7 @@
     m_documentElement = 0;
     m_cssTarget = 0;
     m_dynamicDomRestyler = new khtml::DynamicDomRestyler();
+    m_stateRestorePos = 0;
 }
 
 void DocumentImpl::removedLastRef()
@@ -1075,23 +1076,51 @@
     return n;
 }
 
-QString DocumentImpl::nextState()
+void DocumentImpl::attemptRestoreState(NodeImpl* n)
 {
-   QString state;
-   if (!m_state.isEmpty())
-   {
-      state = m_state.first();
-      m_state.erase(m_state.begin());
-   }
-   return state;
+    if (!n->isElementNode())
+        return;
+
+    ElementImpl* el = static_cast<ElementImpl*>(n);
+
+    if (m_stateRestorePos >= m_state.size())
+        return;
+
+    // Grab the state and element info..
+    QString idStr = m_state[m_stateRestorePos];
+    QString nmStr = m_state[m_stateRestorePos + 1];
+    QString tpStr = m_state[m_stateRestorePos + 2];
+    QString stStr = m_state[m_stateRestorePos + 3];
+
+    // Make sure it matches!
+    if (idStr.toUInt() != el->id())
+        return;
+    if (nmStr != el->getAttribute(ATTR_NAME).string())
+        return;
+    if (tpStr != el->getAttribute(ATTR_TYPE).string())
+        return;
+
+    m_stateRestorePos += 4;
+    if (!stStr.isNull())
+        el->restoreState(stStr);
 }
 
 QStringList DocumentImpl::docState()
 {
     QStringList s;
-    for (QListIterator<NodeImpl*> it(m_maintainsState); it.hasNext();)
-        s.append(it.next()->state());
+    for (QListIterator<NodeImpl*> it(m_maintainsState); it.hasNext();) {
+        NodeImpl* n = it.next();
+        if (!n->isElementNode())
+            continue;
 
+        ElementImpl* el = static_cast<ElementImpl*>(n);
+        // Encode the element ID, as well as the name and type attributes
+        s.append(QString::number(el->id()));
+        s.append(el->getAttribute(ATTR_NAME).string());
+        s.append(el->getAttribute(ATTR_TYPE).string());
+        s.append(el->state());
+    }
+
     return s;
 }
 
@@ -2741,6 +2770,7 @@
 void DOM::DocumentImpl::setRestoreState( const QStringList &s)
 {
     m_state = s;
+    m_stateRestorePos = 0;
 }
 
 KHTMLView* DOM::DocumentImpl::view() const
--- branches/KDE/4.0/kdelibs/khtml/xml/dom_docimpl.h #789901:789902
@@ -269,7 +269,9 @@
     void recalcStyleSelector();
     void rebuildStyleSelector();
 
-    QString nextState();
+    // Tries to restore the elements value from the doc state,
+    // if it seems like the same thing
+    void attemptRestoreState(NodeImpl* e);
 
     // Query all registered elements for their state
     QStringList docState();
@@ -552,6 +554,7 @@
     khtml::CSSStyleSelector *m_styleSelector;
     KHTMLView *m_view;
     QStringList m_state;
+    int         m_stateRestorePos;
 
     khtml::DocLoader *m_docLoader;
     khtml::Tokenizer *m_tokenizer;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic