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

Unified Diff: ui/views/view.cc

Issue 265713007: views: Update event-related API to use PointF/RectF instead of Point/Rect. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/view.cc
diff --git a/ui/views/view.cc b/ui/views/view.cc
index 2918ee1aa908ae9dc847777214cfe680b8c38149..a10ff44423c6681e87e7095bee28fefd4c7aacc8 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -818,18 +818,18 @@ const ui::NativeTheme* View::GetNativeTheme() const {
// Input -----------------------------------------------------------------------
-View* View::GetEventHandlerForPoint(const gfx::Point& point) {
- return GetEventHandlerForRect(gfx::Rect(point, gfx::Size(1, 1)));
+View* View::GetEventHandlerForPoint(const gfx::PointF& point) {
+ return GetEventHandlerForRect(gfx::RectF(point, gfx::Size(1, 1)));
}
-View* View::GetEventHandlerForRect(const gfx::Rect& rect) {
+View* View::GetEventHandlerForRect(const gfx::RectF& rect) {
// |rect_view| represents the current best candidate to return
// if rect-based targeting (i.e., fuzzing) is used.
// |rect_view_distance| is used to keep track of the distance
// between the center point of |rect_view| and the center
// point of |rect|.
View* rect_view = NULL;
- int rect_view_distance = INT_MAX;
+ float rect_view_distance = std::numeric_limits<float>::max();
// |point_view| represents the view that would have been returned
// from this function call if point-based targeting were used.
@@ -841,10 +841,8 @@ View* View::GetEventHandlerForRect(const gfx::Rect& rect) {
// Ignore any children which are invisible or do not intersect |rect|.
if (!child->visible())
continue;
- gfx::RectF rect_in_child_coords_f(rect);
- ConvertRectToTarget(this, child, &rect_in_child_coords_f);
- gfx::Rect rect_in_child_coords = gfx::ToEnclosingRect(
- rect_in_child_coords_f);
+ gfx::RectF rect_in_child_coords(rect);
+ ConvertRectToTarget(this, child, &rect_in_child_coords);
if (!child->HitTestRect(rect_in_child_coords))
continue;
@@ -860,9 +858,9 @@ View* View::GetEventHandlerForRect(const gfx::Rect& rect) {
if (views::PercentCoveredBy(cur_view_bounds, rect) >= kRectTargetOverlap) {
// |cur_view| is a suitable candidate for rect-based targeting.
// Check to see if it is the closest suitable candidate so far.
- gfx::Point touch_center(rect.CenterPoint());
- int cur_dist = views::DistanceSquaredFromCenterToPoint(touch_center,
- cur_view_bounds);
+ gfx::PointF touch_center(rect.CenterPoint());
+ float cur_dist = views::DistanceSquaredFromCenterToPoint(touch_center,
+ cur_view_bounds);
if (!rect_view || cur_dist < rect_view_distance) {
rect_view = cur_view;
rect_view_distance = cur_dist;
@@ -870,7 +868,7 @@ View* View::GetEventHandlerForRect(const gfx::Rect& rect) {
} else if (!rect_view && !point_view) {
// Rect-based targeting has not yielded any candidates so far. Check
// if point-based targeting would have selected |cur_view|.
- gfx::Point point_in_child_coords(rect_in_child_coords.CenterPoint());
+ gfx::PointF point_in_child_coords(rect_in_child_coords.CenterPoint());
if (child->HitTestPoint(point_in_child_coords))
point_view = child->GetEventHandlerForPoint(point_in_child_coords);
}
@@ -883,7 +881,7 @@ View* View::GetEventHandlerForRect(const gfx::Rect& rect) {
// see if it is closer than the current best suitable candidate so far.
gfx::Rect local_bounds(GetLocalBounds());
if (views::PercentCoveredBy(local_bounds, rect) >= kRectTargetOverlap) {
- gfx::Point touch_center(rect.CenterPoint());
+ gfx::PointF touch_center(rect.CenterPoint());
int cur_dist = views::DistanceSquaredFromCenterToPoint(touch_center,
local_bounds);
if (!rect_view || cur_dist < rect_view_distance)
@@ -924,12 +922,13 @@ gfx::NativeCursor View::GetCursor(const ui::MouseEvent& event) {
#endif
}
-bool View::HitTestPoint(const gfx::Point& point) const {
- return HitTestRect(gfx::Rect(point, gfx::Size(1, 1)));
+bool View::HitTestPoint(const gfx::PointF& point) const {
+ return HitTestRect(gfx::RectF(point, gfx::Size(1, 1)));
}
-bool View::HitTestRect(const gfx::Rect& rect) const {
- if (GetLocalBounds().Intersects(rect)) {
+bool View::HitTestRect(const gfx::RectF& rect) const {
+ gfx::RectF local_bounds(GetLocalBounds());
+ if (local_bounds.Intersects(rect)) {
if (HasHitTestMask()) {
gfx::Path mask;
HitTestSource source = HIT_TEST_SOURCE_MOUSE;
@@ -1292,9 +1291,9 @@ void View::OnDragDone() {
}
// static
-bool View::ExceededDragThreshold(const gfx::Vector2d& delta) {
- return (abs(delta.x()) > GetHorizontalDragThreshold() ||
- abs(delta.y()) > GetVerticalDragThreshold());
+bool View::ExceededDragThreshold(const gfx::Vector2dF& delta) {
+ return (fabs(delta.x()) > GetHorizontalDragThreshold() ||
+ fabs(delta.y()) > GetVerticalDragThreshold());
}
// Accessibility----------------------------------------------------------------
@@ -1612,13 +1611,13 @@ gfx::Point View::GetKeyboardContextMenuLocation() {
// Drag and drop ---------------------------------------------------------------
-int View::GetDragOperations(const gfx::Point& press_pt) {
+int View::GetDragOperations(const gfx::PointF& press_pt) {
return drag_controller_ ?
drag_controller_->GetDragOperationsForView(this, press_pt) :
ui::DragDropTypes::DRAG_NONE;
}
-void View::WriteDragData(const gfx::Point& press_pt, OSExchangeData* data) {
+void View::WriteDragData(const gfx::PointF& press_pt, OSExchangeData* data) {
DCHECK(drag_controller_);
drag_controller_->WriteDragDataForView(this, press_pt, data);
}
@@ -1755,10 +1754,10 @@ std::string View::DoPrintViewGraph(bool first, View* view_with_children) {
void View::DragInfo::Reset() {
possible_drag = false;
- start_pt = gfx::Point();
+ start_pt = gfx::PointF();
}
-void View::DragInfo::PossibleDrag(const gfx::Point& p) {
+void View::DragInfo::PossibleDrag(const gfx::PointF& p) {
possible_drag = true;
start_pt = p;
}
@@ -2367,7 +2366,7 @@ void View::UpdateTooltip() {
// Drag and drop ---------------------------------------------------------------
bool View::DoDrag(const ui::LocatedEvent& event,
- const gfx::Point& press_pt,
+ const gfx::PointF& press_pt,
ui::DragDropTypes::DragEventSource source) {
int drag_operations = GetDragOperations(press_pt);
if (drag_operations == ui::DragDropTypes::DRAG_NONE)

Powered by Google App Engine
This is Rietveld 408576698