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

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

Issue 10832282: Replace views::MouseEvent with ui::MouseEvent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/widget/root_view.h ('k') | ui/views/widget/widget.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/widget/root_view.h" 5 #include "ui/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 13 matching lines...) Expand all
24 namespace { 24 namespace {
25 25
26 enum EventType { 26 enum EventType {
27 EVENT_ENTER, 27 EVENT_ENTER,
28 EVENT_EXIT 28 EVENT_EXIT
29 }; 29 };
30 30
31 // |view| is the view receiving |event|. This function sends the event to all 31 // |view| is the view receiving |event|. This function sends the event to all
32 // the Views up the hierarchy that has |notify_enter_exit_on_child_| flag turned 32 // the Views up the hierarchy that has |notify_enter_exit_on_child_| flag turned
33 // on, but does not contain |sibling|. 33 // on, but does not contain |sibling|.
34 void NotifyEnterExitOfDescendant(const MouseEvent& event, 34 void NotifyEnterExitOfDescendant(const ui::MouseEvent& event,
35 EventType type, 35 EventType type,
36 View* view, 36 View* view,
37 View* sibling) { 37 View* sibling) {
38 for (View* p = view->parent(); p; p = p->parent()) { 38 for (View* p = view->parent(); p; p = p->parent()) {
39 if (!p->notify_enter_exit_on_child()) 39 if (!p->notify_enter_exit_on_child())
40 continue; 40 continue;
41 if (sibling && p->Contains(sibling)) 41 if (sibling && p->Contains(sibling))
42 break; 42 break;
43 if (type == EVENT_ENTER) 43 if (type == EVENT_ENTER)
44 p->OnMouseEntered(event); 44 p->OnMouseEntered(event);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 if (layer()) { 190 if (layer()) {
191 layer()->SchedulePaint(rect); 191 layer()->SchedulePaint(rect);
192 } else { 192 } else {
193 gfx::Rect xrect = ConvertRectToParent(rect); 193 gfx::Rect xrect = ConvertRectToParent(rect);
194 gfx::Rect invalid_rect = GetLocalBounds().Intersect(xrect); 194 gfx::Rect invalid_rect = GetLocalBounds().Intersect(xrect);
195 if (!invalid_rect.IsEmpty()) 195 if (!invalid_rect.IsEmpty())
196 widget_->SchedulePaintInRect(invalid_rect); 196 widget_->SchedulePaintInRect(invalid_rect);
197 } 197 }
198 } 198 }
199 199
200 bool RootView::OnMousePressed(const MouseEvent& event) { 200 bool RootView::OnMousePressed(const ui::MouseEvent& event) {
201 UpdateCursor(event); 201 UpdateCursor(event);
202 SetMouseLocationAndFlags(event); 202 SetMouseLocationAndFlags(event);
203 203
204 // If mouse_pressed_handler_ is non null, we are currently processing 204 // If mouse_pressed_handler_ is non null, we are currently processing
205 // a pressed -> drag -> released session. In that case we send the 205 // a pressed -> drag -> released session. In that case we send the
206 // event to mouse_pressed_handler_ 206 // event to mouse_pressed_handler_
207 if (mouse_pressed_handler_) { 207 if (mouse_pressed_handler_) {
208 MouseEvent mouse_pressed_event(event, this, mouse_pressed_handler_); 208 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this),
209 mouse_pressed_handler_);
209 drag_info_.Reset(); 210 drag_info_.Reset();
210 mouse_pressed_handler_->ProcessMousePressed(mouse_pressed_event, 211 mouse_pressed_handler_->ProcessMousePressed(mouse_pressed_event,
211 &drag_info_); 212 &drag_info_);
212 return true; 213 return true;
213 } 214 }
214 DCHECK(!explicit_mouse_handler_); 215 DCHECK(!explicit_mouse_handler_);
215 216
216 bool hit_disabled_view = false; 217 bool hit_disabled_view = false;
217 // Walk up the tree until we find a view that wants the mouse event. 218 // Walk up the tree until we find a view that wants the mouse event.
218 for (mouse_pressed_handler_ = GetEventHandlerForPoint(event.location()); 219 for (mouse_pressed_handler_ = GetEventHandlerForPoint(event.location());
219 mouse_pressed_handler_ && (mouse_pressed_handler_ != this); 220 mouse_pressed_handler_ && (mouse_pressed_handler_ != this);
220 mouse_pressed_handler_ = mouse_pressed_handler_->parent()) { 221 mouse_pressed_handler_ = mouse_pressed_handler_->parent()) {
221 DVLOG(1) << "OnMousePressed testing " 222 DVLOG(1) << "OnMousePressed testing "
222 << mouse_pressed_handler_->GetClassName(); 223 << mouse_pressed_handler_->GetClassName();
223 if (!mouse_pressed_handler_->enabled()) { 224 if (!mouse_pressed_handler_->enabled()) {
224 // Disabled views should eat events instead of propagating them upwards. 225 // Disabled views should eat events instead of propagating them upwards.
225 hit_disabled_view = true; 226 hit_disabled_view = true;
226 break; 227 break;
227 } 228 }
228 229
229 // See if this view wants to handle the mouse press. 230 // See if this view wants to handle the mouse press.
230 MouseEvent mouse_pressed_event(event, this, mouse_pressed_handler_); 231 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this),
232 mouse_pressed_handler_);
231 233
232 // Remove the double-click flag if the handler is different than the 234 // Remove the double-click flag if the handler is different than the
233 // one which got the first click part of the double-click. 235 // one which got the first click part of the double-click.
234 if (mouse_pressed_handler_ != last_click_handler_) 236 if (mouse_pressed_handler_ != last_click_handler_)
235 mouse_pressed_event.set_flags(event.flags() & ~ui::EF_IS_DOUBLE_CLICK); 237 mouse_pressed_event.set_flags(event.flags() & ~ui::EF_IS_DOUBLE_CLICK);
236 238
237 drag_info_.Reset(); 239 drag_info_.Reset();
238 bool handled = mouse_pressed_handler_->ProcessMousePressed( 240 bool handled = mouse_pressed_handler_->ProcessMousePressed(
239 mouse_pressed_event, &drag_info_); 241 mouse_pressed_event, &drag_info_);
240 242
(...skipping 25 matching lines...) Expand all
266 // entire hierarchy (even as a single-click when sent to a different view), 268 // entire hierarchy (even as a single-click when sent to a different view),
267 // it must be marked as handled to avoid anything happening from default 269 // it must be marked as handled to avoid anything happening from default
268 // processing if it the first click-part was handled by us. 270 // processing if it the first click-part was handled by us.
269 if (last_click_handler_ && (event.flags() & ui::EF_IS_DOUBLE_CLICK)) 271 if (last_click_handler_ && (event.flags() & ui::EF_IS_DOUBLE_CLICK))
270 hit_disabled_view = true; 272 hit_disabled_view = true;
271 273
272 last_click_handler_ = NULL; 274 last_click_handler_ = NULL;
273 return hit_disabled_view; 275 return hit_disabled_view;
274 } 276 }
275 277
276 bool RootView::OnMouseDragged(const MouseEvent& event) { 278 bool RootView::OnMouseDragged(const ui::MouseEvent& event) {
277 if (mouse_pressed_handler_) { 279 if (mouse_pressed_handler_) {
278 SetMouseLocationAndFlags(event); 280 SetMouseLocationAndFlags(event);
279 281
280 MouseEvent mouse_event(event, this, mouse_pressed_handler_); 282 ui::MouseEvent mouse_event(event, static_cast<View*>(this),
283 mouse_pressed_handler_);
281 return mouse_pressed_handler_->ProcessMouseDragged(mouse_event, 284 return mouse_pressed_handler_->ProcessMouseDragged(mouse_event,
282 &drag_info_); 285 &drag_info_);
283 } 286 }
284 return false; 287 return false;
285 } 288 }
286 289
287 void RootView::OnMouseReleased(const MouseEvent& event) { 290 void RootView::OnMouseReleased(const ui::MouseEvent& event) {
288 UpdateCursor(event); 291 UpdateCursor(event);
289 292
290 if (mouse_pressed_handler_) { 293 if (mouse_pressed_handler_) {
291 MouseEvent mouse_released(event, this, mouse_pressed_handler_); 294 ui::MouseEvent mouse_released(event, static_cast<View*>(this),
295 mouse_pressed_handler_);
292 // We allow the view to delete us from ProcessMouseReleased. As such, 296 // We allow the view to delete us from ProcessMouseReleased. As such,
293 // configure state such that we're done first, then call View. 297 // configure state such that we're done first, then call View.
294 View* mouse_pressed_handler = mouse_pressed_handler_; 298 View* mouse_pressed_handler = mouse_pressed_handler_;
295 SetMouseHandler(NULL); 299 SetMouseHandler(NULL);
296 mouse_pressed_handler->ProcessMouseReleased(mouse_released); 300 mouse_pressed_handler->ProcessMouseReleased(mouse_released);
297 // WARNING: we may have been deleted. 301 // WARNING: we may have been deleted.
298 } 302 }
299 } 303 }
300 304
301 void RootView::OnMouseCaptureLost() { 305 void RootView::OnMouseCaptureLost() {
302 // TODO: this likely needs to reset touch handler too. 306 // TODO: this likely needs to reset touch handler too.
303 307
304 if (mouse_pressed_handler_ || gesture_handler_) { 308 if (mouse_pressed_handler_ || gesture_handler_) {
305 // Synthesize a release event for UpdateCursor. 309 // Synthesize a release event for UpdateCursor.
306 if (mouse_pressed_handler_) { 310 if (mouse_pressed_handler_) {
307 MouseEvent release_event(ui::ET_MOUSE_RELEASED, last_mouse_event_x_, 311 gfx::Point last_point(last_mouse_event_x_, last_mouse_event_y_);
308 last_mouse_event_y_, last_mouse_event_flags_); 312 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED,
313 last_point, last_point,
314 last_mouse_event_flags_);
309 UpdateCursor(release_event); 315 UpdateCursor(release_event);
310 } 316 }
311 // We allow the view to delete us from OnMouseCaptureLost. As such, 317 // We allow the view to delete us from OnMouseCaptureLost. As such,
312 // configure state such that we're done first, then call View. 318 // configure state such that we're done first, then call View.
313 View* mouse_pressed_handler = mouse_pressed_handler_; 319 View* mouse_pressed_handler = mouse_pressed_handler_;
314 View* gesture_handler = gesture_handler_; 320 View* gesture_handler = gesture_handler_;
315 SetMouseHandler(NULL); 321 SetMouseHandler(NULL);
316 if (mouse_pressed_handler) 322 if (mouse_pressed_handler)
317 mouse_pressed_handler->OnMouseCaptureLost(); 323 mouse_pressed_handler->OnMouseCaptureLost();
318 else 324 else
319 gesture_handler->OnMouseCaptureLost(); 325 gesture_handler->OnMouseCaptureLost();
320 // WARNING: we may have been deleted. 326 // WARNING: we may have been deleted.
321 } 327 }
322 } 328 }
323 329
324 void RootView::OnMouseMoved(const MouseEvent& event) { 330 void RootView::OnMouseMoved(const ui::MouseEvent& event) {
325 View* v = GetEventHandlerForPoint(event.location()); 331 View* v = GetEventHandlerForPoint(event.location());
326 // Find the first enabled view, or the existing move handler, whichever comes 332 // Find the first enabled view, or the existing move handler, whichever comes
327 // first. The check for the existing handler is because if a view becomes 333 // first. The check for the existing handler is because if a view becomes
328 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED 334 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED
329 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet. 335 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet.
330 while (v && !v->enabled() && (v != mouse_move_handler_)) 336 while (v && !v->enabled() && (v != mouse_move_handler_))
331 v = v->parent(); 337 v = v->parent();
332 if (v && v != this) { 338 if (v && v != this) {
333 if (v != mouse_move_handler_) { 339 if (v != mouse_move_handler_) {
334 if (mouse_move_handler_ != NULL && 340 if (mouse_move_handler_ != NULL &&
335 (!mouse_move_handler_->notify_enter_exit_on_child() || 341 (!mouse_move_handler_->notify_enter_exit_on_child() ||
336 !mouse_move_handler_->Contains(v))) { 342 !mouse_move_handler_->Contains(v))) {
337 mouse_move_handler_->OnMouseExited(event); 343 mouse_move_handler_->OnMouseExited(event);
338 NotifyEnterExitOfDescendant(event, EVENT_EXIT, mouse_move_handler_, v); 344 NotifyEnterExitOfDescendant(event, EVENT_EXIT, mouse_move_handler_, v);
339 } 345 }
340 View* old_handler = mouse_move_handler_; 346 View* old_handler = mouse_move_handler_;
341 mouse_move_handler_ = v; 347 mouse_move_handler_ = v;
342 MouseEvent entered_event(event, this, mouse_move_handler_); 348 ui::MouseEvent entered_event(event, static_cast<View*>(this),
349 mouse_move_handler_);
343 if (!mouse_move_handler_->notify_enter_exit_on_child() || 350 if (!mouse_move_handler_->notify_enter_exit_on_child() ||
344 !mouse_move_handler_->Contains(old_handler)) { 351 !mouse_move_handler_->Contains(old_handler)) {
345 mouse_move_handler_->OnMouseEntered(entered_event); 352 mouse_move_handler_->OnMouseEntered(entered_event);
346 NotifyEnterExitOfDescendant(entered_event, EVENT_ENTER, v, 353 NotifyEnterExitOfDescendant(entered_event, EVENT_ENTER, v,
347 old_handler); 354 old_handler);
348 } 355 }
349 } 356 }
350 MouseEvent moved_event(event, this, mouse_move_handler_); 357 ui::MouseEvent moved_event(event, static_cast<View*>(this),
358 mouse_move_handler_);
351 mouse_move_handler_->OnMouseMoved(moved_event); 359 mouse_move_handler_->OnMouseMoved(moved_event);
352 if (!(moved_event.flags() & ui::EF_IS_NON_CLIENT)) 360 if (!(moved_event.flags() & ui::EF_IS_NON_CLIENT))
353 widget_->SetCursor(mouse_move_handler_->GetCursor(moved_event)); 361 widget_->SetCursor(mouse_move_handler_->GetCursor(moved_event));
354 } else if (mouse_move_handler_ != NULL) { 362 } else if (mouse_move_handler_ != NULL) {
355 mouse_move_handler_->OnMouseExited(event); 363 mouse_move_handler_->OnMouseExited(event);
356 NotifyEnterExitOfDescendant(event, EVENT_EXIT, mouse_move_handler_, v); 364 NotifyEnterExitOfDescendant(event, EVENT_EXIT, mouse_move_handler_, v);
357 // On Aura the non-client area extends slightly outside the root view for 365 // On Aura the non-client area extends slightly outside the root view for
358 // some windows. Let the non-client cursor handling code set the cursor 366 // some windows. Let the non-client cursor handling code set the cursor
359 // as we do above. 367 // as we do above.
360 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) 368 if (!(event.flags() & ui::EF_IS_NON_CLIENT))
361 widget_->SetCursor(gfx::kNullCursor); 369 widget_->SetCursor(gfx::kNullCursor);
362 } 370 }
363 } 371 }
364 372
365 void RootView::OnMouseExited(const MouseEvent& event) { 373 void RootView::OnMouseExited(const ui::MouseEvent& event) {
366 if (mouse_move_handler_ != NULL) { 374 if (mouse_move_handler_ != NULL) {
367 mouse_move_handler_->OnMouseExited(event); 375 mouse_move_handler_->OnMouseExited(event);
368 NotifyEnterExitOfDescendant(event, EVENT_EXIT, mouse_move_handler_, NULL); 376 NotifyEnterExitOfDescendant(event, EVENT_EXIT, mouse_move_handler_, NULL);
369 mouse_move_handler_ = NULL; 377 mouse_move_handler_ = NULL;
370 } 378 }
371 } 379 }
372 380
373 bool RootView::OnMouseWheel(const MouseWheelEvent& event) { 381 bool RootView::OnMouseWheel(const MouseWheelEvent& event) {
374 bool consumed = false; 382 bool consumed = false;
375 for (View* v = GetFocusManager()->GetFocusedView(); 383 for (View* v = GetFocusManager()->GetFocusedView();
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 View::CalculateOffsetToAncestorWithLayer(offset, layer_parent); 586 View::CalculateOffsetToAncestorWithLayer(offset, layer_parent);
579 if (!layer()) 587 if (!layer())
580 widget_->CalculateOffsetToAncestorWithLayer(offset, layer_parent); 588 widget_->CalculateOffsetToAncestorWithLayer(offset, layer_parent);
581 } 589 }
582 590
583 //////////////////////////////////////////////////////////////////////////////// 591 ////////////////////////////////////////////////////////////////////////////////
584 // RootView, private: 592 // RootView, private:
585 593
586 // Input ----------------------------------------------------------------------- 594 // Input -----------------------------------------------------------------------
587 595
588 void RootView::UpdateCursor(const MouseEvent& event) { 596 void RootView::UpdateCursor(const ui::MouseEvent& event) {
589 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) { 597 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) {
590 View* v = GetEventHandlerForPoint(event.location()); 598 View* v = GetEventHandlerForPoint(event.location());
591 widget_->SetCursor(v->GetCursor(MouseEvent(event, this, v))); 599 ui::MouseEvent me(event, static_cast<View*>(this), v);
600 widget_->SetCursor(v->GetCursor(me));
592 } 601 }
593 } 602 }
594 603
595 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) { 604 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) {
596 last_mouse_event_flags_ = event.flags(); 605 last_mouse_event_flags_ = event.flags();
597 last_mouse_event_x_ = event.x(); 606 last_mouse_event_x_ = event.x();
598 last_mouse_event_y_ = event.y(); 607 last_mouse_event_y_ = event.y();
599 } 608 }
600 609
601 } // namespace internal 610 } // namespace internal
602 } // namespace views 611 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/root_view.h ('k') | ui/views/widget/widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698