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

Side by Side Diff: views/widget/root_view.cc

Issue 6685069: Disambiguate OnMouseCaptureLost from OnMouseReleased, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, fix tests, cleanup, etc. Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « views/widget/root_view.h ('k') | views/widget/widget_gtk.cc » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/widget/root_view.h" 5 #include "views/widget/root_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 Layout(); 75 Layout();
76 } 76 }
77 77
78 void RootView::NotifyNativeViewHierarchyChanged(bool attached, 78 void RootView::NotifyNativeViewHierarchyChanged(bool attached,
79 gfx::NativeView native_view) { 79 gfx::NativeView native_view) {
80 PropagateNativeViewHierarchyChanged(attached, native_view, this); 80 PropagateNativeViewHierarchyChanged(attached, native_view, this);
81 } 81 }
82 82
83 // Input ----------------------------------------------------------------------- 83 // Input -----------------------------------------------------------------------
84 84
85 void RootView::ProcessMouseDragCanceled() {
86 if (mouse_pressed_handler_) {
87 // Synthesize a release event.
88 MouseEvent release_event(ui::ET_MOUSE_RELEASED, last_mouse_event_x_,
89 last_mouse_event_y_, last_mouse_event_flags_);
90 OnMouseReleased(release_event, true);
91 }
92 }
93
94 bool RootView::ProcessKeyEvent(const KeyEvent& event) { 85 bool RootView::ProcessKeyEvent(const KeyEvent& event) {
95 bool consumed = false; 86 bool consumed = false;
96 87
97 View* v = GetFocusManager()->GetFocusedView(); 88 View* v = GetFocusManager()->GetFocusedView();
98 // Special case to handle right-click context menus triggered by the 89 // Special case to handle right-click context menus triggered by the
99 // keyboard. 90 // keyboard.
100 if (v && v->IsEnabled() && ((event.key_code() == ui::VKEY_APPS) || 91 if (v && v->IsEnabled() && ((event.key_code() == ui::VKEY_APPS) ||
101 (event.key_code() == ui::VKEY_F10 && event.IsShiftDown()))) { 92 (event.key_code() == ui::VKEY_F10 && event.IsShiftDown()))) {
102 v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false); 93 v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false);
103 return true; 94 return true;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 SetMouseLocationAndFlags(e); 245 SetMouseLocationAndFlags(e);
255 246
256 gfx::Point p; 247 gfx::Point p;
257 ConvertPointToMouseHandler(e.location(), &p); 248 ConvertPointToMouseHandler(e.location(), &p);
258 MouseEvent mouse_event(e.type(), p.x(), p.y(), e.flags()); 249 MouseEvent mouse_event(e.type(), p.x(), p.y(), e.flags());
259 return mouse_pressed_handler_->ProcessMouseDragged(mouse_event, &drag_info); 250 return mouse_pressed_handler_->ProcessMouseDragged(mouse_event, &drag_info);
260 } 251 }
261 return false; 252 return false;
262 } 253 }
263 254
264 void RootView::OnMouseReleased(const MouseEvent& event, bool canceled) { 255 void RootView::OnMouseReleased(const MouseEvent& event) {
265 MouseEvent e(event, this); 256 MouseEvent e(event, this);
266 UpdateCursor(e); 257 UpdateCursor(e);
267 258
268 if (mouse_pressed_handler_) { 259 if (mouse_pressed_handler_) {
269 gfx::Point p; 260 gfx::Point p;
270 ConvertPointToMouseHandler(e.location(), &p); 261 ConvertPointToMouseHandler(e.location(), &p);
271 MouseEvent mouse_released(e.type(), p.x(), p.y(), e.flags()); 262 MouseEvent mouse_released(e.type(), p.x(), p.y(), e.flags());
272 // We allow the view to delete us from ProcessMouseReleased. As such, 263 // We allow the view to delete us from ProcessMouseReleased. As such,
273 // configure state such that we're done first, then call View. 264 // configure state such that we're done first, then call View.
274 View* mouse_pressed_handler = mouse_pressed_handler_; 265 View* mouse_pressed_handler = mouse_pressed_handler_;
275 mouse_pressed_handler_ = NULL; 266 SetMouseHandler(NULL);
276 explicit_mouse_handler_ = false; 267 mouse_pressed_handler->ProcessMouseReleased(mouse_released);
277 mouse_pressed_handler->ProcessMouseReleased(mouse_released, canceled);
278 // WARNING: we may have been deleted. 268 // WARNING: we may have been deleted.
279 } 269 }
280 } 270 }
271
272 void RootView::OnMouseCaptureLost() {
273 if (mouse_pressed_handler_) {
274 // Synthesize a release event for UpdateCursor and OnMouseReleased.
275 MouseEvent release_event(ui::ET_MOUSE_RELEASED, last_mouse_event_x_,
276 last_mouse_event_y_, last_mouse_event_flags_);
277 UpdateCursor(release_event);
278 // We allow the view to delete us from OnMouseCaptureLost. As such,
279 // configure state such that we're done first, then call View.
280 View* mouse_pressed_handler = mouse_pressed_handler_;
281 SetMouseHandler(NULL);
282 mouse_pressed_handler->OnMouseCaptureLost();
283 // WARNING: we may have been deleted.
284 }
285 }
281 286
282 void RootView::OnMouseMoved(const MouseEvent& event) { 287 void RootView::OnMouseMoved(const MouseEvent& event) {
283 MouseEvent e(event, this); 288 MouseEvent e(event, this);
284 View* v = GetEventHandlerForPoint(e.location()); 289 View* v = GetEventHandlerForPoint(e.location());
285 // Find the first enabled view, or the existing move handler, whichever comes 290 // Find the first enabled view, or the existing move handler, whichever comes
286 // first. The check for the existing handler is because if a view becomes 291 // first. The check for the existing handler is because if a view becomes
287 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED 292 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED
288 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet. 293 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet.
289 while (v && !v->IsEnabled() && (v != mouse_move_handler_)) 294 while (v && !v->IsEnabled() && (v != mouse_move_handler_))
290 v = v->parent(); 295 v = v->parent();
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 widget_->SetCursor(cursor); 473 widget_->SetCursor(cursor);
469 } 474 }
470 475
471 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) { 476 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) {
472 last_mouse_event_flags_ = event.flags(); 477 last_mouse_event_flags_ = event.flags();
473 last_mouse_event_x_ = event.x(); 478 last_mouse_event_x_ = event.x();
474 last_mouse_event_y_ = event.y(); 479 last_mouse_event_y_ = event.y();
475 } 480 }
476 481
477 } // namespace views 482 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/root_view.h ('k') | views/widget/widget_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698