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

Side by Side Diff: chrome/browser/ui/gtk/bubble/bubble_gtk.cc

Issue 8872004: GTK: More changes from raw widget->allocation to using the accessor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 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"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 return false; 270 return false;
271 271
272 gint toplevel_x = 0, toplevel_y = 0; 272 gint toplevel_x = 0, toplevel_y = 0;
273 gdk_window_get_position( 273 gdk_window_get_position(
274 GTK_WIDGET(toplevel_window_)->window, &toplevel_x, &toplevel_y); 274 GTK_WIDGET(toplevel_window_)->window, &toplevel_x, &toplevel_y);
275 int offset_x, offset_y; 275 int offset_x, offset_y;
276 gtk_widget_translate_coordinates(anchor_widget_, GTK_WIDGET(toplevel_window_), 276 gtk_widget_translate_coordinates(anchor_widget_, GTK_WIDGET(toplevel_window_),
277 rect_.x(), rect_.y(), &offset_x, &offset_y); 277 rect_.x(), rect_.y(), &offset_x, &offset_y);
278 278
279 ArrowLocationGtk old_location = current_arrow_location_; 279 ArrowLocationGtk old_location = current_arrow_location_;
280 GtkAllocation allocation;
281 gtk_widget_get_allocation(window_, &allocation);
280 current_arrow_location_ = GetArrowLocation( 282 current_arrow_location_ = GetArrowLocation(
281 preferred_arrow_location_, 283 preferred_arrow_location_,
282 toplevel_x + offset_x + (rect_.width() / 2), // arrow_x 284 toplevel_x + offset_x + (rect_.width() / 2), // arrow_x
283 window_->allocation.width); 285 allocation.width);
284 286
285 if (force_move_and_reshape || current_arrow_location_ != old_location) { 287 if (force_move_and_reshape || current_arrow_location_ != old_location) {
286 UpdateWindowShape(); 288 UpdateWindowShape();
287 MoveWindow(); 289 MoveWindow();
288 // We need to redraw the entire window to repaint its border. 290 // We need to redraw the entire window to repaint its border.
289 gtk_widget_queue_draw(window_); 291 gtk_widget_queue_draw(window_);
290 return true; 292 return true;
291 } 293 }
292 return false; 294 return false;
293 } 295 }
294 296
295 void BubbleGtk::UpdateWindowShape() { 297 void BubbleGtk::UpdateWindowShape() {
296 if (mask_region_) { 298 if (mask_region_) {
297 gdk_region_destroy(mask_region_); 299 gdk_region_destroy(mask_region_);
298 mask_region_ = NULL; 300 mask_region_ = NULL;
299 } 301 }
302 GtkAllocation allocation;
303 gtk_widget_get_allocation(window_, &allocation);
300 std::vector<GdkPoint> points = MakeFramePolygonPoints( 304 std::vector<GdkPoint> points = MakeFramePolygonPoints(
301 current_arrow_location_, 305 current_arrow_location_, allocation.width, allocation.height,
302 window_->allocation.width, window_->allocation.height,
303 FRAME_MASK); 306 FRAME_MASK);
304 mask_region_ = gdk_region_polygon(&points[0], 307 mask_region_ = gdk_region_polygon(&points[0],
305 points.size(), 308 points.size(),
306 GDK_EVEN_ODD_RULE); 309 GDK_EVEN_ODD_RULE);
307 gdk_window_shape_combine_region(window_->window, NULL, 0, 0); 310 gdk_window_shape_combine_region(window_->window, NULL, 0, 0);
308 gdk_window_shape_combine_region(window_->window, mask_region_, 0, 0); 311 gdk_window_shape_combine_region(window_->window, mask_region_, 0, 0);
309 } 312 }
310 313
311 void BubbleGtk::MoveWindow() { 314 void BubbleGtk::MoveWindow() {
312 if (!toplevel_window_ || !anchor_widget_) 315 if (!toplevel_window_ || !anchor_widget_)
313 return; 316 return;
314 317
315 gint toplevel_x = 0, toplevel_y = 0; 318 gint toplevel_x = 0, toplevel_y = 0;
316 gdk_window_get_position( 319 gdk_window_get_position(
317 GTK_WIDGET(toplevel_window_)->window, &toplevel_x, &toplevel_y); 320 GTK_WIDGET(toplevel_window_)->window, &toplevel_x, &toplevel_y);
318 321
319 int offset_x, offset_y; 322 int offset_x, offset_y;
320 gtk_widget_translate_coordinates(anchor_widget_, GTK_WIDGET(toplevel_window_), 323 gtk_widget_translate_coordinates(anchor_widget_, GTK_WIDGET(toplevel_window_),
321 rect_.x(), rect_.y(), &offset_x, &offset_y); 324 rect_.x(), rect_.y(), &offset_x, &offset_y);
322 325
323 gint screen_x = 0; 326 gint screen_x = 0;
324 if (current_arrow_location_ == ARROW_LOCATION_TOP_LEFT) { 327 if (current_arrow_location_ == ARROW_LOCATION_TOP_LEFT) {
325 screen_x = toplevel_x + offset_x + (rect_.width() / 2) - kArrowX; 328 screen_x = toplevel_x + offset_x + (rect_.width() / 2) - kArrowX;
326 } else if (current_arrow_location_ == ARROW_LOCATION_TOP_RIGHT) { 329 } else if (current_arrow_location_ == ARROW_LOCATION_TOP_RIGHT) {
330 GtkAllocation allocation;
331 gtk_widget_get_allocation(window_, &allocation);
327 screen_x = toplevel_x + offset_x + (rect_.width() / 2) - 332 screen_x = toplevel_x + offset_x + (rect_.width() / 2) -
328 window_->allocation.width + kArrowX; 333 allocation.width + kArrowX;
329 } else { 334 } else {
330 NOTREACHED(); 335 NOTREACHED();
331 } 336 }
332 337
333 gint screen_y = toplevel_y + offset_y + rect_.height() + 338 gint screen_y = toplevel_y + offset_y + rect_.height() +
334 kArrowToContentPadding; 339 kArrowToContentPadding;
335 340
336 gtk_window_move(GTK_WINDOW(window_), screen_x, screen_y); 341 gtk_window_move(GTK_WINDOW(window_), screen_x, screen_y);
337 } 342 }
338 343
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 454
450 return TRUE; 455 return TRUE;
451 } 456 }
452 457
453 gboolean BubbleGtk::OnExpose(GtkWidget* widget, GdkEventExpose* expose) { 458 gboolean BubbleGtk::OnExpose(GtkWidget* widget, GdkEventExpose* expose) {
454 GdkDrawable* drawable = GDK_DRAWABLE(window_->window); 459 GdkDrawable* drawable = GDK_DRAWABLE(window_->window);
455 GdkGC* gc = gdk_gc_new(drawable); 460 GdkGC* gc = gdk_gc_new(drawable);
456 gdk_gc_set_rgb_fg_color(gc, &kFrameColor); 461 gdk_gc_set_rgb_fg_color(gc, &kFrameColor);
457 462
458 // Stroke the frame border. 463 // Stroke the frame border.
464 GtkAllocation allocation;
465 gtk_widget_get_allocation(window_, &allocation);
459 std::vector<GdkPoint> points = MakeFramePolygonPoints( 466 std::vector<GdkPoint> points = MakeFramePolygonPoints(
460 current_arrow_location_, 467 current_arrow_location_, allocation.width, allocation.height,
461 window_->allocation.width, window_->allocation.height,
462 FRAME_STROKE); 468 FRAME_STROKE);
463 gdk_draw_polygon(drawable, gc, FALSE, &points[0], points.size()); 469 gdk_draw_polygon(drawable, gc, FALSE, &points[0], points.size());
464 470
465 g_object_unref(gc); 471 g_object_unref(gc);
466 return FALSE; // Propagate so our children paint, etc. 472 return FALSE; // Propagate so our children paint, etc.
467 } 473 }
468 474
469 // When our size is initially allocated or changed, we need to recompute 475 // When our size is initially allocated or changed, we need to recompute
470 // and apply our shape mask region. 476 // and apply our shape mask region.
471 void BubbleGtk::OnSizeAllocate(GtkWidget* widget, 477 void BubbleGtk::OnSizeAllocate(GtkWidget* widget,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 gboolean BubbleGtk::OnToplevelUnmap(GtkWidget* widget, GdkEvent* event) { 532 gboolean BubbleGtk::OnToplevelUnmap(GtkWidget* widget, GdkEvent* event) {
527 Close(); 533 Close();
528 return FALSE; 534 return FALSE;
529 } 535 }
530 536
531 void BubbleGtk::OnAnchorAllocate(GtkWidget* widget, 537 void BubbleGtk::OnAnchorAllocate(GtkWidget* widget,
532 GtkAllocation* allocation) { 538 GtkAllocation* allocation) {
533 if (!UpdateArrowLocation(false)) 539 if (!UpdateArrowLocation(false))
534 MoveWindow(); 540 MoveWindow();
535 } 541 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc ('k') | chrome/browser/ui/gtk/find_bar_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698