Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: cc/layer_tree_host_common.cc

Issue 11402002: Add API for hit testing layer_impl touchEventHandlerRegions from the host (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed parameters and fixed point conversion Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer_tree_host_common.h ('k') | cc/layer_tree_host_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "cc/layer_iterator.h" 11 #include "cc/layer_iterator.h"
12 #include "cc/layer_sorter.h" 12 #include "cc/layer_sorter.h"
13 #include "cc/math_util.h" 13 #include "cc/math_util.h"
14 #include "cc/render_surface.h" 14 #include "cc/render_surface.h"
15 #include "cc/render_surface_impl.h" 15 #include "cc/render_surface_impl.h"
16 #include "ui/gfx/point_conversions.h"
16 #include "ui/gfx/rect_conversions.h" 17 #include "ui/gfx/rect_conversions.h"
17 #include <algorithm> 18 #include <algorithm>
18 #include <public/WebTransformationMatrix.h> 19 #include <public/WebTransformationMatrix.h>
19 20
20 using WebKit::WebTransformationMatrix; 21 using WebKit::WebTransformationMatrix;
21 22
22 namespace cc { 23 namespace cc {
23 24
24 ScrollAndScaleSet::ScrollAndScaleSet() 25 ScrollAndScaleSet::ScrollAndScaleSet()
25 { 26 {
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 bool clipped = false; 870 bool clipped = false;
870 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(localSpaceToSc reenSpaceTransform.inverse(), screenSpacePoint, clipped); 871 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(localSpaceToSc reenSpaceTransform.inverse(), screenSpacePoint, clipped);
871 872
872 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this rect. 873 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this rect.
873 if (clipped) 874 if (clipped)
874 return false; 875 return false;
875 876
876 return localSpaceRect.Contains(hitTestPointInLocalSpace); 877 return localSpaceRect.Contains(hitTestPointInLocalSpace);
877 } 878 }
878 879
880 static bool pointHitsRegion(const gfx::PointF& screenSpacePoint, const WebTransf ormationMatrix& screenSpaceTransform, Region layerSpaceRegion, float layerConten tScaleX, float layerContentScaleY)
danakj 2012/11/08 02:18:48 You can pass the PointF by value (2 floats), but p
881 {
882 // If the transform is not invertible, then assume that this point doesn't h it this rect.
883 if (!screenSpaceTransform.isInvertible())
884 return false;
885
886 // Transform the hit test point from screen space to the local space of the given rect.
887 bool clipped = false;
888 gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(screenSpaceT ransform.inverse(), screenSpacePoint, clipped);
889 gfx::PointF hitTestPointInLayerSpace = hitTestPointInContentSpace.Scale(1 / layerContentScaleX, 1 / layerContentScaleY);
890
891 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this rect.
892 if (clipped)
893 return false;
894
895 return layerSpaceRegion.Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpac e));
896 }
897
879 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin t, LayerImpl* layer) 898 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin t, LayerImpl* layer)
880 { 899 {
881 LayerImpl* currentLayer = layer; 900 LayerImpl* currentLayer = layer;
882 901
883 // Walk up the layer tree and hit-test any renderSurfaces and any layer clip Rects that are active. 902 // Walk up the layer tree and hit-test any renderSurfaces and any layer clip Rects that are active.
884 while (currentLayer) { 903 while (currentLayer) {
885 if (currentLayer->renderSurface() && !pointHitsRect(screenSpacePoint, cu rrentLayer->renderSurface()->screenSpaceTransform(), currentLayer->renderSurface ()->contentRect())) 904 if (currentLayer->renderSurface() && !pointHitsRect(screenSpacePoint, cu rrentLayer->renderSurface()->screenSpaceTransform(), currentLayer->renderSurface ()->contentRect()))
886 return true; 905 return true;
887 906
888 // Note that drawableContentRects are actually in targetSurface space, s o the transform we 907 // 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
923 continue; 942 continue;
924 943
925 foundLayer = currentLayer; 944 foundLayer = currentLayer;
926 break; 945 break;
927 } 946 }
928 947
929 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer. 948 // 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; 949 return foundLayer;
931 } 950 }
932 951
952 LayerImpl* LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(co nst gfx::PointF& screenSpacePoint, std::vector<LayerImpl*>& renderSurfaceLayerLi st)
953 {
954 LayerImpl* foundLayer = 0;
955
956 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> LayerIteratorType;
957 LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList);
958
959 for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList ); it != end; ++it) {
960 // We don't want to consider renderSurfaces for hit testing.
961 if (!it.representsItself())
962 continue;
963
964 LayerImpl* currentLayer = (*it);
965
966 if (currentLayer->touchEventHandlerRegion().IsEmpty())
967 continue;
968
969 if (!pointHitsRegion(screenSpacePoint, currentLayer->screenSpaceTransfor m(), currentLayer->touchEventHandlerRegion(), currentLayer->contentsScaleX(), cu rrentLayer->contentsScaleY()))
970 continue;
971
972 // At this point, we think the point does hit the touch event handler re gion on the layer, but we need to walk up
973 // the parents to ensure that the layer was not clipped in such a way th at the
974 // hit point actually should not hit the layer.
975 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, currentLayer))
976 continue;
977
978 foundLayer = currentLayer;
979 break;
980 }
981
982 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer.
983 return foundLayer;
984 }
985
933 } // namespace cc 986 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_host_common.h ('k') | cc/layer_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698