| 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 "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/draggable_region.h" | |
| 14 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 15 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/render_widget_host_view.h" | 15 #include "content/public/browser/render_widget_host_view.h" |
| 17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_contents_view.h" | 17 #include "content/public/browser/web_contents_view.h" |
| 19 #include "ui/base/x/active_window_watcher_x.h" | 18 #include "ui/base/x/active_window_watcher_x.h" |
| 20 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 21 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 // 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 |
| 26 // gtk_window_get_position() after the last GTK configure-event signal. | 25 // gtk_window_get_position() after the last GTK configure-event signal. |
| 27 const int kDebounceTimeoutMilliseconds = 100; | 26 const int kDebounceTimeoutMilliseconds = 100; |
| 28 | 27 |
| 29 } // namespace | 28 } // namespace |
| 30 | 29 |
| 31 ShellWindowGtk::ShellWindowGtk(ShellWindow* shell_window, | 30 ShellWindowGtk::ShellWindowGtk(ShellWindow* shell_window, |
| 32 const ShellWindow::CreateParams& params) | 31 const ShellWindow::CreateParams& params) |
| 33 : shell_window_(shell_window), | 32 : NativeShellWindow(params), |
| 33 shell_window_(shell_window), |
| 34 window_(NULL), |
| 34 state_(GDK_WINDOW_STATE_WITHDRAWN), | 35 state_(GDK_WINDOW_STATE_WITHDRAWN), |
| 35 is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()), | 36 is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()), |
| 36 content_thinks_its_fullscreen_(false), | 37 content_thinks_its_fullscreen_(false) { |
| 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(); |
| 42 gtk_container_add(GTK_CONTAINER(window_), native_view); | 42 gtk_container_add(GTK_CONTAINER(window_), native_view); |
| 43 | 43 |
| 44 if (params.bounds.x() >= 0 && params.bounds.y() >= 0) | 44 if (params.bounds.x() >= 0 && params.bounds.y() >= 0) |
| 45 gtk_window_move(window_, params.bounds.x(), params.bounds.y()); | 45 gtk_window_move(window_, params.bounds.x(), params.bounds.y()); |
| 46 | 46 |
| 47 // This is done to avoid a WM "feature" where setting the window size to | 47 // This is done to avoid a WM "feature" where setting the window size to |
| 48 // the monitor size causes the WM to set the EWMH for full screen mode. | 48 // the monitor size causes the WM to set the EWMH for full screen mode. |
| 49 if (frameless_ && | 49 if (frameless() && |
| 50 gtk_window_util::BoundsMatchMonitorSize(window_, params.bounds)) { | 50 gtk_window_util::BoundsMatchMonitorSize(window_, params.bounds)) { |
| 51 gtk_window_set_default_size( | 51 gtk_window_set_default_size( |
| 52 window_, params.bounds.width(), params.bounds.height() - 1); | 52 window_, params.bounds.width(), params.bounds.height() - 1); |
| 53 } else { | 53 } else { |
| 54 gtk_window_set_default_size( | 54 gtk_window_set_default_size( |
| 55 window_, params.bounds.width(), params.bounds.height()); | 55 window_, params.bounds.width(), params.bounds.height()); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // make sure bounds_ and restored_bounds_ have correct values until we | 58 // make sure bounds_ and restored_bounds_ have correct values until we |
| 59 // get our first configure-event | 59 // get our first configure-event |
| 60 bounds_ = restored_bounds_ = params.bounds; | 60 bounds_ = restored_bounds_ = params.bounds; |
| 61 gint x, y; | 61 gint x, y; |
| 62 gtk_window_get_position(window_, &x, &y); | 62 gtk_window_get_position(window_, &x, &y); |
| 63 bounds_.set_origin(gfx::Point(x, y)); | 63 bounds_.set_origin(gfx::Point(x, y)); |
| 64 | 64 |
| 65 // Hide titlebar when {frame: 'none'} specified on ShellWindow. | 65 // Hide titlebar when {frame: 'none'} specified on ShellWindow. |
| 66 if (frameless_) | 66 if (frameless()) |
| 67 gtk_window_set_decorated(window_, false); | 67 gtk_window_set_decorated(window_, false); |
| 68 | 68 |
| 69 int min_width = params.minimum_size.width(); | 69 int min_width = params.minimum_size.width(); |
| 70 int min_height = params.minimum_size.height(); | 70 int min_height = params.minimum_size.height(); |
| 71 int max_width = params.maximum_size.width(); | 71 int max_width = params.maximum_size.width(); |
| 72 int max_height = params.maximum_size.height(); | 72 int max_height = params.maximum_size.height(); |
| 73 GdkGeometry hints; | 73 GdkGeometry hints; |
| 74 int hints_mask = 0; | 74 int hints_mask = 0; |
| 75 if (min_width || min_height) { | 75 if (min_width || min_height) { |
| 76 hints.min_height = min_height; | 76 hints.min_height = min_height; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 101 | 101 |
| 102 gtk_window_util::SetWindowCustomClass(window_, | 102 gtk_window_util::SetWindowCustomClass(window_, |
| 103 web_app::GetWMClassFromAppName(extension()->name())); | 103 web_app::GetWMClassFromAppName(extension()->name())); |
| 104 | 104 |
| 105 g_signal_connect(window_, "delete-event", | 105 g_signal_connect(window_, "delete-event", |
| 106 G_CALLBACK(OnMainWindowDeleteEventThunk), this); | 106 G_CALLBACK(OnMainWindowDeleteEventThunk), this); |
| 107 g_signal_connect(window_, "configure-event", | 107 g_signal_connect(window_, "configure-event", |
| 108 G_CALLBACK(OnConfigureThunk), this); | 108 G_CALLBACK(OnConfigureThunk), this); |
| 109 g_signal_connect(window_, "window-state-event", | 109 g_signal_connect(window_, "window-state-event", |
| 110 G_CALLBACK(OnWindowStateThunk), this); | 110 G_CALLBACK(OnWindowStateThunk), this); |
| 111 if (frameless_) { | 111 if (frameless()) { |
| 112 g_signal_connect(window_, "button-press-event", | 112 g_signal_connect(window_, "button-press-event", |
| 113 G_CALLBACK(OnButtonPressThunk), this); | 113 G_CALLBACK(OnButtonPressThunk), this); |
| 114 } | 114 } |
| 115 | 115 |
| 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_)); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); | 280 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
| 281 if (rvh) | 281 if (rvh) |
| 282 rvh->ExitFullscreen(); | 282 rvh->ExitFullscreen(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 return FALSE; | 285 return FALSE; |
| 286 } | 286 } |
| 287 | 287 |
| 288 gboolean ShellWindowGtk::OnButtonPress(GtkWidget* widget, | 288 gboolean ShellWindowGtk::OnButtonPress(GtkWidget* widget, |
| 289 GdkEventButton* event) { | 289 GdkEventButton* event) { |
| 290 if (!draggable_region_.isEmpty() && | 290 if (IsInsideDraggableRegions(event->x, event->y)) { |
| 291 draggable_region_.contains(event->x, event->y)) { | |
| 292 if (event->button == 1) { | 291 if (event->button == 1) { |
| 293 if (GDK_BUTTON_PRESS == event->type) { | 292 if (GDK_BUTTON_PRESS == event->type) { |
| 294 if (!suppress_window_raise_) | 293 if (!suppress_window_raise_) |
| 295 gdk_window_raise(GTK_WIDGET(widget)->window); | 294 gdk_window_raise(GTK_WIDGET(widget)->window); |
| 296 | 295 |
| 297 return gtk_window_util::HandleTitleBarLeftMousePress( | 296 return gtk_window_util::HandleTitleBarLeftMousePress( |
| 298 GTK_WINDOW(widget), bounds_, event); | 297 GTK_WINDOW(widget), bounds_, event); |
| 299 } else if (GDK_2BUTTON_PRESS == event->type) { | 298 } else if (GDK_2BUTTON_PRESS == event->type) { |
| 300 bool is_maximized = gdk_window_get_state(GTK_WIDGET(widget)->window) & | 299 bool is_maximized = gdk_window_get_state(GTK_WIDGET(widget)->window) & |
| 301 GDK_WINDOW_STATE_MAXIMIZED; | 300 GDK_WINDOW_STATE_MAXIMIZED; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 void ShellWindowGtk::UpdateWindowTitle() { | 339 void ShellWindowGtk::UpdateWindowTitle() { |
| 341 string16 title = shell_window_->GetTitle(); | 340 string16 title = shell_window_->GetTitle(); |
| 342 gtk_window_set_title(window_, UTF16ToUTF8(title).c_str()); | 341 gtk_window_set_title(window_, UTF16ToUTF8(title).c_str()); |
| 343 } | 342 } |
| 344 | 343 |
| 345 void ShellWindowGtk::HandleKeyboardEvent( | 344 void ShellWindowGtk::HandleKeyboardEvent( |
| 346 const content::NativeWebKeyboardEvent& event) { | 345 const content::NativeWebKeyboardEvent& event) { |
| 347 // No-op. | 346 // No-op. |
| 348 } | 347 } |
| 349 | 348 |
| 350 void ShellWindowGtk::UpdateDraggableRegions( | |
| 351 const std::vector<extensions::DraggableRegion>& regions) { | |
| 352 // Draggable region is not supported for non-frameless window. | |
| 353 if (!frameless_) | |
| 354 return; | |
| 355 | |
| 356 SkRegion draggable_region; | |
| 357 | |
| 358 // By default, the whole window is non-draggable. We need to explicitly | |
| 359 // include those draggable regions. | |
| 360 for (std::vector<extensions::DraggableRegion>::const_iterator iter = | |
| 361 regions.begin(); | |
| 362 iter != regions.end(); ++iter) { | |
| 363 const extensions::DraggableRegion& region = *iter; | |
| 364 draggable_region.op( | |
| 365 region.bounds.x(), | |
| 366 region.bounds.y(), | |
| 367 region.bounds.right(), | |
| 368 region.bounds.bottom(), | |
| 369 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | |
| 370 } | |
| 371 | |
| 372 draggable_region_ = draggable_region; | |
| 373 } | |
| 374 | |
| 375 void ShellWindowGtk::UpdateLegacyDraggableRegions( | |
| 376 const std::vector<extensions::DraggableRegion>& regions) { | |
| 377 // Draggable region is not supported for non-frameless window. | |
| 378 if (!frameless_) | |
| 379 return; | |
| 380 | |
| 381 SkRegion draggable_region; | |
| 382 | |
| 383 // By default, the whole window is draggable. | |
| 384 gfx::Rect bounds = GetBounds(); | |
| 385 draggable_region.op(0, 0, bounds.right(), bounds.bottom(), | |
| 386 SkRegion::kUnion_Op); | |
| 387 | |
| 388 // Exclude those designated as non-draggable. | |
| 389 for (std::vector<extensions::DraggableRegion>::const_iterator iter = | |
| 390 regions.begin(); | |
| 391 iter != regions.end(); ++iter) { | |
| 392 const extensions::DraggableRegion& region = *iter; | |
| 393 draggable_region.op(region.bounds.x(), | |
| 394 region.bounds.y(), | |
| 395 region.bounds.right(), | |
| 396 region.bounds.bottom(), | |
| 397 SkRegion::kDifference_Op); | |
| 398 } | |
| 399 | |
| 400 draggable_region_ = draggable_region; | |
| 401 } | |
| 402 | |
| 403 // static | 349 // static |
| 404 NativeShellWindow* NativeShellWindow::Create( | 350 NativeShellWindow* NativeShellWindow::Create( |
| 405 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { | 351 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { |
| 406 return new ShellWindowGtk(shell_window, params); | 352 return new ShellWindowGtk(shell_window, params); |
| 407 } | 353 } |
| OLD | NEW |