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 "chrome/browser/ui/gtk/extensions/shell_window_gtk.h" | 5 #include "chrome/browser/ui/gtk/extensions/shell_window_gtk.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/common/extensions/extension.h" | 8 #include "chrome/common/extensions/extension.h" |
9 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
10 #include "content/public/browser/render_widget_host_view.h" | 10 #include "content/public/browser/render_widget_host_view.h" |
11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
12 #include "content/public/browser/web_contents_view.h" | 12 #include "content/public/browser/web_contents_view.h" |
13 #include "ui/base/x/active_window_watcher_x.h" | 13 #include "ui/base/x/active_window_watcher_x.h" |
14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
15 | 15 |
16 ShellWindowGtk::ShellWindowGtk(Profile* profile, | 16 ShellWindowGtk::ShellWindowGtk(ShellWindow* shell_window, |
17 const extensions::Extension* extension, | |
18 const GURL& url, | |
19 const ShellWindow::CreateParams& params) | 17 const ShellWindow::CreateParams& params) |
20 : ShellWindow(profile, extension, url), | 18 : shell_window_(shell_window), |
21 state_(GDK_WINDOW_STATE_WITHDRAWN), | 19 state_(GDK_WINDOW_STATE_WITHDRAWN), |
22 is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()), | 20 is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()), |
23 content_thinks_its_fullscreen_(false) { | 21 content_thinks_its_fullscreen_(false) { |
24 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 22 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
25 | 23 |
26 gfx::NativeView native_view = | 24 gfx::NativeView native_view = |
27 web_contents()->GetView()->GetNativeView(); | 25 web_contents()->GetView()->GetNativeView(); |
28 gtk_container_add(GTK_CONTAINER(window_), native_view); | 26 gtk_container_add(GTK_CONTAINER(window_), native_view); |
29 | 27 |
30 gtk_window_set_default_size( | 28 gtk_window_set_default_size( |
(...skipping 21 matching lines...) Expand all Loading... |
52 } | 50 } |
53 if (hints_mask) { | 51 if (hints_mask) { |
54 gtk_window_set_geometry_hints( | 52 gtk_window_set_geometry_hints( |
55 window_, | 53 window_, |
56 GTK_WIDGET(window_), | 54 GTK_WIDGET(window_), |
57 &hints, | 55 &hints, |
58 static_cast<GdkWindowHints>(hints_mask)); | 56 static_cast<GdkWindowHints>(hints_mask)); |
59 } | 57 } |
60 | 58 |
61 // TODO(mihaip): Mirror contents of <title> tag in window title | 59 // TODO(mihaip): Mirror contents of <title> tag in window title |
62 gtk_window_set_title(window_, extension->name().c_str()); | 60 gtk_window_set_title(window_, extension()->name().c_str()); |
63 | 61 |
64 g_signal_connect(window_, "delete-event", | 62 g_signal_connect(window_, "delete-event", |
65 G_CALLBACK(OnMainWindowDeleteEventThunk), this); | 63 G_CALLBACK(OnMainWindowDeleteEventThunk), this); |
66 g_signal_connect(window_, "configure-event", | 64 g_signal_connect(window_, "configure-event", |
67 G_CALLBACK(OnConfigureThunk), this); | 65 G_CALLBACK(OnConfigureThunk), this); |
68 g_signal_connect(window_, "window-state-event", | 66 g_signal_connect(window_, "window-state-event", |
69 G_CALLBACK(OnWindowStateThunk), this); | 67 G_CALLBACK(OnWindowStateThunk), this); |
70 | 68 |
71 ui::ActiveWindowWatcherX::AddObserver(this); | 69 ui::ActiveWindowWatcherX::AddObserver(this); |
72 } | 70 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 112 |
115 void ShellWindowGtk::Close() { | 113 void ShellWindowGtk::Close() { |
116 GtkWidget* window = GTK_WIDGET(window_); | 114 GtkWidget* window = GTK_WIDGET(window_); |
117 // To help catch bugs in any event handlers that might get fired during the | 115 // To help catch bugs in any event handlers that might get fired during the |
118 // destruction, set window_ to NULL before any handlers will run. | 116 // destruction, set window_ to NULL before any handlers will run. |
119 window_ = NULL; | 117 window_ = NULL; |
120 | 118 |
121 // OnNativeClose does a delete this so no other members should | 119 // OnNativeClose does a delete this so no other members should |
122 // be accessed after. gtk_widget_destroy is safe (and must | 120 // be accessed after. gtk_widget_destroy is safe (and must |
123 // be last). | 121 // be last). |
124 OnNativeClose(); | 122 shell_window_->OnNativeClose(); |
125 gtk_widget_destroy(window); | 123 gtk_widget_destroy(window); |
126 } | 124 } |
127 | 125 |
128 void ShellWindowGtk::Activate() { | 126 void ShellWindowGtk::Activate() { |
129 gtk_window_present(window_); | 127 gtk_window_present(window_); |
130 } | 128 } |
131 | 129 |
132 void ShellWindowGtk::Deactivate() { | 130 void ShellWindowGtk::Deactivate() { |
133 gdk_window_lower(gtk_widget_get_window(GTK_WIDGET(window_))); | 131 gdk_window_lower(gtk_widget_get_window(GTK_WIDGET(window_))); |
134 } | 132 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 if (fullscreen) | 211 if (fullscreen) |
214 gtk_window_fullscreen(window_); | 212 gtk_window_fullscreen(window_); |
215 else | 213 else |
216 gtk_window_unfullscreen(window_); | 214 gtk_window_unfullscreen(window_); |
217 } | 215 } |
218 | 216 |
219 bool ShellWindowGtk::IsFullscreenOrPending() const { | 217 bool ShellWindowGtk::IsFullscreenOrPending() const { |
220 return content_thinks_its_fullscreen_; | 218 return content_thinks_its_fullscreen_; |
221 } | 219 } |
222 | 220 |
| 221 void ShellWindowGtk::UpdateWindowTitle() { |
| 222 // TODO(jeremya): implement. |
| 223 } |
| 224 |
223 // static | 225 // static |
224 ShellWindow* ShellWindow::CreateImpl(Profile* profile, | 226 NativeShellWindow* NativeShellWindow::Create( |
225 const extensions::Extension* extension, | 227 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { |
226 const GURL& url, | 228 return new ShellWindowGtk(shell_window, params); |
227 const ShellWindow::CreateParams& params) { | |
228 return new ShellWindowGtk(profile, extension, url, params); | |
229 } | 229 } |
OLD | NEW |