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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | sky/tests/layout/document-elementFromPoint-absolute-position.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 if (childZOffset > *zOffset) { 555 if (childZOffset > *zOffset) {
556 *zOffset = childZOffset; 556 *zOffset = childZOffset;
557 return true; 557 return true;
558 } 558 }
559 return false; 559 return false;
560 } 560 }
561 561
562 return true; 562 return true;
563 } 563 }
564 564
565 static inline bool reverseCompareZIndex(RenderBox* first, RenderBox* second) 565 static inline bool forwardCompareZIndex(RenderBox* first, RenderBox* second)
566 { 566 {
567 return first->style()->zIndex() > second->style()->zIndex(); 567 return first->style()->zIndex() < second->style()->zIndex();
568 } 568 }
569 569
570 // hitTestLocation and hitTestRect are relative to rootLayer. 570 // hitTestLocation and hitTestRect are relative to rootLayer.
571 // A 'flattening' layer is one preserves3D() == false. 571 // A 'flattening' layer is one preserves3D() == false.
572 // transformState.m_accumulatedTransform holds the transform from the containing flattening layer. 572 // transformState.m_accumulatedTransform holds the transform from the containing flattening layer.
573 // transformState.m_lastPlanarPoint is the hitTestLocation in the plane of the c ontaining flattening layer. 573 // transformState.m_lastPlanarPoint is the hitTestLocation in the plane of the c ontaining flattening layer.
574 // transformState.m_lastPlanarQuad is the hitTestRect as a quad in the plane of the containing flattening layer. 574 // transformState.m_lastPlanarQuad is the hitTestRect as a quad in the plane of the containing flattening layer.
575 // 575 //
576 // If zOffset is non-null (which indicates that the caller wants z offset inform ation), 576 // If zOffset is non-null (which indicates that the caller wants z offset inform ation),
577 // *zOffset on return is the z offset of the hit point relative to the containi ng flattening layer. 577 // *zOffset on return is the z offset of the hit point relative to the containi ng flattening layer.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 zOffsetForDescendantsPtr = zOffset ? zOffset : &localZOffset; 656 zOffsetForDescendantsPtr = zOffset ? zOffset : &localZOffset;
657 zOffsetForContentsPtr = zOffset ? zOffset : &localZOffset; 657 zOffsetForContentsPtr = zOffset ? zOffset : &localZOffset;
658 } else if (zOffset) { 658 } else if (zOffset) {
659 zOffsetForDescendantsPtr = 0; 659 zOffsetForDescendantsPtr = 0;
660 // Container needs us to give back a z offset for the hit layer. 660 // Container needs us to give back a z offset for the hit layer.
661 zOffsetForContentsPtr = zOffset; 661 zOffsetForContentsPtr = zOffset;
662 } 662 }
663 663
664 Vector<RenderBox*> layers; 664 Vector<RenderBox*> layers;
665 collectSelfPaintingLayers(layers); 665 collectSelfPaintingLayers(layers);
666 std::stable_sort(layers.begin(), layers.end(), reverseCompareZIndex); 666 // Hit testing needs to walk in the backwards direction from paint.
667 // Forward compare and then reverse instead of just reverse comparing
668 // so that elements with the same z-index are walked in reverse tree order.
669 std::stable_sort(layers.begin(), layers.end(), forwardCompareZIndex);
670 layers.reverse();
667 671
668 bool hitLayer = false; 672 bool hitLayer = false;
669 for (auto& currentLayer : layers) { 673 for (auto& currentLayer : layers) {
670 HitTestResult tempResult(result.hitTestLocation()); 674 HitTestResult tempResult(result.hitTestLocation());
671 bool localHitLayer = currentLayer->hitTestLayer(rootLayer, layer(), requ est, tempResult, 675 bool localHitLayer = currentLayer->hitTestLayer(rootLayer, layer(), requ est, tempResult,
672 hitTestRect, hitTestLocation, localTransformState.get(), zOffsetForD escendantsPtr); 676 hitTestRect, hitTestLocation, localTransformState.get(), zOffsetForD escendantsPtr);
673 677
674 // If it a rect-based test, we can safely append the temporary result si nce it might had hit 678 // If it a rect-based test, we can safely append the temporary result si nce it might had hit
675 // nodes but not necesserily had hitLayer set. 679 // nodes but not necesserily had hitLayer set.
676 if (result.isRectBasedTest()) 680 if (result.isRectBasedTest())
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 result.setInnerNode(enclosingElement); 744 result.setInnerNode(enclosingElement);
741 if (!result.innerNonSharedNode()) 745 if (!result.innerNonSharedNode())
742 result.setInnerNonSharedNode(enclosingElement); 746 result.setInnerNonSharedNode(enclosingElement);
743 } 747 }
744 748
745 return true; 749 return true;
746 } 750 }
747 751
748 // --------------------- painting stuff ------------------------------- 752 // --------------------- painting stuff -------------------------------
749 753
750 static inline bool forwardCompareZIndex(RenderBox* first, RenderBox* second)
751 {
752 return first->style()->zIndex() < second->style()->zIndex();
753 }
754
755 void RenderBox::paintLayer(GraphicsContext* context, const LayerPaintingInfo& pa intingInfo) 754 void RenderBox::paintLayer(GraphicsContext* context, const LayerPaintingInfo& pa intingInfo)
756 { 755 {
757 // If this layer is totally invisible then there is nothing to paint. 756 // If this layer is totally invisible then there is nothing to paint.
758 // TODO(ojan): Return false from isSelfPainting and then ASSERT(!opacity()) here. 757 // TODO(ojan): Return false from isSelfPainting and then ASSERT(!opacity()) here.
759 if (!opacity()) 758 if (!opacity())
760 return; 759 return;
761 760
762 if (!transform()) { 761 if (!transform()) {
763 paintLayerContents(context, paintingInfo); 762 paintLayerContents(context, paintingInfo);
764 return; 763 return;
(...skipping 2308 matching lines...) Expand 10 before | Expand all | Expand 10 after
3073 3072
3074 RenderBox::BoxDecorationData::BoxDecorationData(const RenderStyle& style) 3073 RenderBox::BoxDecorationData::BoxDecorationData(const RenderStyle& style)
3075 { 3074 {
3076 backgroundColor = style.colorIncludingFallback(CSSPropertyBackgroundColor); 3075 backgroundColor = style.colorIncludingFallback(CSSPropertyBackgroundColor);
3077 hasBackground = backgroundColor.alpha() || style.hasBackgroundImage(); 3076 hasBackground = backgroundColor.alpha() || style.hasBackgroundImage();
3078 ASSERT(hasBackground == style.hasBackground()); 3077 ASSERT(hasBackground == style.hasBackground());
3079 hasBorder = style.hasBorder(); 3078 hasBorder = style.hasBorder();
3080 } 3079 }
3081 3080
3082 } // namespace blink 3081 } // namespace blink
OLDNEW
« 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