Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/browser/ui/gtk/gtk_util.cc

Issue 10546116: gtk: Extract event functions into event_utils module. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/gtk/gtk_util.h ('k') | chrome/browser/ui/gtk/gtk_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cstdarg> 10 #include <cstdarg>
11 #include <map> 11 #include <map>
12 12
13 #include "base/environment.h" 13 #include "base/environment.h"
14 #include "base/i18n/rtl.h" 14 #include "base/i18n/rtl.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/nix/xdg_util.h" 16 #include "base/nix/xdg_util.h"
17 #include "base/string_number_conversions.h" 17 #include "base/string_number_conversions.h"
18 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19 #include "chrome/browser/autocomplete/autocomplete.h" 19 #include "chrome/browser/autocomplete/autocomplete.h"
20 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 20 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
21 #include "chrome/browser/autocomplete/autocomplete_match.h" 21 #include "chrome/browser/autocomplete/autocomplete_match.h"
22 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/event_disposition.h"
24 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/profiles/profile_info_cache.h" 24 #include "chrome/browser/profiles/profile_info_cache.h"
26 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_list.h" 27 #include "chrome/browser/ui/browser_list.h"
29 #include "chrome/browser/ui/browser_window.h" 28 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/gtk/browser_window_gtk.h" 29 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
31 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 30 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
32 #include "content/public/browser/render_view_host.h" 31 #include "content/public/browser/render_view_host.h"
33 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
34 #include "content/public/common/renderer_preferences.h" 33 #include "content/public/common/renderer_preferences.h"
35 #include "googleurl/src/gurl.h" 34 #include "googleurl/src/gurl.h"
36 #include "grit/theme_resources.h" 35 #include "grit/theme_resources.h"
37 #include "grit/theme_resources_standard.h" 36 #include "grit/theme_resources_standard.h"
38 #include "ui/base/events.h"
39 #include "ui/base/gtk/gtk_compat.h" 37 #include "ui/base/gtk/gtk_compat.h"
40 #include "ui/base/gtk/gtk_hig_constants.h" 38 #include "ui/base/gtk/gtk_hig_constants.h"
41 #include "ui/base/gtk/gtk_screen_util.h" 39 #include "ui/base/gtk/gtk_screen_util.h"
42 #include "ui/base/gtk/menu_label_accelerator_util.h" 40 #include "ui/base/gtk/menu_label_accelerator_util.h"
43 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
44 #include "ui/base/resource/resource_bundle.h" 42 #include "ui/base/resource/resource_bundle.h"
45 #include "ui/base/text/text_elider.h" 43 #include "ui/base/text/text_elider.h"
46 #include "ui/base/x/x11_util.h" 44 #include "ui/base/x/x11_util.h"
47 #include "ui/gfx/image/cairo_cached_surface.h" 45 #include "ui/gfx/image/cairo_cached_surface.h"
48 #include "ui/gfx/image/image.h" 46 #include "ui/gfx/image/image.h"
49 #include "ui/gfx/pango_util.h" 47 #include "ui/gfx/pango_util.h"
50 48
51 // These conflict with base/tracked_objects.h, so need to come last. 49 // These conflict with base/tracked_objects.h, so need to come last.
52 #include <gdk/gdkx.h> // NOLINT 50 #include <gdk/gdkx.h> // NOLINT
53 #include <gtk/gtk.h> // NOLINT
54 51
55 using content::RenderWidgetHost; 52 using content::RenderWidgetHost;
56 using content::WebContents; 53 using content::WebContents;
57 54
58 namespace { 55 namespace {
59 56
60 #if defined(GOOGLE_CHROME_BUILD) 57 #if defined(GOOGLE_CHROME_BUILD)
61 static const char* kIconName = "google-chrome"; 58 static const char* kIconName = "google-chrome";
62 #else 59 #else
63 static const char* kIconName = "chromium-browser"; 60 static const char* kIconName = "chromium-browser";
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 window); 284 window);
288 return browser_window->browser()->GetActiveWebContents(); 285 return browser_window->browser()->GetActiveWebContents();
289 } 286 }
290 287
291 GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) { 288 GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) {
292 return gtk_window_get_focus(window->GetNativeWindow()); 289 return gtk_window_get_focus(window->GetNativeWindow());
293 } 290 }
294 291
295 } // namespace 292 } // namespace
296 293
297 namespace event_utils {
298
299 // TODO(shinyak) This function will be removed after refactoring.
300 WindowOpenDisposition DispositionFromGdkState(guint state) {
301 int event_flags = EventFlagsFromGdkState(state);
302 return browser::DispositionFromEventFlags(event_flags);
303 }
304
305 int EventFlagsFromGdkState(guint state) {
306 int flags = 0;
307 flags |= (state & GDK_LOCK_MASK) ? ui::EF_CAPS_LOCK_DOWN : 0;
308 flags |= (state & GDK_CONTROL_MASK) ? ui::EF_CONTROL_DOWN : 0;
309 flags |= (state & GDK_SHIFT_MASK) ? ui::EF_SHIFT_DOWN : 0;
310 flags |= (state & GDK_MOD1_MASK) ? ui::EF_ALT_DOWN : 0;
311 flags |= (state & GDK_BUTTON1_MASK) ? ui::EF_LEFT_MOUSE_BUTTON : 0;
312 flags |= (state & GDK_BUTTON2_MASK) ? ui::EF_MIDDLE_MOUSE_BUTTON : 0;
313 flags |= (state & GDK_BUTTON3_MASK) ? ui::EF_RIGHT_MOUSE_BUTTON : 0;
314 return flags;
315 }
316
317 } // namespace event_utils
318
319 namespace gtk_util { 294 namespace gtk_util {
320 295
321 GtkWidget* CreateLabeledControlsGroup(std::vector<GtkWidget*>* labels, 296 GtkWidget* CreateLabeledControlsGroup(std::vector<GtkWidget*>* labels,
322 const char* text, ...) { 297 const char* text, ...) {
323 va_list ap; 298 va_list ap;
324 va_start(ap, text); 299 va_start(ap, text);
325 GtkWidget* table = gtk_table_new(0, 2, FALSE); 300 GtkWidget* table = gtk_table_new(0, 2, FALSE);
326 gtk_table_set_col_spacing(GTK_TABLE(table), 0, ui::kLabelSpacing); 301 gtk_table_set_col_spacing(GTK_TABLE(table), 0, ui::kLabelSpacing);
327 gtk_table_set_row_spacings(GTK_TABLE(table), ui::kControlSpacing); 302 gtk_table_set_row_spacings(GTK_TABLE(table), ui::kControlSpacing);
328 303
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 GtkAllocation allocation; 897 GtkAllocation allocation;
923 gtk_widget_get_allocation(widget, &allocation); 898 gtk_widget_get_allocation(widget, &allocation);
924 return gfx::Rect(x, y, allocation.width, allocation.height); 899 return gfx::Rect(x, y, allocation.width, allocation.height);
925 } 900 }
926 901
927 void SuppressDefaultPainting(GtkWidget* container) { 902 void SuppressDefaultPainting(GtkWidget* container) {
928 g_signal_connect(container, "expose-event", 903 g_signal_connect(container, "expose-event",
929 G_CALLBACK(PaintNoBackground), NULL); 904 G_CALLBACK(PaintNoBackground), NULL);
930 } 905 }
931 906
932 WindowOpenDisposition DispositionForCurrentButtonPressEvent() {
933 GdkEvent* event = gtk_get_current_event();
934 if (!event) {
935 NOTREACHED();
936 return NEW_FOREGROUND_TAB;
937 }
938
939 guint state = event->button.state;
940 gdk_event_free(event);
941 return event_utils::DispositionFromGdkState(state);
942 }
943
944 bool GrabAllInput(GtkWidget* widget) { 907 bool GrabAllInput(GtkWidget* widget) {
945 guint time = gtk_get_current_event_time(); 908 guint time = gtk_get_current_event_time();
946 909
947 if (!gtk_widget_get_visible(widget)) 910 if (!gtk_widget_get_visible(widget))
948 return false; 911 return false;
949 912
950 GdkWindow* gdk_window = gtk_widget_get_window(widget); 913 GdkWindow* gdk_window = gtk_widget_get_window(widget);
951 if (!gdk_pointer_grab(gdk_window, 914 if (!gdk_pointer_grab(gdk_window,
952 TRUE, 915 TRUE,
953 GdkEventMask(GDK_BUTTON_PRESS_MASK | 916 GdkEventMask(GDK_BUTTON_PRESS_MASK |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 1133
1171 void DoCopy(BrowserWindow* window) { 1134 void DoCopy(BrowserWindow* window) {
1172 DoCutCopyPaste(window, &RenderWidgetHost::Copy, "copy-clipboard"); 1135 DoCutCopyPaste(window, &RenderWidgetHost::Copy, "copy-clipboard");
1173 } 1136 }
1174 1137
1175 void DoPaste(BrowserWindow* window) { 1138 void DoPaste(BrowserWindow* window) {
1176 DoCutCopyPaste(window, &RenderWidgetHost::Paste, "paste-clipboard"); 1139 DoCutCopyPaste(window, &RenderWidgetHost::Paste, "paste-clipboard");
1177 } 1140 }
1178 1141
1179 } // namespace gtk_util 1142 } // namespace gtk_util
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/gtk_util.h ('k') | chrome/browser/ui/gtk/gtk_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698