OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/controls/button/menu_button.h" | 5 #include "views/controls/button/menu_button.h" |
6 | 6 |
7 #include "app/drag_drop_types.h" | |
8 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
9 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
10 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
11 #include "gfx/canvas.h" | 10 #include "gfx/canvas.h" |
12 #include "grit/app_strings.h" | 11 #include "grit/app_strings.h" |
13 #include "grit/app_resources.h" | 12 #include "grit/app_resources.h" |
| 13 #include "ui/base/dragdrop/drag_drop_types.h" |
14 #include "views/controls/button/button.h" | 14 #include "views/controls/button/button.h" |
15 #include "views/controls/menu/view_menu_delegate.h" | 15 #include "views/controls/menu/view_menu_delegate.h" |
16 #include "views/event.h" | 16 #include "views/event.h" |
17 #include "views/screen.h" | 17 #include "views/screen.h" |
18 #include "views/widget/root_view.h" | 18 #include "views/widget/root_view.h" |
19 #include "views/widget/widget.h" | 19 #include "views/widget/widget.h" |
20 #include "views/window/window.h" | 20 #include "views/window/window.h" |
21 | 21 |
22 using base::Time; | 22 using base::Time; |
23 using base::TimeDelta; | 23 using base::TimeDelta; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 186 } |
187 return true; | 187 return true; |
188 } | 188 } |
189 | 189 |
190 bool MenuButton::OnMousePressed(const MouseEvent& e) { | 190 bool MenuButton::OnMousePressed(const MouseEvent& e) { |
191 RequestFocus(); | 191 RequestFocus(); |
192 if (state() != BS_DISABLED) { | 192 if (state() != BS_DISABLED) { |
193 // If we're draggable (GetDragOperations returns a non-zero value), then | 193 // If we're draggable (GetDragOperations returns a non-zero value), then |
194 // don't pop on press, instead wait for release. | 194 // don't pop on press, instead wait for release. |
195 if (e.IsOnlyLeftMouseButton() && HitTest(e.location()) && | 195 if (e.IsOnlyLeftMouseButton() && HitTest(e.location()) && |
196 GetDragOperations(e.location()) == DragDropTypes::DRAG_NONE) { | 196 GetDragOperations(e.location()) == ui::DragDropTypes::DRAG_NONE) { |
197 TimeDelta delta = Time::Now() - menu_closed_time_; | 197 TimeDelta delta = Time::Now() - menu_closed_time_; |
198 int64 delta_in_milliseconds = delta.InMilliseconds(); | 198 int64 delta_in_milliseconds = delta.InMilliseconds(); |
199 if (delta_in_milliseconds > kMinimumTimeBetweenButtonClicks) { | 199 if (delta_in_milliseconds > kMinimumTimeBetweenButtonClicks) { |
200 return Activate(); | 200 return Activate(); |
201 } | 201 } |
202 } | 202 } |
203 } | 203 } |
204 return true; | 204 return true; |
205 } | 205 } |
206 | 206 |
207 void MenuButton::OnMouseReleased(const MouseEvent& e, | 207 void MenuButton::OnMouseReleased(const MouseEvent& e, |
208 bool canceled) { | 208 bool canceled) { |
209 // Explicitly test for left mouse button to show the menu. If we tested for | 209 // Explicitly test for left mouse button to show the menu. If we tested for |
210 // !IsTriggerableEvent it could lead to a situation where we end up showing | 210 // !IsTriggerableEvent it could lead to a situation where we end up showing |
211 // the menu and context menu (this would happen if the right button is not | 211 // the menu and context menu (this would happen if the right button is not |
212 // triggerable and there's a context menu). | 212 // triggerable and there's a context menu). |
213 if (GetDragOperations(e.location()) != DragDropTypes::DRAG_NONE && | 213 if (GetDragOperations(e.location()) != ui::DragDropTypes::DRAG_NONE && |
214 state() != BS_DISABLED && !canceled && !InDrag() && | 214 state() != BS_DISABLED && !canceled && !InDrag() && |
215 e.IsOnlyLeftMouseButton() && HitTest(e.location())) { | 215 e.IsOnlyLeftMouseButton() && HitTest(e.location())) { |
216 Activate(); | 216 Activate(); |
217 } else { | 217 } else { |
218 TextButton::OnMouseReleased(e, canceled); | 218 TextButton::OnMouseReleased(e, canceled); |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 bool MenuButton::OnKeyPressed(const KeyEvent& e) { | 222 bool MenuButton::OnKeyPressed(const KeyEvent& e) { |
223 if (e.GetKeyCode() == ui::VKEY_SPACE || | 223 if (e.GetKeyCode() == ui::VKEY_SPACE || |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 266 |
267 AccessibilityTypes::State MenuButton::GetAccessibleState() { | 267 AccessibilityTypes::State MenuButton::GetAccessibleState() { |
268 return AccessibilityTypes::STATE_HASPOPUP; | 268 return AccessibilityTypes::STATE_HASPOPUP; |
269 } | 269 } |
270 | 270 |
271 std::string MenuButton::GetClassName() const { | 271 std::string MenuButton::GetClassName() const { |
272 return kViewClassName; | 272 return kViewClassName; |
273 } | 273 } |
274 | 274 |
275 } // namespace views | 275 } // namespace views |
OLD | NEW |