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