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

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

Issue 139983009: ui::LocatedEvent location() returns gfx::PointF (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Undo accidental change. Created 6 years, 7 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) 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/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 ui::EventDispatchDetails dispatch_details = 269 ui::EventDispatchDetails dispatch_details =
270 DispatchEvent(mouse_pressed_handler_, &mouse_pressed_event); 270 DispatchEvent(mouse_pressed_handler_, &mouse_pressed_event);
271 if (dispatch_details.dispatcher_destroyed) 271 if (dispatch_details.dispatcher_destroyed)
272 return true; 272 return true;
273 return true; 273 return true;
274 } 274 }
275 DCHECK(!explicit_mouse_handler_); 275 DCHECK(!explicit_mouse_handler_);
276 276
277 bool hit_disabled_view = false; 277 bool hit_disabled_view = false;
278 // Walk up the tree until we find a view that wants the mouse event. 278 // Walk up the tree until we find a view that wants the mouse event.
279 for (mouse_pressed_handler_ = GetEventHandlerForPoint(event.location()); 279 for (mouse_pressed_handler_ =
280 GetEventHandlerForPoint(gfx::ToFlooredPoint(event.location()));
280 mouse_pressed_handler_ && (mouse_pressed_handler_ != this); 281 mouse_pressed_handler_ && (mouse_pressed_handler_ != this);
281 mouse_pressed_handler_ = mouse_pressed_handler_->parent()) { 282 mouse_pressed_handler_ = mouse_pressed_handler_->parent()) {
282 DVLOG(1) << "OnMousePressed testing " 283 DVLOG(1) << "OnMousePressed testing "
283 << mouse_pressed_handler_->GetClassName(); 284 << mouse_pressed_handler_->GetClassName();
284 if (!mouse_pressed_handler_->enabled()) { 285 if (!mouse_pressed_handler_->enabled()) {
285 // Disabled views should eat events instead of propagating them upwards. 286 // Disabled views should eat events instead of propagating them upwards.
286 hit_disabled_view = true; 287 hit_disabled_view = true;
287 break; 288 break;
288 } 289 }
289 290
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 SetMouseHandler(NULL); 389 SetMouseHandler(NULL);
389 if (mouse_pressed_handler) 390 if (mouse_pressed_handler)
390 mouse_pressed_handler->OnMouseCaptureLost(); 391 mouse_pressed_handler->OnMouseCaptureLost();
391 else 392 else
392 gesture_handler->OnMouseCaptureLost(); 393 gesture_handler->OnMouseCaptureLost();
393 // WARNING: we may have been deleted. 394 // WARNING: we may have been deleted.
394 } 395 }
395 } 396 }
396 397
397 void RootView::OnMouseMoved(const ui::MouseEvent& event) { 398 void RootView::OnMouseMoved(const ui::MouseEvent& event) {
398 View* v = GetEventHandlerForPoint(event.location()); 399 View* v = GetEventHandlerForPoint(gfx::ToFlooredPoint(event.location()));
399 // Find the first enabled view, or the existing move handler, whichever comes 400 // Find the first enabled view, or the existing move handler, whichever comes
400 // first. The check for the existing handler is because if a view becomes 401 // first. The check for the existing handler is because if a view becomes
401 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED 402 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED
402 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet. 403 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet.
403 while (v && !v->enabled() && (v != mouse_move_handler_)) 404 while (v && !v->enabled() && (v != mouse_move_handler_))
404 v = v->parent(); 405 v = v->parent();
405 if (v && v != this) { 406 if (v && v != this) {
406 if (v != mouse_move_handler_) { 407 if (v != mouse_move_handler_) {
407 if (mouse_move_handler_ != NULL && 408 if (mouse_move_handler_ != NULL &&
408 (!mouse_move_handler_->notify_enter_exit_on_child() || 409 (!mouse_move_handler_->notify_enter_exit_on_child() ||
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 DispatchEvent(mouse_move_handler_, &exited); 465 DispatchEvent(mouse_move_handler_, &exited);
465 if (dispatch_details.dispatcher_destroyed) 466 if (dispatch_details.dispatcher_destroyed)
466 return; 467 return;
467 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, 468 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED,
468 mouse_move_handler_, NULL); 469 mouse_move_handler_, NULL);
469 mouse_move_handler_ = NULL; 470 mouse_move_handler_ = NULL;
470 } 471 }
471 } 472 }
472 473
473 bool RootView::OnMouseWheel(const ui::MouseWheelEvent& event) { 474 bool RootView::OnMouseWheel(const ui::MouseWheelEvent& event) {
474 for (View* v = GetEventHandlerForPoint(event.location()); 475 for (View* v = GetEventHandlerForPoint(gfx::ToFlooredPoint(event.location()));
475 v && v != this && !event.handled(); v = v->parent()) { 476 v && v != this && !event.handled();
477 v = v->parent()) {
476 ui::EventDispatchDetails dispatch_details = 478 ui::EventDispatchDetails dispatch_details =
477 DispatchEvent(v, const_cast<ui::MouseWheelEvent*>(&event)); 479 DispatchEvent(v, const_cast<ui::MouseWheelEvent*>(&event));
478 if (dispatch_details.dispatcher_destroyed || 480 if (dispatch_details.dispatcher_destroyed ||
479 dispatch_details.target_destroyed) { 481 dispatch_details.target_destroyed) {
480 return event.handled(); 482 return event.handled();
481 } 483 }
482 } 484 }
483 return event.handled(); 485 return event.handled();
484 } 486 }
485 487
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 default: 584 default:
583 break; 585 break;
584 } 586 }
585 587
586 View* gesture_handler = NULL; 588 View* gesture_handler = NULL;
587 if (views::switches::IsRectBasedTargetingEnabled() && 589 if (views::switches::IsRectBasedTargetingEnabled() &&
588 !event->details().bounding_box().IsEmpty()) { 590 !event->details().bounding_box().IsEmpty()) {
589 // TODO(tdanderson): Pass in the bounding box to GetEventHandlerForRect() 591 // TODO(tdanderson): Pass in the bounding box to GetEventHandlerForRect()
590 // once crbug.com/313392 is resolved. 592 // once crbug.com/313392 is resolved.
591 gfx::Rect touch_rect(event->details().bounding_box()); 593 gfx::Rect touch_rect(event->details().bounding_box());
592 touch_rect.set_origin(event->location()); 594 touch_rect.set_origin(gfx::ToFlooredPoint(event->location()));
593 touch_rect.Offset(-touch_rect.width() / 2, -touch_rect.height() / 2); 595 touch_rect.Offset(-touch_rect.width() / 2, -touch_rect.height() / 2);
594 gesture_handler = GetEventHandlerForRect(touch_rect); 596 gesture_handler = GetEventHandlerForRect(touch_rect);
595 } else { 597 } else {
596 gesture_handler = GetEventHandlerForPoint(event->location()); 598 gesture_handler =
599 GetEventHandlerForPoint(gfx::ToFlooredPoint(event->location()));
597 } 600 }
598 601
599 // Walk up the tree until we find a view that wants the gesture event. 602 // Walk up the tree until we find a view that wants the gesture event.
600 for (gesture_handler_ = gesture_handler; 603 for (gesture_handler_ = gesture_handler;
601 gesture_handler_ && (gesture_handler_ != this); 604 gesture_handler_ && (gesture_handler_ != this);
602 gesture_handler_ = gesture_handler_->parent()) { 605 gesture_handler_ = gesture_handler_->parent()) {
603 if (!gesture_handler_->enabled()) { 606 if (!gesture_handler_->enabled()) {
604 // Disabled views eat events but are treated as not handled. 607 // Disabled views eat events but are treated as not handled.
605 return; 608 return;
606 } 609 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 View::DragInfo* RootView::GetDragInfo() { 697 View::DragInfo* RootView::GetDragInfo() {
695 return &drag_info_; 698 return &drag_info_;
696 } 699 }
697 700
698 //////////////////////////////////////////////////////////////////////////////// 701 ////////////////////////////////////////////////////////////////////////////////
699 // RootView, private: 702 // RootView, private:
700 703
701 // Input ----------------------------------------------------------------------- 704 // Input -----------------------------------------------------------------------
702 705
703 void RootView::DispatchScrollEvent(ui::ScrollEvent* event) { 706 void RootView::DispatchScrollEvent(ui::ScrollEvent* event) {
704 for (View* v = GetEventHandlerForPoint(event->location()); 707 for (View* v =
705 v && v != this && !event->stopped_propagation(); v = v->parent()) { 708 GetEventHandlerForPoint(gfx::ToFlooredPoint(event->location()));
709 v && v != this && !event->stopped_propagation();
710 v = v->parent()) {
706 ui::EventDispatchDetails dispatch_details = DispatchEvent(v, event); 711 ui::EventDispatchDetails dispatch_details = DispatchEvent(v, event);
707 if (dispatch_details.dispatcher_destroyed || 712 if (dispatch_details.dispatcher_destroyed ||
708 dispatch_details.target_destroyed) { 713 dispatch_details.target_destroyed) {
709 return; 714 return;
710 } 715 }
711 } 716 }
712 717
713 if (event->handled() || event->type() != ui::ET_SCROLL) 718 if (event->handled() || event->type() != ui::ET_SCROLL)
714 return; 719 return;
715 720
716 // Convert unprocessed scroll events into mouse-wheel events. 721 // Convert unprocessed scroll events into mouse-wheel events.
717 ui::MouseWheelEvent wheel(*event); 722 ui::MouseWheelEvent wheel(*event);
718 if (OnMouseWheel(wheel)) 723 if (OnMouseWheel(wheel))
719 event->SetHandled(); 724 event->SetHandled();
720 } 725 }
721 726
722 void RootView::UpdateCursor(const ui::MouseEvent& event) { 727 void RootView::UpdateCursor(const ui::MouseEvent& event) {
723 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) { 728 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) {
724 View* v = GetEventHandlerForPoint(event.location()); 729 View* v = GetEventHandlerForPoint(gfx::ToFlooredPoint(event.location()));
725 ui::MouseEvent me(event, static_cast<View*>(this), v); 730 ui::MouseEvent me(event, static_cast<View*>(this), v);
726 widget_->SetCursor(v->GetCursor(me)); 731 widget_->SetCursor(v->GetCursor(me));
727 } 732 }
728 } 733 }
729 734
730 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { 735 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) {
731 last_mouse_event_flags_ = event.flags(); 736 last_mouse_event_flags_ = event.flags();
732 last_mouse_event_x_ = event.x(); 737 last_mouse_event_x_ = event.x();
733 last_mouse_event_y_ = event.y(); 738 last_mouse_event_y_ = event.y();
734 } 739 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 781
777 #ifndef NDEBUG 782 #ifndef NDEBUG
778 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); 783 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_));
779 #endif 784 #endif
780 785
781 return details; 786 return details;
782 } 787 }
783 788
784 } // namespace internal 789 } // namespace internal
785 } // namespace views 790 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698