Home | History | Annotate | Download | only in gtk
      1 /*
      2 * Copyright (C) 2006 Michael Emmel mike.emmel (at) gmail.com
      3 * All rights reserved.
      4 *
      5 * Redistribution and use in source and binary forms, with or without
      6 * modification, are permitted provided that the following conditions
      7 * are met:
      8 * 1. Redistributions of source code must retain the above copyright
      9 *    notice, this list of conditions and the following disclaimer.
     10 * 2. Redistributions in binary form must reproduce the above copyright
     11 *    notice, this list of conditions and the following disclaimer in the
     12 *    documentation and/or other materials provided with the distribution.
     13 *
     14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 */
     26 
     27 #include "config.h"
     28 #include "PlatformMouseEvent.h"
     29 
     30 #include "Assertions.h"
     31 
     32 #include <gdk/gdk.h>
     33 
     34 namespace WebCore {
     35 
     36 // FIXME: Would be even better to figure out which modifier is Alt instead of always using GDK_MOD1_MASK.
     37 
     38 // Keep this in sync with the other platform event constructors
     39 PlatformMouseEvent::PlatformMouseEvent(GdkEventButton* event)
     40 {
     41     m_timestamp = event->time;
     42     m_position = IntPoint((int)event->x, (int)event->y);
     43     m_globalPosition = IntPoint((int)event->x_root, (int)event->y_root);
     44     m_shiftKey = event->state & GDK_SHIFT_MASK;
     45     m_ctrlKey = event->state & GDK_CONTROL_MASK;
     46     m_altKey = event->state & GDK_MOD1_MASK;
     47     m_metaKey = event->state & GDK_META_MASK;
     48 
     49     switch (event->type) {
     50     case GDK_BUTTON_PRESS:
     51     case GDK_2BUTTON_PRESS:
     52     case GDK_3BUTTON_PRESS:
     53     case GDK_BUTTON_RELEASE:
     54         m_eventType = MouseEventPressed;
     55         if (event->type == GDK_BUTTON_RELEASE) {
     56             m_eventType = MouseEventReleased;
     57             m_clickCount = 0;
     58         } else if (event->type == GDK_BUTTON_PRESS)
     59             m_clickCount = 1;
     60         else if (event->type == GDK_2BUTTON_PRESS)
     61             m_clickCount = 2;
     62         else if (event->type == GDK_3BUTTON_PRESS)
     63             m_clickCount = 3;
     64 
     65         if (event->button == 1)
     66             m_button = LeftButton;
     67         else if (event->button == 2)
     68             m_button = MiddleButton;
     69         else if (event->button == 3)
     70             m_button = RightButton;
     71         break;
     72 
     73     default:
     74         ASSERT_NOT_REACHED();
     75     };
     76 }
     77 
     78 PlatformMouseEvent::PlatformMouseEvent(GdkEventMotion* motion)
     79 {
     80     m_timestamp = motion->time;
     81     m_position = IntPoint((int)motion->x, (int)motion->y);
     82     m_globalPosition = IntPoint((int)motion->x_root, (int)motion->y_root);
     83     m_shiftKey = motion->state & GDK_SHIFT_MASK;
     84     m_ctrlKey = motion->state & GDK_CONTROL_MASK;
     85     m_altKey = motion->state & GDK_MOD1_MASK;
     86     m_metaKey = motion->state & GDK_MOD2_MASK;
     87 
     88     switch (motion->type) {
     89     case GDK_MOTION_NOTIFY:
     90         m_eventType = MouseEventMoved;
     91         m_button = NoButton;
     92         m_clickCount = 0;
     93         break;
     94     default:
     95         ASSERT_NOT_REACHED();
     96     };
     97 
     98     if (motion->state & GDK_BUTTON1_MASK)
     99         m_button = LeftButton;
    100     else if (motion->state & GDK_BUTTON2_MASK)
    101         m_button = MiddleButton;
    102     else if (motion->state & GDK_BUTTON3_MASK)
    103         m_button = RightButton;
    104 }
    105 }
    106