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

Side by Side Diff: ui/views/view.cc

Issue 10790019: Add gesture target fuzzing to views (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fuzzing performed on ET_GESTURE_BEGIN 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
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/view.h" 5 #include "ui/views/view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "third_party/skia/include/core/SkRect.h" 15 #include "third_party/skia/include/core/SkRect.h"
16 #include "ui/base/accessibility/accessibility_types.h" 16 #include "ui/base/accessibility/accessibility_types.h"
17 #include "ui/base/dragdrop/drag_drop_types.h" 17 #include "ui/base/dragdrop/drag_drop_types.h"
18 #include "ui/compositor/compositor.h" 18 #include "ui/compositor/compositor.h"
19 #include "ui/compositor/layer.h" 19 #include "ui/compositor/layer.h"
20 #include "ui/compositor/layer_animator.h" 20 #include "ui/compositor/layer_animator.h"
21 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/interpolated_transform.h" 22 #include "ui/gfx/interpolated_transform.h"
23 #include "ui/gfx/path.h" 23 #include "ui/gfx/path.h"
24 #include "ui/gfx/point3.h" 24 #include "ui/gfx/point3.h"
25 #include "ui/gfx/transform.h" 25 #include "ui/gfx/transform.h"
26 #include "ui/views/background.h" 26 #include "ui/views/background.h"
27 #include "ui/views/context_menu_controller.h" 27 #include "ui/views/context_menu_controller.h"
28 #include "ui/views/drag_controller.h" 28 #include "ui/views/drag_controller.h"
29 #include "ui/views/layout/layout_manager.h" 29 #include "ui/views/layout/layout_manager.h"
30 #include "ui/views/view_constants.h"
30 #include "ui/views/views_delegate.h" 31 #include "ui/views/views_delegate.h"
31 #include "ui/views/widget/native_widget_private.h" 32 #include "ui/views/widget/native_widget_private.h"
32 #include "ui/views/widget/root_view.h" 33 #include "ui/views/widget/root_view.h"
33 #include "ui/views/widget/tooltip_manager.h" 34 #include "ui/views/widget/tooltip_manager.h"
34 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
35 36
36 #if defined(OS_WIN) 37 #if defined(OS_WIN)
37 #include "base/win/scoped_gdi_object.h" 38 #include "base/win/scoped_gdi_object.h"
38 #include "ui/views/accessibility/native_view_accessibility_win.h" 39 #include "ui/views/accessibility/native_view_accessibility_win.h"
39 #endif 40 #endif
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 }; 74 };
74 75
75 // Returns the top view in |view|'s hierarchy. 76 // Returns the top view in |view|'s hierarchy.
76 const views::View* GetHierarchyRoot(const views::View* view) { 77 const views::View* GetHierarchyRoot(const views::View* view) {
77 const views::View* root = view; 78 const views::View* root = view;
78 while (root && root->parent()) 79 while (root && root->parent())
79 root = root->parent(); 80 root = root->parent();
80 return root; 81 return root;
81 } 82 }
82 83
84 // Returns the percentage of |rect_1|'s area that is covered by |rect_2|.
85 float PercentCoveredBy(const gfx::Rect& rect_1, const gfx::Rect& rect_2) {
86 gfx::Rect intersection(rect_1.Intersect(rect_2));
87 float intersection_area = intersection.size().GetArea();
88 float rect_1_area = rect_1.size().GetArea();
89 return intersection_area / rect_1_area;
90 }
91
92 int DistanceToInterval(int pos, int start, int end) {
93 if (pos < start)
94 return start - pos;
95 if (pos > end)
96 return end - pos;
97 return 0;
98 }
99
100 // Returns the square of the distance from |point| to the center line of
101 // |target_rect|. The center line of a rectangle is obtained by repeatedly
102 // stripping away 1px borders around the rectangle until a line remains.
103 int DistanceSquaredFromCenterLineToPoint(const gfx::Point& point,
104 const gfx::Rect& target_rect) {
105 gfx::Point center_point = target_rect.CenterPoint();
106 int dx = center_point.x() - point.x();
107 int dy = center_point.y() - point.y();
108
109 if (target_rect.width() > target_rect.height()) {
110 dx = DistanceToInterval(point.x(),
111 target_rect.x() + (target_rect.height() / 2),
112 target_rect.right() - (target_rect.height() / 2));
113 } else {
114 dy = DistanceToInterval(point.y(),
115 target_rect.y() + (target_rect.width() / 2),
116 target_rect.bottom() - (target_rect.width() / 2));
117 }
118
119 return (dx * dx) + (dy * dy);
120 }
121
83 } // namespace 122 } // namespace
84 123
85 namespace views { 124 namespace views {
86 125
87 // static 126 // static
88 ViewsDelegate* ViewsDelegate::views_delegate = NULL; 127 ViewsDelegate* ViewsDelegate::views_delegate = NULL;
89 128
90 // static 129 // static
91 const char View::kViewClassName[] = "views/View"; 130 const char View::kViewClassName[] = "views/View";
92 131
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 continue; 796 continue;
758 797
759 gfx::Point point_in_child_coords(point); 798 gfx::Point point_in_child_coords(point);
760 View::ConvertPointToView(this, child, &point_in_child_coords); 799 View::ConvertPointToView(this, child, &point_in_child_coords);
761 if (child->HitTest(point_in_child_coords)) 800 if (child->HitTest(point_in_child_coords))
762 return child->GetEventHandlerForPoint(point_in_child_coords); 801 return child->GetEventHandlerForPoint(point_in_child_coords);
763 } 802 }
764 return this; 803 return this;
765 } 804 }
766 805
806 View* View::GetEventHandlerForRect(const gfx::Rect& touch_rect) {
807 if (!child_count()) {
808 gfx::Rect view_rect(GetBoundsInScreen());
809 if (PercentCoveredBy(view_rect, touch_rect) >= kFuzzingOverlapPercentage)
810 return this;
811 return NULL;
sadrul 2012/07/26 18:41:28 I still think as long as the touch_rect intersecti
tdanderson 2012/07/27 15:27:04 We talked about this offline, but for the benefit
812 }
813
814 View* closest_view = NULL;
815 int best_dist_so_far = INT_MAX;
816 for (int i = child_count() - 1; i >= 0; --i) {
817 View* child = child_at(i);
818 if (!child->visible())
819 continue;
820
821 gfx::Rect child_rect(child->GetBoundsInScreen());
822 if (!child_rect.Intersects(touch_rect))
823 continue;
824
825 View* cur_view = child->GetEventHandlerForRect(touch_rect);
826 if (!cur_view)
827 continue;
828
829 gfx::Point touch_center(touch_rect.CenterPoint());
830 gfx::Rect cur_rect(cur_view->GetBoundsInScreen());
831 int cur_dist = DistanceSquaredFromCenterLineToPoint(touch_center,
832 cur_rect);
833 if (!closest_view || cur_dist < best_dist_so_far) {
834 closest_view = cur_view;
835 best_dist_so_far = cur_dist;
836 }
837 }
838
839 return closest_view;
840 }
841
767 gfx::NativeCursor View::GetCursor(const MouseEvent& event) { 842 gfx::NativeCursor View::GetCursor(const MouseEvent& event) {
768 #if defined(OS_WIN) && !defined(USE_AURA) 843 #if defined(OS_WIN) && !defined(USE_AURA)
769 static HCURSOR arrow = LoadCursor(NULL, IDC_ARROW); 844 static HCURSOR arrow = LoadCursor(NULL, IDC_ARROW);
770 return arrow; 845 return arrow;
771 #else 846 #else
772 return gfx::kNullCursor; 847 return gfx::kNullCursor;
773 #endif 848 #endif
774 } 849 }
775 850
776 bool View::HitTest(const gfx::Point& l) const { 851 bool View::HitTest(const gfx::Point& l) const {
(...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 gfx::Point widget_location(event.location()); 2182 gfx::Point widget_location(event.location());
2108 ConvertPointToWidget(this, &widget_location); 2183 ConvertPointToWidget(this, &widget_location);
2109 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations); 2184 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations);
2110 return true; 2185 return true;
2111 #else 2186 #else
2112 return false; 2187 return false;
2113 #endif // !defined(OS_MACOSX) 2188 #endif // !defined(OS_MACOSX)
2114 } 2189 }
2115 2190
2116 } // namespace views 2191 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.h ('k') | ui/views/view_constants.h » ('j') | ui/views/widget/root_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698