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 "grit/app_strings.h" | 11 #include "grit/app_strings.h" |
12 #include "grit/app_resources.h" | 12 #include "grit/app_resources.h" |
13 #include "views/controls/button/button.h" | 13 #include "views/controls/button/button.h" |
14 #include "views/controls/menu/view_menu_delegate.h" | 14 #include "views/controls/menu/view_menu_delegate.h" |
15 #include "views/event.h" | 15 #include "views/event.h" |
| 16 #include "views/screen.h" |
16 #include "views/widget/root_view.h" | 17 #include "views/widget/root_view.h" |
17 #include "views/widget/widget.h" | 18 #include "views/widget/widget.h" |
18 | 19 #include "views/window/window.h" |
19 #if defined(OS_WIN) | |
20 #include "app/win_util.h" | |
21 #endif | |
22 | 20 |
23 using base::Time; | 21 using base::Time; |
24 using base::TimeDelta; | 22 using base::TimeDelta; |
25 | 23 |
26 namespace views { | 24 namespace views { |
27 | 25 |
28 // The amount of time, in milliseconds, we wait before allowing another mouse | 26 // The amount of time, in milliseconds, we wait before allowing another mouse |
29 // pressed event to show the menu. | 27 // pressed event to show the menu. |
30 static const int64 kMinimumTimeBetweenButtonClicks = 100; | 28 static const int64 kMinimumTimeBetweenButtonClicks = 100; |
31 | 29 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 96 } |
99 } | 97 } |
100 | 98 |
101 //////////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////////// |
102 // | 100 // |
103 // MenuButton - Events | 101 // MenuButton - Events |
104 // | 102 // |
105 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
106 | 104 |
107 int MenuButton::GetMaximumScreenXCoordinate() { | 105 int MenuButton::GetMaximumScreenXCoordinate() { |
108 Widget* widget = GetWidget(); | 106 if (!GetWindow()) { |
109 | |
110 if (!widget) { | |
111 NOTREACHED(); | 107 NOTREACHED(); |
112 return 0; | 108 return 0; |
113 } | 109 } |
114 | 110 |
115 #if defined(OS_WIN) | 111 gfx::Rect monitor_bounds = |
116 HWND hwnd = widget->GetNativeView(); | 112 Screen::GetMonitorWorkAreaNearestWindow(GetWindow()->GetNativeWindow()); |
117 RECT t; | 113 return monitor_bounds.right() - 1; |
118 ::GetWindowRect(hwnd, &t); | |
119 | |
120 gfx::Rect r(t); | |
121 gfx::Rect monitor_rect = win_util::GetMonitorBoundsForRect(r); | |
122 return monitor_rect.x() + monitor_rect.width() - 1; | |
123 #else | |
124 NOTIMPLEMENTED(); | |
125 return 1000000; | |
126 #endif | |
127 } | 114 } |
128 | 115 |
129 bool MenuButton::Activate() { | 116 bool MenuButton::Activate() { |
130 SetState(BS_PUSHED); | 117 SetState(BS_PUSHED); |
131 // We need to synchronously paint here because subsequently we enter a | 118 // We need to synchronously paint here because subsequently we enter a |
132 // menu modal loop which will stop this window from updating and | 119 // menu modal loop which will stop this window from updating and |
133 // receiving the paint message that should be spawned by SetState until | 120 // receiving the paint message that should be spawned by SetState until |
134 // after the menu closes. | 121 // after the menu closes. |
135 PaintNow(); | 122 PaintNow(); |
136 if (menu_delegate_) { | 123 if (menu_delegate_) { |
(...skipping 18 matching lines...) Expand all Loading... |
155 // We're about to show the menu from a mouse press. By showing from the | 142 // We're about to show the menu from a mouse press. By showing from the |
156 // mouse press event we block RootView in mouse dispatching. This also | 143 // mouse press event we block RootView in mouse dispatching. This also |
157 // appears to cause RootView to get a mouse pressed BEFORE the mouse | 144 // appears to cause RootView to get a mouse pressed BEFORE the mouse |
158 // release is seen, which means RootView sends us another mouse press no | 145 // release is seen, which means RootView sends us another mouse press no |
159 // matter where the user pressed. To force RootView to recalculate the | 146 // matter where the user pressed. To force RootView to recalculate the |
160 // mouse target during the mouse press we explicitly set the mouse handler | 147 // mouse target during the mouse press we explicitly set the mouse handler |
161 // to NULL. | 148 // to NULL. |
162 GetRootView()->SetMouseHandler(NULL); | 149 GetRootView()->SetMouseHandler(NULL); |
163 | 150 |
164 menu_visible_ = true; | 151 menu_visible_ = true; |
165 menu_delegate_->RunMenu(this, menu_position, GetWidget()->GetNativeView()); | 152 menu_delegate_->RunMenu(this, menu_position); |
166 menu_visible_ = false; | 153 menu_visible_ = false; |
167 menu_closed_time_ = Time::Now(); | 154 menu_closed_time_ = Time::Now(); |
168 | 155 |
169 // Now that the menu has closed, we need to manually reset state to | 156 // Now that the menu has closed, we need to manually reset state to |
170 // "normal" since the menu modal loop will have prevented normal | 157 // "normal" since the menu modal loop will have prevented normal |
171 // mouse move messages from getting to this View. We set "normal" | 158 // mouse move messages from getting to this View. We set "normal" |
172 // and not "hot" because the likelihood is that the mouse is now | 159 // and not "hot" because the likelihood is that the mouse is now |
173 // somewhere else (user clicked elsewhere on screen to close the menu | 160 // somewhere else (user clicked elsewhere on screen to close the menu |
174 // or selected an item) and we will inevitably refresh the hot state | 161 // or selected an item) and we will inevitably refresh the hot state |
175 // in the event the mouse _is_ over the view. | 162 // in the event the mouse _is_ over the view. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } | 243 } |
257 | 244 |
258 bool MenuButton::GetAccessibleState(AccessibilityTypes::State* state) { | 245 bool MenuButton::GetAccessibleState(AccessibilityTypes::State* state) { |
259 DCHECK(state); | 246 DCHECK(state); |
260 | 247 |
261 *state = AccessibilityTypes::STATE_HASPOPUP; | 248 *state = AccessibilityTypes::STATE_HASPOPUP; |
262 return true; | 249 return true; |
263 } | 250 } |
264 | 251 |
265 } // namespace views | 252 } // namespace views |
OLD | NEW |