| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bubble/bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.h" | 10 #include "chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.h" |
| 11 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 11 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 mask_region_ = NULL; | 300 mask_region_ = NULL; |
| 301 } | 301 } |
| 302 GtkAllocation allocation; | 302 GtkAllocation allocation; |
| 303 gtk_widget_get_allocation(window_, &allocation); | 303 gtk_widget_get_allocation(window_, &allocation); |
| 304 std::vector<GdkPoint> points = MakeFramePolygonPoints( | 304 std::vector<GdkPoint> points = MakeFramePolygonPoints( |
| 305 current_arrow_location_, allocation.width, allocation.height, | 305 current_arrow_location_, allocation.width, allocation.height, |
| 306 FRAME_MASK); | 306 FRAME_MASK); |
| 307 mask_region_ = gdk_region_polygon(&points[0], | 307 mask_region_ = gdk_region_polygon(&points[0], |
| 308 points.size(), | 308 points.size(), |
| 309 GDK_EVEN_ODD_RULE); | 309 GDK_EVEN_ODD_RULE); |
| 310 | 310 gdk_window_shape_combine_region(window_->window, NULL, 0, 0); |
| 311 GdkWindow* gdk_window = gtk_widget_get_window(window_); | 311 gdk_window_shape_combine_region(window_->window, mask_region_, 0, 0); |
| 312 gdk_window_shape_combine_region(gdk_window, NULL, 0, 0); | |
| 313 gdk_window_shape_combine_region(gdk_window, mask_region_, 0, 0); | |
| 314 } | 312 } |
| 315 | 313 |
| 316 void BubbleGtk::MoveWindow() { | 314 void BubbleGtk::MoveWindow() { |
| 317 if (!toplevel_window_ || !anchor_widget_) | 315 if (!toplevel_window_ || !anchor_widget_) |
| 318 return; | 316 return; |
| 319 | 317 |
| 320 gint toplevel_x = 0, toplevel_y = 0; | 318 gint toplevel_x = 0, toplevel_y = 0; |
| 321 gdk_window_get_position(gtk_widget_get_window(toplevel_window_), | 319 gdk_window_get_position(gtk_widget_get_window(toplevel_window_), |
| 322 &toplevel_x, &toplevel_y); | 320 &toplevel_x, &toplevel_y); |
| 323 | 321 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 366 |
| 369 void BubbleGtk::Close() { | 367 void BubbleGtk::Close() { |
| 370 // We don't need to ungrab the pointer or keyboard here; the X server will | 368 // We don't need to ungrab the pointer or keyboard here; the X server will |
| 371 // automatically do that when we destroy our window. | 369 // automatically do that when we destroy our window. |
| 372 DCHECK(window_); | 370 DCHECK(window_); |
| 373 gtk_widget_destroy(window_); | 371 gtk_widget_destroy(window_); |
| 374 // |this| has been deleted, see OnDestroy. | 372 // |this| has been deleted, see OnDestroy. |
| 375 } | 373 } |
| 376 | 374 |
| 377 void BubbleGtk::GrabPointerAndKeyboard() { | 375 void BubbleGtk::GrabPointerAndKeyboard() { |
| 378 GdkWindow* gdk_window = gtk_widget_get_window(window_); | |
| 379 | |
| 380 // Install X pointer and keyboard grabs to make sure that we have the focus | 376 // Install X pointer and keyboard grabs to make sure that we have the focus |
| 381 // and get all mouse and keyboard events until we're closed. | 377 // and get all mouse and keyboard events until we're closed. |
| 382 GdkGrabStatus pointer_grab_status = | 378 GdkGrabStatus pointer_grab_status = |
| 383 gdk_pointer_grab(gdk_window, | 379 gdk_pointer_grab(window_->window, |
| 384 TRUE, // owner_events | 380 TRUE, // owner_events |
| 385 GDK_BUTTON_PRESS_MASK, // event_mask | 381 GDK_BUTTON_PRESS_MASK, // event_mask |
| 386 NULL, // confine_to | 382 NULL, // confine_to |
| 387 NULL, // cursor | 383 NULL, // cursor |
| 388 GDK_CURRENT_TIME); | 384 GDK_CURRENT_TIME); |
| 389 if (pointer_grab_status != GDK_GRAB_SUCCESS) { | 385 if (pointer_grab_status != GDK_GRAB_SUCCESS) { |
| 390 // This will fail if someone else already has the pointer grabbed, but | 386 // This will fail if someone else already has the pointer grabbed, but |
| 391 // there's not really anything we can do about that. | 387 // there's not really anything we can do about that. |
| 392 DLOG(ERROR) << "Unable to grab pointer (status=" | 388 DLOG(ERROR) << "Unable to grab pointer (status=" |
| 393 << pointer_grab_status << ")"; | 389 << pointer_grab_status << ")"; |
| 394 } | 390 } |
| 395 GdkGrabStatus keyboard_grab_status = | 391 GdkGrabStatus keyboard_grab_status = |
| 396 gdk_keyboard_grab(gdk_window, | 392 gdk_keyboard_grab(window_->window, |
| 397 FALSE, // owner_events | 393 FALSE, // owner_events |
| 398 GDK_CURRENT_TIME); | 394 GDK_CURRENT_TIME); |
| 399 if (keyboard_grab_status != GDK_GRAB_SUCCESS) { | 395 if (keyboard_grab_status != GDK_GRAB_SUCCESS) { |
| 400 DLOG(ERROR) << "Unable to grab keyboard (status=" | 396 DLOG(ERROR) << "Unable to grab keyboard (status=" |
| 401 << keyboard_grab_status << ")"; | 397 << keyboard_grab_status << ")"; |
| 402 } | 398 } |
| 403 } | 399 } |
| 404 | 400 |
| 405 gboolean BubbleGtk::OnGtkAccelerator(GtkAccelGroup* group, | 401 gboolean BubbleGtk::OnGtkAccelerator(GtkAccelGroup* group, |
| 406 GObject* acceleratable, | 402 GObject* acceleratable, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 } | 449 } |
| 454 break; | 450 break; |
| 455 default: | 451 default: |
| 456 return FALSE; | 452 return FALSE; |
| 457 } | 453 } |
| 458 | 454 |
| 459 return TRUE; | 455 return TRUE; |
| 460 } | 456 } |
| 461 | 457 |
| 462 gboolean BubbleGtk::OnExpose(GtkWidget* widget, GdkEventExpose* expose) { | 458 gboolean BubbleGtk::OnExpose(GtkWidget* widget, GdkEventExpose* expose) { |
| 463 // TODO(erg): This whole method will need to be rewritten in cairo. | |
| 464 GdkDrawable* drawable = GDK_DRAWABLE(window_->window); | 459 GdkDrawable* drawable = GDK_DRAWABLE(window_->window); |
| 465 GdkGC* gc = gdk_gc_new(drawable); | 460 GdkGC* gc = gdk_gc_new(drawable); |
| 466 gdk_gc_set_rgb_fg_color(gc, &kFrameColor); | 461 gdk_gc_set_rgb_fg_color(gc, &kFrameColor); |
| 467 | 462 |
| 468 // Stroke the frame border. | 463 // Stroke the frame border. |
| 469 GtkAllocation allocation; | 464 GtkAllocation allocation; |
| 470 gtk_widget_get_allocation(window_, &allocation); | 465 gtk_widget_get_allocation(window_, &allocation); |
| 471 std::vector<GdkPoint> points = MakeFramePolygonPoints( | 466 std::vector<GdkPoint> points = MakeFramePolygonPoints( |
| 472 current_arrow_location_, allocation.width, allocation.height, | 467 current_arrow_location_, allocation.width, allocation.height, |
| 473 FRAME_STROKE); | 468 FRAME_STROKE); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 gboolean BubbleGtk::OnToplevelUnmap(GtkWidget* widget, GdkEvent* event) { | 532 gboolean BubbleGtk::OnToplevelUnmap(GtkWidget* widget, GdkEvent* event) { |
| 538 Close(); | 533 Close(); |
| 539 return FALSE; | 534 return FALSE; |
| 540 } | 535 } |
| 541 | 536 |
| 542 void BubbleGtk::OnAnchorAllocate(GtkWidget* widget, | 537 void BubbleGtk::OnAnchorAllocate(GtkWidget* widget, |
| 543 GtkAllocation* allocation) { | 538 GtkAllocation* allocation) { |
| 544 if (!UpdateArrowLocation(false)) | 539 if (!UpdateArrowLocation(false)) |
| 545 MoveWindow(); | 540 MoveWindow(); |
| 546 } | 541 } |
| OLD | NEW |