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

Side by Side Diff: ui/views/controls/button/menu_button.cc

Issue 9693022: views: Rename MenuButtonDelegate::RunMenu to something more obvious. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: menu_button_listener.h Created 8 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
« no previous file with comments | « ui/views/controls/button/menu_button.h ('k') | ui/views/controls/button/menu_button_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/button/menu_button.h" 5 #include "ui/views/controls/button/menu_button.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "grit/ui_resources.h" 8 #include "grit/ui_resources.h"
9 #include "grit/ui_strings.h" 9 #include "grit/ui_strings.h"
10 #include "ui/base/accessibility/accessible_view_state.h" 10 #include "ui/base/accessibility/accessible_view_state.h"
11 #include "ui/base/dragdrop/drag_drop_types.h" 11 #include "ui/base/dragdrop/drag_drop_types.h"
12 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/resource/resource_bundle.h" 13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/image/image.h" 15 #include "ui/gfx/image/image.h"
16 #include "ui/gfx/screen.h" 16 #include "ui/gfx/screen.h"
17 #include "ui/views/controls/button/button.h" 17 #include "ui/views/controls/button/button.h"
18 #include "ui/views/controls/button/menu_button_delegate.h" 18 #include "ui/views/controls/button/menu_button_listener.h"
19 #include "ui/views/events/event.h" 19 #include "ui/views/events/event.h"
20 #include "ui/views/widget/root_view.h" 20 #include "ui/views/widget/root_view.h"
21 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
22 22
23 using base::Time; 23 using base::Time;
24 using base::TimeDelta; 24 using base::TimeDelta;
25 25
26 namespace views { 26 namespace views {
27 27
28 // The amount of time, in milliseconds, we wait before allowing another mouse 28 // The amount of time, in milliseconds, we wait before allowing another mouse
(...skipping 12 matching lines...) Expand all
41 const char MenuButton::kViewClassName[] = "views/MenuButton"; 41 const char MenuButton::kViewClassName[] = "views/MenuButton";
42 42
43 //////////////////////////////////////////////////////////////////////////////// 43 ////////////////////////////////////////////////////////////////////////////////
44 // 44 //
45 // MenuButton - constructors, destructors, initialization 45 // MenuButton - constructors, destructors, initialization
46 // 46 //
47 //////////////////////////////////////////////////////////////////////////////// 47 ////////////////////////////////////////////////////////////////////////////////
48 48
49 MenuButton::MenuButton(ButtonListener* listener, 49 MenuButton::MenuButton(ButtonListener* listener,
50 const string16& text, 50 const string16& text,
51 MenuButtonDelegate* menu_delegate, 51 MenuButtonListener* menu_button_listener,
52 bool show_menu_marker) 52 bool show_menu_marker)
53 : TextButton(listener, text), 53 : TextButton(listener, text),
54 menu_visible_(false), 54 menu_visible_(false),
55 menu_offset_(kDefaultMenuOffsetX, kDefaultMenuOffsetY), 55 menu_offset_(kDefaultMenuOffsetX, kDefaultMenuOffsetY),
56 menu_delegate_(menu_delegate), 56 listener_(menu_button_listener),
57 show_menu_marker_(show_menu_marker), 57 show_menu_marker_(show_menu_marker),
58 menu_marker_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( 58 menu_marker_(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
59 IDR_MENU_DROPARROW).ToSkBitmap()), 59 IDR_MENU_DROPARROW).ToSkBitmap()),
60 destroyed_flag_(NULL) { 60 destroyed_flag_(NULL) {
61 set_alignment(TextButton::ALIGN_LEFT); 61 set_alignment(TextButton::ALIGN_LEFT);
62 } 62 }
63 63
64 MenuButton::~MenuButton() { 64 MenuButton::~MenuButton() {
65 if (destroyed_flag_) 65 if (destroyed_flag_)
66 *destroyed_flag_ = true; 66 *destroyed_flag_ = true;
67 } 67 }
68 68
69 //////////////////////////////////////////////////////////////////////////////// 69 ////////////////////////////////////////////////////////////////////////////////
70 // 70 //
71 // MenuButton - Public APIs 71 // MenuButton - Public APIs
72 // 72 //
73 //////////////////////////////////////////////////////////////////////////////// 73 ////////////////////////////////////////////////////////////////////////////////
74 74
75 bool MenuButton::Activate() { 75 bool MenuButton::Activate() {
76 SetState(BS_PUSHED); 76 SetState(BS_PUSHED);
77 if (menu_delegate_) { 77 if (listener_) {
78 gfx::Rect lb = GetLocalBounds(); 78 gfx::Rect lb = GetLocalBounds();
79 79
80 // The position of the menu depends on whether or not the locale is 80 // The position of the menu depends on whether or not the locale is
81 // right-to-left. 81 // right-to-left.
82 gfx::Point menu_position(lb.right(), lb.bottom()); 82 gfx::Point menu_position(lb.right(), lb.bottom());
83 if (base::i18n::IsRTL()) 83 if (base::i18n::IsRTL())
84 menu_position.set_x(lb.x()); 84 menu_position.set_x(lb.x());
85 85
86 View::ConvertPointToScreen(this, &menu_position); 86 View::ConvertPointToScreen(this, &menu_position);
87 if (base::i18n::IsRTL()) 87 if (base::i18n::IsRTL())
(...skipping 13 matching lines...) Expand all
101 // mouse target during the mouse press we explicitly set the mouse handler 101 // mouse target during the mouse press we explicitly set the mouse handler
102 // to NULL. 102 // to NULL.
103 static_cast<internal::RootView*>(GetWidget()->GetRootView())-> 103 static_cast<internal::RootView*>(GetWidget()->GetRootView())->
104 SetMouseHandler(NULL); 104 SetMouseHandler(NULL);
105 105
106 menu_visible_ = true; 106 menu_visible_ = true;
107 107
108 bool destroyed = false; 108 bool destroyed = false;
109 destroyed_flag_ = &destroyed; 109 destroyed_flag_ = &destroyed;
110 110
111 menu_delegate_->RunMenu(this, menu_position); 111 listener_->OnMenuButtonClicked(this, menu_position);
112 112
113 if (destroyed) { 113 if (destroyed) {
114 // The menu was deleted while showing. Don't attempt any processing. 114 // The menu was deleted while showing. Don't attempt any processing.
115 return false; 115 return false;
116 } 116 }
117 117
118 destroyed_flag_ = NULL; 118 destroyed_flag_ = NULL;
119 119
120 menu_visible_ = false; 120 menu_visible_ = false;
121 menu_closed_time_ = Time::Now(); 121 menu_closed_time_ = Time::Now();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 if (!GetWidget()) { 255 if (!GetWidget()) {
256 NOTREACHED(); 256 NOTREACHED();
257 return 0; 257 return 0;
258 } 258 }
259 259
260 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); 260 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen();
261 return monitor_bounds.right() - 1; 261 return monitor_bounds.right() - 1;
262 } 262 }
263 263
264 } // namespace views 264 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/menu_button.h ('k') | ui/views/controls/button/menu_button_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698