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/common/extensions/draggable_region.h" | |
| 8 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
| 9 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 10 #include "content/public/browser/render_widget_host_view.h" | 11 #include "content/public/browser/render_widget_host_view.h" |
| 11 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/browser/web_contents_view.h" | 13 #include "content/public/browser/web_contents_view.h" |
| 13 #include "ui/base/x/active_window_watcher_x.h" | 14 #include "ui/base/x/active_window_watcher_x.h" |
| 14 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 15 | 16 |
| 16 ShellWindowGtk::ShellWindowGtk(Profile* profile, | 17 ShellWindowGtk::ShellWindowGtk(Profile* profile, |
| 17 const extensions::Extension* extension, | 18 const extensions::Extension* extension, |
| 18 const GURL& url, | 19 const GURL& url, |
| 19 const ShellWindow::CreateParams& params) | 20 const ShellWindow::CreateParams& params) |
| 20 : ShellWindow(profile, extension, url), | 21 : ShellWindow(profile, extension, url), |
| 21 state_(GDK_WINDOW_STATE_WITHDRAWN), | 22 state_(GDK_WINDOW_STATE_WITHDRAWN), |
| 22 is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()), | 23 is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()), |
| 23 content_thinks_its_fullscreen_(false) { | 24 content_thinks_its_fullscreen_(false), |
| 25 frameless_(params.frame == ShellWindow::CreateParams::FRAME_NONE) { | |
| 24 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 26 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
| 25 | 27 |
| 26 gfx::NativeView native_view = | 28 gfx::NativeView native_view = |
| 27 web_contents()->GetView()->GetNativeView(); | 29 web_contents()->GetView()->GetNativeView(); |
| 28 gtk_container_add(GTK_CONTAINER(window_), native_view); | 30 gtk_container_add(GTK_CONTAINER(window_), native_view); |
| 29 | 31 |
| 30 gtk_window_set_default_size( | 32 gtk_window_set_default_size( |
| 31 window_, params.bounds.width(), params.bounds.height()); | 33 window_, params.bounds.width(), params.bounds.height()); |
| 32 | 34 |
| 33 // Hide titlebar when {frame: 'none'} specified on ShellWindow. | 35 // Hide titlebar when {frame: 'none'} specified on ShellWindow. |
| 34 if (params.frame == ShellWindow::CreateParams::FRAME_NONE) | 36 if (frameless_) |
| 35 gtk_window_set_decorated(window_, false); | 37 gtk_window_set_decorated(window_, false); |
| 36 | 38 |
| 37 int min_width = params.minimum_size.width(); | 39 int min_width = params.minimum_size.width(); |
| 38 int min_height = params.minimum_size.height(); | 40 int min_height = params.minimum_size.height(); |
| 39 int max_width = params.maximum_size.width(); | 41 int max_width = params.maximum_size.width(); |
| 40 int max_height = params.maximum_size.height(); | 42 int max_height = params.maximum_size.height(); |
| 41 GdkGeometry hints; | 43 GdkGeometry hints; |
| 42 int hints_mask = 0; | 44 int hints_mask = 0; |
| 43 if (min_width || min_height) { | 45 if (min_width || min_height) { |
| 44 hints.min_height = min_height; | 46 hints.min_height = min_height; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 60 | 62 |
| 61 // TODO(mihaip): Mirror contents of <title> tag in window title | 63 // TODO(mihaip): Mirror contents of <title> tag in window title |
| 62 gtk_window_set_title(window_, extension->name().c_str()); | 64 gtk_window_set_title(window_, extension->name().c_str()); |
| 63 | 65 |
| 64 g_signal_connect(window_, "delete-event", | 66 g_signal_connect(window_, "delete-event", |
| 65 G_CALLBACK(OnMainWindowDeleteEventThunk), this); | 67 G_CALLBACK(OnMainWindowDeleteEventThunk), this); |
| 66 g_signal_connect(window_, "configure-event", | 68 g_signal_connect(window_, "configure-event", |
| 67 G_CALLBACK(OnConfigureThunk), this); | 69 G_CALLBACK(OnConfigureThunk), this); |
| 68 g_signal_connect(window_, "window-state-event", | 70 g_signal_connect(window_, "window-state-event", |
| 69 G_CALLBACK(OnWindowStateThunk), this); | 71 G_CALLBACK(OnWindowStateThunk), this); |
| 72 if (frameless_) | |
|
Evan Stade
2012/08/08 21:01:42
curlies
| |
| 73 g_signal_connect(window_, "button-press-event", | |
| 74 G_CALLBACK(OnButtonPressThunk), this); | |
| 70 | 75 |
| 71 ui::ActiveWindowWatcherX::AddObserver(this); | 76 ui::ActiveWindowWatcherX::AddObserver(this); |
| 72 } | 77 } |
| 73 | 78 |
| 74 ShellWindowGtk::~ShellWindowGtk() { | 79 ShellWindowGtk::~ShellWindowGtk() { |
| 75 ui::ActiveWindowWatcherX::RemoveObserver(this); | 80 ui::ActiveWindowWatcherX::RemoveObserver(this); |
| 76 } | 81 } |
| 77 | 82 |
| 78 bool ShellWindowGtk::IsActive() const { | 83 bool ShellWindowGtk::IsActive() const { |
| 79 return is_active_; | 84 return is_active_; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 !(state_ & GDK_WINDOW_STATE_FULLSCREEN)) { | 206 !(state_ & GDK_WINDOW_STATE_FULLSCREEN)) { |
| 202 content_thinks_its_fullscreen_ = false; | 207 content_thinks_its_fullscreen_ = false; |
| 203 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); | 208 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
| 204 if (rvh) | 209 if (rvh) |
| 205 rvh->ExitFullscreen(); | 210 rvh->ExitFullscreen(); |
| 206 } | 211 } |
| 207 | 212 |
| 208 return FALSE; | 213 return FALSE; |
| 209 } | 214 } |
| 210 | 215 |
| 216 gboolean ShellWindowGtk::OnButtonPress(GtkWidget* widget, | |
| 217 GdkEventButton* event) { | |
| 218 if (frameless_ && draggable_region_.get() && | |
|
Evan Stade
2012/08/08 21:01:42
you don't need the frameless_ check now.
| |
| 219 draggable_region_->contains(event->x, event->y)) { | |
| 220 if (event->type == GDK_BUTTON_PRESS && event->button == 1) { | |
| 221 gtk_window_begin_move_drag(GTK_WINDOW(widget), event->button, | |
| 222 event->x_root, event->y_root, event->time); | |
| 223 return TRUE; | |
| 224 } else if (event->type == GDK_2BUTTON_PRESS) { | |
| 225 bool is_maximized_ = gdk_window_get_state(GTK_WIDGET(widget)->window) & | |
|
Evan Stade
2012/08/08 21:01:42
there are too many spaces after the =
| |
| 226 GDK_WINDOW_STATE_MAXIMIZED; | |
| 227 !is_maximized_ ? gtk_window_maximize(GTK_WINDOW(widget)) : | |
|
Evan Stade
2012/08/08 21:01:42
nit: I would get rid of the ! here because it just
| |
| 228 gtk_window_unmaximize(GTK_WINDOW(widget)); | |
| 229 return TRUE; | |
| 230 } | |
| 231 } | |
| 232 | |
| 233 return FALSE; | |
| 234 } | |
| 235 | |
| 211 void ShellWindowGtk::SetFullscreen(bool fullscreen) { | 236 void ShellWindowGtk::SetFullscreen(bool fullscreen) { |
| 212 content_thinks_its_fullscreen_ = fullscreen; | 237 content_thinks_its_fullscreen_ = fullscreen; |
| 213 if (fullscreen) | 238 if (fullscreen) |
| 214 gtk_window_fullscreen(window_); | 239 gtk_window_fullscreen(window_); |
| 215 else | 240 else |
| 216 gtk_window_unfullscreen(window_); | 241 gtk_window_unfullscreen(window_); |
| 217 } | 242 } |
| 218 | 243 |
| 219 bool ShellWindowGtk::IsFullscreenOrPending() const { | 244 bool ShellWindowGtk::IsFullscreenOrPending() const { |
| 220 return content_thinks_its_fullscreen_; | 245 return content_thinks_its_fullscreen_; |
| 221 } | 246 } |
| 222 | 247 |
| 248 void ShellWindowGtk::UpdateDraggableRegions( | |
| 249 const std::vector<extensions::DraggableRegion>& regions) { | |
| 250 // Draggable region is not supported for non-frameless window. | |
| 251 if (!frameless_) | |
| 252 return; | |
| 253 | |
| 254 SkRegion* draggable_region = new SkRegion; | |
| 255 | |
| 256 // By default, the whole window is draggable. | |
| 257 gfx::Rect bounds = GetBounds(); | |
| 258 draggable_region->op(0, 0, bounds.right(), bounds.bottom(), | |
| 259 SkRegion::kUnion_Op); | |
| 260 | |
| 261 // Exclude those desinated as non-draggable. | |
|
Evan Stade
2012/08/08 21:01:42
designated
| |
| 262 for (std::vector<extensions::DraggableRegion>::const_iterator iter = | |
| 263 regions.begin(); | |
| 264 iter != regions.end(); ++iter) { | |
| 265 const extensions::DraggableRegion& region = *iter; | |
| 266 draggable_region->op(region.bounds.x(), | |
| 267 region.bounds.y(), | |
| 268 region.bounds.right(), | |
| 269 region.bounds.bottom(), | |
| 270 SkRegion::kDifference_Op); | |
| 271 } | |
| 272 | |
| 273 draggable_region_.reset(draggable_region); | |
| 274 } | |
| 275 | |
| 223 // static | 276 // static |
| 224 ShellWindow* ShellWindow::CreateImpl(Profile* profile, | 277 ShellWindow* ShellWindow::CreateImpl(Profile* profile, |
| 225 const extensions::Extension* extension, | 278 const extensions::Extension* extension, |
| 226 const GURL& url, | 279 const GURL& url, |
| 227 const ShellWindow::CreateParams& params) { | 280 const ShellWindow::CreateParams& params) { |
| 228 return new ShellWindowGtk(profile, extension, url, params); | 281 return new ShellWindowGtk(profile, extension, url, params); |
| 229 } | 282 } |
| OLD | NEW |