OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/gtk/gtk_util.h" | 5 #include "chrome/browser/ui/gtk/gtk_util.h" |
6 | 6 |
7 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 | 10 |
11 #include <cstdarg> | 11 #include <cstdarg> |
12 #include <map> | 12 #include <map> |
13 | 13 |
14 #include "base/environment.h" | 14 #include "base/environment.h" |
15 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
16 #include "base/linux_util.h" | 16 #include "base/linux_util.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/nix/xdg_util.h" | 18 #include "base/nix/xdg_util.h" |
19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
21 #include "chrome/browser/autocomplete/autocomplete.h" | 21 #include "chrome/browser/autocomplete/autocomplete.h" |
22 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 22 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
23 #include "chrome/browser/autocomplete/autocomplete_match.h" | 23 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 24 #include "chrome/browser/event_disposition.h" |
24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
26 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/browser/ui/gtk/cairo_cached_surface.h" | 28 #include "chrome/browser/ui/gtk/cairo_cached_surface.h" |
28 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 29 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
29 #include "content/browser/disposition_utils.h" | 30 #include "content/browser/disposition_utils.h" |
30 #include "content/browser/renderer_host/render_view_host.h" | 31 #include "content/browser/renderer_host/render_view_host.h" |
31 #include "content/browser/tab_contents/tab_contents.h" | 32 #include "content/browser/tab_contents/tab_contents.h" |
32 #include "content/common/renderer_preferences.h" | 33 #include "content/common/renderer_preferences.h" |
33 #include "googleurl/src/gurl.h" | 34 #include "googleurl/src/gurl.h" |
34 #include "grit/theme_resources.h" | 35 #include "grit/theme_resources.h" |
35 #include "grit/theme_resources_standard.h" | 36 #include "grit/theme_resources_standard.h" |
36 #include "third_party/skia/include/core/SkBitmap.h" | 37 #include "third_party/skia/include/core/SkBitmap.h" |
37 #include "third_party/skia/include/core/SkColor.h" | 38 #include "third_party/skia/include/core/SkColor.h" |
| 39 #include "ui/base/events.h" |
38 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
39 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
40 #include "ui/base/text/text_elider.h" | 42 #include "ui/base/text/text_elider.h" |
41 #include "ui/base/x/x11_util.h" | 43 #include "ui/base/x/x11_util.h" |
42 #include "ui/gfx/gtk_util.h" | 44 #include "ui/gfx/gtk_util.h" |
43 #include "ui/gfx/image/image.h" | 45 #include "ui/gfx/image/image.h" |
44 | 46 |
45 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
46 #include "chrome/browser/chromeos/frame/browser_view.h" | 48 #include "chrome/browser/chromeos/frame/browser_view.h" |
47 #include "chrome/browser/chromeos/native_dialog_window.h" | 49 #include "chrome/browser/chromeos/native_dialog_window.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) { | 190 GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) { |
189 return gtk_window_get_focus(window->GetNativeHandle()); | 191 return gtk_window_get_focus(window->GetNativeHandle()); |
190 } | 192 } |
191 | 193 |
192 #endif | 194 #endif |
193 | 195 |
194 } // namespace | 196 } // namespace |
195 | 197 |
196 namespace event_utils { | 198 namespace event_utils { |
197 | 199 |
198 WindowOpenDisposition DispositionFromEventFlags(guint event_flags) { | 200 // TODO(shinyak) This function will be removed after refactoring. |
199 return disposition_utils::DispositionFromClick( | 201 WindowOpenDisposition DispositionFromGdkState(guint state) { |
200 event_flags & GDK_BUTTON2_MASK, | 202 int event_flags = EventFlagsFromGdkState(state); |
201 event_flags & GDK_MOD1_MASK, | 203 return browser::DispositionFromEventFlags(event_flags); |
202 event_flags & GDK_CONTROL_MASK, | 204 } |
203 event_flags & GDK_META_MASK, | 205 |
204 event_flags & GDK_SHIFT_MASK); | 206 int EventFlagsFromGdkState(guint state) { |
| 207 int flags = 0; |
| 208 flags |= (state & GDK_LOCK_MASK) ? ui::EF_CAPS_LOCK_DOWN : 0; |
| 209 flags |= (state & GDK_CONTROL_MASK) ? ui::EF_CONTROL_DOWN : 0; |
| 210 flags |= (state & GDK_SHIFT_MASK) ? ui::EF_SHIFT_DOWN : 0; |
| 211 flags |= (state & GDK_MOD1_MASK) ? ui::EF_ALT_DOWN : 0; |
| 212 flags |= (state & GDK_BUTTON1_MASK) ? ui::EF_LEFT_BUTTON_DOWN : 0; |
| 213 flags |= (state & GDK_BUTTON2_MASK) ? ui::EF_MIDDLE_BUTTON_DOWN : 0; |
| 214 flags |= (state & GDK_BUTTON3_MASK) ? ui::EF_RIGHT_BUTTON_DOWN : 0; |
| 215 return flags; |
205 } | 216 } |
206 | 217 |
207 } // namespace event_utils | 218 } // namespace event_utils |
208 | 219 |
209 namespace gtk_util { | 220 namespace gtk_util { |
210 | 221 |
211 const GdkColor kGdkWhite = GDK_COLOR_RGB(0xff, 0xff, 0xff); | 222 const GdkColor kGdkWhite = GDK_COLOR_RGB(0xff, 0xff, 0xff); |
212 const GdkColor kGdkGray = GDK_COLOR_RGB(0x7f, 0x7f, 0x7f); | 223 const GdkColor kGdkGray = GDK_COLOR_RGB(0x7f, 0x7f, 0x7f); |
213 const GdkColor kGdkBlack = GDK_COLOR_RGB(0x00, 0x00, 0x00); | 224 const GdkColor kGdkBlack = GDK_COLOR_RGB(0x00, 0x00, 0x00); |
214 const GdkColor kGdkGreen = GDK_COLOR_RGB(0x00, 0xff, 0x00); | 225 const GdkColor kGdkGreen = GDK_COLOR_RGB(0x00, 0xff, 0x00); |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 | 932 |
922 WindowOpenDisposition DispositionForCurrentButtonPressEvent() { | 933 WindowOpenDisposition DispositionForCurrentButtonPressEvent() { |
923 GdkEvent* event = gtk_get_current_event(); | 934 GdkEvent* event = gtk_get_current_event(); |
924 if (!event) { | 935 if (!event) { |
925 NOTREACHED(); | 936 NOTREACHED(); |
926 return NEW_FOREGROUND_TAB; | 937 return NEW_FOREGROUND_TAB; |
927 } | 938 } |
928 | 939 |
929 guint state = event->button.state; | 940 guint state = event->button.state; |
930 gdk_event_free(event); | 941 gdk_event_free(event); |
931 return event_utils::DispositionFromEventFlags(state); | 942 return event_utils::DispositionFromGdkState(state); |
932 } | 943 } |
933 | 944 |
934 bool GrabAllInput(GtkWidget* widget) { | 945 bool GrabAllInput(GtkWidget* widget) { |
935 guint time = gtk_get_current_event_time(); | 946 guint time = gtk_get_current_event_time(); |
936 | 947 |
937 if (!gtk_widget_get_visible(widget)) | 948 if (!gtk_widget_get_visible(widget)) |
938 return false; | 949 return false; |
939 | 950 |
940 if (!gdk_pointer_grab(widget->window, TRUE, | 951 if (!gdk_pointer_grab(widget->window, TRUE, |
941 GdkEventMask(GDK_BUTTON_PRESS_MASK | | 952 GdkEventMask(GDK_BUTTON_PRESS_MASK | |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 | 1293 |
1283 void DoCopy(BrowserWindow* window) { | 1294 void DoCopy(BrowserWindow* window) { |
1284 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); | 1295 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); |
1285 } | 1296 } |
1286 | 1297 |
1287 void DoPaste(BrowserWindow* window) { | 1298 void DoPaste(BrowserWindow* window) { |
1288 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); | 1299 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); |
1289 } | 1300 } |
1290 | 1301 |
1291 } // namespace gtk_util | 1302 } // namespace gtk_util |
OLD | NEW |