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. |