| 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 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2473 // 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 |
| 2474 // the RootView can detect it and avoid calling us back. | 2478 // the RootView can detect it and avoid calling us back. |
| 2475 gfx::Point widget_location(event.location()); | 2479 gfx::Point widget_location(event.location()); |
| 2476 ConvertPointToWidget(this, &widget_location); | 2480 ConvertPointToWidget(this, &widget_location); |
| 2477 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2481 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
| 2478 // WARNING: we may have been deleted. | 2482 // WARNING: we may have been deleted. |
| 2479 return true; | 2483 return true; |
| 2480 } | 2484 } |
| 2481 | 2485 |
| 2482 } // namespace views | 2486 } // namespace views |
| OLD | NEW |