Bug 48259 - Navigate Next/Previous links with keyboard
Summary: Navigate Next/Previous links with keyboard
Status: RESOLVED FIXED
Alias: None
Product: khelpcenter
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR wishlist
Target Milestone: ---
Assignee: Cornelius Schumacher
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-09-25 09:10 UTC by peter_s_d
Modified: 2003-05-01 09:07 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description peter_s_d 2002-09-25 09:10:18 UTC
Version:            (using KDE KDE 3.0.3)
Installed from:    SuSE RPMs
OS:          Linux

KDE HelpCentre correctly scrolls through a page
when the space bar is used.

Since all (?) help pages seem to have a "Next"
link, could hitting the space bar when at the
bottom of a page follow the "Next" link?
Comment 1 Lauri Watts 2002-09-25 11:58:07 UTC
Probably not possible with just the space bar, but we ought to be able to add some    
kind of keybinding to the links, which I hope would be satisfactory for you.    
   
I've changed the summary a little to make it easier to find if duplicate reports come up.  
Comment 2 Stephan Kulow 2002-09-25 14:46:07 UTC
I find the idea quite nice and perhaps it's even easier to do than the key navigation 
as this requires an implemented feature in khtml. 
Comment 3 Lauri Watts 2002-09-26 14:58:26 UTC
Seems accesskeys are already created, and header links as well, but accesskey    
support is not available in khtml yet (45788 is the wishlist item)    
   
In either case, this will have to wait for 3.2. 
Comment 4 Frerich Raabe 2003-05-01 09:07:59 UTC
Subject: kdebase/khelpcenter

CVS commit by raabe: 

- Pressing Space again at the bottom of the page will follow the Next link,
  pressing Shift+Space at the top of the page will follow the Previous link.
CCMAIL:48259-done@bugs.kde.org


  M +47 -0     view.cpp   1.13
  M +8 -0      view.h   1.11


--- kdebase/khelpcenter/view.cpp  #1.12:1.13
@@ -4,4 +4,7 @@
 #include <klocale.h>
 #include <kdebug.h>
+#include <khtmlview.h>
+#include <dom/html_document.h>
+#include <dom/html_misc.h>
 
 
@@ -31,4 +34,6 @@ View::View( QWidget *parentWidget, const
        }
     }
+
+    view()->installEventFilter( this );
 }
 
@@ -190,4 +195,46 @@ void View::slotDecFontSizes()
 {
   setZoomFactor( zoomFactor() - m_zoomStepping );
+}
+
+bool View::eventFilter( QObject *o, QEvent *e )
+{
+  if ( e->type() != QEvent::KeyPress )
+    return false;
+
+  QKeyEvent *ke = static_cast<QKeyEvent *>( e );
+  if ( ke->state() & Qt::ShiftButton && ke->key() == Key_Space ) {
+    const QScrollBar * const scrollBar = view()->verticalScrollBar();
+    if ( scrollBar->value() == scrollBar->minValue() ) {
+      const DOM::HTMLCollection links = htmlDocument().links();
+      const DOM::Node prevLinkNode = links.item( 0 );
+      openURL( urlFromLinkNode( prevLinkNode ) );
+      return true;
+    }
+  } else if ( ke->key() == Key_Space ) {
+    const QScrollBar * const scrollBar = view()->verticalScrollBar();
+    if ( scrollBar->value() == scrollBar->maxValue() ) {
+      const DOM::HTMLCollection links = htmlDocument().links();
+      const DOM::Node nextLinkNode = links.item( links.length() - 2 );
+      openURL( urlFromLinkNode( nextLinkNode ) );
+      return true;
+    }
+  }
+  return false;
+}
+
+KURL View::urlFromLinkNode( const DOM::Node &n ) const
+{
+  if ( n.nodeType() != DOM::Node::ELEMENT_NODE )
+    return KURL();
+
+  DOM::Element elem = static_cast<DOM::Element>( n );
+
+  QString link = baseURL().path();
+  link.truncate( link.findRev( '/' ) + 1 );
+  link += "/" + elem.getAttribute( "href" ).string();
+
+  KURL url = baseURL();
+  url.setPath( link );
+  return url;
 }
 

--- kdebase/khelpcenter/view.h  #1.10:1.11
@@ -7,4 +7,8 @@
 #include "navigator.h"
 
+namespace DOM {
+  class Node;
+}
+
 namespace KHC {
 
@@ -42,4 +46,7 @@ class View : public KHTMLPart
     void searchResultCacheAvailable();
 
+  protected:
+    bool eventFilter( QObject *o, QEvent *e );
+
   private slots:
     void setTitle( const QString &title );
@@ -47,4 +54,5 @@ class View : public KHTMLPart
   private:
     void showAboutPage();
+    KURL urlFromLinkNode( const DOM::Node &n ) const;
  
     int mState;