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

Unified Diff: sky/engine/core/rendering/RenderBox.cpp

Issue 986793002: Fix hit-testing of elements with the same z-index. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/tests/layout/document-elementFromPoint-absolute-position.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/rendering/RenderBox.cpp
diff --git a/sky/engine/core/rendering/RenderBox.cpp b/sky/engine/core/rendering/RenderBox.cpp
index d623089552c49c15360ae7829e5f97455e9734b5..e732794aed7346e44d14ec73e8562ce8130490c2 100644
--- a/sky/engine/core/rendering/RenderBox.cpp
+++ b/sky/engine/core/rendering/RenderBox.cpp
@@ -562,9 +562,9 @@ static bool isHitCandidate(bool canDepthSort, double* zOffset, const HitTestingT
return true;
}
-static inline bool reverseCompareZIndex(RenderBox* first, RenderBox* second)
+static inline bool forwardCompareZIndex(RenderBox* first, RenderBox* second)
{
- return first->style()->zIndex() > second->style()->zIndex();
+ return first->style()->zIndex() < second->style()->zIndex();
}
// hitTestLocation and hitTestRect are relative to rootLayer.
@@ -663,7 +663,11 @@ bool RenderBox::hitTestLayer(RenderLayer* rootLayer, RenderLayer* containerLayer
Vector<RenderBox*> layers;
collectSelfPaintingLayers(layers);
- std::stable_sort(layers.begin(), layers.end(), reverseCompareZIndex);
+ // Hit testing needs to walk in the backwards direction from paint.
+ // Forward compare and then reverse instead of just reverse comparing
+ // so that elements with the same z-index are walked in reverse tree order.
+ std::stable_sort(layers.begin(), layers.end(), forwardCompareZIndex);
+ layers.reverse();
bool hitLayer = false;
for (auto& currentLayer : layers) {
@@ -747,11 +751,6 @@ bool RenderBox::hitTestNonLayerDescendants(const HitTestRequest& request, HitTes
// --------------------- painting stuff -------------------------------
-static inline bool forwardCompareZIndex(RenderBox* first, RenderBox* second)
-{
- return first->style()->zIndex() < second->style()->zIndex();
-}
-
void RenderBox::paintLayer(GraphicsContext* context, const LayerPaintingInfo& paintingInfo)
{
// If this layer is totally invisible then there is nothing to paint.
« no previous file with comments | « no previous file | sky/tests/layout/document-elementFromPoint-absolute-position.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698