viking

webkit based web browser for Enlightenment
Log | Files | Refs | LICENSE

commit ae28e70ae23578bbbe77afc0a7a782e7c383c201
parent 3b6efb1ca4c850ec084d1972e3fe32196c93274f
Author: Kyle Milz <kmilz@ucalgary.ca>
Date:   Fri, 14 Dec 2012 18:16:47 -0700

zoom: port MiniBrowsers zoom_level_set() function

Diffstat:
Msrc/buffer.c | 1+
Msrc/commands.c | 40+++++++++++++++++++++++++++++++---------
Msrc/keymap.h | 15+++++----------
Msrc/main.c | 1-
Msrc/viking.h | 17++++++++---------
5 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/src/buffer.c b/src/buffer.c @@ -1091,6 +1091,7 @@ buffer_add(const unsigned char flags, Window_Data *wd, const char *url, Session_ bd->window = wd; bd->buf_number = wd->buf_total; bd->inspector_enabled = EINA_FALSE; + bd->zoom_level = DEFAULT_ZOOM_LEVEL; #if 1 Ewk_View_Smart_Class *ewkViewClass = miniBrowserViewSmartClass(); diff --git a/src/commands.c b/src/commands.c @@ -13,6 +13,8 @@ // static unsigned int scrollstep = 40; /* cursor difference in pixel */ // static unsigned int pagingkeep = 40; /* pixels kept when paging */ +// The zoom values are chosen to be like in Mozilla Firefox 3. +const static float zoom_levels[] = {0.3, 0.5, 0.67, 0.8, 0.9, 1.0, 1.1, 1.2, 1.33, 1.5, 1.7, 2.0, 2.4, 3.0}; Eina_Bool complete(const Arg *arg, void *data) @@ -774,20 +776,40 @@ scroll(const Arg *arg, void *data) Eina_Bool zoom(const Arg *arg, void *data) { + Evas_Coord ox, oy, mx, my, cx, cy; + int diff = 0; + Eina_Bool result; Window_Data *wd = data; - App_Data *ad = wd->app; - float zoom; + Buffer_Data *bd = wd->cur_buf; + unsigned int level = bd->zoom_level; - zoom = (arg->i & ZoomOut) ? - ewk_view_scale_get(wd->cur_buf->view) + - (((double)(wd->count ? wd->count : 1)) * (arg->i & (1 << 1) ? 1.0 : -1.0) * ad->zoomstep) : - (wd->count ? (double)wd->count / 100.0 : 1.0); + /* Get current mouse position on window. */ + evas_pointer_canvas_xy_get(evas_object_evas_get(bd->view), &mx, &my); - ewk_view_scale_set(wd->cur_buf->view, zoom, 0, 0); + /* Get webview's position on window. */ + evas_object_geometry_get(bd->view, &ox, &oy, NULL, NULL); - gui_zoom_update(wd, zoom); + cx = mx - ox; // current x position = mouse x position - webview x position + cy = my - oy; // current y position = mouse y position - webview y position - return EINA_TRUE; + if (arg->i == ZoomReset) { + bd->zoom_level = DEFAULT_ZOOM_LEVEL; + } + else { + diff = (arg->i == ZoomIn) ? 1 : -1; + printf("zoom() diff = %i\n", diff); + diff *= (wd->count == 0) ? 1 : wd->count; + + if (level+diff < 0 || level+diff >= sizeof(zoom_levels) / sizeof(float)) + return EINA_FALSE; + + bd->zoom_level = level + diff; + } + + result = ewk_view_scale_set(bd->view, zoom_levels[bd->zoom_level], cx, cy); + gui_zoom_update(wd, zoom_levels[bd->zoom_level]); + + return result; } Eina_Bool diff --git a/src/keymap.h b/src/keymap.h @@ -65,16 +65,11 @@ static Key keys[] = { { 0, 0, "R", navigate, {NavigationForceReload} }, { 0, 0, "c", navigate, {NavigationCancel} }, - { 0, 0, "plus", zoom, {ZoomIn | ZoomText} }, - { 0, 0, "minus", zoom, {ZoomOut | ZoomText} }, - // { 0, 0, GDK_KP_Add, zoom, {ZoomIn | ZoomText} }, - // { 0, 0, GDK_KP_Subtract, zoom, {ZoomOut | ZoomText} }, - { 0, 'z', "i", zoom, {ZoomIn | ZoomText} }, - { 0, 'z', "o", zoom, {ZoomOut | ZoomText} }, - { 0, 'z', "z", zoom, {ZoomReset | ZoomText} }, - { 0, 'z', "I", zoom, {ZoomIn | ZoomFullContent} }, - { 0, 'z', "O", zoom, {ZoomOut | ZoomFullContent} }, - { 0, 'z', "Z", zoom, {ZoomReset | ZoomFullContent} }, + { 0, 0, "plus", zoom, {ZoomIn} }, + { 0, 0, "minus", zoom, {ZoomOut} }, + { 0, 'z', "i", zoom, {ZoomIn} }, + { 0, 'z', "o", zoom, {ZoomOut} }, + { 0, 'z', "z", zoom, {ZoomReset} }, { 0, 0, "y", yank, {SourceURL | ClipboardPrimary | ClipboardGTK} }, { 0, 0, "Y", yank, {SourceSelection| ClipboardPrimary | ClipboardGTK} }, diff --git a/src/main.c b/src/main.c @@ -464,7 +464,6 @@ elm_main(int argc, char *argv[]) ad->session = session; ad->session_save_timer = session_save_timer; ad->keylistroot = make_keyslist(); - ad->zoomstep = 0.1f; if (!(svr = ecore_con_server_add(ECORE_CON_LOCAL_USER, "viking", 0, NULL))) { printf("could not create server -- this is bad!\n"); diff --git a/src/viking.h b/src/viking.h @@ -54,16 +54,13 @@ enum { NavigationCancel, */ enum { ClipboardPrimary = 1 << 1, ClipboardGTK = 1 << 2 }; enum { SourceSelection = 1 << 4, SourceURL = 1 << 3 }; -/* bitmask: - 1 << 0: 0 = ZoomReset 1 = ZoomIn/Out - 1 << 1: 0 = ZoomOut 1 = ZoomIn - 1 << 2: 0 = TextZoom 1 = FullContentZoom -*/ -enum { ZoomReset, + +enum { + ZoomReset, + ZoomIn, ZoomOut, - ZoomIn = ZoomOut | (1 << 1) }; -enum { ZoomText, ZoomFullContent = (1 << 2) }; + /* bitmask: 0 = Info, 1 = Warning, 2 = Error 1 << 2: 0 = AutoHide 1 = NoAutoHide @@ -152,7 +149,6 @@ typedef struct Eina_List *downloads; Eina_List *keylistroot; - float zoomstep; char *modkeys; Ecore_Timer *session_save_timer; @@ -212,6 +208,7 @@ struct _Buffer_Data { Evas_Object *view; unsigned int buf_number; + unsigned int zoom_level; Eina_Bool inspector_enabled; Evas_Object *web_inspector; @@ -241,3 +238,5 @@ struct _Buffer_Data #define INF(...) EINA_LOG_INFO(__VA_ARGS__) #define DBG(...) EINA_LOG_DBG(__VA_ARGS__) +#define DEFAULT_ZOOM_LEVEL 5 // Set default zoom level to 1.0 (index 5 on zoomLevels). +