| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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" | 7 #include "app/drag_drop_types.h" |
| 8 #include "app/gfx/canvas.h" | 8 #include "app/gfx/canvas.h" |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| 11 #include "app/win_util.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" |
| 14 #include "views/controls/button/button.h" | 13 #include "views/controls/button/button.h" |
| 15 #include "views/controls/menu/view_menu_delegate.h" | 14 #include "views/controls/menu/view_menu_delegate.h" |
| 16 #include "views/event.h" | 15 #include "views/event.h" |
| 17 #include "views/widget/root_view.h" | 16 #include "views/widget/root_view.h" |
| 18 #include "views/widget/widget.h" | 17 #include "views/widget/widget.h" |
| 19 | 18 |
| 19 #if defined(OS_WIN) |
| 20 #include "app/win_util.h" |
| 21 #endif |
| 22 |
| 20 using base::Time; | 23 using base::Time; |
| 21 using base::TimeDelta; | 24 using base::TimeDelta; |
| 22 | 25 |
| 23 namespace views { | 26 namespace views { |
| 24 | 27 |
| 25 // 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 |
| 26 // pressed event to show the menu. | 29 // pressed event to show the menu. |
| 27 static const int64 kMinimumTimeBetweenButtonClicks = 100; | 30 static const int64 kMinimumTimeBetweenButtonClicks = 100; |
| 28 | 31 |
| 29 // The down arrow used to differentiate the menu button from normal | 32 // The down arrow used to differentiate the menu button from normal |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 //////////////////////////////////////////////////////////////////////////////// | 105 //////////////////////////////////////////////////////////////////////////////// |
| 103 | 106 |
| 104 int MenuButton::GetMaximumScreenXCoordinate() { | 107 int MenuButton::GetMaximumScreenXCoordinate() { |
| 105 Widget* widget = GetWidget(); | 108 Widget* widget = GetWidget(); |
| 106 | 109 |
| 107 if (!widget) { | 110 if (!widget) { |
| 108 NOTREACHED(); | 111 NOTREACHED(); |
| 109 return 0; | 112 return 0; |
| 110 } | 113 } |
| 111 | 114 |
| 115 #if defined(OS_WIN) |
| 112 HWND hwnd = widget->GetNativeView(); | 116 HWND hwnd = widget->GetNativeView(); |
| 113 RECT t; | 117 RECT t; |
| 114 ::GetWindowRect(hwnd, &t); | 118 ::GetWindowRect(hwnd, &t); |
| 115 | 119 |
| 116 gfx::Rect r(t); | 120 gfx::Rect r(t); |
| 117 gfx::Rect monitor_rect = win_util::GetMonitorBoundsForRect(r); | 121 gfx::Rect monitor_rect = win_util::GetMonitorBoundsForRect(r); |
| 118 return monitor_rect.x() + monitor_rect.width() - 1; | 122 return monitor_rect.x() + monitor_rect.width() - 1; |
| 123 #else |
| 124 NOTIMPLEMENTED(); |
| 125 return 1000000; |
| 126 #endif |
| 119 } | 127 } |
| 120 | 128 |
| 121 bool MenuButton::Activate() { | 129 bool MenuButton::Activate() { |
| 122 SetState(BS_PUSHED); | 130 SetState(BS_PUSHED); |
| 123 // We need to synchronously paint here because subsequently we enter a | 131 // We need to synchronously paint here because subsequently we enter a |
| 124 // menu modal loop which will stop this window from updating and | 132 // menu modal loop which will stop this window from updating and |
| 125 // receiving the paint message that should be spawned by SetState until | 133 // receiving the paint message that should be spawned by SetState until |
| 126 // after the menu closes. | 134 // after the menu closes. |
| 127 PaintNow(); | 135 PaintNow(); |
| 128 if (menu_delegate_) { | 136 if (menu_delegate_) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 state() != BS_DISABLED && !canceled && !InDrag() && | 206 state() != BS_DISABLED && !canceled && !InDrag() && |
| 199 e.IsOnlyLeftMouseButton() && HitTest(e.location())) { | 207 e.IsOnlyLeftMouseButton() && HitTest(e.location())) { |
| 200 Activate(); | 208 Activate(); |
| 201 } else { | 209 } else { |
| 202 TextButton::OnMouseReleased(e, canceled); | 210 TextButton::OnMouseReleased(e, canceled); |
| 203 } | 211 } |
| 204 } | 212 } |
| 205 | 213 |
| 206 // When the space bar or the enter key is pressed we need to show the menu. | 214 // When the space bar or the enter key is pressed we need to show the menu. |
| 207 bool MenuButton::OnKeyReleased(const KeyEvent& e) { | 215 bool MenuButton::OnKeyReleased(const KeyEvent& e) { |
| 216 #if defined(OS_WIN) |
| 208 if ((e.GetCharacter() == VK_SPACE) || (e.GetCharacter() == VK_RETURN)) { | 217 if ((e.GetCharacter() == VK_SPACE) || (e.GetCharacter() == VK_RETURN)) { |
| 209 return Activate(); | 218 return Activate(); |
| 210 } | 219 } |
| 220 #else |
| 221 NOTIMPLEMENTED(); |
| 222 #endif |
| 211 return true; | 223 return true; |
| 212 } | 224 } |
| 213 | 225 |
| 214 // The reason we override View::OnMouseExited is because we get this event when | 226 // The reason we override View::OnMouseExited is because we get this event when |
| 215 // we display the menu. If we don't override this method then | 227 // we display the menu. If we don't override this method then |
| 216 // BaseButton::OnMouseExited will get the event and will set the button's state | 228 // BaseButton::OnMouseExited will get the event and will set the button's state |
| 217 // to BS_NORMAL instead of keeping the state BM_PUSHED. This, in turn, will | 229 // to BS_NORMAL instead of keeping the state BM_PUSHED. This, in turn, will |
| 218 // cause the button to appear depressed while the menu is displayed. | 230 // cause the button to appear depressed while the menu is displayed. |
| 219 void MenuButton::OnMouseExited(const MouseEvent& event) { | 231 void MenuButton::OnMouseExited(const MouseEvent& event) { |
| 220 if ((state_ != BS_DISABLED) && (!menu_visible_) && (!InDrag())) { | 232 if ((state_ != BS_DISABLED) && (!menu_visible_) && (!InDrag())) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 243 } | 255 } |
| 244 | 256 |
| 245 bool MenuButton::GetAccessibleState(AccessibilityTypes::State* state) { | 257 bool MenuButton::GetAccessibleState(AccessibilityTypes::State* state) { |
| 246 DCHECK(state); | 258 DCHECK(state); |
| 247 | 259 |
| 248 *state = AccessibilityTypes::STATE_HASPOPUP; | 260 *state = AccessibilityTypes::STATE_HASPOPUP; |
| 249 return true; | 261 return true; |
| 250 } | 262 } |
| 251 | 263 |
| 252 } // namespace views | 264 } // namespace views |
| OLD | NEW |