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 10 matching lines...) Expand all Loading... |
21 #include "ui/base/dragdrop/drag_drop_types.h" | 21 #include "ui/base/dragdrop/drag_drop_types.h" |
22 #include "ui/compositor/compositor.h" | 22 #include "ui/compositor/compositor.h" |
23 #include "ui/compositor/layer.h" | 23 #include "ui/compositor/layer.h" |
24 #include "ui/compositor/layer_animator.h" | 24 #include "ui/compositor/layer_animator.h" |
25 #include "ui/events/event_target_iterator.h" | 25 #include "ui/events/event_target_iterator.h" |
26 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/interpolated_transform.h" | 27 #include "ui/gfx/interpolated_transform.h" |
28 #include "ui/gfx/path.h" | 28 #include "ui/gfx/path.h" |
29 #include "ui/gfx/point3_f.h" | 29 #include "ui/gfx/point3_f.h" |
30 #include "ui/gfx/point_conversions.h" | 30 #include "ui/gfx/point_conversions.h" |
31 #include "ui/gfx/rect_conversions.h" | 31 //#include "ui/gfx/rect_conversions.h" |
32 #include "ui/gfx/scoped_canvas.h" | 32 #include "ui/gfx/scoped_canvas.h" |
33 #include "ui/gfx/screen.h" | 33 #include "ui/gfx/screen.h" |
34 #include "ui/gfx/skia_util.h" | 34 #include "ui/gfx/skia_util.h" |
35 #include "ui/gfx/transform.h" | 35 #include "ui/gfx/transform.h" |
36 #include "ui/native_theme/native_theme.h" | 36 #include "ui/native_theme/native_theme.h" |
37 #include "ui/views/accessibility/native_view_accessibility.h" | 37 #include "ui/views/accessibility/native_view_accessibility.h" |
38 #include "ui/views/background.h" | 38 #include "ui/views/background.h" |
39 #include "ui/views/border.h" | 39 #include "ui/views/border.h" |
40 #include "ui/views/context_menu_controller.h" | 40 #include "ui/views/context_menu_controller.h" |
41 #include "ui/views/drag_controller.h" | 41 #include "ui/views/drag_controller.h" |
42 #include "ui/views/focus/view_storage.h" | 42 #include "ui/views/focus/view_storage.h" |
43 #include "ui/views/layout/layout_manager.h" | 43 #include "ui/views/layout/layout_manager.h" |
44 #include "ui/views/rect_based_targeting_utils.h" | 44 //#include "ui/views/rect_based_targeting_utils.h" |
45 #include "ui/views/views_delegate.h" | 45 #include "ui/views/views_delegate.h" |
46 #include "ui/views/widget/native_widget_private.h" | 46 #include "ui/views/widget/native_widget_private.h" |
47 #include "ui/views/widget/root_view.h" | 47 #include "ui/views/widget/root_view.h" |
48 #include "ui/views/widget/tooltip_manager.h" | 48 #include "ui/views/widget/tooltip_manager.h" |
49 #include "ui/views/widget/widget.h" | 49 #include "ui/views/widget/widget.h" |
50 | 50 |
51 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
52 #include "base/win/scoped_gdi_object.h" | 52 #include "base/win/scoped_gdi_object.h" |
53 #endif | 53 #endif |
54 | 54 |
55 namespace { | 55 namespace { |
56 | 56 |
57 #if defined(OS_WIN) | 57 #if defined(OS_WIN) |
58 const bool kContextMenuOnMousePress = false; | 58 const bool kContextMenuOnMousePress = false; |
59 #else | 59 #else |
60 const bool kContextMenuOnMousePress = true; | 60 const bool kContextMenuOnMousePress = true; |
61 #endif | 61 #endif |
62 | 62 |
63 // The minimum percentage of a view's area that needs to be covered by a rect | |
64 // representing a touch region in order for that view to be considered by the | |
65 // rect-based targeting algorithm. | |
66 static const float kRectTargetOverlap = 0.6f; | |
67 | |
68 // Default horizontal drag threshold in pixels. | 63 // Default horizontal drag threshold in pixels. |
69 // Same as what gtk uses. | 64 // Same as what gtk uses. |
70 const int kDefaultHorizontalDragThreshold = 8; | 65 const int kDefaultHorizontalDragThreshold = 8; |
71 | 66 |
72 // Default vertical drag threshold in pixels. | 67 // Default vertical drag threshold in pixels. |
73 // Same as what gtk uses. | 68 // Same as what gtk uses. |
74 const int kDefaultVerticalDragThreshold = 8; | 69 const int kDefaultVerticalDragThreshold = 8; |
75 | 70 |
76 // Returns the top view in |view|'s hierarchy. | 71 // Returns the top view in |view|'s hierarchy. |
77 const views::View* GetHierarchyRoot(const views::View* view) { | 72 const views::View* GetHierarchyRoot(const views::View* view) { |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 return widget ? widget->GetNativeTheme() : ui::NativeTheme::instance(); | 823 return widget ? widget->GetNativeTheme() : ui::NativeTheme::instance(); |
829 } | 824 } |
830 | 825 |
831 // Input ----------------------------------------------------------------------- | 826 // Input ----------------------------------------------------------------------- |
832 | 827 |
833 View* View::GetEventHandlerForPoint(const gfx::Point& point) { | 828 View* View::GetEventHandlerForPoint(const gfx::Point& point) { |
834 return GetEventHandlerForRect(gfx::Rect(point, gfx::Size(1, 1))); | 829 return GetEventHandlerForRect(gfx::Rect(point, gfx::Size(1, 1))); |
835 } | 830 } |
836 | 831 |
837 View* View::GetEventHandlerForRect(const gfx::Rect& rect) { | 832 View* View::GetEventHandlerForRect(const gfx::Rect& rect) { |
| 833 // Terry - make a helper for this logic |
| 834 ViewTargeter* view_targeter = targeter(); |
| 835 if (!view_targeter) |
| 836 view_targeter = GetWidget()->GetRootView()->targeter(); |
| 837 CHECK(view_targeter); |
| 838 return view_targeter->TargetForRect(this, rect); |
| 839 |
| 840 /* |
838 // |rect_view| represents the current best candidate to return | 841 // |rect_view| represents the current best candidate to return |
839 // if rect-based targeting (i.e., fuzzing) is used. | 842 // if rect-based targeting (i.e., fuzzing) is used. |
840 // |rect_view_distance| is used to keep track of the distance | 843 // |rect_view_distance| is used to keep track of the distance |
841 // between the center point of |rect_view| and the center | 844 // between the center point of |rect_view| and the center |
842 // point of |rect|. | 845 // point of |rect|. |
843 View* rect_view = NULL; | 846 View* rect_view = NULL; |
844 int rect_view_distance = INT_MAX; | 847 int rect_view_distance = INT_MAX; |
845 | 848 |
846 // |point_view| represents the view that would have been returned | 849 // |point_view| represents the view that would have been returned |
847 // from this function call if point-based targeting were used. | 850 // from this function call if point-based targeting were used. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 gfx::Rect local_bounds(GetLocalBounds()); | 902 gfx::Rect local_bounds(GetLocalBounds()); |
900 if (views::PercentCoveredBy(local_bounds, rect) >= kRectTargetOverlap) { | 903 if (views::PercentCoveredBy(local_bounds, rect) >= kRectTargetOverlap) { |
901 gfx::Point touch_center(rect.CenterPoint()); | 904 gfx::Point touch_center(rect.CenterPoint()); |
902 int cur_dist = views::DistanceSquaredFromCenterToPoint(touch_center, | 905 int cur_dist = views::DistanceSquaredFromCenterToPoint(touch_center, |
903 local_bounds); | 906 local_bounds); |
904 if (!rect_view || cur_dist < rect_view_distance) | 907 if (!rect_view || cur_dist < rect_view_distance) |
905 rect_view = this; | 908 rect_view = this; |
906 } | 909 } |
907 | 910 |
908 return rect_view ? rect_view : point_view; | 911 return rect_view ? rect_view : point_view; |
| 912 */ |
909 } | 913 } |
910 | 914 |
911 bool View::CanProcessEventsWithinSubtree() const { | 915 bool View::CanProcessEventsWithinSubtree() const { |
912 return true; | 916 return true; |
913 } | 917 } |
914 | 918 |
915 View* View::GetTooltipHandlerForPoint(const gfx::Point& point) { | 919 View* View::GetTooltipHandlerForPoint(const gfx::Point& point) { |
916 if (!HitTestPoint(point) || !CanProcessEventsWithinSubtree()) | 920 if (!HitTestPoint(point) || !CanProcessEventsWithinSubtree()) |
917 return NULL; | 921 return NULL; |
918 | 922 |
(...skipping 22 matching lines...) Expand all Loading... |
941 #else | 945 #else |
942 return gfx::kNullCursor; | 946 return gfx::kNullCursor; |
943 #endif | 947 #endif |
944 } | 948 } |
945 | 949 |
946 bool View::HitTestPoint(const gfx::Point& point) const { | 950 bool View::HitTestPoint(const gfx::Point& point) const { |
947 return HitTestRect(gfx::Rect(point, gfx::Size(1, 1))); | 951 return HitTestRect(gfx::Rect(point, gfx::Size(1, 1))); |
948 } | 952 } |
949 | 953 |
950 bool View::HitTestRect(const gfx::Rect& rect) const { | 954 bool View::HitTestRect(const gfx::Rect& rect) const { |
951 // If no ViewTargeter is installed on |this|, use the ViewTargeter installed | |
952 // on our root view instead. | |
953 ViewTargeter* view_targeter = targeter(); | 955 ViewTargeter* view_targeter = targeter(); |
954 if (!view_targeter) | 956 if (!view_targeter) |
955 view_targeter = GetWidget()->GetRootView()->targeter(); | 957 view_targeter = GetWidget()->GetRootView()->targeter(); |
956 CHECK(view_targeter); | 958 CHECK(view_targeter); |
957 | 959 return view_targeter->DoesIntersectRect(this, rect); |
958 // TODO(tdanderson): The check for !HasHitTestMask() is temporary. Remove | |
959 // the check along with the duplicated code below once all | |
960 // of the masked views subclass MaskedViewDelegate. | |
961 // HasHitTestMask() and GetHitTestMaskDeprecated() can also | |
962 // be removed from the View interface at that time. | |
963 if (!HasHitTestMask()) | |
964 return view_targeter->DoesIntersectRect(this, rect); | |
965 | |
966 if (GetLocalBounds().Intersects(rect)) { | |
967 gfx::Path mask; | |
968 HitTestSource source = HIT_TEST_SOURCE_MOUSE; | |
969 if (!views::UsePointBasedTargeting(rect)) | |
970 source = HIT_TEST_SOURCE_TOUCH; | |
971 GetHitTestMaskDeprecated(source, &mask); | |
972 SkRegion clip_region; | |
973 clip_region.setRect(0, 0, width(), height()); | |
974 SkRegion mask_region; | |
975 return mask_region.setPath(mask, clip_region) && | |
976 mask_region.intersects(RectToSkIRect(rect)); | |
977 } | |
978 // Outside our bounds. | |
979 return false; | |
980 } | 960 } |
981 | 961 |
982 bool View::IsMouseHovered() { | 962 bool View::IsMouseHovered() { |
983 // If we haven't yet been placed in an onscreen view hierarchy, we can't be | 963 // If we haven't yet been placed in an onscreen view hierarchy, we can't be |
984 // hovered. | 964 // hovered. |
985 if (!GetWidget()) | 965 if (!GetWidget()) |
986 return false; | 966 return false; |
987 | 967 |
988 // If mouse events are disabled, then the mouse cursor is invisible and | 968 // If mouse events are disabled, then the mouse cursor is invisible and |
989 // is therefore not hovering over this button. | 969 // is therefore not hovering over this button. |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 // the front. | 1565 // the front. |
1586 for (Views::reverse_iterator it(children_.rbegin()); | 1566 for (Views::reverse_iterator it(children_.rbegin()); |
1587 it != children_.rend(); ++it) { | 1567 it != children_.rend(); ++it) { |
1588 (*it)->ReorderChildLayers(parent_layer); | 1568 (*it)->ReorderChildLayers(parent_layer); |
1589 } | 1569 } |
1590 } | 1570 } |
1591 } | 1571 } |
1592 | 1572 |
1593 // Input ----------------------------------------------------------------------- | 1573 // Input ----------------------------------------------------------------------- |
1594 | 1574 |
1595 bool View::HasHitTestMask() const { | |
1596 return false; | |
1597 } | |
1598 | |
1599 void View::GetHitTestMaskDeprecated(HitTestSource source, | |
1600 gfx::Path* mask) const { | |
1601 DCHECK(mask); | |
1602 } | |
1603 | |
1604 View::DragInfo* View::GetDragInfo() { | 1575 View::DragInfo* View::GetDragInfo() { |
1605 return parent_ ? parent_->GetDragInfo() : NULL; | 1576 return parent_ ? parent_->GetDragInfo() : NULL; |
1606 } | 1577 } |
1607 | 1578 |
1608 // Focus ----------------------------------------------------------------------- | 1579 // Focus ----------------------------------------------------------------------- |
1609 | 1580 |
1610 void View::OnFocus() { | 1581 void View::OnFocus() { |
1611 // TODO(beng): Investigate whether it's possible for us to move this to | 1582 // TODO(beng): Investigate whether it's possible for us to move this to |
1612 // Focus(). | 1583 // Focus(). |
1613 // By default, we clear the native focus. This ensures that no visible native | 1584 // By default, we clear the native focus. This ensures that no visible native |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2506 // Message the RootView to do the drag and drop. That way if we're removed | 2477 // Message the RootView to do the drag and drop. That way if we're removed |
2507 // the RootView can detect it and avoid calling us back. | 2478 // the RootView can detect it and avoid calling us back. |
2508 gfx::Point widget_location(event.location()); | 2479 gfx::Point widget_location(event.location()); |
2509 ConvertPointToWidget(this, &widget_location); | 2480 ConvertPointToWidget(this, &widget_location); |
2510 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2481 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2511 // WARNING: we may have been deleted. | 2482 // WARNING: we may have been deleted. |
2512 return true; | 2483 return true; |
2513 } | 2484 } |
2514 | 2485 |
2515 } // namespace views | 2486 } // namespace views |
OLD | NEW |