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

Side by Side Diff: chrome/browser/ui/gtk/gtk_custom_menu_item.cc

Issue 8773025: GTK: More removal of raw GtkWidget->allocation access. (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/gtk_custom_menu_item.h" 5 #include "chrome/browser/ui/gtk/gtk_custom_menu_item.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "chrome/browser/ui/gtk/gtk_custom_menu.h" 8 #include "chrome/browser/ui/gtk/gtk_custom_menu.h"
9 9
10 // This method was autogenerated by the program glib-genmarshall, which 10 // This method was autogenerated by the program glib-genmarshall, which
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 198
199 GtkWidget* last_button = current_button; 199 GtkWidget* last_button = current_button;
200 for (GList* i = button_item; i && GTK_IS_BUTTON(i->data); 200 for (GList* i = button_item; i && GTK_IS_BUTTON(i->data);
201 i = g_list_next(i)) { 201 i = g_list_next(i)) {
202 last_button = GTK_WIDGET(i->data); 202 last_button = GTK_WIDGET(i->data);
203 } 203 }
204 204
205 if (base::i18n::IsRTL()) 205 if (base::i18n::IsRTL())
206 std::swap(first_button, last_button); 206 std::swap(first_button, last_button);
207 207
208 int x = first_button->allocation.x; 208 GtkAllocation first_allocation;
209 int y = first_button->allocation.y; 209 gtk_widget_get_allocation(first_button, &first_allocation);
210 int width = last_button->allocation.width + last_button->allocation.x - 210 GtkAllocation current_allocation;
211 first_button->allocation.x; 211 gtk_widget_get_allocation(current_button, &current_allocation);
212 int height = last_button->allocation.height; 212 GtkAllocation last_allocation;
213 gtk_widget_get_allocation(last_button, &last_allocation);
214
215 int x = first_allocation.x;
216 int y = first_allocation.y;
217 int width = last_allocation.width + last_allocation.x - first_allocation.x;
218 int height = last_allocation.height;
213 219
214 gtk_paint_box(hbox->style, hbox->window, 220 gtk_paint_box(hbox->style, hbox->window,
215 gtk_widget_get_state(current_button), 221 gtk_widget_get_state(current_button),
216 GTK_SHADOW_OUT, 222 GTK_SHADOW_OUT,
217 &current_button->allocation, hbox, "button", 223 &current_allocation, hbox, "button",
218 x, y, width, height); 224 x, y, width, height);
219 225
220 // Propagate to the button's children. 226 // Propagate to the button's children.
221 gtk_container_propagate_expose( 227 gtk_container_propagate_expose(
222 GTK_CONTAINER(current_button), 228 GTK_CONTAINER(current_button),
223 gtk_bin_get_child(GTK_BIN(current_button)), 229 gtk_bin_get_child(GTK_BIN(current_button)),
224 event); 230 event);
225 } 231 }
226 232
227 static gboolean gtk_custom_menu_item_hbox_expose(GtkWidget* widget, 233 static gboolean gtk_custom_menu_item_hbox_expose(GtkWidget* widget,
(...skipping 13 matching lines...) Expand all
241 // As a separate pass, draw the buton separators above. We need to draw the 247 // As a separate pass, draw the buton separators above. We need to draw the
242 // separators in a separate pass because we are drawing on top of the 248 // separators in a separate pass because we are drawing on top of the
243 // buttons. Otherwise, the vlines are overwritten by the next button. 249 // buttons. Otherwise, the vlines are overwritten by the next button.
244 for (GList* current_item = menu_item->all_widgets; 250 for (GList* current_item = menu_item->all_widgets;
245 current_item != NULL; current_item = g_list_next(current_item)) { 251 current_item != NULL; current_item = g_list_next(current_item)) {
246 if (GTK_IS_BUTTON(current_item->data)) { 252 if (GTK_IS_BUTTON(current_item->data)) {
247 // Check to see if this is the last button in a run. 253 // Check to see if this is the last button in a run.
248 GList* next_item = g_list_next(current_item); 254 GList* next_item = g_list_next(current_item);
249 if (next_item && GTK_IS_BUTTON(next_item->data)) { 255 if (next_item && GTK_IS_BUTTON(next_item->data)) {
250 GtkWidget* current_button = GTK_WIDGET(current_item->data); 256 GtkWidget* current_button = GTK_WIDGET(current_item->data);
251 GtkAllocation child_alloc = 257 GtkAllocation button_allocation;
252 gtk_bin_get_child(GTK_BIN(current_button))->allocation; 258 gtk_widget_get_allocation(current_button, &button_allocation);
259 GtkAllocation child_alloc;
260 gtk_widget_get_allocation(gtk_bin_get_child(GTK_BIN(current_button)),
261 &child_alloc);
253 int half_offset = widget->style->xthickness / 2; 262 int half_offset = widget->style->xthickness / 2;
254 gtk_paint_vline(widget->style, widget->window, 263 gtk_paint_vline(widget->style, widget->window,
255 gtk_widget_get_state(current_button), 264 gtk_widget_get_state(current_button),
256 &event->area, widget, "button", 265 &event->area, widget, "button",
257 child_alloc.y, 266 child_alloc.y,
258 child_alloc.y + child_alloc.height, 267 child_alloc.y + child_alloc.height,
259 current_button->allocation.x + 268 button_allocation.x +
260 current_button->allocation.width - half_offset); 269 button_allocation.width - half_offset);
261 } 270 }
262 } 271 }
263 } 272 }
264 273
265 // Finally, draw the selected item on top of the separators so there are no 274 // Finally, draw the selected item on top of the separators so there are no
266 // artifacts inside the button area. 275 // artifacts inside the button area.
267 GList* selected = g_list_find(menu_item->all_widgets, 276 GList* selected = g_list_find(menu_item->all_widgets,
268 menu_item->currently_selected_button); 277 menu_item->currently_selected_button);
269 if (selected) { 278 if (selected) {
270 gtk_custom_menu_item_expose_button(widget, event, selected); 279 gtk_custom_menu_item_expose_button(widget, event, selected);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 370
362 menu_item->all_widgets = g_list_append(menu_item->all_widgets, fixed); 371 menu_item->all_widgets = g_list_append(menu_item->all_widgets, fixed);
363 } 372 }
364 373
365 void gtk_custom_menu_item_receive_motion_event(GtkCustomMenuItem* menu_item, 374 void gtk_custom_menu_item_receive_motion_event(GtkCustomMenuItem* menu_item,
366 gdouble x, gdouble y) { 375 gdouble x, gdouble y) {
367 GtkWidget* new_selected_widget = NULL; 376 GtkWidget* new_selected_widget = NULL;
368 GList* current = menu_item->button_widgets; 377 GList* current = menu_item->button_widgets;
369 for (; current != NULL; current = current->next) { 378 for (; current != NULL; current = current->next) {
370 GtkWidget* current_widget = GTK_WIDGET(current->data); 379 GtkWidget* current_widget = GTK_WIDGET(current->data);
371 GtkAllocation alloc = current_widget->allocation; 380 GtkAllocation alloc;
381 gtk_widget_get_allocation(current_widget, &alloc);
372 int offset_x, offset_y; 382 int offset_x, offset_y;
373 gtk_widget_translate_coordinates(current_widget, GTK_WIDGET(menu_item), 383 gtk_widget_translate_coordinates(current_widget, GTK_WIDGET(menu_item),
374 0, 0, &offset_x, &offset_y); 384 0, 0, &offset_x, &offset_y);
375 if (x >= offset_x && x < (offset_x + alloc.width) && 385 if (x >= offset_x && x < (offset_x + alloc.width) &&
376 y >= offset_y && y < (offset_y + alloc.height)) { 386 y >= offset_y && y < (offset_y + alloc.height)) {
377 new_selected_widget = current_widget; 387 new_selected_widget = current_widget;
378 break; 388 break;
379 } 389 }
380 } 390 }
381 391
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 gpointer callback_data) { 479 gpointer callback_data) {
470 // Even though we're filtering |all_widgets| on GTK_IS_BUTTON(), this isn't 480 // Even though we're filtering |all_widgets| on GTK_IS_BUTTON(), this isn't
471 // equivalent to |button_widgets| because we also want the button-labels. 481 // equivalent to |button_widgets| because we also want the button-labels.
472 for (GList* i = menu_item->all_widgets; i && GTK_IS_BUTTON(i->data); 482 for (GList* i = menu_item->all_widgets; i && GTK_IS_BUTTON(i->data);
473 i = g_list_next(i)) { 483 i = g_list_next(i)) {
474 if (GTK_IS_BUTTON(i->data)) { 484 if (GTK_IS_BUTTON(i->data)) {
475 callback(GTK_WIDGET(i->data), callback_data); 485 callback(GTK_WIDGET(i->data), callback_data);
476 } 486 }
477 } 487 }
478 } 488 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/gtk_chrome_link_button.cc ('k') | chrome/browser/ui/gtk/gtk_input_event_box.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698