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> |
11 | 11 |
12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "third_party/skia/include/core/SkRect.h" | 18 #include "third_party/skia/include/core/SkRect.h" |
19 #include "ui/accessibility/ax_enums.h" | 19 #include "ui/accessibility/ax_enums.h" |
| 20 #include "ui/base/cursor/cursor.h" |
20 #include "ui/base/dragdrop/drag_drop_types.h" | 21 #include "ui/base/dragdrop/drag_drop_types.h" |
21 #include "ui/base/ui_base_switches_util.h" | 22 #include "ui/base/ui_base_switches_util.h" |
22 #include "ui/compositor/compositor.h" | 23 #include "ui/compositor/compositor.h" |
23 #include "ui/compositor/layer.h" | 24 #include "ui/compositor/layer.h" |
24 #include "ui/compositor/layer_animator.h" | 25 #include "ui/compositor/layer_animator.h" |
25 #include "ui/events/event_target_iterator.h" | 26 #include "ui/events/event_target_iterator.h" |
26 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/interpolated_transform.h" | 28 #include "ui/gfx/interpolated_transform.h" |
28 #include "ui/gfx/path.h" | 29 #include "ui/gfx/path.h" |
29 #include "ui/gfx/point3_f.h" | 30 #include "ui/gfx/point3_f.h" |
(...skipping 10 matching lines...) Expand all Loading... |
40 #include "ui/views/context_menu_controller.h" | 41 #include "ui/views/context_menu_controller.h" |
41 #include "ui/views/drag_controller.h" | 42 #include "ui/views/drag_controller.h" |
42 #include "ui/views/layout/layout_manager.h" | 43 #include "ui/views/layout/layout_manager.h" |
43 #include "ui/views/rect_based_targeting_utils.h" | 44 #include "ui/views/rect_based_targeting_utils.h" |
44 #include "ui/views/views_delegate.h" | 45 #include "ui/views/views_delegate.h" |
45 #include "ui/views/widget/native_widget_private.h" | 46 #include "ui/views/widget/native_widget_private.h" |
46 #include "ui/views/widget/root_view.h" | 47 #include "ui/views/widget/root_view.h" |
47 #include "ui/views/widget/tooltip_manager.h" | 48 #include "ui/views/widget/tooltip_manager.h" |
48 #include "ui/views/widget/widget.h" | 49 #include "ui/views/widget/widget.h" |
49 | 50 |
50 #if defined(USE_AURA) | |
51 #include "ui/base/cursor/cursor.h" | |
52 #endif | |
53 | |
54 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
55 #include "base/win/scoped_gdi_object.h" | 52 #include "base/win/scoped_gdi_object.h" |
56 #endif | 53 #endif |
57 | 54 |
58 namespace { | 55 namespace { |
59 | 56 |
60 // Whether to use accelerated compositing when necessary (e.g. when a view has a | 57 // Whether to use accelerated compositing when necessary (e.g. when a view has a |
61 // transformation). | 58 // transformation). |
62 #if defined(USE_AURA) | 59 // TODO(sky): nuke this as its always true now. |
63 bool use_acceleration_when_possible = true; | 60 bool use_acceleration_when_possible = true; |
64 #else | |
65 bool use_acceleration_when_possible = false; | |
66 #endif | |
67 | 61 |
68 #if defined(OS_WIN) | 62 #if defined(OS_WIN) |
69 const bool kContextMenuOnMousePress = false; | 63 const bool kContextMenuOnMousePress = false; |
70 #else | 64 #else |
71 const bool kContextMenuOnMousePress = true; | 65 const bool kContextMenuOnMousePress = true; |
72 #endif | 66 #endif |
73 | 67 |
74 // The minimum percentage of a view's area that needs to be covered by a rect | 68 // The minimum percentage of a view's area that needs to be covered by a rect |
75 // representing a touch region in order for that view to be considered by the | 69 // representing a touch region in order for that view to be considered by the |
76 // rect-based targeting algorithm. | 70 // rect-based targeting algorithm. |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 ConvertPointToTarget(this, child, &point_in_child_coords); | 917 ConvertPointToTarget(this, child, &point_in_child_coords); |
924 View* handler = child->GetTooltipHandlerForPoint(point_in_child_coords); | 918 View* handler = child->GetTooltipHandlerForPoint(point_in_child_coords); |
925 if (handler) | 919 if (handler) |
926 return handler; | 920 return handler; |
927 } | 921 } |
928 return this; | 922 return this; |
929 } | 923 } |
930 | 924 |
931 gfx::NativeCursor View::GetCursor(const ui::MouseEvent& event) { | 925 gfx::NativeCursor View::GetCursor(const ui::MouseEvent& event) { |
932 #if defined(OS_WIN) | 926 #if defined(OS_WIN) |
933 #if defined(USE_AURA) | |
934 static ui::Cursor arrow; | 927 static ui::Cursor arrow; |
935 if (!arrow.platform()) | 928 if (!arrow.platform()) |
936 arrow.SetPlatformCursor(LoadCursor(NULL, IDC_ARROW)); | 929 arrow.SetPlatformCursor(LoadCursor(NULL, IDC_ARROW)); |
937 return arrow; | 930 return arrow; |
938 #else | 931 #else |
939 static HCURSOR arrow = LoadCursor(NULL, IDC_ARROW); | |
940 return arrow; | |
941 #endif | |
942 #else | |
943 return gfx::kNullCursor; | 932 return gfx::kNullCursor; |
944 #endif | 933 #endif |
945 } | 934 } |
946 | 935 |
947 bool View::HitTestPoint(const gfx::Point& point) const { | 936 bool View::HitTestPoint(const gfx::Point& point) const { |
948 return HitTestRect(gfx::Rect(point, gfx::Size(1, 1))); | 937 return HitTestRect(gfx::Rect(point, gfx::Size(1, 1))); |
949 } | 938 } |
950 | 939 |
951 bool View::HitTestRect(const gfx::Rect& rect) const { | 940 bool View::HitTestRect(const gfx::Rect& rect) const { |
952 if (GetLocalBounds().Intersects(rect)) { | 941 if (GetLocalBounds().Intersects(rect)) { |
953 if (HasHitTestMask()) { | 942 if (HasHitTestMask()) { |
954 gfx::Path mask; | 943 gfx::Path mask; |
955 HitTestSource source = HIT_TEST_SOURCE_MOUSE; | 944 HitTestSource source = HIT_TEST_SOURCE_MOUSE; |
956 if (!views::UsePointBasedTargeting(rect)) | 945 if (!views::UsePointBasedTargeting(rect)) |
957 source = HIT_TEST_SOURCE_TOUCH; | 946 source = HIT_TEST_SOURCE_TOUCH; |
958 GetHitTestMask(source, &mask); | 947 GetHitTestMask(source, &mask); |
959 #if defined(USE_AURA) | |
960 // TODO: should we use this every where? | |
961 SkRegion clip_region; | 948 SkRegion clip_region; |
962 clip_region.setRect(0, 0, width(), height()); | 949 clip_region.setRect(0, 0, width(), height()); |
963 SkRegion mask_region; | 950 SkRegion mask_region; |
964 return mask_region.setPath(mask, clip_region) && | 951 return mask_region.setPath(mask, clip_region) && |
965 mask_region.intersects(RectToSkIRect(rect)); | 952 mask_region.intersects(RectToSkIRect(rect)); |
966 #elif defined(OS_WIN) | |
967 base::win::ScopedRegion rgn(mask.CreateNativeRegion()); | |
968 const RECT r(rect.ToRECT()); | |
969 return RectInRegion(rgn, &r) != 0; | |
970 #endif | |
971 } | 953 } |
972 // No mask, but inside our bounds. | 954 // No mask, but inside our bounds. |
973 return true; | 955 return true; |
974 } | 956 } |
975 // Outside our bounds. | 957 // Outside our bounds. |
976 return false; | 958 return false; |
977 } | 959 } |
978 | 960 |
979 bool View::IsMouseHovered() { | 961 bool View::IsMouseHovered() { |
980 // If we haven't yet been placed in an onscreen view hierarchy, we can't be | 962 // If we haven't yet been placed in an onscreen view hierarchy, we can't be |
(...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2390 // Message the RootView to do the drag and drop. That way if we're removed | 2372 // Message the RootView to do the drag and drop. That way if we're removed |
2391 // the RootView can detect it and avoid calling us back. | 2373 // the RootView can detect it and avoid calling us back. |
2392 gfx::Point widget_location(event.location()); | 2374 gfx::Point widget_location(event.location()); |
2393 ConvertPointToWidget(this, &widget_location); | 2375 ConvertPointToWidget(this, &widget_location); |
2394 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2376 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2395 // WARNING: we may have been deleted. | 2377 // WARNING: we may have been deleted. |
2396 return true; | 2378 return true; |
2397 } | 2379 } |
2398 | 2380 |
2399 } // namespace views | 2381 } // namespace views |
OLD | NEW |