OLD | NEW |
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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
6 | 6 |
7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 return cur_view; | 868 return cur_view; |
869 | 869 |
870 gfx::RectF cur_view_bounds_f(cur_view->GetLocalBounds()); | 870 gfx::RectF cur_view_bounds_f(cur_view->GetLocalBounds()); |
871 ConvertRectToTarget(cur_view, this, &cur_view_bounds_f); | 871 ConvertRectToTarget(cur_view, this, &cur_view_bounds_f); |
872 gfx::Rect cur_view_bounds = gfx::ToEnclosingRect( | 872 gfx::Rect cur_view_bounds = gfx::ToEnclosingRect( |
873 cur_view_bounds_f); | 873 cur_view_bounds_f); |
874 if (views::PercentCoveredBy(cur_view_bounds, rect) >= kRectTargetOverlap) { | 874 if (views::PercentCoveredBy(cur_view_bounds, rect) >= kRectTargetOverlap) { |
875 // |cur_view| is a suitable candidate for rect-based targeting. | 875 // |cur_view| is a suitable candidate for rect-based targeting. |
876 // Check to see if it is the closest suitable candidate so far. | 876 // Check to see if it is the closest suitable candidate so far. |
877 gfx::Point touch_center(rect.CenterPoint()); | 877 gfx::Point touch_center(rect.CenterPoint()); |
878 int cur_dist = views::DistanceSquaredFromCenterLineToPoint( | 878 int cur_dist = views::DistanceSquaredFromCenterToPoint(touch_center, |
879 touch_center, cur_view_bounds); | 879 cur_view_bounds); |
880 if (!rect_view || cur_dist < rect_view_distance) { | 880 if (!rect_view || cur_dist < rect_view_distance) { |
881 rect_view = cur_view; | 881 rect_view = cur_view; |
882 rect_view_distance = cur_dist; | 882 rect_view_distance = cur_dist; |
883 } | 883 } |
884 } else if (!rect_view && !point_view) { | 884 } else if (!rect_view && !point_view) { |
885 // Rect-based targeting has not yielded any candidates so far. Check | 885 // Rect-based targeting has not yielded any candidates so far. Check |
886 // if point-based targeting would have selected |cur_view|. | 886 // if point-based targeting would have selected |cur_view|. |
887 gfx::Point point_in_child_coords(rect_in_child_coords.CenterPoint()); | 887 gfx::Point point_in_child_coords(rect_in_child_coords.CenterPoint()); |
888 if (child->HitTestPoint(point_in_child_coords)) | 888 if (child->HitTestPoint(point_in_child_coords)) |
889 point_view = child->GetEventHandlerForPoint(point_in_child_coords); | 889 point_view = child->GetEventHandlerForPoint(point_in_child_coords); |
890 } | 890 } |
891 } | 891 } |
892 | 892 |
893 if (views::UsePointBasedTargeting(rect) || (!rect_view && !point_view)) | 893 if (views::UsePointBasedTargeting(rect) || (!rect_view && !point_view)) |
894 return this; | 894 return this; |
895 | 895 |
896 // If |this| is a suitable candidate for rect-based targeting, check to | 896 // If |this| is a suitable candidate for rect-based targeting, check to |
897 // see if it is closer than the current best suitable candidate so far. | 897 // see if it is closer than the current best suitable candidate so far. |
898 gfx::Rect local_bounds(GetLocalBounds()); | 898 gfx::Rect local_bounds(GetLocalBounds()); |
899 if (views::PercentCoveredBy(local_bounds, rect) >= kRectTargetOverlap) { | 899 if (views::PercentCoveredBy(local_bounds, rect) >= kRectTargetOverlap) { |
900 gfx::Point touch_center(rect.CenterPoint()); | 900 gfx::Point touch_center(rect.CenterPoint()); |
901 int cur_dist = views::DistanceSquaredFromCenterLineToPoint(touch_center, | 901 int cur_dist = views::DistanceSquaredFromCenterToPoint(touch_center, |
902 local_bounds); | 902 local_bounds); |
903 if (!rect_view || cur_dist < rect_view_distance) | 903 if (!rect_view || cur_dist < rect_view_distance) |
904 rect_view = this; | 904 rect_view = this; |
905 } | 905 } |
906 | 906 |
907 return rect_view ? rect_view : point_view; | 907 return rect_view ? rect_view : point_view; |
908 } | 908 } |
909 | 909 |
910 View* View::GetTooltipHandlerForPoint(const gfx::Point& point) { | 910 View* View::GetTooltipHandlerForPoint(const gfx::Point& point) { |
911 if (!HitTestPoint(point)) | 911 if (!HitTestPoint(point)) |
912 return NULL; | 912 return NULL; |
(...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2395 // Message the RootView to do the drag and drop. That way if we're removed | 2395 // Message the RootView to do the drag and drop. That way if we're removed |
2396 // the RootView can detect it and avoid calling us back. | 2396 // the RootView can detect it and avoid calling us back. |
2397 gfx::Point widget_location(event.location()); | 2397 gfx::Point widget_location(event.location()); |
2398 ConvertPointToWidget(this, &widget_location); | 2398 ConvertPointToWidget(this, &widget_location); |
2399 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2399 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2400 // WARNING: we may have been deleted. | 2400 // WARNING: we may have been deleted. |
2401 return true; | 2401 return true; |
2402 } | 2402 } |
2403 | 2403 |
2404 } // namespace views | 2404 } // namespace views |
OLD | NEW |