OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/layer_tree_host_common.h" | 5 #include "cc/layer_tree_host_common.h" |
6 | 6 |
7 #include "cc/layer.h" | 7 #include "cc/layer.h" |
8 #include "cc/layer_impl.h" | 8 #include "cc/layer_impl.h" |
9 #include "cc/layer_iterator.h" | 9 #include "cc/layer_iterator.h" |
10 #include "cc/layer_sorter.h" | 10 #include "cc/layer_sorter.h" |
11 #include "cc/math_util.h" | 11 #include "cc/math_util.h" |
12 #include "cc/render_surface.h" | 12 #include "cc/render_surface.h" |
13 #include "cc/render_surface_impl.h" | 13 #include "cc/render_surface_impl.h" |
| 14 #include "ui/gfx/point_conversions.h" |
14 #include "ui/gfx/rect_conversions.h" | 15 #include "ui/gfx/rect_conversions.h" |
15 #include <algorithm> | 16 #include <algorithm> |
16 #include <public/WebTransformationMatrix.h> | 17 #include <public/WebTransformationMatrix.h> |
17 | 18 |
18 using WebKit::WebTransformationMatrix; | 19 using WebKit::WebTransformationMatrix; |
19 | 20 |
20 namespace cc { | 21 namespace cc { |
21 | 22 |
22 ScrollAndScaleSet::ScrollAndScaleSet() | 23 ScrollAndScaleSet::ScrollAndScaleSet() |
23 { | 24 { |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 bool clipped = false; | 872 bool clipped = false; |
872 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(localSpaceToSc
reenSpaceTransform.inverse(), screenSpacePoint, clipped); | 873 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(localSpaceToSc
reenSpaceTransform.inverse(), screenSpacePoint, clipped); |
873 | 874 |
874 // If projectPoint could not project to a valid value, then we assume that t
his point doesn't hit this rect. | 875 // If projectPoint could not project to a valid value, then we assume that t
his point doesn't hit this rect. |
875 if (clipped) | 876 if (clipped) |
876 return false; | 877 return false; |
877 | 878 |
878 return localSpaceRect.Contains(hitTestPointInLocalSpace); | 879 return localSpaceRect.Contains(hitTestPointInLocalSpace); |
879 } | 880 } |
880 | 881 |
| 882 static bool pointHitsRegion(gfx::PointF screenSpacePoint, const WebTransformatio
nMatrix& screenSpaceTransform, const Region& layerSpaceRegion, float layerConten
tScaleX, float layerContentScaleY) |
| 883 { |
| 884 // If the transform is not invertible, then assume that this point doesn't h
it this region. |
| 885 if (!screenSpaceTransform.isInvertible()) |
| 886 return false; |
| 887 |
| 888 // Transform the hit test point from screen space to the local space of the
given region. |
| 889 bool clipped = false; |
| 890 gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(screenSpaceT
ransform.inverse(), screenSpacePoint, clipped); |
| 891 gfx::PointF hitTestPointInLayerSpace = gfx::ScalePoint(hitTestPointInContent
Space, 1 / layerContentScaleX, 1 / layerContentScaleY); |
| 892 |
| 893 // If projectPoint could not project to a valid value, then we assume that t
his point doesn't hit this region. |
| 894 if (clipped) |
| 895 return false; |
| 896 |
| 897 return layerSpaceRegion.Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpac
e)); |
| 898 } |
| 899 |
881 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin
t, LayerImpl* layer) | 900 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin
t, LayerImpl* layer) |
882 { | 901 { |
883 LayerImpl* currentLayer = layer; | 902 LayerImpl* currentLayer = layer; |
884 | 903 |
885 // Walk up the layer tree and hit-test any renderSurfaces and any layer clip
Rects that are active. | 904 // Walk up the layer tree and hit-test any renderSurfaces and any layer clip
Rects that are active. |
886 while (currentLayer) { | 905 while (currentLayer) { |
887 if (currentLayer->renderSurface() && !pointHitsRect(screenSpacePoint, cu
rrentLayer->renderSurface()->screenSpaceTransform(), currentLayer->renderSurface
()->contentRect())) | 906 if (currentLayer->renderSurface() && !pointHitsRect(screenSpacePoint, cu
rrentLayer->renderSurface()->screenSpaceTransform(), currentLayer->renderSurface
()->contentRect())) |
888 return true; | 907 return true; |
889 | 908 |
890 // Note that drawableContentRects are actually in targetSurface space, s
o the transform we | 909 // Note that drawableContentRects are actually in targetSurface space, s
o the transform we |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 continue; | 944 continue; |
926 | 945 |
927 foundLayer = currentLayer; | 946 foundLayer = currentLayer; |
928 break; | 947 break; |
929 } | 948 } |
930 | 949 |
931 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. | 950 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. |
932 return foundLayer; | 951 return foundLayer; |
933 } | 952 } |
934 | 953 |
| 954 LayerImpl* LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(co
nst gfx::PointF& screenSpacePoint, std::vector<LayerImpl*>& renderSurfaceLayerLi
st) |
| 955 { |
| 956 LayerImpl* foundLayer = 0; |
| 957 |
| 958 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl,
LayerIteratorActions::FrontToBack> LayerIteratorType; |
| 959 LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList); |
| 960 |
| 961 for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList
); it != end; ++it) { |
| 962 // We don't want to consider renderSurfaces for hit testing. |
| 963 if (!it.representsItself()) |
| 964 continue; |
| 965 |
| 966 LayerImpl* currentLayer = (*it); |
| 967 |
| 968 if (currentLayer->touchEventHandlerRegion().IsEmpty()) |
| 969 continue; |
| 970 |
| 971 if (!pointHitsRegion(screenSpacePoint, currentLayer->screenSpaceTransfor
m(), currentLayer->touchEventHandlerRegion(), currentLayer->contentsScaleX(), cu
rrentLayer->contentsScaleY())) |
| 972 continue; |
| 973 |
| 974 // At this point, we think the point does hit the touch event handler re
gion on the layer, but we need to walk up |
| 975 // the parents to ensure that the layer was not clipped in such a way th
at the |
| 976 // hit point actually should not hit the layer. |
| 977 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, currentLayer)) |
| 978 continue; |
| 979 |
| 980 foundLayer = currentLayer; |
| 981 break; |
| 982 } |
| 983 |
| 984 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. |
| 985 return foundLayer; |
| 986 } |
| 987 |
935 } // namespace cc | 988 } // namespace cc |
OLD | NEW |