| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/layer_tree_host_common.h" | 7 #include "cc/layer_tree_host_common.h" |
| 8 | 8 |
| 9 #include "cc/layer.h" | 9 #include "cc/layer.h" |
| 10 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" |
| (...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, | 852 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, |
| 853 dummyLayerList, layerSorter, maxTextureSize, | 853 dummyLayerList, layerSorter, maxTextureSize, |
| 854 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); | 854 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); |
| 855 | 855 |
| 856 // The dummy layer list should not have been used. | 856 // The dummy layer list should not have been used. |
| 857 DCHECK(dummyLayerList.size() == 0); | 857 DCHECK(dummyLayerList.size() == 0); |
| 858 // A root layer renderSurface should always exist after calculateDrawTransfo
rms. | 858 // A root layer renderSurface should always exist after calculateDrawTransfo
rms. |
| 859 DCHECK(rootLayer->renderSurface()); | 859 DCHECK(rootLayer->renderSurface()); |
| 860 } | 860 } |
| 861 | 861 |
| 862 static bool pointHitsRect(const gfx::Point& screenSpacePoint, const WebTransform
ationMatrix& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) | 862 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const WebTransfor
mationMatrix& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) |
| 863 { | 863 { |
| 864 // If the transform is not invertible, then assume that this point doesn't h
it this rect. | 864 // If the transform is not invertible, then assume that this point doesn't h
it this rect. |
| 865 if (!localSpaceToScreenSpaceTransform.isInvertible()) | 865 if (!localSpaceToScreenSpaceTransform.isInvertible()) |
| 866 return false; | 866 return false; |
| 867 | 867 |
| 868 // Transform the hit test point from screen space to the local space of the
given rect. | 868 // Transform the hit test point from screen space to the local space of the
given rect. |
| 869 bool clipped = false; | 869 bool clipped = false; |
| 870 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(localSpaceToSc
reenSpaceTransform.inverse(), gfx::PointF(screenSpacePoint), clipped); | 870 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(localSpaceToSc
reenSpaceTransform.inverse(), screenSpacePoint, clipped); |
| 871 | 871 |
| 872 // If projectPoint could not project to a valid value, then we assume that t
his point doesn't hit this rect. | 872 // If projectPoint could not project to a valid value, then we assume that t
his point doesn't hit this rect. |
| 873 if (clipped) | 873 if (clipped) |
| 874 return false; | 874 return false; |
| 875 | 875 |
| 876 return localSpaceRect.Contains(hitTestPointInLocalSpace); | 876 return localSpaceRect.Contains(hitTestPointInLocalSpace); |
| 877 } | 877 } |
| 878 | 878 |
| 879 static bool pointIsClippedBySurfaceOrClipRect(const gfx::Point& screenSpacePoint
, LayerImpl* layer) | 879 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin
t, LayerImpl* layer) |
| 880 { | 880 { |
| 881 LayerImpl* currentLayer = layer; | 881 LayerImpl* currentLayer = layer; |
| 882 | 882 |
| 883 // Walk up the layer tree and hit-test any renderSurfaces and any layer clip
Rects that are active. | 883 // Walk up the layer tree and hit-test any renderSurfaces and any layer clip
Rects that are active. |
| 884 while (currentLayer) { | 884 while (currentLayer) { |
| 885 if (currentLayer->renderSurface() && !pointHitsRect(screenSpacePoint, cu
rrentLayer->renderSurface()->screenSpaceTransform(), currentLayer->renderSurface
()->contentRect())) | 885 if (currentLayer->renderSurface() && !pointHitsRect(screenSpacePoint, cu
rrentLayer->renderSurface()->screenSpaceTransform(), currentLayer->renderSurface
()->contentRect())) |
| 886 return true; | 886 return true; |
| 887 | 887 |
| 888 // Note that drawableContentRects are actually in targetSurface space, s
o the transform we | 888 // Note that drawableContentRects are actually in targetSurface space, s
o the transform we |
| 889 // have to provide is the target surface's screenSpaceTransform. | 889 // have to provide is the target surface's screenSpaceTransform. |
| 890 LayerImpl* renderTarget = currentLayer->renderTarget(); | 890 LayerImpl* renderTarget = currentLayer->renderTarget(); |
| 891 if (layerClipsSubtree(currentLayer) && !pointHitsRect(screenSpacePoint,
renderTarget->renderSurface()->screenSpaceTransform(), currentLayer->drawableCon
tentRect())) | 891 if (layerClipsSubtree(currentLayer) && !pointHitsRect(screenSpacePoint,
renderTarget->renderSurface()->screenSpaceTransform(), currentLayer->drawableCon
tentRect())) |
| 892 return true; | 892 return true; |
| 893 | 893 |
| 894 currentLayer = currentLayer->parent(); | 894 currentLayer = currentLayer->parent(); |
| 895 } | 895 } |
| 896 | 896 |
| 897 // If we have finished walking all ancestors without having already exited,
then the point is not clipped by any ancestors. | 897 // If we have finished walking all ancestors without having already exited,
then the point is not clipped by any ancestors. |
| 898 return false; | 898 return false; |
| 899 } | 899 } |
| 900 | 900 |
| 901 LayerImpl* LayerTreeHostCommon::findLayerThatIsHitByPoint(const gfx::Point& scre
enSpacePoint, std::vector<LayerImpl*>& renderSurfaceLayerList) | 901 LayerImpl* LayerTreeHostCommon::findLayerThatIsHitByPoint(const gfx::PointF& scr
eenSpacePoint, std::vector<LayerImpl*>& renderSurfaceLayerList) |
| 902 { | 902 { |
| 903 LayerImpl* foundLayer = 0; | 903 LayerImpl* foundLayer = 0; |
| 904 | 904 |
| 905 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl,
LayerIteratorActions::FrontToBack> LayerIteratorType; | 905 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl,
LayerIteratorActions::FrontToBack> LayerIteratorType; |
| 906 LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList); | 906 LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList); |
| 907 | 907 |
| 908 for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList
); it != end; ++it) { | 908 for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList
); it != end; ++it) { |
| 909 // We don't want to consider renderSurfaces for hit testing. | 909 // We don't want to consider renderSurfaces for hit testing. |
| 910 if (!it.representsItself()) | 910 if (!it.representsItself()) |
| 911 continue; | 911 continue; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 924 | 924 |
| 925 foundLayer = currentLayer; | 925 foundLayer = currentLayer; |
| 926 break; | 926 break; |
| 927 } | 927 } |
| 928 | 928 |
| 929 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. | 929 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. |
| 930 return foundLayer; | 930 return foundLayer; |
| 931 } | 931 } |
| 932 | 932 |
| 933 } // namespace cc | 933 } // namespace cc |
| OLD | NEW |