Changeset 85214 in webkit


Ignore:
Timestamp:
Apr 28, 2011 11:37:33 AM (13 years ago)
Author:
Martin Robinson
Message:

2011-04-28 Martin Robinson <mrobinson@igalia.com>

Reviewed by Xan Lopez.

[GTK] Click counting logic should be shared between WebKit1 and WebKit2
https://bugs.webkit.org/show_bug.cgi?id=59715

Added a GtkClickCounter class which is just the logic from WebKit1 pushed down
into WebCore so that WebKit1 and WebKit2 can share the code.

No new tests. This is covered by fast/events/click-count.html.

  • GNUmakefile.list.am: Added new files.
  • platform/gtk/GtkClickCounter.cpp: Added. (WebCore::GtkClickCounter::GtkClickCounter): Added. (WebCore::GtkClickCounter::reset): Added. (WebCore::GtkClickCounter::shouldProcessButtonEvent): Added. (WebCore::getEventTime): Added. (WebCore::GtkClickCounter::clickCountForGdkButtonEvent): Added.
  • platform/gtk/GtkClickCounter.h: Added.

2011-04-28 Martin Robinson <mrobinson@igalia.com>

Reviewed by Xan Lopez.

[GTK] Click counting logic should be shared between WebKit1 and WebKit2
https://bugs.webkit.org/show_bug.cgi?id=59715

Switch WebKit1 to use the new GtkClickCounter for counting > 3 clicks in a row.
This allows the code to be shared between WebKit1 and WebKit2.

  • WebCoreSupport/DragClientGtk.cpp: (WebKit::DragClient::startDrag): Call GtkClickCounter::reset instead of fiddling the WebView private data directly.
  • WebCoreSupport/FrameLoaderClientGtk.cpp: (WebKit::postCommitFrameViewSetup): Ditto.
  • webkit/webkitwebview.cpp: (webkit_web_view_button_press_event): Call into GtkClickCounter now. (webkit_web_view_init): Remove private member intialization.
  • webkit/webkitwebviewprivate.h: Remove unneeded private members.

2011-04-28 Martin Robinson <mrobinson@igalia.com>

Reviewed by Xan Lopez.

[GTK] Click counting logic should be shared between WebKit1 and WebKit2
https://bugs.webkit.org/show_bug.cgi?id=59715

Use the GtkClickCounter instead of doing click counting manually. This means that
the code will now be shared between WebKit1 and WebKit2.

  • UIProcess/API/gtk/WebKitWebViewBase.cpp: (webkit_web_view_base_init): Remove private member initialization. (webViewButtonPressEvent): Call into GtkClickCounter.
Location:
trunk/Source
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r85213 r85214  
     12011-04-28  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Xan Lopez.
     4
     5        [GTK] Click counting logic should be shared between WebKit1 and WebKit2
     6        https://bugs.webkit.org/show_bug.cgi?id=59715
     7
     8        Added a GtkClickCounter class which is just the logic from WebKit1 pushed down
     9        into WebCore so that WebKit1 and WebKit2 can share the code.
     10
     11        No new tests. This is covered by fast/events/click-count.html.
     12
     13        * GNUmakefile.list.am: Added new files.
     14        * platform/gtk/GtkClickCounter.cpp: Added.
     15        (WebCore::GtkClickCounter::GtkClickCounter): Added.
     16        (WebCore::GtkClickCounter::reset): Added.
     17        (WebCore::GtkClickCounter::shouldProcessButtonEvent): Added.
     18        (WebCore::getEventTime): Added.
     19        (WebCore::GtkClickCounter::clickCountForGdkButtonEvent): Added.
     20        * platform/gtk/GtkClickCounter.h: Added.
     21
    1222011-04-28  Dan Bernstein  <mitz@apple.com>
    223
  • trunk/Source/WebCore/GNUmakefile.list.am

    r85180 r85214  
    37583758        Source/WebCore/platform/gtk/FileChooserGtk.cpp \
    37593759        Source/WebCore/platform/gtk/FileSystemGtk.cpp \
     3760        Source/WebCore/platform/gtk/GtkClickCounter.cpp \
     3761        Source/WebCore/platform/gtk/GtkClickCounter.h \
    37603762        Source/WebCore/platform/gtk/GeolocationServiceGtk.cpp \
    37613763        Source/WebCore/platform/gtk/GeolocationServiceGtk.h \
  • trunk/Source/WebKit/gtk/ChangeLog

    r85066 r85214  
     12011-04-28  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Xan Lopez.
     4
     5        [GTK] Click counting logic should be shared between WebKit1 and WebKit2
     6        https://bugs.webkit.org/show_bug.cgi?id=59715
     7
     8        Switch WebKit1 to use the new GtkClickCounter for counting > 3 clicks in a row.
     9        This allows the code to be shared between WebKit1 and WebKit2.
     10
     11        * WebCoreSupport/DragClientGtk.cpp:
     12        (WebKit::DragClient::startDrag): Call GtkClickCounter::reset instead of fiddling
     13        the WebView private data directly.
     14        * WebCoreSupport/FrameLoaderClientGtk.cpp:
     15        (WebKit::postCommitFrameViewSetup): Ditto.
     16        * webkit/webkitwebview.cpp:
     17        (webkit_web_view_button_press_event): Call into GtkClickCounter now.
     18        (webkit_web_view_init): Remove private member intialization.
     19        * webkit/webkitwebviewprivate.h: Remove unneeded private members.
     20
    1212011-04-27  Martin Robinson  <mrobinson@igalia.com>
    222
  • trunk/Source/WebKit/gtk/WebCoreSupport/DragClientGtk.cpp

    r77870 r85214  
    112112    // A drag starting should prevent a double-click from happening. This might
    113113    // happen if a drag is followed very quickly by another click (like in the DRT).
    114     webView->priv->previousClickTime = 0;
     114    webView->priv->clickCounter.reset();
    115115
    116116    // This strategy originally comes from Chromium:
  • trunk/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp

    r84260 r85214  
    13751375
    13761376    // Do not allow click counting between main frame loads.
    1377     priv->previousClickTime = 0;
     1377    priv->clickCounter.reset();
    13781378}
    13791379
  • trunk/Source/WebKit/gtk/webkit/webkitwebview.cpp

    r83153 r85214  
    758758}
    759759
    760 static guint32 getEventTime(GdkEvent* event)
    761 {
    762     guint32 time = gdk_event_get_time(event);
    763     if (time)
    764         return time;
    765 
    766     // Real events always have a non-zero time, but events synthesized
    767     // by the DRT do not and we must calculate a time manually. This time
    768     // is not calculated in the DRT, because GTK+ does not work well with
    769     // anything other than GDK_CURRENT_TIME on synthesized events.
    770     GTimeVal timeValue;
    771     g_get_current_time(&timeValue);
    772     return (timeValue.tv_sec * 1000) + (timeValue.tv_usec / 1000);
    773 }
    774 
    775760static gboolean webkit_web_view_button_press_event(GtkWidget* widget, GdkEventButton* event)
    776761{
     
    781766    gtk_widget_grab_focus(widget);
    782767
    783     // For double and triple clicks GDK sends both a normal button press event
    784     // and a specific type (like GDK_2BUTTON_PRESS). If we detect a special press
    785     // coming up, ignore this event as it certainly generated the double or triple
    786     // click. The consequence of not eating this event is two DOM button press events
    787     // are generated.
    788     GOwnPtr<GdkEvent> nextEvent(gdk_event_peek());
    789     if (nextEvent && (nextEvent->any.type == GDK_2BUTTON_PRESS || nextEvent->any.type == GDK_3BUTTON_PRESS))
     768    if (!priv->clickCounter.shouldProcessButtonEvent(event))
    790769        return TRUE;
    791770
    792     gint doubleClickDistance = 250;
    793     gint doubleClickTime = 5;
    794     GtkSettings* settings = gtk_settings_get_for_screen(gtk_widget_get_screen(widget));
    795     g_object_get(settings,
    796         "gtk-double-click-distance", &doubleClickDistance,
    797         "gtk-double-click-time", &doubleClickTime, NULL);
    798 
    799     // GTK+ only counts up to triple clicks, but WebCore wants to know about
    800     // quadruple clicks, quintuple clicks, ad infinitum. Here, we replicate the
    801     // GDK logic for counting clicks.
    802     guint32 eventTime = getEventTime(reinterpret_cast<GdkEvent*>(event));
    803     if ((event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS)
    804         || ((abs(event->x - priv->previousClickPoint.x()) < doubleClickDistance)
    805             && (abs(event->y - priv->previousClickPoint.y()) < doubleClickDistance)
    806             && (eventTime - priv->previousClickTime < static_cast<guint>(doubleClickTime))
    807             && (event->button == priv->previousClickButton)))
    808         priv->currentClickCount++;
    809     else
    810         priv->currentClickCount = 1;
    811 
    812771    PlatformMouseEvent platformEvent(event);
    813     platformEvent.setClickCount(priv->currentClickCount);
    814     priv->previousClickPoint = platformEvent.pos();
    815     priv->previousClickButton = event->button;
    816     priv->previousClickTime = eventTime;
     772    platformEvent.setClickCount(priv->clickCounter.clickCountForGdkButtonEvent(widget, event));
    817773
    818774    if (event->button == 3)
     
    35363492    priv->subResources = adoptGRef(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref));
    35373493
    3538     priv->currentClickCount = 0;
    3539     priv->previousClickButton = 0;
    3540     priv->previousClickTime = 0;
    35413494    gtk_drag_dest_set(GTK_WIDGET(webView), static_cast<GtkDestDefaults>(0), 0, 0, static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE));
    35423495    gtk_drag_dest_set_target_list(GTK_WIDGET(webView), pasteboardHelperInstance()->targetList());
  • trunk/Source/WebKit/gtk/webkit/webkitwebviewprivate.h

    r79953 r85214  
    2626#include "DataObjectGtk.h"
    2727#include "FullscreenVideoController.h"
     28#include "GtkClickCounter.h"
    2829#include "GOwnPtr.h"
    2930#include "ResourceHandle.h"
     
    102103    WebCore::IntRect tooltipArea;
    103104
    104     int currentClickCount;
    105     WebCore::IntPoint previousClickPoint;
    106     guint previousClickButton;
    107     guint32 previousClickTime;
     105    WebCore::GtkClickCounter clickCounter;
    108106    HashMap<GdkDragContext*, RefPtr<WebCore::DataObjectGtk> > draggingDataObjects;
    109107    HashMap<GdkDragContext*, WebKit::DroppingContext*> droppingContexts;
  • trunk/Source/WebKit2/ChangeLog

    r85208 r85214  
     12011-04-28  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Xan Lopez.
     4
     5        [GTK] Click counting logic should be shared between WebKit1 and WebKit2
     6        https://bugs.webkit.org/show_bug.cgi?id=59715
     7
     8        Use the GtkClickCounter instead of doing click counting manually. This means that
     9        the code will now be shared between WebKit1 and WebKit2.
     10
     11        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     12        (webkit_web_view_base_init): Remove private member initialization.
     13        (webViewButtonPressEvent): Call into GtkClickCounter.
     14
    1152011-04-28  Martin Robinson  <mrobinson@igalia.com>
    216
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r85208 r85214  
    3030
    3131#include "GOwnPtrGtk.h"
     32#include "GtkClickCounter.h"
    3233#include "GtkVersioning.h"
    3334#include "NativeWebKeyboardEvent.h"
     
    5051    gboolean isPageActive;
    5152    GtkIMContext* imContext;
    52     gint currentClickCount;
    53     IntPoint previousClickPoint;
    54     guint previousClickButton;
    55     guint32 previousClickTime;
     53    GtkClickCounter clickCounter;
    5654};
    5755
     
    144142    gtk_widget_set_can_focus(GTK_WIDGET(webkitWebViewBase), TRUE);
    145143    priv->imContext = gtk_im_multicontext_new();
    146 
    147     priv->currentClickCount = 0;
    148     priv->previousClickButton = 0;
    149     priv->previousClickTime = 0;
    150 
    151     priv->pageClient = PageClientImpl::create(GTK_WIDGET(webkitWebViewBase));
    152144}
    153145
     
    242234}
    243235
    244 // Copied from webkitwebview.cpp
    245 static guint32 getEventTime(GdkEvent* event)
    246 {
    247     guint32 time = gdk_event_get_time(event);
    248     if (time)
    249         return time;
    250 
    251     // Real events always have a non-zero time, but events synthesized
    252     // by the DRT do not and we must calculate a time manually. This time
    253     // is not calculated in the DRT, because GTK+ does not work well with
    254     // anything other than GDK_CURRENT_TIME on synthesized events.
    255     GTimeVal timeValue;
    256     g_get_current_time(&timeValue);
    257     return (timeValue.tv_sec * 1000) + (timeValue.tv_usec / 1000);
    258 }
    259 
    260236static gboolean webViewButtonPressEvent(GtkWidget* widget, GdkEventButton* buttonEvent)
    261237{
    262     if (buttonEvent->button == 3) {
    263         // FIXME: [GTK] Add context menu support for Webkit2.
    264         // https://bugs.webkit.org/show_bug.cgi?id=54827
    265         notImplemented();
    266         return FALSE;
    267     }
    268 
     238    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     239    WebKitWebViewBasePrivate* priv = webViewBase->priv;
    269240    gtk_widget_grab_focus(widget);
    270241
    271     // For double and triple clicks GDK sends both a normal button press event
    272     // and a specific type (like GDK_2BUTTON_PRESS). If we detect a special press
    273     // coming up, ignore this event as it certainly generated the double or triple
    274     // click. The consequence of not eating this event is two DOM button press events
    275     // are generated.
    276     GOwnPtr<GdkEvent> nextEvent(gdk_event_peek());
    277     if (nextEvent && (nextEvent->any.type == GDK_2BUTTON_PRESS || nextEvent->any.type == GDK_3BUTTON_PRESS))
     242    if (!priv->clickCounter.shouldProcessButtonEvent(buttonEvent))
    278243        return TRUE;
    279 
    280     gint doubleClickDistance = 250;
    281     gint doubleClickTime = 5;
    282     GtkSettings* settings = gtk_settings_get_for_screen(gtk_widget_get_screen(widget));
    283     g_object_get(settings,
    284                  "gtk-double-click-distance", &doubleClickDistance,
    285                  "gtk-double-click-time", &doubleClickTime, NULL);
    286 
    287     // GTK+ only counts up to triple clicks, but WebCore wants to know about
    288     // quadruple clicks, quintuple clicks, ad infinitum. Here, we replicate the
    289     // GDK logic for counting clicks.
    290     GdkEvent* event(reinterpret_cast<GdkEvent*>(buttonEvent));
    291     guint32 eventTime = getEventTime(event);
    292     WebKitWebViewBase* webkitWebViewBase = WEBKIT_WEB_VIEW_BASE(widget);
    293     WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv;
    294     if ((event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS)
    295         || ((abs(buttonEvent->x - priv->previousClickPoint.x()) < doubleClickDistance)
    296             && (abs(buttonEvent->y - priv->previousClickPoint.y()) < doubleClickDistance)
    297             && (eventTime - priv->previousClickTime < static_cast<guint>(doubleClickTime))
    298             && (buttonEvent->button == priv->previousClickButton)))
    299         priv->currentClickCount++;
    300     else
    301         priv->currentClickCount = 1;
    302 
    303     priv->page->handleMouseEvent(NativeWebMouseEvent(event, priv->currentClickCount));
    304 
    305     gdouble x, y;
    306     gdk_event_get_coords(event, &x, &y);
    307     priv->previousClickPoint = IntPoint(x, y);
    308     priv->previousClickButton = buttonEvent->button;
    309     priv->previousClickTime = eventTime;
    310 
     244    priv->page->handleMouseEvent(NativeWebMouseEvent(reinterpret_cast<GdkEvent*>(buttonEvent),
     245                                                     priv->clickCounter.clickCountForGdkButtonEvent(widget, buttonEvent)));
    311246    return FALSE;
    312247}
Note: See TracChangeset for help on using the changeset viewer.