1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/gtk/event_utils.h" 6 7 #include "base/logging.h" 8 #include "ui/base/events/event_constants.h" 9 #include "ui/base/window_open_disposition.h" 10 11 namespace event_utils { 12 13 int EventFlagsFromGdkState(guint state) { 14 int flags = ui::EF_NONE; 15 flags |= (state & GDK_LOCK_MASK) ? ui::EF_CAPS_LOCK_DOWN : ui::EF_NONE; 16 flags |= (state & GDK_CONTROL_MASK) ? ui::EF_CONTROL_DOWN : ui::EF_NONE; 17 flags |= (state & GDK_SHIFT_MASK) ? ui::EF_SHIFT_DOWN : ui::EF_NONE; 18 flags |= (state & GDK_MOD1_MASK) ? ui::EF_ALT_DOWN : ui::EF_NONE; 19 flags |= (state & GDK_BUTTON1_MASK) ? ui::EF_LEFT_MOUSE_BUTTON : ui::EF_NONE; 20 flags |= (state & GDK_BUTTON2_MASK) ? ui::EF_MIDDLE_MOUSE_BUTTON 21 : ui::EF_NONE; 22 flags |= (state & GDK_BUTTON3_MASK) ? ui::EF_RIGHT_MOUSE_BUTTON : ui::EF_NONE; 23 return flags; 24 } 25 26 // TODO(shinyak) This function will be removed after refactoring. 27 WindowOpenDisposition DispositionFromGdkState(guint state) { 28 int event_flags = EventFlagsFromGdkState(state); 29 return ui::DispositionFromEventFlags(event_flags); 30 } 31 32 WindowOpenDisposition DispositionForCurrentButtonPressEvent() { 33 GdkEvent* event = gtk_get_current_event(); 34 if (!event) { 35 NOTREACHED(); 36 return NEW_FOREGROUND_TAB; 37 } 38 39 guint state = event->button.state; 40 gdk_event_free(event); 41 return DispositionFromGdkState(state); 42 } 43 44 } // namespace event_utils 45