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

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

Issue 8921022: GTK: Even more cleanup to access allocation through 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/menu_bar_helper.h" 5 #include "chrome/browser/ui/gtk/menu_bar_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/browser/ui/gtk/gtk_util.h" 10 #include "chrome/browser/ui/gtk/gtk_util.h"
11 #include "ui/base/gtk/gtk_signal_registrar.h" 11 #include "ui/base/gtk/gtk_signal_registrar.h"
12 12
13 namespace { 13 namespace {
14 14
15 // Recursively find all the GtkMenus that are attached to menu item |child| 15 // Recursively find all the GtkMenus that are attached to menu item |child|
16 // and add them to |data|, which is a vector of GtkWidgets. 16 // and add them to |data|, which is a vector of GtkWidgets.
17 void PopulateSubmenus(GtkWidget* child, gpointer data) { 17 void PopulateSubmenus(GtkWidget* child, gpointer data) {
18 std::vector<GtkWidget*>* submenus = 18 std::vector<GtkWidget*>* submenus =
19 static_cast<std::vector<GtkWidget*>*>(data); 19 static_cast<std::vector<GtkWidget*>*>(data);
20 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(child)); 20 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(child));
21 if (submenu) { 21 if (submenu) {
22 submenus->push_back(submenu); 22 submenus->push_back(submenu);
23 gtk_container_foreach(GTK_CONTAINER(submenu), PopulateSubmenus, submenus); 23 gtk_container_foreach(GTK_CONTAINER(submenu), PopulateSubmenus, submenus);
24 } 24 }
25 } 25 }
26 26
27 // Is the cursor over |menu| or one of its parent menus? 27 // Is the cursor over |menu| or one of its parent menus?
28 bool MotionIsOverMenu(GtkWidget* menu, GdkEventMotion* motion) { 28 bool MotionIsOverMenu(GtkWidget* menu, GdkEventMotion* motion) {
29 GtkAllocation allocation;
30 gtk_widget_get_allocation(menu, &allocation);
31
29 if (motion->x >= 0 && motion->y >= 0 && 32 if (motion->x >= 0 && motion->y >= 0 &&
30 motion->x < menu->allocation.width && 33 motion->x < allocation.width &&
31 motion->y < menu->allocation.height) { 34 motion->y < allocation.height) {
32 return true; 35 return true;
33 } 36 }
34 37
35 while (menu) { 38 while (menu) {
36 GtkWidget* menu_item = gtk_menu_get_attach_widget(GTK_MENU(menu)); 39 GtkWidget* menu_item = gtk_menu_get_attach_widget(GTK_MENU(menu));
37 if (!menu_item) 40 if (!menu_item)
38 return false; 41 return false;
39 GtkWidget* parent = gtk_widget_get_parent(menu_item); 42 GtkWidget* parent = gtk_widget_get_parent(menu_item);
40 43
41 if (gtk_util::WidgetContainsCursor(parent)) 44 if (gtk_util::WidgetContainsCursor(parent))
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 gint last_y = y; 127 gint last_y = y;
125 if (!gtk_widget_translate_coordinates( 128 if (!gtk_widget_translate_coordinates(
126 last_button, button, last_x, last_y, &x, &y)) { 129 last_button, button, last_x, last_y, &x, &y)) {
127 // |button| may not be realized. 130 // |button| may not be realized.
128 continue; 131 continue;
129 } 132 }
130 } 133 }
131 134
132 last_button = button; 135 last_button = button;
133 136
134 if (x >= 0 && y >= 0 && x < button->allocation.width && 137 GtkAllocation allocation;
135 y < button->allocation.height) { 138 gtk_widget_get_allocation(button, &allocation);
139
140 if (x >= 0 && y >= 0 && x < allocation.width && y < allocation.height) {
136 if (button != button_showing_menu_) 141 if (button != button_showing_menu_)
137 delegate_->PopupForButton(button); 142 delegate_->PopupForButton(button);
138 return TRUE; 143 return TRUE;
139 } 144 }
140 } 145 }
141 146
142 return FALSE; 147 return FALSE;
143 } 148 }
144 149
145 void MenuBarHelper::OnMenuHiddenOrDestroyed(GtkWidget* menu) { 150 void MenuBarHelper::OnMenuHiddenOrDestroyed(GtkWidget* menu) {
(...skipping 28 matching lines...) Expand all
174 break; 179 break;
175 } 180 }
176 default: 181 default:
177 return; 182 return;
178 } 183 }
179 184
180 // This signal doesn't have a return value; we have to manually stop its 185 // This signal doesn't have a return value; we have to manually stop its
181 // propagation. 186 // propagation.
182 g_signal_stop_emission_by_name(menu, "move-current"); 187 g_signal_stop_emission_by_name(menu, "move-current");
183 } 188 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/location_bar_view_gtk.cc ('k') | chrome/browser/ui/gtk/tabs/dragged_view_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698