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