Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: ui/views/controls/button/menu_button.cc

Issue 10827198: Change View::HitTest to View::HitTestRect (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed errors reported by trybots Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/button/custom_button.cc ('k') | ui/views/controls/label.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « ui/views/controls/button/custom_button.cc ('k') | ui/views/controls/label.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698