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

Side by Side Diff: chrome/browser/ui/gtk/extensions/native_app_window_gtk.cc

Issue 11280173: Rename ShellWindow* classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge fix Created 8 years 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
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/extensions/shell_window_gtk.h" 5 #include "chrome/browser/ui/gtk/extensions/native_app_window_gtk.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.h" 9 #include "chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.h"
10 #include "chrome/browser/ui/gtk/gtk_util.h" 10 #include "chrome/browser/ui/gtk/gtk_util.h"
11 #include "chrome/browser/ui/gtk/gtk_window_util.h" 11 #include "chrome/browser/ui/gtk/gtk_window_util.h"
12 #include "chrome/browser/web_applications/web_app.h" 12 #include "chrome/browser/web_applications/web_app.h"
13 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
14 #include "content/public/browser/render_view_host.h" 14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/render_widget_host_view.h" 15 #include "content/public/browser/render_widget_host_view.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 "ui/base/x/active_window_watcher_x.h" 18 #include "ui/base/x/active_window_watcher_x.h"
19 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
20 #include "ui/gfx/rect.h" 20 #include "ui/gfx/rect.h"
21 21
22 namespace { 22 namespace {
23 23
24 // The timeout in milliseconds before we'll get the true window position with 24 // The timeout in milliseconds before we'll get the true window position with
25 // gtk_window_get_position() after the last GTK configure-event signal. 25 // gtk_window_get_position() after the last GTK configure-event signal.
26 const int kDebounceTimeoutMilliseconds = 100; 26 const int kDebounceTimeoutMilliseconds = 100;
27 27
28 } // namespace 28 } // namespace
29 29
30 ShellWindowGtk::ShellWindowGtk(ShellWindow* shell_window, 30 NativeAppWindowGtk::NativeAppWindowGtk(ShellWindow* shell_window,
31 const ShellWindow::CreateParams& params) 31 const ShellWindow::CreateParams& params)
32 : shell_window_(shell_window), 32 : shell_window_(shell_window),
33 window_(NULL), 33 window_(NULL),
34 state_(GDK_WINDOW_STATE_WITHDRAWN), 34 state_(GDK_WINDOW_STATE_WITHDRAWN),
35 is_active_(false), 35 is_active_(false),
36 content_thinks_its_fullscreen_(false), 36 content_thinks_its_fullscreen_(false),
37 frameless_(params.frame == ShellWindow::CreateParams::FRAME_NONE) { 37 frameless_(params.frame == ShellWindow::CreateParams::FRAME_NONE) {
38 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); 38 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
39 39
40 gfx::NativeView native_view = 40 gfx::NativeView native_view =
41 web_contents()->GetView()->GetNativeView(); 41 web_contents()->GetView()->GetNativeView();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // Add the keybinding registry. 116 // Add the keybinding registry.
117 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryGtk( 117 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryGtk(
118 shell_window_->profile(), 118 shell_window_->profile(),
119 window_, 119 window_,
120 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, 120 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY,
121 shell_window_)); 121 shell_window_));
122 122
123 ui::ActiveWindowWatcherX::AddObserver(this); 123 ui::ActiveWindowWatcherX::AddObserver(this);
124 } 124 }
125 125
126 ShellWindowGtk::~ShellWindowGtk() { 126 NativeAppWindowGtk::~NativeAppWindowGtk() {
127 ui::ActiveWindowWatcherX::RemoveObserver(this); 127 ui::ActiveWindowWatcherX::RemoveObserver(this);
128 } 128 }
129 129
130 bool ShellWindowGtk::IsActive() const { 130 bool NativeAppWindowGtk::IsActive() const {
131 if (ui::ActiveWindowWatcherX::WMSupportsActivation()) 131 if (ui::ActiveWindowWatcherX::WMSupportsActivation())
132 return is_active_; 132 return is_active_;
133 133
134 // This still works even though we don't get the activation notification. 134 // This still works even though we don't get the activation notification.
135 return gtk_window_is_active(window_); 135 return gtk_window_is_active(window_);
136 } 136 }
137 137
138 bool ShellWindowGtk::IsMaximized() const { 138 bool NativeAppWindowGtk::IsMaximized() const {
139 return (state_ & GDK_WINDOW_STATE_MAXIMIZED); 139 return (state_ & GDK_WINDOW_STATE_MAXIMIZED);
140 } 140 }
141 141
142 bool ShellWindowGtk::IsMinimized() const { 142 bool NativeAppWindowGtk::IsMinimized() const {
143 return (state_ & GDK_WINDOW_STATE_ICONIFIED); 143 return (state_ & GDK_WINDOW_STATE_ICONIFIED);
144 } 144 }
145 145
146 bool ShellWindowGtk::IsFullscreen() const { 146 bool NativeAppWindowGtk::IsFullscreen() const {
147 return false; 147 return false;
148 } 148 }
149 149
150 gfx::NativeWindow ShellWindowGtk::GetNativeWindow() { 150 gfx::NativeWindow NativeAppWindowGtk::GetNativeWindow() {
151 return window_; 151 return window_;
152 } 152 }
153 153
154 gfx::Rect ShellWindowGtk::GetRestoredBounds() const { 154 gfx::Rect NativeAppWindowGtk::GetRestoredBounds() const {
155 return restored_bounds_; 155 return restored_bounds_;
156 } 156 }
157 157
158 gfx::Rect ShellWindowGtk::GetBounds() const { 158 gfx::Rect NativeAppWindowGtk::GetBounds() const {
159 return bounds_; 159 return bounds_;
160 } 160 }
161 161
162 void ShellWindowGtk::Show() { 162 void NativeAppWindowGtk::Show() {
163 gtk_window_present(window_); 163 gtk_window_present(window_);
164 } 164 }
165 165
166 void ShellWindowGtk::ShowInactive() { 166 void NativeAppWindowGtk::ShowInactive() {
167 gtk_window_set_focus_on_map(window_, false); 167 gtk_window_set_focus_on_map(window_, false);
168 gtk_widget_show(GTK_WIDGET(window_)); 168 gtk_widget_show(GTK_WIDGET(window_));
169 } 169 }
170 170
171 void ShellWindowGtk::Hide() { 171 void NativeAppWindowGtk::Hide() {
172 gtk_widget_hide(GTK_WIDGET(window_)); 172 gtk_widget_hide(GTK_WIDGET(window_));
173 } 173 }
174 174
175 void ShellWindowGtk::Close() { 175 void NativeAppWindowGtk::Close() {
176 shell_window_->OnNativeWindowChanged(); 176 shell_window_->OnNativeWindowChanged();
177 177
178 // Cancel any pending callback from the window configure debounce timer. 178 // Cancel any pending callback from the window configure debounce timer.
179 window_configure_debounce_timer_.Stop(); 179 window_configure_debounce_timer_.Stop();
180 180
181 GtkWidget* window = GTK_WIDGET(window_); 181 GtkWidget* window = GTK_WIDGET(window_);
182 // To help catch bugs in any event handlers that might get fired during the 182 // To help catch bugs in any event handlers that might get fired during the
183 // destruction, set window_ to NULL before any handlers will run. 183 // destruction, set window_ to NULL before any handlers will run.
184 window_ = NULL; 184 window_ = NULL;
185 185
186 // OnNativeClose does a delete this so no other members should 186 // OnNativeClose does a delete this so no other members should
187 // be accessed after. gtk_widget_destroy is safe (and must 187 // be accessed after. gtk_widget_destroy is safe (and must
188 // be last). 188 // be last).
189 shell_window_->OnNativeClose(); 189 shell_window_->OnNativeClose();
190 gtk_widget_destroy(window); 190 gtk_widget_destroy(window);
191 } 191 }
192 192
193 void ShellWindowGtk::Activate() { 193 void NativeAppWindowGtk::Activate() {
194 gtk_window_present(window_); 194 gtk_window_present(window_);
195 } 195 }
196 196
197 void ShellWindowGtk::Deactivate() { 197 void NativeAppWindowGtk::Deactivate() {
198 gdk_window_lower(gtk_widget_get_window(GTK_WIDGET(window_))); 198 gdk_window_lower(gtk_widget_get_window(GTK_WIDGET(window_)));
199 } 199 }
200 200
201 void ShellWindowGtk::Maximize() { 201 void NativeAppWindowGtk::Maximize() {
202 gtk_window_maximize(window_); 202 gtk_window_maximize(window_);
203 } 203 }
204 204
205 void ShellWindowGtk::Minimize() { 205 void NativeAppWindowGtk::Minimize() {
206 gtk_window_iconify(window_); 206 gtk_window_iconify(window_);
207 shell_window_->OnNativeWindowChanged();
208 } 207 }
209 208
210 void ShellWindowGtk::Restore() { 209 void NativeAppWindowGtk::Restore() {
211 if (IsMaximized()) 210 if (IsMaximized())
212 gtk_window_unmaximize(window_); 211 gtk_window_unmaximize(window_);
213 else if (IsMinimized()) 212 else if (IsMinimized())
214 gtk_window_deiconify(window_); 213 gtk_window_deiconify(window_);
215 shell_window_->OnNativeWindowChanged();
216 } 214 }
217 215
218 void ShellWindowGtk::SetBounds(const gfx::Rect& bounds) { 216 void NativeAppWindowGtk::SetBounds(const gfx::Rect& bounds) {
219 gtk_window_move(window_, bounds.x(), bounds.y()); 217 gtk_window_move(window_, bounds.x(), bounds.y());
220 gtk_window_util::SetWindowSize(window_, 218 gtk_window_util::SetWindowSize(window_,
221 gfx::Size(bounds.width(), bounds.height())); 219 gfx::Size(bounds.width(), bounds.height()));
222 } 220 }
223 221
224 void ShellWindowGtk::FlashFrame(bool flash) { 222 void NativeAppWindowGtk::FlashFrame(bool flash) {
225 gtk_window_set_urgency_hint(window_, flash); 223 gtk_window_set_urgency_hint(window_, flash);
226 } 224 }
227 225
228 bool ShellWindowGtk::IsAlwaysOnTop() const { 226 bool NativeAppWindowGtk::IsAlwaysOnTop() const {
229 return false; 227 return false;
230 } 228 }
231 229
232 void ShellWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { 230 void NativeAppWindowGtk::ActiveWindowChanged(GdkWindow* active_window) {
233 // Do nothing if we're in the process of closing the browser window. 231 // Do nothing if we're in the process of closing the browser window.
234 if (!window_) 232 if (!window_)
235 return; 233 return;
236 234
237 is_active_ = gtk_widget_get_window(GTK_WIDGET(window_)) == active_window; 235 is_active_ = gtk_widget_get_window(GTK_WIDGET(window_)) == active_window;
238 } 236 }
239 237
240 // Callback for the delete event. This event is fired when the user tries to 238 // Callback for the delete event. This event is fired when the user tries to
241 // close the window (e.g., clicking on the X in the window manager title bar). 239 // close the window (e.g., clicking on the X in the window manager title bar).
242 gboolean ShellWindowGtk::OnMainWindowDeleteEvent(GtkWidget* widget, 240 gboolean NativeAppWindowGtk::OnMainWindowDeleteEvent(GtkWidget* widget,
243 GdkEvent* event) { 241 GdkEvent* event) {
244 Close(); 242 Close();
245 243
246 // Return true to prevent the GTK window from being destroyed. Close will 244 // Return true to prevent the GTK window from being destroyed. Close will
247 // destroy it for us. 245 // destroy it for us.
248 return TRUE; 246 return TRUE;
249 } 247 }
250 248
251 gboolean ShellWindowGtk::OnConfigure(GtkWidget* widget, 249 gboolean NativeAppWindowGtk::OnConfigure(GtkWidget* widget,
252 GdkEventConfigure* event) { 250 GdkEventConfigure* event) {
253 // We update |bounds_| but not |restored_bounds_| here. The latter needs 251 // We update |bounds_| but not |restored_bounds_| here. The latter needs
254 // to be updated conditionally when the window is non-maximized and non- 252 // to be updated conditionally when the window is non-maximized and non-
255 // fullscreen, but whether those state updates have been processed yet is 253 // fullscreen, but whether those state updates have been processed yet is
256 // window-manager specific. We update |restored_bounds_| in the debounced 254 // window-manager specific. We update |restored_bounds_| in the debounced
257 // handler below, after the window state has been updated. 255 // handler below, after the window state has been updated.
258 bounds_.SetRect(event->x, event->y, event->width, event->height); 256 bounds_.SetRect(event->x, event->y, event->width, event->height);
259 257
260 // The GdkEventConfigure* we get here doesn't have quite the right 258 // The GdkEventConfigure* we get here doesn't have quite the right
261 // coordinates though (they're relative to the drawable window area, rather 259 // coordinates though (they're relative to the drawable window area, rather
262 // than any window manager decorations, if enabled), so we need to call 260 // than any window manager decorations, if enabled), so we need to call
263 // gtk_window_get_position() to get the right values. (Otherwise session 261 // gtk_window_get_position() to get the right values. (Otherwise session
264 // restore, if enabled, will restore windows to incorrect positions.) That's 262 // restore, if enabled, will restore windows to incorrect positions.) That's
265 // a round trip to the X server though, so we set a debounce timer and only 263 // a round trip to the X server though, so we set a debounce timer and only
266 // call it (in OnDebouncedBoundsChanged() below) after we haven't seen a 264 // call it (in OnDebouncedBoundsChanged() below) after we haven't seen a
267 // reconfigure event in a short while. 265 // reconfigure event in a short while.
268 // We don't use Reset() because the timer may not yet be running. 266 // We don't use Reset() because the timer may not yet be running.
269 // (In that case Stop() is a no-op.) 267 // (In that case Stop() is a no-op.)
270 window_configure_debounce_timer_.Stop(); 268 window_configure_debounce_timer_.Stop();
271 window_configure_debounce_timer_.Start(FROM_HERE, 269 window_configure_debounce_timer_.Start(FROM_HERE,
272 base::TimeDelta::FromMilliseconds(kDebounceTimeoutMilliseconds), this, 270 base::TimeDelta::FromMilliseconds(kDebounceTimeoutMilliseconds), this,
273 &ShellWindowGtk::OnDebouncedBoundsChanged); 271 &NativeAppWindowGtk::OnDebouncedBoundsChanged);
274 272
275 return FALSE; 273 return FALSE;
276 } 274 }
277 275
278 void ShellWindowGtk::OnDebouncedBoundsChanged() { 276 void NativeAppWindowGtk::OnDebouncedBoundsChanged() {
279 gtk_window_util::UpdateWindowPosition(this, &bounds_, &restored_bounds_); 277 gtk_window_util::UpdateWindowPosition(this, &bounds_, &restored_bounds_);
280 shell_window_->OnNativeWindowChanged(); 278 shell_window_->OnNativeWindowChanged();
281 } 279 }
282 280
283 gboolean ShellWindowGtk::OnWindowState(GtkWidget* sender, 281 gboolean NativeAppWindowGtk::OnWindowState(GtkWidget* sender,
284 GdkEventWindowState* event) { 282 GdkEventWindowState* event) {
285 state_ = event->new_window_state; 283 state_ = event->new_window_state;
286 284
287 if (content_thinks_its_fullscreen_ && 285 if (content_thinks_its_fullscreen_ &&
288 !(state_ & GDK_WINDOW_STATE_FULLSCREEN)) { 286 !(state_ & GDK_WINDOW_STATE_FULLSCREEN)) {
289 content_thinks_its_fullscreen_ = false; 287 content_thinks_its_fullscreen_ = false;
290 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); 288 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
291 if (rvh) 289 if (rvh)
292 rvh->ExitFullscreen(); 290 rvh->ExitFullscreen();
293 } 291 }
294 292
295 shell_window_->OnNativeWindowChanged();
296 return FALSE; 293 return FALSE;
297 } 294 }
298 295
299 gboolean ShellWindowGtk::OnButtonPress(GtkWidget* widget, 296 gboolean NativeAppWindowGtk::OnButtonPress(GtkWidget* widget,
300 GdkEventButton* event) { 297 GdkEventButton* event) {
301 if (draggable_region_ && draggable_region_->contains(event->x, event->y)) { 298 if (draggable_region_ && draggable_region_->contains(event->x, event->y)) {
302 if (event->button == 1) { 299 if (event->button == 1) {
303 if (GDK_BUTTON_PRESS == event->type) { 300 if (GDK_BUTTON_PRESS == event->type) {
304 if (!suppress_window_raise_) 301 if (!suppress_window_raise_)
305 gdk_window_raise(GTK_WIDGET(widget)->window); 302 gdk_window_raise(GTK_WIDGET(widget)->window);
306 303
307 return gtk_window_util::HandleTitleBarLeftMousePress( 304 return gtk_window_util::HandleTitleBarLeftMousePress(
308 GTK_WINDOW(widget), bounds_, event); 305 GTK_WINDOW(widget), bounds_, event);
309 } else if (GDK_2BUTTON_PRESS == event->type) { 306 } else if (GDK_2BUTTON_PRESS == event->type) {
310 bool is_maximized = gdk_window_get_state(GTK_WIDGET(widget)->window) & 307 bool is_maximized = gdk_window_get_state(GTK_WIDGET(widget)->window) &
311 GDK_WINDOW_STATE_MAXIMIZED; 308 GDK_WINDOW_STATE_MAXIMIZED;
312 if (is_maximized) { 309 if (is_maximized) {
313 gtk_window_util::UnMaximize(GTK_WINDOW(widget), 310 gtk_window_util::UnMaximize(GTK_WINDOW(widget),
314 bounds_, restored_bounds_); 311 bounds_, restored_bounds_);
315 } else { 312 } else {
316 gtk_window_maximize(GTK_WINDOW(widget)); 313 gtk_window_maximize(GTK_WINDOW(widget));
317 } 314 }
318 return TRUE; 315 return TRUE;
319 } 316 }
320 } else if (event->button == 2) { 317 } else if (event->button == 2) {
321 gdk_window_lower(GTK_WIDGET(widget)->window); 318 gdk_window_lower(GTK_WIDGET(widget)->window);
322 return TRUE; 319 return TRUE;
323 } 320 }
324 } 321 }
325 322
326 return FALSE; 323 return FALSE;
327 } 324 }
328 325
329 void ShellWindowGtk::SetFullscreen(bool fullscreen) { 326 void NativeAppWindowGtk::SetFullscreen(bool fullscreen) {
330 content_thinks_its_fullscreen_ = fullscreen; 327 content_thinks_its_fullscreen_ = fullscreen;
331 if (fullscreen) 328 if (fullscreen)
332 gtk_window_fullscreen(window_); 329 gtk_window_fullscreen(window_);
333 else 330 else
334 gtk_window_unfullscreen(window_); 331 gtk_window_unfullscreen(window_);
335 } 332 }
336 333
337 bool ShellWindowGtk::IsFullscreenOrPending() const { 334 bool NativeAppWindowGtk::IsFullscreenOrPending() const {
338 return content_thinks_its_fullscreen_; 335 return content_thinks_its_fullscreen_;
339 } 336 }
340 337
341 void ShellWindowGtk::UpdateWindowIcon() { 338 void NativeAppWindowGtk::UpdateWindowIcon() {
342 Profile* profile = shell_window_->profile(); 339 Profile* profile = shell_window_->profile();
343 gfx::Image app_icon = shell_window_->app_icon(); 340 gfx::Image app_icon = shell_window_->app_icon();
344 if (!app_icon.IsEmpty()) 341 if (!app_icon.IsEmpty())
345 gtk_util::SetWindowIcon(window_, profile, app_icon.ToGdkPixbuf()); 342 gtk_util::SetWindowIcon(window_, profile, app_icon.ToGdkPixbuf());
346 else 343 else
347 gtk_util::SetWindowIcon(window_, profile); 344 gtk_util::SetWindowIcon(window_, profile);
348 } 345 }
349 346
350 void ShellWindowGtk::UpdateWindowTitle() { 347 void NativeAppWindowGtk::UpdateWindowTitle() {
351 string16 title = shell_window_->GetTitle(); 348 string16 title = shell_window_->GetTitle();
352 gtk_window_set_title(window_, UTF16ToUTF8(title).c_str()); 349 gtk_window_set_title(window_, UTF16ToUTF8(title).c_str());
353 } 350 }
354 351
355 void ShellWindowGtk::HandleKeyboardEvent( 352 void NativeAppWindowGtk::HandleKeyboardEvent(
356 const content::NativeWebKeyboardEvent& event) { 353 const content::NativeWebKeyboardEvent& event) {
357 // No-op. 354 // No-op.
358 } 355 }
359 356
360 void ShellWindowGtk::UpdateDraggableRegions( 357 void NativeAppWindowGtk::UpdateDraggableRegions(
361 const std::vector<extensions::DraggableRegion>& regions) { 358 const std::vector<extensions::DraggableRegion>& regions) {
362 // Draggable region is not supported for non-frameless window. 359 // Draggable region is not supported for non-frameless window.
363 if (!frameless_) 360 if (!frameless_)
364 return; 361 return;
365 362
366 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions)); 363 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions));
367 } 364 }
368 365
369 // static 366 // static
370 NativeShellWindow* NativeShellWindow::Create( 367 NativeAppWindow* NativeAppWindow::Create(
371 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { 368 ShellWindow* shell_window,
372 return new ShellWindowGtk(shell_window, params); 369 const ShellWindow::CreateParams& params) {
370 return new NativeAppWindowGtk(shell_window, params);
373 } 371 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/extensions/native_app_window_gtk.h ('k') | chrome/browser/ui/gtk/extensions/shell_window_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698