Chromium Code Reviews| 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/browser/ui/gtk/gtk_window_util.h" | |
| 9 #include "chrome/common/extensions/draggable_region.h" | |
| 8 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| 9 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 10 #include "content/public/browser/render_widget_host_view.h" | 12 #include "content/public/browser/render_widget_host_view.h" |
| 11 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/browser/web_contents_view.h" | 14 #include "content/public/browser/web_contents_view.h" |
| 13 #include "ui/base/x/active_window_watcher_x.h" | 15 #include "ui/base/x/active_window_watcher_x.h" |
| 14 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 15 | 17 |
| 16 ShellWindowGtk::ShellWindowGtk(Profile* profile, | 18 ShellWindowGtk::ShellWindowGtk(Profile* profile, |
| 17 const extensions::Extension* extension, | 19 const extensions::Extension* extension, |
| 18 const GURL& url, | 20 const GURL& url, |
| 19 const ShellWindow::CreateParams& params) | 21 const ShellWindow::CreateParams& params) |
| 20 : ShellWindow(profile, extension, url), | 22 : ShellWindow(profile, extension, url), |
| 21 state_(GDK_WINDOW_STATE_WITHDRAWN), | 23 state_(GDK_WINDOW_STATE_WITHDRAWN), |
| 22 is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()), | 24 is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()), |
| 23 content_thinks_its_fullscreen_(false) { | 25 content_thinks_its_fullscreen_(false), |
| 26 frameless_(params.frame == ShellWindow::CreateParams::FRAME_NONE) { | |
| 24 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 27 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
| 25 | 28 |
| 26 gfx::NativeView native_view = | 29 gfx::NativeView native_view = |
| 27 web_contents()->GetView()->GetNativeView(); | 30 web_contents()->GetView()->GetNativeView(); |
| 28 gtk_container_add(GTK_CONTAINER(window_), native_view); | 31 gtk_container_add(GTK_CONTAINER(window_), native_view); |
| 29 | 32 |
| 30 gtk_window_set_default_size( | 33 gtk_window_set_default_size( |
| 31 window_, params.bounds.width(), params.bounds.height()); | 34 window_, params.bounds.width(), params.bounds.height()); |
| 32 | 35 |
| 33 // Hide titlebar when {frame: 'none'} specified on ShellWindow. | 36 // Hide titlebar when {frame: 'none'} specified on ShellWindow. |
| 34 if (params.frame == ShellWindow::CreateParams::FRAME_NONE) | 37 if (frameless_) |
| 35 gtk_window_set_decorated(window_, false); | 38 gtk_window_set_decorated(window_, false); |
| 36 | 39 |
| 37 int min_width = params.minimum_size.width(); | 40 int min_width = params.minimum_size.width(); |
| 38 int min_height = params.minimum_size.height(); | 41 int min_height = params.minimum_size.height(); |
| 39 int max_width = params.maximum_size.width(); | 42 int max_width = params.maximum_size.width(); |
| 40 int max_height = params.maximum_size.height(); | 43 int max_height = params.maximum_size.height(); |
| 41 GdkGeometry hints; | 44 GdkGeometry hints; |
| 42 int hints_mask = 0; | 45 int hints_mask = 0; |
| 43 if (min_width || min_height) { | 46 if (min_width || min_height) { |
| 44 hints.min_height = min_height; | 47 hints.min_height = min_height; |
| 45 hints.min_width = min_width; | 48 hints.min_width = min_width; |
| 46 hints_mask |= GDK_HINT_MIN_SIZE; | 49 hints_mask |= GDK_HINT_MIN_SIZE; |
| 47 } | 50 } |
| 48 if (max_width || max_height) { | 51 if (max_width || max_height) { |
| 49 hints.max_height = max_height ? max_height : G_MAXINT; | 52 hints.max_height = max_height ? max_height : G_MAXINT; |
| 50 hints.max_width = max_width ? max_width : G_MAXINT; | 53 hints.max_width = max_width ? max_width : G_MAXINT; |
| 51 hints_mask |= GDK_HINT_MAX_SIZE; | 54 hints_mask |= GDK_HINT_MAX_SIZE; |
| 52 } | 55 } |
| 53 if (hints_mask) { | 56 if (hints_mask) { |
| 54 gtk_window_set_geometry_hints( | 57 gtk_window_set_geometry_hints( |
| 55 window_, | 58 window_, |
| 56 GTK_WIDGET(window_), | 59 GTK_WIDGET(window_), |
| 57 &hints, | 60 &hints, |
| 58 static_cast<GdkWindowHints>(hints_mask)); | 61 static_cast<GdkWindowHints>(hints_mask)); |
| 59 } | 62 } |
| 60 | 63 |
| 64 // In some (older) versions of compiz, raising top-level windows when they | |
| 65 // are partially off-screen causes them to get snapped back on screen, not | |
| 66 // always even on the current virtual desktop. If we are running under | |
| 67 // compiz, suppress such raises, as they are not necessary in compiz anyway. | |
| 68 if (ui::GuessWindowManager() == ui::WM_COMPIZ) | |
| 69 suppress_window_raise_ = true; | |
| 70 | |
| 61 // TODO(mihaip): Mirror contents of <title> tag in window title | 71 // TODO(mihaip): Mirror contents of <title> tag in window title |
| 62 gtk_window_set_title(window_, extension->name().c_str()); | 72 gtk_window_set_title(window_, extension->name().c_str()); |
| 63 | 73 |
| 64 g_signal_connect(window_, "delete-event", | 74 g_signal_connect(window_, "delete-event", |
| 65 G_CALLBACK(OnMainWindowDeleteEventThunk), this); | 75 G_CALLBACK(OnMainWindowDeleteEventThunk), this); |
| 66 g_signal_connect(window_, "configure-event", | 76 g_signal_connect(window_, "configure-event", |
| 67 G_CALLBACK(OnConfigureThunk), this); | 77 G_CALLBACK(OnConfigureThunk), this); |
| 68 g_signal_connect(window_, "window-state-event", | 78 g_signal_connect(window_, "window-state-event", |
| 69 G_CALLBACK(OnWindowStateThunk), this); | 79 G_CALLBACK(OnWindowStateThunk), this); |
| 80 if (frameless_) { | |
| 81 g_signal_connect(window_, "button-press-event", | |
| 82 G_CALLBACK(OnButtonPressThunk), this); | |
| 83 } | |
| 70 | 84 |
| 71 ui::ActiveWindowWatcherX::AddObserver(this); | 85 ui::ActiveWindowWatcherX::AddObserver(this); |
| 72 } | 86 } |
| 73 | 87 |
| 74 ShellWindowGtk::~ShellWindowGtk() { | 88 ShellWindowGtk::~ShellWindowGtk() { |
| 75 ui::ActiveWindowWatcherX::RemoveObserver(this); | 89 ui::ActiveWindowWatcherX::RemoveObserver(this); |
| 76 } | 90 } |
| 77 | 91 |
| 78 bool ShellWindowGtk::IsActive() const { | 92 bool ShellWindowGtk::IsActive() const { |
| 79 return is_active_; | 93 return is_active_; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 !(state_ & GDK_WINDOW_STATE_FULLSCREEN)) { | 215 !(state_ & GDK_WINDOW_STATE_FULLSCREEN)) { |
| 202 content_thinks_its_fullscreen_ = false; | 216 content_thinks_its_fullscreen_ = false; |
| 203 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); | 217 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
| 204 if (rvh) | 218 if (rvh) |
| 205 rvh->ExitFullscreen(); | 219 rvh->ExitFullscreen(); |
| 206 } | 220 } |
| 207 | 221 |
| 208 return FALSE; | 222 return FALSE; |
| 209 } | 223 } |
| 210 | 224 |
| 225 gboolean ShellWindowGtk::OnButtonPress(GtkWidget* widget, | |
| 226 GdkEventButton* event) { | |
| 227 if (!draggable_region_.isEmpty() && | |
| 228 draggable_region_.contains(event->x, event->y)) { | |
| 229 if (event->button == 1) { | |
| 230 if (GDK_BUTTON_PRESS == event->type) { | |
| 231 guint32 last_click_time = last_click_time_; | |
| 232 gfx::Point last_click_position = last_click_position_; | |
| 233 last_click_time_ = event->time; | |
| 234 last_click_position_ = gfx::Point(static_cast<int>(event->x), | |
|
Evan Stade
2012/08/15 21:20:40
you could share more code if you passed &last_clic
| |
| 235 static_cast<int>(event->y)); | |
| 236 | |
| 237 if (!suppress_window_raise_) | |
| 238 gdk_window_raise(GTK_WIDGET(widget)->window); | |
| 239 | |
| 240 return gtk_window_util::HandleTitleBarLeftMousePress(GTK_WINDOW(widget), | |
| 241 bounds_, event, last_click_time, last_click_position); | |
| 242 } else if (event->type == GDK_2BUTTON_PRESS) { | |
|
Evan Stade
2012/08/15 21:20:40
nit: it's weird that the if and the else if cases
| |
| 243 bool is_maximized_ = gdk_window_get_state(GTK_WIDGET(widget)->window) & | |
|
Evan Stade
2012/08/15 21:20:40
first, local variables should not have final under
| |
| 244 GDK_WINDOW_STATE_MAXIMIZED; | |
| 245 is_maximized_ ? gtk_window_unmaximize(GTK_WINDOW(widget)) : | |
| 246 gtk_window_maximize(GTK_WINDOW(widget)); | |
| 247 return TRUE; | |
| 248 } | |
| 249 } else if (event->button == 2) { | |
| 250 gdk_window_lower(GTK_WIDGET(widget)->window); | |
| 251 return TRUE; | |
| 252 } | |
| 253 } | |
| 254 | |
| 255 return FALSE; | |
| 256 } | |
| 257 | |
| 211 void ShellWindowGtk::SetFullscreen(bool fullscreen) { | 258 void ShellWindowGtk::SetFullscreen(bool fullscreen) { |
| 212 content_thinks_its_fullscreen_ = fullscreen; | 259 content_thinks_its_fullscreen_ = fullscreen; |
| 213 if (fullscreen) | 260 if (fullscreen) |
| 214 gtk_window_fullscreen(window_); | 261 gtk_window_fullscreen(window_); |
| 215 else | 262 else |
| 216 gtk_window_unfullscreen(window_); | 263 gtk_window_unfullscreen(window_); |
| 217 } | 264 } |
| 218 | 265 |
| 219 bool ShellWindowGtk::IsFullscreenOrPending() const { | 266 bool ShellWindowGtk::IsFullscreenOrPending() const { |
| 220 return content_thinks_its_fullscreen_; | 267 return content_thinks_its_fullscreen_; |
| 221 } | 268 } |
| 222 | 269 |
| 270 void ShellWindowGtk::UpdateDraggableRegions( | |
| 271 const std::vector<extensions::DraggableRegion>& regions) { | |
| 272 // Draggable region is not supported for non-frameless window. | |
| 273 if (!frameless_) | |
| 274 return; | |
| 275 | |
| 276 SkRegion draggable_region; | |
| 277 | |
| 278 // By default, the whole window is draggable. | |
| 279 gfx::Rect bounds = GetBounds(); | |
| 280 draggable_region.op(0, 0, bounds.right(), bounds.bottom(), | |
| 281 SkRegion::kUnion_Op); | |
| 282 | |
| 283 // Exclude those designated as non-draggable. | |
| 284 for (std::vector<extensions::DraggableRegion>::const_iterator iter = | |
| 285 regions.begin(); | |
| 286 iter != regions.end(); ++iter) { | |
| 287 const extensions::DraggableRegion& region = *iter; | |
| 288 draggable_region.op(region.bounds.x(), | |
| 289 region.bounds.y(), | |
| 290 region.bounds.right(), | |
| 291 region.bounds.bottom(), | |
| 292 SkRegion::kDifference_Op); | |
| 293 } | |
| 294 | |
| 295 draggable_region_ = draggable_region; | |
| 296 } | |
| 297 | |
| 223 // static | 298 // static |
| 224 ShellWindow* ShellWindow::CreateImpl(Profile* profile, | 299 ShellWindow* ShellWindow::CreateImpl(Profile* profile, |
| 225 const extensions::Extension* extension, | 300 const extensions::Extension* extension, |
| 226 const GURL& url, | 301 const GURL& url, |
| 227 const ShellWindow::CreateParams& params) { | 302 const ShellWindow::CreateParams& params) { |
| 228 return new ShellWindowGtk(profile, extension, url, params); | 303 return new ShellWindowGtk(profile, extension, url, params); |
| 229 } | 304 } |
| OLD | NEW |