changeset 1209:6b35322fb5f2

keybindings for scrolling
author corvid <corvid@lavabit.com>
date Sun, 05 Jul 2009 22:17:41 +0000
parents 7ea0944187ad
children f26e773057d5
files ChangeLog dw/fltkpreview.cc dw/fltkpreview.hh dw/fltkviewport.cc dw/fltkviewport.hh dw/layout.cc dw/layout.hh dw/types.hh dw/view.hh src/keys.cc src/keys.hh src/keysrc src/ui.cc src/uicmd.cc src/uicmd.hh
diffstat 15 files changed, 148 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jul 02 14:39:11 2009 +0000
+++ b/ChangeLog	Sun Jul 05 22:17:41 2009 +0000
@@ -2,6 +2,13 @@
 Dillo project
 =============================================================================
 
+dillo-2.2 [??]
+
++- Added keybindings for scrolling.
+   Patch: corvid, Jorge Arellano Cid
+
+-----------------------------------------------------------------------------
+
 dillo-2.1.1 [Jul 3, 2009]
 
 +- Add additional size checks for images.
--- a/dw/fltkpreview.cc	Thu Jul 02 14:39:11 2009 +0000
+++ b/dw/fltkpreview.cc	Sun Jul 05 22:17:41 2009 +0000
@@ -17,7 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
+#include "../lout/msg.h"
 
 #include "fltkpreview.hh"
 #include "fltkmisc.hh"
@@ -103,6 +103,11 @@
    scrollY = y;
 }
 
+void FltkPreview::scroll (dw::core::ScrollCommand cmd)
+{
+   MSG_ERR("FltkPreview::scroll not implemented\n");
+}
+
 void FltkPreview::setViewportSize (int width, int height,
                                    int hScrollbarThickness,
                                    int vScrollbarThickness)
--- a/dw/fltkpreview.hh	Thu Jul 02 14:39:11 2009 +0000
+++ b/dw/fltkpreview.hh	Sun Jul 05 22:17:41 2009 +0000
@@ -34,6 +34,7 @@
    int getHScrollbarThickness ();
    int getVScrollbarThickness ();
    void scrollTo (int x, int y);
+   void scroll (dw::core::ScrollCommand cmd);
    void setViewportSize (int width, int height,
                          int hScrollbarThickness, int vScrollbarThickness);
 
--- a/dw/fltkviewport.cc	Thu Jul 02 14:39:11 2009 +0000
+++ b/dw/fltkviewport.cc	Sun Jul 05 22:17:41 2009 +0000
@@ -225,6 +225,15 @@
    }
 
    switch(event) {
+   case ::fltk::KEY:
+      /* Tell fltk we want to receive KEY events as SHORTCUTs.
+       * As we don't know the exact keybindings set by the user, we ask
+       * for all of them (except TabKey to keep navigation between form
+       * widgets). */
+      if (::fltk::event_key() != TabKey)
+         return 0;
+      break;
+
    case ::fltk::FOCUS:
       /** \bug Draw focus box. */
       return 1;
@@ -279,60 +288,6 @@
    case ::fltk::LEAVE:
       mouse_x = mouse_y = -1;
       break;
-
-   case ::fltk::KEY:
-      /* tell fltk we want to receive these KEY events as SHORTCUT */
-      switch (::fltk::event_key()) {
-      case PageUpKey:
-      case PageDownKey:
-      case SpaceKey:
-      case DownKey:
-      case UpKey:
-      case RightKey:
-      case LeftKey:
-      case HomeKey:
-      case EndKey:
-         return 0;
-      }
-      break;
-
-   case ::fltk::SHORTCUT:
-      switch (::fltk::event_key()) {
-      case PageUpKey:
-      case 'b':
-      case 'B':
-         scroll (0, -vscrollbar->pagesize ());
-         return 1;
-
-      case PageDownKey:
-      case SpaceKey:
-         scroll (0, vscrollbar->pagesize ());
-         return 1;
-
-      case DownKey:
-         scroll (0, (int) vscrollbar->linesize ());
-         return 1;
-
-      case UpKey:
-         scroll (0, (int) -vscrollbar->linesize ());
-         return 1;
-
-      case RightKey:
-         scroll ((int) hscrollbar->linesize (), 0);
-         return 1;
-
-      case LeftKey:
-         scroll ((int) -hscrollbar->linesize (), 0);
-         return 1;
-
-      case HomeKey:
-         scrollTo (scrollX, 0);
-         return 1;
-
-      case EndKey:
-         scrollTo (scrollX, canvasHeight); /* gets adjusted in scrollTo () */
-         return 1;
-      }
    }
 
    return FltkWidgetView::handle (event);
@@ -419,6 +374,27 @@
    scrollTo (scrollX + dx, scrollY + dy);
 }
 
+void FltkViewport::scroll (core::ScrollCommand cmd)
+{
+   if (cmd == core::SCREEN_UP_CMD) {
+      scroll (0, -vscrollbar->pagesize ());
+   } else if (cmd == core::SCREEN_DOWN_CMD) {
+      scroll (0, vscrollbar->pagesize ());
+   } else if (cmd == core::LINE_UP_CMD) {
+      scroll (0, (int) -vscrollbar->linesize ());
+   } else if (cmd == core::LINE_DOWN_CMD) {
+      scroll (0, (int) vscrollbar->linesize ());
+   } else if (cmd == core::LEFT_CMD) {
+      scroll ((int) -hscrollbar->linesize (), 0);
+   } else if (cmd == core::RIGHT_CMD) {
+      scroll ((int) hscrollbar->linesize (), 0);
+   } else if (cmd == core::TOP_CMD) {
+      scrollTo (scrollX, 0);
+   } else if (cmd == core::BOTTOM_CMD) {
+      scrollTo (scrollX, canvasHeight); /* gets adjusted in scrollTo () */
+   }
+}
+
 void FltkViewport::setViewportSize (int width, int height,
                                     int hScrollbarThickness,
                                     int vScrollbarThickness)
--- a/dw/fltkviewport.hh	Thu Jul 02 14:39:11 2009 +0000
+++ b/dw/fltkviewport.hh	Sun Jul 05 22:17:41 2009 +0000
@@ -60,6 +60,7 @@
    int getHScrollbarThickness ();
    int getVScrollbarThickness ();
    void scroll(int dx, int dy);
+   void scroll(dw::core::ScrollCommand cmd);
    void scrollTo (int x, int y);
    void setViewportSize (int width, int height,
                          int hScrollbarThickness, int vScrollbarThickness);
--- a/dw/layout.cc	Thu Jul 02 14:39:11 2009 +0000
+++ b/dw/layout.cc	Sun Jul 05 22:17:41 2009 +0000
@@ -248,6 +248,16 @@
     */
 }
 
+void Layout::scroll(ScrollCommand cmd)
+{
+   for (typed::Iterator <View> it = views->iterator (); it.hasNext (); ) {
+      View *view = it.getNext ();
+
+      if (view->usesViewport ())
+         view->scroll(cmd);
+   }
+}
+
 /**
  * \brief Scrolls all viewports, so that the region [x, y, width, height]
  *    is seen, according to hpos and vpos.
--- a/dw/layout.hh	Thu Jul 02 14:39:11 2009 +0000
+++ b/dw/layout.hh	Sun Jul 05 22:17:41 2009 +0000
@@ -159,6 +159,7 @@
 
    void scrollTo (HPosition hpos, VPosition vpos,
                   int x, int y, int width, int height);
+   void scroll (ScrollCommand);
    void setAnchor (const char *anchor);
 
    /* View */
--- a/dw/types.hh	Thu Jul 02 14:39:11 2009 +0000
+++ b/dw/types.hh	Sun Jul 05 22:17:41 2009 +0000
@@ -30,6 +30,8 @@
    VPOS_NO_CHANGE
 };
 
+enum ScrollCommand {SCREEN_UP_CMD, SCREEN_DOWN_CMD, LINE_UP_CMD, LINE_DOWN_CMD,
+                    LEFT_CMD, RIGHT_CMD, TOP_CMD, BOTTOM_CMD};
 
 /*
  * Different "layers" may be highlighted in a widget.
--- a/dw/view.hh	Thu Jul 02 14:39:11 2009 +0000
+++ b/dw/view.hh	Sun Jul 05 22:17:41 2009 +0000
@@ -80,6 +80,11 @@
    virtual void scrollTo (int x, int y) = 0;
 
    /**
+    * \brief Scroll the viewport as commanded.
+    */
+   virtual void scroll (ScrollCommand) { };
+
+   /**
     * \brief Set the viewport size.
     *
     * Does not have to be implemented, when usesViewport returns false.
--- a/src/keys.cc	Thu Jul 02 14:39:11 2009 +0000
+++ b/src/keys.cc	Sun Jul 05 22:17:41 2009 +0000
@@ -99,7 +99,17 @@
    { "forward"      , KEYS_FORWARD      , fltk::SHIFT  , fltk::BackSpaceKey },
    { "forward"      , KEYS_FORWARD      , 0            , '.'                },
    { "goto"         , KEYS_GOTO         , fltk::CTRL   , 'l'                },
-   { "home"         , KEYS_HOME         , fltk::CTRL   , 'h'                }
+   { "home"         , KEYS_HOME         , fltk::CTRL   , 'h'                },
+   { "screen-up"    , KEYS_SCREEN_UP    , 0            , fltk::PageUpKey    },
+   { "screen-up"    , KEYS_SCREEN_UP    , 0            , 'b'                },
+   { "screen-down"  , KEYS_SCREEN_DOWN  , 0            , fltk::PageDownKey  },
+   { "screen-down"  , KEYS_SCREEN_DOWN  , 0            , fltk::SpaceKey     },
+   { "line-up"      , KEYS_LINE_UP      , 0            , fltk::UpKey        },
+   { "line-down"    , KEYS_LINE_DOWN    , 0            , fltk::DownKey      },
+   { "left"         , KEYS_LEFT         , 0            , fltk::LeftKey      },
+   { "right"        , KEYS_RIGHT        , 0            , fltk::RightKey     },
+   { "top"          , KEYS_TOP          , 0            , fltk::HomeKey      },
+   { "bottom"       , KEYS_BOTTOM       , 0            , fltk::EndKey       },
 };
 
 static Dlist *bindings;
--- a/src/keys.hh	Thu Jul 02 14:39:11 2009 +0000
+++ b/src/keys.hh	Sun Jul 05 22:17:41 2009 +0000
@@ -36,7 +36,15 @@
    KEYS_BACK,
    KEYS_FORWARD,
    KEYS_GOTO,
-   KEYS_HOME
+   KEYS_HOME,
+   KEYS_SCREEN_UP,
+   KEYS_SCREEN_DOWN,
+   KEYS_LINE_UP,
+   KEYS_LINE_DOWN,
+   KEYS_LEFT,
+   KEYS_RIGHT,
+   KEYS_TOP,
+   KEYS_BOTTOM
 } KeysCommand_t;
 
 class Keys {
--- a/src/keysrc	Thu Jul 02 14:39:11 2009 +0000
+++ b/src/keysrc	Sun Jul 05 22:17:41 2009 +0000
@@ -69,3 +69,26 @@
 
 # "stop" loading the page. 
 #(stop has no default binding)
+
+#--------------------------------------------------------------------
+#                     MOTION COMMANDS
+#--------------------------------------------------------------------
+
+#pageup = screen-up
+#b = screen-up
+
+#pagedown = screen-down
+#space = screen-down
+
+#up = line-up
+
+#down = line-down
+
+#left = left
+
+#right = right
+
+#home = top
+
+#end = bottom
+
--- a/src/ui.cc	Thu Jul 02 14:39:11 2009 +0000
+++ b/src/ui.cc	Sun Jul 05 22:17:41 2009 +0000
@@ -750,6 +750,12 @@
       KeysCommand_t cmd = Keys::getKeyCmd();
       if (cmd == KEYS_NOP) {
          // Do nothing
+      } else if (cmd == KEYS_SCREEN_UP || cmd == KEYS_SCREEN_DOWN ||
+                 cmd == KEYS_LINE_UP || cmd == KEYS_LINE_DOWN ||
+                 cmd == KEYS_LEFT || cmd == KEYS_RIGHT ||
+                 cmd == KEYS_TOP || cmd == KEYS_BOTTOM) {
+         a_UIcmd_scroll(a_UIcmd_get_bw_by_widget(this), cmd);
+         ret = 1;
       } else if (cmd == KEYS_BACK) {
          a_UIcmd_back(a_UIcmd_get_bw_by_widget(this));
          ret = 1;
--- a/src/uicmd.cc	Thu Jul 02 14:39:11 2009 +0000
+++ b/src/uicmd.cc	Sun Jul 05 22:17:41 2009 +0000
@@ -23,6 +23,7 @@
 #include <fltk/Tooltip.h>
 
 #include "paths.hh"
+#include "keys.hh"
 #include "ui.hh"
 #include "uicmd.hh"
 #include "timeout.hh"
@@ -1088,6 +1089,40 @@
 }
 
 /*
+ * Pass scrolling command to dw.
+ */
+void a_UIcmd_scroll(BrowserWindow *bw, int icmd)
+{
+   Layout *layout = (Layout*)bw->render_layout;
+
+   if (layout) {
+      typedef struct {
+         KeysCommand_t keys_cmd;
+         ScrollCommand dw_cmd;
+      } mapping_t;
+
+      const mapping_t map[] = {
+         {KEYS_SCREEN_UP, SCREEN_UP_CMD},
+         {KEYS_SCREEN_DOWN, SCREEN_DOWN_CMD},
+         {KEYS_LINE_UP, LINE_UP_CMD},
+         {KEYS_LINE_DOWN, LINE_DOWN_CMD},
+         {KEYS_LEFT, LEFT_CMD},
+         {KEYS_RIGHT, RIGHT_CMD},
+         {KEYS_TOP, TOP_CMD},
+         {KEYS_BOTTOM, BOTTOM_CMD},
+      };
+      KeysCommand_t keycmd = (KeysCommand_t)icmd;
+
+      for (uint_t i = 0; i < (sizeof(map)/sizeof(mapping_t)); i++) {
+         if (keycmd == map[i].keys_cmd) {
+            layout->scroll(map[i].dw_cmd);
+            break;
+         }
+      }
+   }
+}
+         
+/*
  * Get location's text
  */
 char *a_UIcmd_get_location_text(BrowserWindow *bw)
--- a/src/uicmd.hh	Thu Jul 02 14:39:11 2009 +0000
+++ b/src/uicmd.hh	Sun Jul 05 22:17:41 2009 +0000
@@ -68,6 +68,7 @@
 void a_UIcmd_get_scroll_xy(BrowserWindow *bw, int *x, int *y);
 void a_UIcmd_set_scroll_xy(BrowserWindow *bw, int x, int y);
 void a_UIcmd_set_scroll_by_fragment(BrowserWindow *bw, const char *f);
+void a_UIcmd_scroll(BrowserWindow *bw, int icmd);
 char *a_UIcmd_get_location_text(BrowserWindow *bw);
 void a_UIcmd_set_location_text(void *vbw, const char *text);
 void a_UIcmd_set_page_prog(BrowserWindow *bw, size_t nbytes, int cmd);