| 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/strings/utf_string_conversions.h" | 7 #include "base/strings/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/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 const char* MenuButton::GetClassName() const { | 159 const char* MenuButton::GetClassName() const { |
| 160 return kViewClassName; | 160 return kViewClassName; |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool MenuButton::OnMousePressed(const ui::MouseEvent& event) { | 163 bool MenuButton::OnMousePressed(const ui::MouseEvent& event) { |
| 164 RequestFocus(); | 164 RequestFocus(); |
| 165 if (state() != STATE_DISABLED) { | 165 if (state() != STATE_DISABLED) { |
| 166 // If we're draggable (GetDragOperations returns a non-zero value), then | 166 // If we're draggable (GetDragOperations returns a non-zero value), then |
| 167 // don't pop on press, instead wait for release. | 167 // don't pop on press, instead wait for release. |
| 168 if (event.IsOnlyLeftMouseButton() && | 168 if (event.IsOnlyLeftMouseButton() && |
| 169 HitTestPoint(event.location()) && | 169 HitTestPoint(gfx::ToFlooredPoint(event.location())) && |
| 170 GetDragOperations(event.location()) == ui::DragDropTypes::DRAG_NONE) { | 170 GetDragOperations(gfx::ToFlooredPoint(event.location())) == |
| 171 ui::DragDropTypes::DRAG_NONE) { |
| 171 TimeDelta delta = TimeTicks::Now() - menu_closed_time_; | 172 TimeDelta delta = TimeTicks::Now() - menu_closed_time_; |
| 172 if (delta.InMilliseconds() > kMinimumMsBetweenButtonClicks) | 173 if (delta.InMilliseconds() > kMinimumMsBetweenButtonClicks) |
| 173 return Activate(); | 174 return Activate(); |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 return true; | 177 return true; |
| 177 } | 178 } |
| 178 | 179 |
| 179 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) { | 180 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 180 // Explicitly test for left mouse button to show the menu. If we tested for | 181 // Explicitly test for left mouse button to show the menu. If we tested for |
| 181 // !IsTriggerableEvent it could lead to a situation where we end up showing | 182 // !IsTriggerableEvent it could lead to a situation where we end up showing |
| 182 // the menu and context menu (this would happen if the right button is not | 183 // the menu and context menu (this would happen if the right button is not |
| 183 // triggerable and there's a context menu). | 184 // triggerable and there's a context menu). |
| 184 if (GetDragOperations(event.location()) != ui::DragDropTypes::DRAG_NONE && | 185 if (GetDragOperations(gfx::ToFlooredPoint(event.location())) != |
| 186 ui::DragDropTypes::DRAG_NONE && |
| 185 state() != STATE_DISABLED && !InDrag() && event.IsOnlyLeftMouseButton() && | 187 state() != STATE_DISABLED && !InDrag() && event.IsOnlyLeftMouseButton() && |
| 186 HitTestPoint(event.location())) { | 188 HitTestPoint(gfx::ToFlooredPoint(event.location()))) { |
| 187 Activate(); | 189 Activate(); |
| 188 } else { | 190 } else { |
| 189 TextButton::OnMouseReleased(event); | 191 TextButton::OnMouseReleased(event); |
| 190 } | 192 } |
| 191 } | 193 } |
| 192 | 194 |
| 193 // The reason we override View::OnMouseExited is because we get this event when | 195 // The reason we override View::OnMouseExited is because we get this event when |
| 194 // we display the menu. If we don't override this method then | 196 // we display the menu. If we don't override this method then |
| 195 // BaseButton::OnMouseExited will get the event and will set the button's state | 197 // BaseButton::OnMouseExited will get the event and will set the button's state |
| 196 // to STATE_NORMAL instead of keeping the state BM_PUSHED. This, in turn, will | 198 // to STATE_NORMAL instead of keeping the state BM_PUSHED. This, in turn, will |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 if (!GetWidget()) { | 269 if (!GetWidget()) { |
| 268 NOTREACHED(); | 270 NOTREACHED(); |
| 269 return 0; | 271 return 0; |
| 270 } | 272 } |
| 271 | 273 |
| 272 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | 274 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); |
| 273 return monitor_bounds.right() - 1; | 275 return monitor_bounds.right() - 1; |
| 274 } | 276 } |
| 275 | 277 |
| 276 } // namespace views | 278 } // namespace views |
| OLD | NEW |