OLD | NEW |
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 "content/shell/shell.h" | 5 #include "content/shell/shell.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/string_piece.h" | 12 #include "base/string_piece.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
15 #include "content/public/browser/native_web_keyboard_event.h" | 15 #include "content/public/browser/native_web_keyboard_event.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_contents_view.h" | 17 #include "content/public/browser/web_contents_view.h" |
18 #include "content/public/common/renderer_preferences.h" | 18 #include "content/public/common/renderer_preferences.h" |
19 #include "content/shell/shell_switches.h" | 19 #include "content/shell/shell_switches.h" |
20 #include "third_party/skia/include/core/SkColor.h" | 20 #include "third_party/skia/include/core/SkColor.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
| 24 namespace { |
| 25 |
| 26 // Callback for Debug > Show web inspector... menu item. |
| 27 gboolean ShowWebInspectorActivated(GtkWidget* widget, Shell* shell) { |
| 28 shell->ShowDevTools(); |
| 29 return FALSE; // Don't stop this message. |
| 30 } |
| 31 |
| 32 GtkWidget* AddMenuEntry(GtkWidget* menu_widget, const char* text, |
| 33 GCallback callback, Shell* shell) { |
| 34 GtkWidget* entry = gtk_menu_item_new_with_label(text); |
| 35 g_signal_connect(entry, "activate", callback, shell); |
| 36 gtk_menu_shell_append(GTK_MENU_SHELL(menu_widget), entry); |
| 37 return entry; |
| 38 } |
| 39 |
| 40 GtkWidget* CreateMenu(GtkWidget* menu_bar, const char* text) { |
| 41 GtkWidget* menu_widget = gtk_menu_new(); |
| 42 GtkWidget* menu_header = gtk_menu_item_new_with_label(text); |
| 43 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_header), menu_widget); |
| 44 gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), menu_header); |
| 45 return menu_widget; |
| 46 } |
| 47 |
| 48 GtkWidget* CreateMenuBar(Shell* shell) { |
| 49 GtkWidget* menu_bar = gtk_menu_bar_new(); |
| 50 GtkWidget* debug_menu = CreateMenu(menu_bar, "Debug"); |
| 51 AddMenuEntry(debug_menu, "Show web inspector...", |
| 52 G_CALLBACK(ShowWebInspectorActivated), shell); |
| 53 return menu_bar; |
| 54 } |
| 55 |
| 56 } // namespace |
| 57 |
24 void Shell::PlatformInitialize() { | 58 void Shell::PlatformInitialize() { |
25 } | 59 } |
26 | 60 |
27 base::StringPiece Shell::PlatformResourceProvider(int key) { | 61 base::StringPiece Shell::PlatformResourceProvider(int key) { |
28 NOTIMPLEMENTED(); | 62 NOTIMPLEMENTED(); |
29 return base::StringPiece(); | 63 return base::StringPiece(); |
30 } | 64 } |
31 | 65 |
32 void Shell::PlatformCleanUp() { | 66 void Shell::PlatformCleanUp() { |
33 // Nothing to clean up; GTK will clean up the widgets shortly after. | 67 // Nothing to clean up; GTK will clean up the widgets shortly after. |
(...skipping 30 matching lines...) Expand all Loading... |
64 } | 98 } |
65 | 99 |
66 void Shell::PlatformCreateWindow(int width, int height) { | 100 void Shell::PlatformCreateWindow(int width, int height) { |
67 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 101 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
68 gtk_window_set_title(window_, "Content Shell"); | 102 gtk_window_set_title(window_, "Content Shell"); |
69 g_signal_connect(G_OBJECT(window_), "destroy", | 103 g_signal_connect(G_OBJECT(window_), "destroy", |
70 G_CALLBACK(OnWindowDestroyedThunk), this); | 104 G_CALLBACK(OnWindowDestroyedThunk), this); |
71 | 105 |
72 vbox_ = gtk_vbox_new(FALSE, 0); | 106 vbox_ = gtk_vbox_new(FALSE, 0); |
73 | 107 |
| 108 // Create the menu bar. |
| 109 GtkWidget* menu_bar = CreateMenuBar(this); |
| 110 gtk_box_pack_start(GTK_BOX(vbox_), menu_bar, FALSE, FALSE, 0); |
| 111 |
74 // Create the object that mediates accelerators. | 112 // Create the object that mediates accelerators. |
75 GtkAccelGroup* accel_group = gtk_accel_group_new(); | 113 GtkAccelGroup* accel_group = gtk_accel_group_new(); |
76 gtk_window_add_accel_group(GTK_WINDOW(window_), accel_group); | 114 gtk_window_add_accel_group(GTK_WINDOW(window_), accel_group); |
77 | 115 |
78 // Set global window handling accelerators: | 116 // Set global window handling accelerators: |
79 gtk_accel_group_connect( | 117 gtk_accel_group_connect( |
80 accel_group, GDK_w, GDK_CONTROL_MASK, | 118 accel_group, GDK_w, GDK_CONTROL_MASK, |
81 GTK_ACCEL_VISIBLE, | 119 GTK_ACCEL_VISIBLE, |
82 g_cclosure_new(G_CALLBACK(OnCloseWindowKeyPressedThunk), | 120 g_cclosure_new(G_CALLBACK(OnCloseWindowKeyPressedThunk), |
83 this, NULL)); | 121 this, NULL)); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 gtk_widget_grab_focus(GTK_WIDGET(url_edit_view_)); | 269 gtk_widget_grab_focus(GTK_WIDGET(url_edit_view_)); |
232 return TRUE; | 270 return TRUE; |
233 } | 271 } |
234 | 272 |
235 void Shell::PlatformSetTitle(const string16& title) { | 273 void Shell::PlatformSetTitle(const string16& title) { |
236 std::string title_utf8 = UTF16ToUTF8(title); | 274 std::string title_utf8 = UTF16ToUTF8(title); |
237 gtk_window_set_title(GTK_WINDOW(window_), title_utf8.c_str()); | 275 gtk_window_set_title(GTK_WINDOW(window_), title_utf8.c_str()); |
238 } | 276 } |
239 | 277 |
240 } // namespace content | 278 } // namespace content |
OLD | NEW |