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

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

Issue 11028125: Remove legacy draggable region code and refactor to share common draggable region code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Created 8 years, 2 months 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/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 : shell_window_(shell_window),
33 window_(NULL),
34 state_(GDK_WINDOW_STATE_WITHDRAWN), 34 state_(GDK_WINDOW_STATE_WITHDRAWN),
35 is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()), 35 is_active_(!ui::ActiveWindowWatcherX::WMSupportsActivation()),
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();
42 gtk_container_add(GTK_CONTAINER(window_), native_view); 42 gtk_container_add(GTK_CONTAINER(window_), native_view);
43 43
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (!draggable_region_->isEmpty() &&
291 draggable_region_.contains(event->x, event->y)) { 291 draggable_region_->contains(event->x, event->y)) {
292 if (event->button == 1) { 292 if (event->button == 1) {
293 if (GDK_BUTTON_PRESS == event->type) { 293 if (GDK_BUTTON_PRESS == event->type) {
294 if (!suppress_window_raise_) 294 if (!suppress_window_raise_)
295 gdk_window_raise(GTK_WIDGET(widget)->window); 295 gdk_window_raise(GTK_WIDGET(widget)->window);
296 296
297 return gtk_window_util::HandleTitleBarLeftMousePress( 297 return gtk_window_util::HandleTitleBarLeftMousePress(
298 GTK_WINDOW(widget), bounds_, event); 298 GTK_WINDOW(widget), bounds_, event);
299 } else if (GDK_2BUTTON_PRESS == event->type) { 299 } else if (GDK_2BUTTON_PRESS == event->type) {
300 bool is_maximized = gdk_window_get_state(GTK_WIDGET(widget)->window) & 300 bool is_maximized = gdk_window_get_state(GTK_WIDGET(widget)->window) &
301 GDK_WINDOW_STATE_MAXIMIZED; 301 GDK_WINDOW_STATE_MAXIMIZED;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 const content::NativeWebKeyboardEvent& event) { 346 const content::NativeWebKeyboardEvent& event) {
347 // No-op. 347 // No-op.
348 } 348 }
349 349
350 void ShellWindowGtk::UpdateDraggableRegions( 350 void ShellWindowGtk::UpdateDraggableRegions(
351 const std::vector<extensions::DraggableRegion>& regions) { 351 const std::vector<extensions::DraggableRegion>& regions) {
352 // Draggable region is not supported for non-frameless window. 352 // Draggable region is not supported for non-frameless window.
353 if (!frameless_) 353 if (!frameless_)
354 return; 354 return;
355 355
356 SkRegion draggable_region; 356 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions));
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 } 357 }
402 358
403 // static 359 // static
404 NativeShellWindow* NativeShellWindow::Create( 360 NativeShellWindow* NativeShellWindow::Create(
405 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { 361 ShellWindow* shell_window, const ShellWindow::CreateParams& params) {
406 return new ShellWindowGtk(shell_window, params); 362 return new ShellWindowGtk(shell_window, params);
407 } 363 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/extensions/shell_window_gtk.h ('k') | chrome/browser/ui/views/extensions/shell_window_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698