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

List:       kde-commits
Subject:    KDE/kdelibs/khtml
From:       Rolf Eike Beer <kde () opensource ! sf-tec ! de>
Date:       2010-10-06 18:28:59
Message-ID: 20101006182859.9E9E3AC88C () svn ! kde ! org
[Download RAW message or body]

SVN commit 1183254 by dakon:

avoid duplicate accesskeys for the same URL, this time without endless loop

CCBUG:122356


 M  +16 -4     khtmlview.cpp  


--- trunk/KDE/kdelibs/khtml/khtmlview.cpp #1183253:1183254
@@ -2922,13 +2922,13 @@
     QLinkedList< AccessKeyData > data; // Note: this has to be a list type that keep iterators valid
                                        // when other entries are removed
     QMap< NodeImpl*, QString > labels = buildLabels( m_part->xmlDocImpl());
+    QMap< QString, QChar > hrefs;
+
     for( NodeImpl* n = m_part->xmlDocImpl();
          n != NULL;
          n = n->traverseNextNode()) {
         if( n->isElementNode()) {
             ElementImpl* element = static_cast< ElementImpl* >( n );
-            if( element->getAttribute( ATTR_ACCESSKEY ).length() == 1 )
-                continue; // has accesskey set, ignore
             if( element->renderer() == NULL )
                 continue; // not visible
             QString text;
@@ -3021,6 +3021,13 @@
             }
             if( ignore )
                 continue;
+
+            // build map of manually assigned accesskeys and their targets
+            DOMString akey = element->getAttribute( ATTR_ACCESSKEY );
+            if( akey.length() == 1 ) {
+                hrefs[url] = akey.string()[ 0 ].toUpper();
+                continue; // has accesskey set, ignore
+            }
             if( text.isNull() && labels.contains( element ))
                 text = labels[ element ];
             if( text.isNull() && text_before )
@@ -3073,7 +3080,13 @@
                 break;
             QString text = (*it).text;
             QChar key;
-            if( key.isNull() && !text.isEmpty()) {
+            const QString url = (*it).url;
+            // an identical link already has an accesskey assigned
+            if( hrefs.contains( url ) ) {
+                it = data.erase( it );
+                continue;
+            }
+            if( !text.isEmpty()) {
                 const QList< QPair< QString, QChar > > priorities
                     = m_part->settings()->fallbackAccessKeysAssignments();
                 for( QList< QPair< QString, QChar > >::ConstIterator it = priorities.begin();
@@ -3110,7 +3123,6 @@
                 key = keys.front();
             ret[ (*it).element ] = key;
             keys.removeAll( key );
-            QString url = (*it).url;
             it = data.erase( it );
             // assign the same accesskey also to other elements pointing to the same url
             if( !url.isEmpty() && !url.startsWith( "javascript:", Qt::CaseInsensitive )) {
[prev in list] [next in list] [prev in thread] [next in thread] 

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