OLD | NEW |
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" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 std::string MenuButton::GetClassName() const { | 175 std::string MenuButton::GetClassName() const { |
176 return kViewClassName; | 176 return kViewClassName; |
177 } | 177 } |
178 | 178 |
179 bool MenuButton::OnMousePressed(const MouseEvent& event) { | 179 bool MenuButton::OnMousePressed(const MouseEvent& event) { |
180 RequestFocus(); | 180 RequestFocus(); |
181 if (state() != BS_DISABLED) { | 181 if (state() != BS_DISABLED) { |
182 // If we're draggable (GetDragOperations returns a non-zero value), then | 182 // If we're draggable (GetDragOperations returns a non-zero value), then |
183 // don't pop on press, instead wait for release. | 183 // don't pop on press, instead wait for release. |
184 if (event.IsOnlyLeftMouseButton() && HitTest(event.location()) && | 184 if (event.IsOnlyLeftMouseButton() && |
| 185 HitTestPoint(event.location()) && |
185 GetDragOperations(event.location()) == ui::DragDropTypes::DRAG_NONE) { | 186 GetDragOperations(event.location()) == ui::DragDropTypes::DRAG_NONE) { |
186 TimeDelta delta = Time::Now() - menu_closed_time_; | 187 TimeDelta delta = Time::Now() - menu_closed_time_; |
187 int64 delta_in_milliseconds = delta.InMilliseconds(); | 188 int64 delta_in_milliseconds = delta.InMilliseconds(); |
188 if (delta_in_milliseconds > kMinimumTimeBetweenButtonClicks) { | 189 if (delta_in_milliseconds > kMinimumTimeBetweenButtonClicks) { |
189 return Activate(); | 190 return Activate(); |
190 } | 191 } |
191 } | 192 } |
192 } | 193 } |
193 return true; | 194 return true; |
194 } | 195 } |
195 | 196 |
196 void MenuButton::OnMouseReleased(const MouseEvent& event) { | 197 void MenuButton::OnMouseReleased(const MouseEvent& event) { |
197 // Explicitly test for left mouse button to show the menu. If we tested for | 198 // Explicitly test for left mouse button to show the menu. If we tested for |
198 // !IsTriggerableEvent it could lead to a situation where we end up showing | 199 // !IsTriggerableEvent it could lead to a situation where we end up showing |
199 // the menu and context menu (this would happen if the right button is not | 200 // the menu and context menu (this would happen if the right button is not |
200 // triggerable and there's a context menu). | 201 // triggerable and there's a context menu). |
201 if (GetDragOperations(event.location()) != ui::DragDropTypes::DRAG_NONE && | 202 if (GetDragOperations(event.location()) != ui::DragDropTypes::DRAG_NONE && |
202 state() != BS_DISABLED && !InDrag() && event.IsOnlyLeftMouseButton() && | 203 state() != BS_DISABLED && !InDrag() && event.IsOnlyLeftMouseButton() && |
203 HitTest(event.location())) { | 204 HitTestPoint(event.location())) { |
204 Activate(); | 205 Activate(); |
205 } else { | 206 } else { |
206 TextButton::OnMouseReleased(event); | 207 TextButton::OnMouseReleased(event); |
207 } | 208 } |
208 } | 209 } |
209 | 210 |
210 // The reason we override View::OnMouseExited is because we get this event when | 211 // The reason we override View::OnMouseExited is because we get this event when |
211 // we display the menu. If we don't override this method then | 212 // we display the menu. If we don't override this method then |
212 // BaseButton::OnMouseExited will get the event and will set the button's state | 213 // BaseButton::OnMouseExited will get the event and will set the button's state |
213 // to BS_NORMAL instead of keeping the state BM_PUSHED. This, in turn, will | 214 // to BS_NORMAL instead of keeping the state BM_PUSHED. This, in turn, will |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 if (!GetWidget()) { | 264 if (!GetWidget()) { |
264 NOTREACHED(); | 265 NOTREACHED(); |
265 return 0; | 266 return 0; |
266 } | 267 } |
267 | 268 |
268 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | 269 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); |
269 return monitor_bounds.right() - 1; | 270 return monitor_bounds.right() - 1; |
270 } | 271 } |
271 | 272 |
272 } // namespace views | 273 } // namespace views |
OLD | NEW |