Home | History | Annotate | Download | only in haiku
      1 /*
      2  * Copyright (C) 2007 Ryan Leavengood <leavengood (at) gmail.com>
      3  * Copyright (C) 2009 Maxime Simon <simon.maxime (at) gmail.com>
      4  * Copyright (C) 2010 Stephan Amus <superstippi (at) gmx.de>
      5  *
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     25  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include "config.h"
     31 #include "PlatformMouseEvent.h"
     32 
     33 #include <Message.h>
     34 #include <View.h>
     35 
     36 namespace WebCore {
     37 
     38 PlatformMouseEvent::PlatformMouseEvent(const BMessage* message)
     39     : m_position(message->FindPoint("be:view_where"))
     40     , m_globalPosition(message->FindPoint("screen_where"))
     41     , m_clickCount(message->FindInt32("clicks"))
     42     , m_timestamp(message->FindInt64("when") / 1000000.0)
     43 {
     44     int32 buttons = 0;
     45     if (message->what == B_MOUSE_UP)
     46         message->FindInt32("previous buttons", &buttons);
     47     else
     48         message->FindInt32("buttons", &buttons);
     49 
     50     if (buttons & B_PRIMARY_MOUSE_BUTTON)
     51         m_button = LeftButton;
     52     else if (buttons & B_SECONDARY_MOUSE_BUTTON)
     53         m_button = RightButton;
     54     else if (buttons & B_TERTIARY_MOUSE_BUTTON)
     55         m_button = MiddleButton;
     56     else
     57         m_button = NoButton;
     58 
     59     switch (message->what) {
     60     case B_MOUSE_DOWN:
     61         m_eventType = MouseEventPressed;
     62         break;
     63     case B_MOUSE_UP:
     64         m_eventType = MouseEventReleased;
     65         break;
     66     case B_MOUSE_MOVED:
     67     default:
     68         m_eventType = MouseEventMoved;
     69         break;
     70     };
     71 
     72     int32 modifiers = message->FindInt32("modifiers");
     73     m_shiftKey = modifiers & B_SHIFT_KEY;
     74     m_ctrlKey = modifiers & B_CONTROL_KEY;
     75     m_altKey = modifiers & B_COMMAND_KEY;
     76     m_metaKey = modifiers & B_OPTION_KEY;
     77 }
     78 
     79 } // namespace WebCore
     80 
     81