| 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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 void Shell::PlatformInitialize() { | 57 void Shell::PlatformInitialize() { |
| 58 } | 58 } |
| 59 | 59 |
| 60 void Shell::PlatformCleanUp() { | 60 void Shell::PlatformCleanUp() { |
| 61 // Nothing to clean up; GTK will clean up the widgets shortly after. | 61 // Nothing to clean up; GTK will clean up the widgets shortly after. |
| 62 } | 62 } |
| 63 | 63 |
| 64 void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { | 64 void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { |
| 65 if (headless_) |
| 66 return; |
| 67 |
| 65 GtkToolItem* item = NULL; | 68 GtkToolItem* item = NULL; |
| 66 switch (control) { | 69 switch (control) { |
| 67 case BACK_BUTTON: | 70 case BACK_BUTTON: |
| 68 item = back_button_; | 71 item = back_button_; |
| 69 break; | 72 break; |
| 70 case FORWARD_BUTTON: | 73 case FORWARD_BUTTON: |
| 71 item = forward_button_; | 74 item = forward_button_; |
| 72 break; | 75 break; |
| 73 case STOP_BUTTON: | 76 case STOP_BUTTON: |
| 74 item = stop_button_; | 77 item = stop_button_; |
| 75 break; | 78 break; |
| 76 default: | 79 default: |
| 77 NOTREACHED() << "Unknown UI control"; | 80 NOTREACHED() << "Unknown UI control"; |
| 78 return; | 81 return; |
| 79 } | 82 } |
| 80 gtk_widget_set_sensitive(GTK_WIDGET(item), is_enabled); | 83 gtk_widget_set_sensitive(GTK_WIDGET(item), is_enabled); |
| 81 } | 84 } |
| 82 | 85 |
| 83 void Shell::PlatformSetAddressBarURL(const GURL& url) { | 86 void Shell::PlatformSetAddressBarURL(const GURL& url) { |
| 87 if (headless_) |
| 88 return; |
| 89 |
| 84 gtk_entry_set_text(GTK_ENTRY(url_edit_view_), url.spec().c_str()); | 90 gtk_entry_set_text(GTK_ENTRY(url_edit_view_), url.spec().c_str()); |
| 85 } | 91 } |
| 86 | 92 |
| 87 void Shell::PlatformSetIsLoading(bool loading) { | 93 void Shell::PlatformSetIsLoading(bool loading) { |
| 94 if (headless_) |
| 95 return; |
| 96 |
| 88 if (loading) | 97 if (loading) |
| 89 gtk_spinner_start(GTK_SPINNER(spinner_)); | 98 gtk_spinner_start(GTK_SPINNER(spinner_)); |
| 90 else | 99 else |
| 91 gtk_spinner_stop(GTK_SPINNER(spinner_)); | 100 gtk_spinner_stop(GTK_SPINNER(spinner_)); |
| 92 } | 101 } |
| 93 | 102 |
| 94 void Shell::PlatformCreateWindow(int width, int height) { | 103 void Shell::PlatformCreateWindow(int width, int height) { |
| 104 if (headless_) |
| 105 return; |
| 106 |
| 95 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 107 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
| 96 gtk_window_set_title(window_, "Content Shell"); | 108 gtk_window_set_title(window_, "Content Shell"); |
| 97 g_signal_connect(G_OBJECT(window_), "destroy", | 109 g_signal_connect(G_OBJECT(window_), "destroy", |
| 98 G_CALLBACK(OnWindowDestroyedThunk), this); | 110 G_CALLBACK(OnWindowDestroyedThunk), this); |
| 99 | 111 |
| 100 vbox_ = gtk_vbox_new(FALSE, 0); | 112 vbox_ = gtk_vbox_new(FALSE, 0); |
| 101 | 113 |
| 102 // Create the menu bar. | 114 // Create the menu bar. |
| 103 GtkWidget* menu_bar = CreateMenuBar(this); | 115 GtkWidget* menu_bar = CreateMenuBar(this); |
| 104 gtk_box_pack_start(GTK_BOX(vbox_), menu_bar, FALSE, FALSE, 0); | 116 gtk_box_pack_start(GTK_BOX(vbox_), menu_bar, FALSE, FALSE, 0); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 192 |
| 181 gtk_box_pack_start(GTK_BOX(vbox_), toolbar, FALSE, FALSE, 0); | 193 gtk_box_pack_start(GTK_BOX(vbox_), toolbar, FALSE, FALSE, 0); |
| 182 | 194 |
| 183 gtk_container_add(GTK_CONTAINER(window_), vbox_); | 195 gtk_container_add(GTK_CONTAINER(window_), vbox_); |
| 184 gtk_widget_show_all(GTK_WIDGET(window_)); | 196 gtk_widget_show_all(GTK_WIDGET(window_)); |
| 185 | 197 |
| 186 SizeTo(width, height); | 198 SizeTo(width, height); |
| 187 } | 199 } |
| 188 | 200 |
| 189 void Shell::PlatformSetContents() { | 201 void Shell::PlatformSetContents() { |
| 202 if (headless_) |
| 203 return; |
| 204 |
| 190 WebContentsView* content_view = web_contents_->GetView(); | 205 WebContentsView* content_view = web_contents_->GetView(); |
| 191 gtk_container_add(GTK_CONTAINER(vbox_), content_view->GetNativeView()); | 206 gtk_container_add(GTK_CONTAINER(vbox_), content_view->GetNativeView()); |
| 192 } | 207 } |
| 193 | 208 |
| 194 void Shell::SizeTo(int width, int height) { | 209 void Shell::SizeTo(int width, int height) { |
| 195 content_width_ = width; | 210 content_width_ = width; |
| 196 content_height_ = height; | 211 content_height_ = height; |
| 197 if (web_contents_.get()) { | 212 if (web_contents_.get()) |
| 198 gtk_widget_set_size_request(web_contents_->GetNativeView(), width, height); | 213 gtk_widget_set_size_request(web_contents_->GetNativeView(), width, height); |
| 199 } | |
| 200 } | 214 } |
| 201 | 215 |
| 202 void Shell::PlatformResizeSubViews() { | 216 void Shell::PlatformResizeSubViews() { |
| 203 SizeTo(content_width_, content_height_); | 217 SizeTo(content_width_, content_height_); |
| 204 } | 218 } |
| 205 | 219 |
| 206 void Shell::Close() { | 220 void Shell::Close() { |
| 221 if (headless_) |
| 222 return; |
| 223 |
| 207 gtk_widget_destroy(GTK_WIDGET(window_)); | 224 gtk_widget_destroy(GTK_WIDGET(window_)); |
| 208 } | 225 } |
| 209 | 226 |
| 210 void Shell::OnBackButtonClicked(GtkWidget* widget) { | 227 void Shell::OnBackButtonClicked(GtkWidget* widget) { |
| 211 GoBackOrForward(-1); | 228 GoBackOrForward(-1); |
| 212 } | 229 } |
| 213 | 230 |
| 214 void Shell::OnForwardButtonClicked(GtkWidget* widget) { | 231 void Shell::OnForwardButtonClicked(GtkWidget* widget) { |
| 215 GoBackOrForward(1); | 232 GoBackOrForward(1); |
| 216 } | 233 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 279 |
| 263 gboolean Shell::OnHighlightURLView(GtkAccelGroup* accel_group, | 280 gboolean Shell::OnHighlightURLView(GtkAccelGroup* accel_group, |
| 264 GObject* acceleratable, | 281 GObject* acceleratable, |
| 265 guint keyval, | 282 guint keyval, |
| 266 GdkModifierType modifier) { | 283 GdkModifierType modifier) { |
| 267 gtk_widget_grab_focus(GTK_WIDGET(url_edit_view_)); | 284 gtk_widget_grab_focus(GTK_WIDGET(url_edit_view_)); |
| 268 return TRUE; | 285 return TRUE; |
| 269 } | 286 } |
| 270 | 287 |
| 271 void Shell::PlatformSetTitle(const string16& title) { | 288 void Shell::PlatformSetTitle(const string16& title) { |
| 289 if (headless_) |
| 290 return; |
| 291 |
| 272 std::string title_utf8 = UTF16ToUTF8(title); | 292 std::string title_utf8 = UTF16ToUTF8(title); |
| 273 gtk_window_set_title(GTK_WINDOW(window_), title_utf8.c_str()); | 293 gtk_window_set_title(GTK_WINDOW(window_), title_utf8.c_str()); |
| 274 } | 294 } |
| 275 | 295 |
| 276 } // namespace content | 296 } // namespace content |
| OLD | NEW |