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.
5 #include "chrome/browser/ui/gtk/event_utils.h"
7 #include "base/logging.h"
8 #include "ui/base/window_open_disposition.h"
9 #include "ui/events/event_constants.h"
11 namespace event_utils
{
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
22 flags
|= (state
& GDK_BUTTON3_MASK
) ? ui::EF_RIGHT_MOUSE_BUTTON
: ui::EF_NONE
;
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
);
32 WindowOpenDisposition
DispositionForCurrentButtonPressEvent() {
33 GdkEvent
* event
= gtk_get_current_event();
36 return NEW_FOREGROUND_TAB
;
39 guint state
= event
->button
.state
;
40 gdk_event_free(event
);
41 return DispositionFromGdkState(state
);
44 } // namespace event_utils