| Index: ui/views/view.cc
|
| diff --git a/ui/views/view.cc b/ui/views/view.cc
|
| index 078d42a75a3b0855fad2aca1fdbb7eb20fdf0fbb..52ffc0876bb90e0207e73af477e87d9439fa344d 100644
|
| --- a/ui/views/view.cc
|
| +++ b/ui/views/view.cc
|
| @@ -27,6 +27,7 @@
|
| #include "ui/views/context_menu_controller.h"
|
| #include "ui/views/drag_controller.h"
|
| #include "ui/views/layout/layout_manager.h"
|
| +#include "ui/views/view_constants.h"
|
| #include "ui/views/views_delegate.h"
|
| #include "ui/views/widget/native_widget_private.h"
|
| #include "ui/views/widget/root_view.h"
|
| @@ -80,6 +81,44 @@ const views::View* GetHierarchyRoot(const views::View* view) {
|
| return root;
|
| }
|
|
|
| +// Returns the percentage of |rect_1|'s area that is covered by |rect_2|.
|
| +float PercentCoveredBy(const gfx::Rect& rect_1, const gfx::Rect& rect_2) {
|
| + gfx::Rect intersection(rect_1.Intersect(rect_2));
|
| + float intersection_area = intersection.size().GetArea();
|
| + float rect_1_area = rect_1.size().GetArea();
|
| + return intersection_area / rect_1_area;
|
| +}
|
| +
|
| +int DistanceToInterval(int pos, int start, int end) {
|
| + if (pos < start)
|
| + return start - pos;
|
| + if (pos > end)
|
| + return end - pos;
|
| + return 0;
|
| +}
|
| +
|
| +// Returns the square of the distance from |point| to the center line of
|
| +// |target_rect|. The center line of a rectangle is obtained by repeatedly
|
| +// stripping away 1px borders around the rectangle until a line remains.
|
| +int DistanceSquaredFromCenterLineToPoint(const gfx::Point& point,
|
| + const gfx::Rect& target_rect) {
|
| + gfx::Point center_point = target_rect.CenterPoint();
|
| + int dx = center_point.x() - point.x();
|
| + int dy = center_point.y() - point.y();
|
| +
|
| + if (target_rect.width() > target_rect.height()) {
|
| + dx = DistanceToInterval(point.x(),
|
| + target_rect.x() + (target_rect.height() / 2),
|
| + target_rect.right() - (target_rect.height() / 2));
|
| + } else {
|
| + dy = DistanceToInterval(point.y(),
|
| + target_rect.y() + (target_rect.width() / 2),
|
| + target_rect.bottom() - (target_rect.width() / 2));
|
| + }
|
| +
|
| + return (dx * dx) + (dy * dy);
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace views {
|
| @@ -764,6 +803,42 @@ View* View::GetEventHandlerForPoint(const gfx::Point& point) {
|
| return this;
|
| }
|
|
|
| +View* View::GetEventHandlerForRect(const gfx::Rect& touch_rect) {
|
| + if (!child_count()) {
|
| + gfx::Rect view_rect(GetBoundsInScreen());
|
| + if (PercentCoveredBy(view_rect, touch_rect) >= kFuzzingOverlapPercentage)
|
| + return this;
|
| + return NULL;
|
| + }
|
| +
|
| + View* closest_view = NULL;
|
| + int best_dist_so_far = INT_MAX;
|
| + for (int i = child_count() - 1; i >= 0; --i) {
|
| + View* child = child_at(i);
|
| + if (!child->visible())
|
| + continue;
|
| +
|
| + gfx::Rect child_rect(child->GetBoundsInScreen());
|
| + if (!child_rect.Intersects(touch_rect))
|
| + continue;
|
| +
|
| + View* cur_view = child->GetEventHandlerForRect(touch_rect);
|
| + if (!cur_view)
|
| + continue;
|
| +
|
| + gfx::Point touch_center(touch_rect.CenterPoint());
|
| + gfx::Rect cur_rect(cur_view->GetBoundsInScreen());
|
| + int cur_dist = DistanceSquaredFromCenterLineToPoint(touch_center,
|
| + cur_rect);
|
| + if (!closest_view || cur_dist < best_dist_so_far) {
|
| + closest_view = cur_view;
|
| + best_dist_so_far = cur_dist;
|
| + }
|
| + }
|
| +
|
| + return closest_view;
|
| +}
|
| +
|
| gfx::NativeCursor View::GetCursor(const MouseEvent& event) {
|
| #if defined(OS_WIN) && !defined(USE_AURA)
|
| static HCURSOR arrow = LoadCursor(NULL, IDC_ARROW);
|
|
|