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

Side by Side Diff: ui/views/controls/menu/menu_runner.cc

Issue 12549009: Added finch experiment to track new menu style effect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 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 "ui/views/controls/menu/menu_runner.h" 5 #include "ui/views/controls/menu/menu_runner.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/metrics/histogram.h"
9 #include "ui/views/controls/button/menu_button.h" 10 #include "ui/views/controls/button/menu_button.h"
10 #include "ui/views/controls/menu/menu_controller.h" 11 #include "ui/views/controls/menu/menu_controller.h"
11 #include "ui/views/controls/menu/menu_controller_delegate.h" 12 #include "ui/views/controls/menu/menu_controller_delegate.h"
12 #include "ui/views/controls/menu/menu_delegate.h" 13 #include "ui/views/controls/menu/menu_delegate.h"
14 #include "ui/views/controls/menu/submenu_view.h"
13 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
14 16
15 #if defined(OS_WIN) 17 #if defined(OS_WIN)
16 #include "base/win/win_util.h" 18 #include "base/win/win_util.h"
17 #endif 19 #endif
18 20
19 namespace views { 21 namespace views {
20 22
21 namespace internal { 23 namespace internal {
22 24
25 void RecordSelectedIndexes(const MenuItemView* menu_item) {
26 const MenuItemView* parent = menu_item->GetParentMenuItem();
sky 2013/03/06 22:34:21 menu_item could be NULL.
yefimt 2013/03/06 23:11:57 This function is called only when menu_item is not
27 if (!parent)
28 return;
29
30 SubmenuView* submenu = parent->GetSubmenu();
31 for (int i = 0; i < submenu->GetMenuItemCount(); ++i) {
32 if (submenu->GetMenuItemAt(i) == menu_item) {
33 HISTOGRAM_COUNTS_100("MenuSelection.Index", i);
34 break;
35 }
36 }
37
38 RecordSelectedIndexes(parent);
39 }
40
41 void RecordMenuStats(MenuItemView* result, base::TimeDelta time_elapsed) {
42 // Report if user made a selection.
43 HISTOGRAM_BOOLEAN("MenuSelection", result != NULL);
44
45 if (result) {
46 // Report how much time it took to make a selection.
47 HISTOGRAM_TIMES("MenuSelection.Time", time_elapsed);
48 RecordSelectedIndexes(result);
49 }
50 }
51
23 // Manages the menu. To destroy a MenuRunnerImpl invoke Release(). Release() 52 // Manages the menu. To destroy a MenuRunnerImpl invoke Release(). Release()
24 // deletes immediately if the menu isn't showing. If the menu is showing 53 // deletes immediately if the menu isn't showing. If the menu is showing
25 // Release() cancels the menu and when the nested RunMenuAt() call returns 54 // Release() cancels the menu and when the nested RunMenuAt() call returns
26 // deletes itself and the menu. 55 // deletes itself and the menu.
27 class MenuRunnerImpl : public internal::MenuControllerDelegate { 56 class MenuRunnerImpl : public internal::MenuControllerDelegate {
28 public: 57 public:
29 explicit MenuRunnerImpl(MenuItemView* menu); 58 explicit MenuRunnerImpl(MenuItemView* menu);
30 59
31 MenuItemView* menu() { return menu_; } 60 MenuItemView* menu() { return menu_; }
32 61
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // We can't open another menu, otherwise the message loop would become 180 // We can't open another menu, otherwise the message loop would become
152 // twice nested. This isn't necessarily a problem, but generally isn't 181 // twice nested. This isn't necessarily a problem, but generally isn't
153 // expected. 182 // expected.
154 return MenuRunner::NORMAL_EXIT; 183 return MenuRunner::NORMAL_EXIT;
155 } 184 }
156 // Drop menus don't block the message loop, so it's ok to create a new 185 // Drop menus don't block the message loop, so it's ok to create a new
157 // MenuController. 186 // MenuController.
158 controller = NULL; 187 controller = NULL;
159 } 188 }
160 } 189 }
190
161 running_ = true; 191 running_ = true;
162 for_drop_ = (types & MenuRunner::FOR_DROP) != 0; 192 for_drop_ = (types & MenuRunner::FOR_DROP) != 0;
163 bool has_mnemonics = (types & MenuRunner::HAS_MNEMONICS) != 0 && !for_drop_; 193 bool has_mnemonics = (types & MenuRunner::HAS_MNEMONICS) != 0 && !for_drop_;
164 owns_controller_ = false; 194 owns_controller_ = false;
165 if (!controller) { 195 if (!controller) {
166 // No menus are showing, show one. 196 // No menus are showing, show one.
167 ui::NativeTheme* theme = parent ? parent->GetNativeTheme() : 197 ui::NativeTheme* theme = parent ? parent->GetNativeTheme() :
168 ui::NativeTheme::instance(); 198 ui::NativeTheme::instance();
169 controller = new MenuController(theme, !for_drop_, this); 199 controller = new MenuController(theme, !for_drop_, this);
170 owns_controller_ = true; 200 owns_controller_ = true;
171 } 201 }
172 controller_ = controller; 202 controller_ = controller;
173 menu_->set_controller(controller_); 203 menu_->set_controller(controller_);
174 menu_->PrepareForRun(owns_controller_, 204 menu_->PrepareForRun(owns_controller_,
175 has_mnemonics, 205 has_mnemonics,
176 !for_drop_ && ShouldShowMnemonics(button)); 206 !for_drop_ && ShouldShowMnemonics(button));
177 207
178 // Run the loop. 208 // Run the loop.
209 base::TimeTicks start_time = base::TimeTicks::Now();
179 int mouse_event_flags = 0; 210 int mouse_event_flags = 0;
180 MenuItemView* result = controller->Run(parent, button, menu_, bounds, anchor, 211 MenuItemView* result = controller->Run(parent, button, menu_, bounds, anchor,
181 (types & MenuRunner::CONTEXT_MENU) != 0, 212 (types & MenuRunner::CONTEXT_MENU) != 0,
182 &mouse_event_flags); 213 &mouse_event_flags);
183 214
184 if (for_drop_) { 215 if (for_drop_) {
185 // Drop menus return immediately. We finish processing in DropMenuClosed. 216 // Drop menus return immediately. We finish processing in DropMenuClosed.
186 return MenuRunner::NORMAL_EXIT; 217 return MenuRunner::NORMAL_EXIT;
187 } 218 }
188 219 RecordMenuStats(result, base::TimeTicks::Now() - start_time);
189 return MenuDone(result, mouse_event_flags); 220 return MenuDone(result, mouse_event_flags);
190 } 221 }
191 222
192 void MenuRunnerImpl::Cancel() { 223 void MenuRunnerImpl::Cancel() {
193 if (running_) 224 if (running_)
194 controller_->Cancel(MenuController::EXIT_ALL); 225 controller_->Cancel(MenuController::EXIT_ALL);
195 } 226 }
196 227
197 void MenuRunnerImpl::DropMenuClosed(NotifyType type, MenuItemView* menu) { 228 void MenuRunnerImpl::DropMenuClosed(NotifyType type, MenuItemView* menu) {
198 MenuDone(NULL, 0); 229 MenuDone(NULL, 0);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 331
301 bool MenuRunner::IsRunning() const { 332 bool MenuRunner::IsRunning() const {
302 return holder_->running(); 333 return holder_->running();
303 } 334 }
304 335
305 void MenuRunner::Cancel() { 336 void MenuRunner::Cancel() {
306 holder_->Cancel(); 337 holder_->Cancel();
307 } 338 }
308 339
309 } // namespace views 340 } // namespace views
OLDNEW
« ui/native_theme/native_theme.cc ('K') | « ui/native_theme/native_theme.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698