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

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 most TODOs and sync. 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
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 mouse_pressed_handler_ = NULL;
276 explicit_mouse_handler_ = false; 267 explicit_mouse_handler_ = false;
277 mouse_pressed_handler->ProcessMouseReleased(mouse_released, canceled); 268 mouse_pressed_handler->ProcessMouseReleased(mouse_released);
278 // WARNING: we may have been deleted. 269 // WARNING: we may have been deleted.
279 } 270 }
280 } 271 }
272
273 void RootView::OnMouseCaptureLost() {
274 // Synthesize a release event for UpdateCursor.
275 MouseEvent release_event(ui::ET_MOUSE_RELEASED, last_mouse_event_x_,
276 last_mouse_event_y_, last_mouse_event_flags_);
277 UpdateCursor(MouseEvent(release_event, this));
sadrul 2011/03/19 09:15:30 The purpose of MouseEvent(event, RootView*) is to
msw 2011/03/26 00:09:50 Done.
278
279 if (mouse_pressed_handler_) {
280 // We allow the view to delete us from ProcessMouseReleased. As such,
281 // configure state such that we're done first, then call View.
282 View* mouse_pressed_handler = mouse_pressed_handler_;
283 mouse_pressed_handler_ = NULL;
284 explicit_mouse_handler_ = false;
285 mouse_pressed_handler->OnMouseCaptureLost();
286 // WARNING: we may have been deleted.
287 }
288 }
281 289
282 void RootView::OnMouseMoved(const MouseEvent& event) { 290 void RootView::OnMouseMoved(const MouseEvent& event) {
283 MouseEvent e(event, this); 291 MouseEvent e(event, this);
284 View* v = GetEventHandlerForPoint(e.location()); 292 View* v = GetEventHandlerForPoint(e.location());
285 // Find the first enabled view, or the existing move handler, whichever comes 293 // 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 294 // 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 295 // 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. 296 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet.
289 while (v && !v->IsEnabled() && (v != mouse_move_handler_)) 297 while (v && !v->IsEnabled() && (v != mouse_move_handler_))
290 v = v->parent(); 298 v = v->parent();
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 widget_->SetCursor(cursor); 462 widget_->SetCursor(cursor);
455 } 463 }
456 464
457 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) { 465 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) {
458 last_mouse_event_flags_ = event.flags(); 466 last_mouse_event_flags_ = event.flags();
459 last_mouse_event_x_ = event.x(); 467 last_mouse_event_x_ = event.x();
460 last_mouse_event_y_ = event.y(); 468 last_mouse_event_y_ = event.y();
461 } 469 }
462 470
463 } // namespace views 471 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698