Changeset 84427 in webkit


Ignore:
Timestamp:
Apr 20, 2011 3:32:47 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-04-20 Yuzhu Shen <yzshen@chromium.org>

Reviewed by Tony Chang.

[chromium] linux chromium doesn't set click count for mouse up events.
https://bugs.webkit.org/show_bug.cgi?id=58921

The reason why we need such a fix is that the Pepper API passes this information to plugins,
and some consumers (e.g., Flash) need it to detect double-clicks.

  • src/gtk/WebInputEventFactory.cpp: set click count for mouse up events.
Location:
trunk/Source/WebKit/chromium
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/chromium/ChangeLog

    r84400 r84427  
     12011-04-20  Yuzhu Shen  <yzshen@chromium.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        [chromium] linux chromium doesn't set click count for mouse up events.
     6        https://bugs.webkit.org/show_bug.cgi?id=58921
     7
     8        The reason why we need such a fix is that the Pepper API passes this information to plugins,
     9        and some consumers (e.g., Flash) need it to detect double-clicks.
     10
     11        * src/gtk/WebInputEventFactory.cpp: set click count for mouse up events.
     12        * tests/WebInputEventFactoryTestGtk.cpp: added test case MouseUpClickCount.
    1132011-04-20  Evan Martin  <evan@chromium.org>
    214
  • trunk/Source/WebKit/chromium/src/gtk/WebInputEventFactory.cpp

    r68691 r84427  
    4646namespace {
    4747
    48 bool countsAsDoubleClick(gint timeDiff, gint xDiff, gint yDiff)
     48// For click count tracking.
     49static int gNumClicks = 0;
     50static GdkWindow* gLastClickEventWindow = 0;
     51static gint gLastClickTime = 0;
     52static gint gLastClickX = 0;
     53static gint gLastClickY = 0;
     54static WebKit::WebMouseEvent::Button gLastClickButton = WebKit::WebMouseEvent::ButtonNone;
     55
     56bool shouldForgetPreviousClick(GdkWindow* window, gint time, gint x, gint y)
    4957{
    5058    static GtkSettings* settings = gtk_settings_get_default();
     59
     60    if (window != gLastClickEventWindow)
     61      return true;
     62
    5163    gint doubleClickTime = 250;
    5264    gint doubleClickDistance = 5;
     
    5466                 "gtk-double-click-time", &doubleClickTime,
    5567                 "gtk-double-click-distance", &doubleClickDistance, NULL);
    56     return timeDiff <= doubleClickTime && abs(xDiff) <= doubleClickDistance && abs(yDiff) <= doubleClickDistance;
     68    return (time - gLastClickTime) > doubleClickTime
     69           || abs(x - gLastClickX) > doubleClickDistance
     70           || abs(y - gLastClickY) > doubleClickDistance;
     71}
     72
     73void resetClickCountState()
     74{
     75    gNumClicks = 0;
     76    gLastClickEventWindow = 0;
     77    gLastClickTime = 0;
     78    gLastClickX = 0;
     79    gLastClickY = 0;
     80    gLastClickButton = WebKit::WebMouseEvent::ButtonNone;
    5781}
    5882
     
    408432    };
    409433
    410     if (GDK_BUTTON_PRESS == event->type) {
    411         static int numClicks = 0;
    412         static GdkWindow* eventWindow = 0;
    413         static gint lastLeftClickTime = 0;
    414         static gint lastLeftClickX = 0;
    415         static gint lastLeftClickY = 0;
    416 
    417         gint timeDiff = event->time - lastLeftClickTime;
    418         gint xDiff = event->x - lastLeftClickX;
    419         gint yDiff = event->y - lastLeftClickY;
    420         if (eventWindow == event->window && countsAsDoubleClick(timeDiff, xDiff, yDiff))
    421             numClicks++;
    422         else
    423             numClicks = 1;
    424 
    425         result.clickCount = numClicks;
    426         eventWindow = event->window;
    427         lastLeftClickTime = event->time;
    428         lastLeftClickX = event->x;
    429         lastLeftClickY = event->y;
    430     }
    431 
    432434    result.button = WebMouseEvent::ButtonNone;
    433435    if (event->button == 1)
     
    437439    else if (event->button == 3)
    438440        result.button = WebMouseEvent::ButtonRight;
     441
     442    if (result.type == WebInputEvent::MouseDown) {
     443        bool forgetPreviousClick = shouldForgetPreviousClick(event->window, event->time, event->x, event->y);
     444
     445        if (!forgetPreviousClick && result.button == gLastClickButton)
     446            ++gNumClicks;
     447        else {
     448            gNumClicks = 1;
     449
     450            gLastClickEventWindow = event->window;
     451            gLastClickX = event->x;
     452            gLastClickY = event->y;
     453            gLastClickButton = result.button;
     454        }
     455        gLastClickTime = event->time;
     456    }
     457    result.clickCount = gNumClicks;
    439458
    440459    return result;
     
    470489        result.button = WebMouseEvent::ButtonRight;
    471490
     491    if (shouldForgetPreviousClick(event->window, event->time, event->x, event->y))
     492        resetClickCountState();
     493
    472494    return result;
    473495}
     
    505527    else if (event->state & GDK_BUTTON3_MASK)
    506528        result.button = WebMouseEvent::ButtonRight;
     529
     530    if (shouldForgetPreviousClick(event->window, event->time, event->x, event->y))
     531        resetClickCountState();
    507532
    508533    return result;
  • trunk/Source/WebKit/chromium/tests/WebInputEventFactoryTestGtk.cpp

    r65152 r84427  
    110110}
    111111
     112TEST(WebInputEventFactoryTest, MouseUpClickCount)
     113{
     114    GdkEventButton mouseDown;
     115    memset(&mouseDown, 0, sizeof(mouseDown));
     116    mouseDown.type = GDK_BUTTON_PRESS;
     117    mouseDown.window = static_cast<GdkWindow*>(GINT_TO_POINTER(1));
     118    mouseDown.x = mouseDown.y = mouseDown.x_root = mouseDown.y_root = 100;
     119    mouseDown.time = 0;
     120    mouseDown.button = 1;
     121
     122    // Properly set the last click time, so that the internal state won't be affected by previous tests.
     123    WebInputEventFactory::mouseEvent(&mouseDown);
     124
     125    mouseDown.time += 10000;
     126    GdkEventButton mouseUp = mouseDown;
     127    mouseUp.type = GDK_BUTTON_RELEASE;
     128    WebMouseEvent mouseDownEvent;
     129    WebMouseEvent mouseUpEvent;
     130
     131    // Click for three times.
     132    for (int i = 1; i < 4; ++i) {
     133        mouseDown.time += 100;
     134        mouseDownEvent = WebInputEventFactory::mouseEvent(&mouseDown);
     135        EXPECT_EQ(i, mouseDownEvent.clickCount);
     136
     137        mouseUp.time = mouseDown.time + 50;
     138        mouseUpEvent = WebInputEventFactory::mouseEvent(&mouseUp);
     139        EXPECT_EQ(i, mouseUpEvent.clickCount);
     140    }
     141
     142    // Reset the click count.
     143    mouseDown.time += 10000;
     144    mouseDownEvent = WebInputEventFactory::mouseEvent(&mouseDown);
     145    EXPECT_EQ(1, mouseDownEvent.clickCount);
     146
     147    // Moving the cursor for a significant distance will reset the click count to 0.
     148    GdkEventMotion mouseMove;
     149    memset(&mouseMove, 0, sizeof(mouseMove));
     150    mouseMove.type = GDK_MOTION_NOTIFY;
     151    mouseMove.window = mouseDown.window;
     152    mouseMove.time = mouseDown.time;
     153    mouseMove.x = mouseMove.y = mouseMove.x_root = mouseMove.y_root = mouseDown.x + 100;
     154    WebInputEventFactory::mouseEvent(&mouseMove);
     155
     156    mouseUp.time = mouseDown.time + 50;
     157    mouseUpEvent = WebInputEventFactory::mouseEvent(&mouseUp);
     158    EXPECT_EQ(0, mouseUpEvent.clickCount);
     159
     160    // Reset the click count.
     161    mouseDown.time += 10000;
     162    mouseDownEvent = WebInputEventFactory::mouseEvent(&mouseDown);
     163    EXPECT_EQ(1, mouseDownEvent.clickCount);
     164
     165    // Moving the cursor with a significant delay will reset the click count to 0.
     166    mouseMove.time = mouseDown.time + 1000;
     167    mouseMove.x = mouseMove.y = mouseMove.x_root = mouseMove.y_root = mouseDown.x;
     168    WebInputEventFactory::mouseEvent(&mouseMove);
     169
     170    mouseUp.time = mouseMove.time + 50;
     171    mouseUpEvent = WebInputEventFactory::mouseEvent(&mouseUp);
     172    EXPECT_EQ(0, mouseUpEvent.clickCount);
     173}
     174
    112175} // anonymous namespace
Note: See TracChangeset for help on using the changeset viewer.