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

Side by Side Diff: cc/layer_tree_host_common.cc

Issue 12280014: cc: Don't consider HUD layer for touches (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moved funcs around Created 7 years, 10 months 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
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 "cc/layer_tree_host_common.h" 5 #include "cc/layer_tree_host_common.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "cc/layer.h" 10 #include "cc/layer.h"
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 dummyLayerList, &layerSorter, maxTextureSize, 1064 dummyLayerList, &layerSorter, maxTextureSize,
1065 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR ect, 1065 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR ect,
1066 updateTilePriorities); 1066 updateTilePriorities);
1067 1067
1068 // The dummy layer list should not have been used. 1068 // The dummy layer list should not have been used.
1069 DCHECK(dummyLayerList.size() == 0); 1069 DCHECK(dummyLayerList.size() == 0);
1070 // A root layer renderSurface should always exist after calculateDrawPropert ies. 1070 // A root layer renderSurface should always exist after calculateDrawPropert ies.
1071 DCHECK(rootLayer->renderSurface()); 1071 DCHECK(rootLayer->renderSurface());
1072 } 1072 }
1073 1073
1074 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect)
1075 {
1076 // If the transform is not invertible, then assume that this point doesn't h it this rect.
1077 gfx::Transform inverseLocalSpaceToScreenSpace(gfx::Transform::kSkipInitializ ation);
1078 if (!localSpaceToScreenSpaceTransform.GetInverse(&inverseLocalSpaceToScreenS pace))
1079 return false;
1080
1081 // Transform the hit test point from screen space to the local space of the given rect.
1082 bool clipped = false;
1083 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(inverseLocalSp aceToScreenSpace, screenSpacePoint, clipped);
1084
1085 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this rect.
1086 if (clipped)
1087 return false;
1088
1089 return localSpaceRect.Contains(hitTestPointInLocalSpace);
1090 }
1091
1092 static bool pointHitsRegion(gfx::PointF screenSpacePoint, const gfx::Transform& screenSpaceTransform, const Region& layerSpaceRegion, float layerContentScaleX, float layerContentScaleY) 1074 static bool pointHitsRegion(gfx::PointF screenSpacePoint, const gfx::Transform& screenSpaceTransform, const Region& layerSpaceRegion, float layerContentScaleX, float layerContentScaleY)
1093 { 1075 {
1094 // If the transform is not invertible, then assume that this point doesn't h it this region. 1076 // If the transform is not invertible, then assume that this point doesn't h it this region.
1095 gfx::Transform inverseScreenSpaceTransform(gfx::Transform::kSkipInitializati on); 1077 gfx::Transform inverseScreenSpaceTransform(gfx::Transform::kSkipInitializati on);
1096 if (!screenSpaceTransform.GetInverse(&inverseScreenSpaceTransform)) 1078 if (!screenSpaceTransform.GetInverse(&inverseScreenSpaceTransform))
1097 return false; 1079 return false;
1098 1080
1099 // Transform the hit test point from screen space to the local space of the given region. 1081 // Transform the hit test point from screen space to the local space of the given region.
1100 bool clipped = false; 1082 bool clipped = false;
1101 gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(inverseScree nSpaceTransform, screenSpacePoint, clipped); 1083 gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(inverseScree nSpaceTransform, screenSpacePoint, clipped);
1102 gfx::PointF hitTestPointInLayerSpace = gfx::ScalePoint(hitTestPointInContent Space, 1 / layerContentScaleX, 1 / layerContentScaleY); 1084 gfx::PointF hitTestPointInLayerSpace = gfx::ScalePoint(hitTestPointInContent Space, 1 / layerContentScaleX, 1 / layerContentScaleY);
1103 1085
1104 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this region. 1086 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this region.
1105 if (clipped) 1087 if (clipped)
1106 return false; 1088 return false;
1107 1089
1108 return layerSpaceRegion.Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpac e)); 1090 return layerSpaceRegion.Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpac e));
1109 } 1091 }
1110 1092
1111 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin t, LayerImpl* layer) 1093 bool LayerTreeHostCommon::pointIsClippedBySurfaceOrClipRect(const gfx::PointF& s creenSpacePoint, LayerImpl* layer)
1112 { 1094 {
1113 LayerImpl* currentLayer = layer; 1095 LayerImpl* currentLayer = layer;
1114 1096
1115 // Walk up the layer tree and hit-test any renderSurfaces and any layer clip Rects that are active. 1097 // Walk up the layer tree and hit-test any renderSurfaces and any layer clip Rects that are active.
1116 while (currentLayer) { 1098 while (currentLayer) {
1117 if (currentLayer->renderSurface() && !pointHitsRect(screenSpacePoint, cu rrentLayer->renderSurface()->screenSpaceTransform(), currentLayer->renderSurface ()->contentRect())) 1099 if (currentLayer->renderSurface() && !MathUtil::pointHitsRect(screenSpac ePoint, currentLayer->renderSurface()->screenSpaceTransform(), currentLayer->ren derSurface()->contentRect()))
1118 return true; 1100 return true;
1119 1101
1120 // Note that drawableContentRects are actually in targetSurface space, s o the transform we 1102 // Note that drawableContentRects are actually in targetSurface space, s o the transform we
1121 // have to provide is the target surface's screenSpaceTransform. 1103 // have to provide is the target surface's screenSpaceTransform.
1122 LayerImpl* renderTarget = currentLayer->renderTarget(); 1104 LayerImpl* renderTarget = currentLayer->renderTarget();
1123 if (layerClipsSubtree(currentLayer) && !pointHitsRect(screenSpacePoint, renderTarget->renderSurface()->screenSpaceTransform(), currentLayer->drawableCon tentRect())) 1105 if (layerClipsSubtree(currentLayer) && !MathUtil::pointHitsRect(screenSp acePoint, renderTarget->renderSurface()->screenSpaceTransform(), currentLayer->d rawableContentRect()))
1124 return true; 1106 return true;
1125 1107
1126 currentLayer = currentLayer->parent(); 1108 currentLayer = currentLayer->parent();
1127 } 1109 }
1128 1110
1129 // If we have finished walking all ancestors without having already exited, then the point is not clipped by any ancestors. 1111 // If we have finished walking all ancestors without having already exited, then the point is not clipped by any ancestors.
1130 return false; 1112 return false;
1131 } 1113 }
1132 1114
1133 LayerImpl* LayerTreeHostCommon::findLayerThatIsHitByPoint(const gfx::PointF& scr eenSpacePoint, const std::vector<LayerImpl*>& renderSurfaceLayerList)
1134 {
1135 LayerImpl* foundLayer = 0;
1136
1137 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> LayerIteratorType;
1138 LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList);
1139
1140 for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList ); it != end; ++it) {
1141 // We don't want to consider renderSurfaces for hit testing.
1142 if (!it.representsItself())
1143 continue;
1144
1145 LayerImpl* currentLayer = (*it);
1146
1147 gfx::RectF contentRect(gfx::PointF(), currentLayer->contentBounds());
1148 if (!pointHitsRect(screenSpacePoint, currentLayer->screenSpaceTransform( ), contentRect))
1149 continue;
1150
1151 // At this point, we think the point does hit the layer, but we need to walk up
1152 // the parents to ensure that the layer was not clipped in such a way th at the
1153 // hit point actually should not hit the layer.
1154 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, currentLayer))
1155 continue;
1156
1157 foundLayer = currentLayer;
1158 break;
1159 }
1160
1161 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer.
1162 return foundLayer;
1163 }
1164
1165 LayerImpl* LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(co nst gfx::PointF& screenSpacePoint, const std::vector<LayerImpl*>& renderSurfaceL ayerList) 1115 LayerImpl* LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(co nst gfx::PointF& screenSpacePoint, const std::vector<LayerImpl*>& renderSurfaceL ayerList)
1166 { 1116 {
1167 LayerImpl* foundLayer = 0; 1117 LayerImpl* foundLayer = 0;
1168 1118
1169 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> LayerIteratorType; 1119 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> LayerIteratorType;
1170 LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList); 1120 LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList);
1171 1121
1172 for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList ); it != end; ++it) { 1122 for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList ); it != end; ++it) {
1173 // We don't want to consider renderSurfaces for hit testing. 1123 // We don't want to consider renderSurfaces for hit testing.
1174 if (!it.representsItself()) 1124 if (!it.representsItself())
(...skipping 21 matching lines...) Expand all
1196 1146
1197 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up 1147 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up
1198 // the parents to ensure that the layer was not clipped in such a way that the 1148 // the parents to ensure that the layer was not clipped in such a way that the
1199 // hit point actually should not hit the layer. 1149 // hit point actually should not hit the layer.
1200 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) 1150 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl))
1201 return false; 1151 return false;
1202 1152
1203 return true; 1153 return true;
1204 } 1154 }
1205 } // namespace cc 1155 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698