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/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 "content/public/common/draggable_region.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 g_signal_connect(window_, "button-press-event", | |
|
Evan Stade
2012/08/07 23:20:58
you only need to this if frameless.
| |
| 73 G_CALLBACK(OnButtonPressThunk), this); | |
| 70 | 74 |
| 71 ui::ActiveWindowWatcherX::AddObserver(this); | 75 ui::ActiveWindowWatcherX::AddObserver(this); |
| 72 } | 76 } |
| 73 | 77 |
| 74 ShellWindowGtk::~ShellWindowGtk() { | 78 ShellWindowGtk::~ShellWindowGtk() { |
| 75 ui::ActiveWindowWatcherX::RemoveObserver(this); | 79 ui::ActiveWindowWatcherX::RemoveObserver(this); |
| 76 } | 80 } |
| 77 | 81 |
| 78 bool ShellWindowGtk::IsActive() const { | 82 bool ShellWindowGtk::IsActive() const { |
| 79 return is_active_; | 83 return is_active_; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 !(state_ & GDK_WINDOW_STATE_FULLSCREEN)) { | 209 !(state_ & GDK_WINDOW_STATE_FULLSCREEN)) { |
| 206 content_thinks_its_fullscreen_ = false; | 210 content_thinks_its_fullscreen_ = false; |
| 207 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); | 211 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
| 208 if (rvh) | 212 if (rvh) |
| 209 rvh->ExitFullscreen(); | 213 rvh->ExitFullscreen(); |
| 210 } | 214 } |
| 211 | 215 |
| 212 return FALSE; | 216 return FALSE; |
| 213 } | 217 } |
| 214 | 218 |
| 219 gboolean ShellWindowGtk::OnButtonPress(GtkWidget* widget, | |
| 220 GdkEventButton * event) { | |
|
Evan Stade
2012/08/07 23:20:58
no space before *
| |
| 221 if (event->type == GDK_BUTTON_PRESS && event->button == 1) { | |
| 222 if (frameless_ && draggable_region_.Get() && | |
| 223 draggable_region_.Get()->contains(event->x, event->y)) { | |
| 224 gtk_window_begin_move_drag(GTK_WINDOW(widget), event->button, | |
| 225 event->x_root, event->y_root, event->time); | |
|
Evan Stade
2012/08/07 23:20:58
I think you actually want to return TRUE to indica
| |
| 226 } | |
| 227 } | |
|
jeremya
2012/08/08 04:38:37
Is this sufficient? Do we get behaviour like maxim
| |
| 228 | |
| 229 return FALSE; | |
| 230 } | |
| 231 | |
| 215 void ShellWindowGtk::SetFullscreen(bool fullscreen) { | 232 void ShellWindowGtk::SetFullscreen(bool fullscreen) { |
| 216 content_thinks_its_fullscreen_ = fullscreen; | 233 content_thinks_its_fullscreen_ = fullscreen; |
| 217 if (fullscreen) | 234 if (fullscreen) |
| 218 gtk_window_fullscreen(window_); | 235 gtk_window_fullscreen(window_); |
| 219 else | 236 else |
| 220 gtk_window_unfullscreen(window_); | 237 gtk_window_unfullscreen(window_); |
| 221 } | 238 } |
| 222 | 239 |
| 223 bool ShellWindowGtk::IsFullscreenOrPending() const { | 240 bool ShellWindowGtk::IsFullscreenOrPending() const { |
| 224 return content_thinks_its_fullscreen_; | 241 return content_thinks_its_fullscreen_; |
| 225 } | 242 } |
| 226 | 243 |
| 244 void ShellWindowGtk::UpdateDraggableRegions( | |
| 245 const std::vector<content::DraggableRegion>& regions) { | |
| 246 // Draggable region is not supported for non-frameless window. | |
| 247 if (!frameless_) | |
| 248 return; | |
| 249 | |
| 250 SkRegion* draggable_region = new SkRegion; | |
| 251 | |
| 252 // By default, the whole window is draggable. | |
| 253 gfx::Rect bounds = GetBounds(); | |
| 254 draggable_region->op(0, 0, bounds.right(), bounds.bottom(), | |
| 255 SkRegion::kUnion_Op); | |
| 256 | |
| 257 // Exclude those desinated as non-draggable. | |
| 258 for (std::vector<content::DraggableRegion>::const_iterator iter = | |
| 259 regions.begin(); | |
| 260 iter != regions.end(); ++iter) { | |
| 261 const content::DraggableRegion& region = *iter; | |
| 262 draggable_region->op(region.bounds.x(), | |
| 263 region.bounds.y(), | |
| 264 region.bounds.right(), | |
| 265 region.bounds.bottom(), | |
| 266 SkRegion::kDifference_Op); | |
| 267 } | |
| 268 | |
| 269 draggable_region_.Set(draggable_region); | |
| 270 } | |
| 271 | |
| 227 // static | 272 // static |
| 228 ShellWindow* ShellWindow::CreateImpl(Profile* profile, | 273 ShellWindow* ShellWindow::CreateImpl(Profile* profile, |
| 229 const extensions::Extension* extension, | 274 const extensions::Extension* extension, |
| 230 const GURL& url, | 275 const GURL& url, |
| 231 const ShellWindow::CreateParams& params) { | 276 const ShellWindow::CreateParams& params) { |
| 232 return new ShellWindowGtk(profile, extension, url, params); | 277 return new ShellWindowGtk(profile, extension, url, params); |
| 233 } | 278 } |
| OLD | NEW |