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

Side by Side Diff: Source/core/layout/line/InlineFlowBox.cpp

Issue 1142283004: Implement a Hit Test Cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 968
969 LayoutRect visualOverflow(isHorizontal() ? logicalVisualOverflow : logicalVi sualOverflow.transposedRect()); 969 LayoutRect visualOverflow(isHorizontal() ? logicalVisualOverflow : logicalVi sualOverflow.transposedRect());
970 setVisualOverflow(visualOverflow, frameBox); 970 setVisualOverflow(visualOverflow, frameBox);
971 } 971 }
972 972
973 bool InlineFlowBox::nodeAtPoint(HitTestResult& result, const HitTestLocation& lo cationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, Lay outUnit lineBottom) 973 bool InlineFlowBox::nodeAtPoint(HitTestResult& result, const HitTestLocation& lo cationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, Lay outUnit lineBottom)
974 { 974 {
975 LayoutRect overflowRect(visualOverflowRect(lineTop, lineBottom)); 975 LayoutRect overflowRect(visualOverflowRect(lineTop, lineBottom));
976 flipForWritingMode(overflowRect); 976 flipForWritingMode(overflowRect);
977 overflowRect.moveBy(accumulatedOffset); 977 overflowRect.moveBy(accumulatedOffset);
978 if (!locationInContainer.intersects(overflowRect)) 978 if (!locationInContainer.intersects(overflowRect)) {
979 result.shrinkValidityRect(overflowRect);
979 return false; 980 return false;
981 }
980 982
981 // We need to hit test both our inline children (InlineBoxes) and culled inl ines 983 // We need to hit test both our inline children (InlineBoxes) and culled inl ines
982 // (LayoutObjects). We check our inlines in the same order as line layout bu t 984 // (LayoutObjects). We check our inlines in the same order as line layout bu t
983 // for each inline we additionally need to hit test its culled inline parent s. 985 // for each inline we additionally need to hit test its culled inline parent s.
984 // While hit testing culled inline parents, we can stop once we reach 986 // While hit testing culled inline parents, we can stop once we reach
985 // a non-inline parent or a culled inline associated with a different inline box. 987 // a non-inline parent or a culled inline associated with a different inline box.
986 InlineBox* prev; 988 InlineBox* prev;
987 for (InlineBox* curr = lastChild(); curr; curr = prev) { 989 for (InlineBox* curr = lastChild(); curr; curr = prev) {
988 prev = curr->prevOnLine(); 990 prev = curr->prevOnLine();
989 991
990 // Layers will handle hit testing themselves. 992 // Layers will handle hit testing themselves.
991 if (curr->boxModelObject() && curr->boxModelObject()->hasSelfPaintingLay er()) 993 if (curr->boxModelObject() && curr->boxModelObject()->hasSelfPaintingLay er())
992 continue; 994 continue;
993 995
994 if (curr->nodeAtPoint(result, locationInContainer, accumulatedOffset, li neTop, lineBottom)) { 996 if (curr->nodeAtPoint(result, locationInContainer, accumulatedOffset, li neTop, lineBottom)) {
995 layoutObject().updateHitTestResult(result, locationInContainer.point () - toLayoutSize(accumulatedOffset)); 997 // TODO(dtapuska): Calculate pos based on lineTop/lineBottom
998 layoutObject().updateHitTestResult(result, locationInContainer.point () - toLayoutSize(accumulatedOffset), result.validityRect());
996 return true; 999 return true;
997 } 1000 }
998 1001
999 // If the current inlinebox's layout object and the previous inlinebox's layout object are same, 1002 // If the current inlinebox's layout object and the previous inlinebox's layout object are same,
1000 // we should yield the hit-test to the previous inlinebox. 1003 // we should yield the hit-test to the previous inlinebox.
1001 if (prev && curr->layoutObject() == prev->layoutObject()) 1004 if (prev && curr->layoutObject() == prev->layoutObject())
1002 continue; 1005 continue;
1003 1006
1004 LayoutObject* culledParent = &curr->layoutObject(); 1007 LayoutObject* culledParent = &curr->layoutObject();
1005 while (true) { 1008 while (true) {
1006 LayoutObject* sibling = culledParent->style()->isLeftToRightDirectio n() ? culledParent->previousSibling() : culledParent->nextSibling(); 1009 LayoutObject* sibling = culledParent->style()->isLeftToRightDirectio n() ? culledParent->previousSibling() : culledParent->nextSibling();
1007 culledParent = culledParent->parent(); 1010 culledParent = culledParent->parent();
1008 ASSERT(culledParent); 1011 ASSERT(culledParent);
1009 1012
1010 if (culledParent == layoutObject() || (sibling && prev && prev->layo utObject().isDescendantOf(culledParent))) 1013 if (culledParent == layoutObject() || (sibling && prev && prev->layo utObject().isDescendantOf(culledParent)))
1011 break; 1014 break;
1012 1015
1013 if (culledParent->isLayoutInline() && toLayoutInline(culledParent)-> hitTestCulledInline(result, locationInContainer, accumulatedOffset)) 1016 if (culledParent->isLayoutInline() && toLayoutInline(culledParent)-> hitTestCulledInline(result, locationInContainer, accumulatedOffset))
1014 return true; 1017 return true;
1015 } 1018 }
1016 } 1019 }
1017 1020
1018 if (layoutObject().style()->hasBorderRadius()) { 1021 if (layoutObject().style()->hasBorderRadius()) {
1019 LayoutRect borderRect = logicalFrameRect(); 1022 LayoutRect borderRect = logicalFrameRect();
1020 borderRect.moveBy(accumulatedOffset); 1023 borderRect.moveBy(accumulatedOffset);
1021 FloatRoundedRect border = layoutObject().style()->getRoundedBorderFor(bo rderRect, includeLogicalLeftEdge(), includeLogicalRightEdge()); 1024 FloatRoundedRect border = layoutObject().style()->getRoundedBorderFor(bo rderRect, includeLogicalLeftEdge(), includeLogicalRightEdge());
1022 if (!locationInContainer.intersects(border)) 1025 if (!locationInContainer.intersects(border)) {
1026 result.shrinkValidityRect(borderRect);
1023 return false; 1027 return false;
1028 }
1024 } 1029 }
1025 1030
1026 // Now check ourselves. Pixel snap hit testing. 1031 // Now check ourselves. Pixel snap hit testing.
1027 LayoutRect frameRect(roundedFrameRect()); 1032 LayoutRect frameRect(roundedFrameRect());
1028 LayoutUnit minX = frameRect.x(); 1033 LayoutUnit minX = frameRect.x();
1029 LayoutUnit minY = frameRect.y(); 1034 LayoutUnit minY = frameRect.y();
1030 LayoutUnit width = frameRect.width(); 1035 LayoutUnit width = frameRect.width();
1031 LayoutUnit height = frameRect.height(); 1036 LayoutUnit height = frameRect.height();
1032 1037
1033 // Constrain our hit testing to the line top and bottom if necessary. 1038 // Constrain our hit testing to the line top and bottom if necessary.
1034 bool noQuirksMode = layoutObject().document().inNoQuirksMode(); 1039 bool noQuirksMode = layoutObject().document().inNoQuirksMode();
1035 if (!noQuirksMode && !hasTextChildren() && !(descendantsHaveSameLineHeightAn dBaseline() && hasTextDescendants())) { 1040 if (!noQuirksMode && !hasTextChildren() && !(descendantsHaveSameLineHeightAn dBaseline() && hasTextDescendants())) {
1036 RootInlineBox& rootBox = root(); 1041 RootInlineBox& rootBox = root();
1037 LayoutUnit& top = isHorizontal() ? minY : minX; 1042 LayoutUnit& top = isHorizontal() ? minY : minX;
1038 LayoutUnit& logicalHeight = isHorizontal() ? height : width; 1043 LayoutUnit& logicalHeight = isHorizontal() ? height : width;
1039 LayoutUnit bottom = std::min(rootBox.lineBottom(), top + logicalHeight); 1044 LayoutUnit bottom = std::min(rootBox.lineBottom(), top + logicalHeight);
1040 top = std::max(rootBox.lineTop(), top); 1045 top = std::max(rootBox.lineTop(), top);
1041 logicalHeight = bottom - top; 1046 logicalHeight = bottom - top;
1042 } 1047 }
1043 1048
1044 // Move x/y to our coordinates. 1049 // Move x/y to our coordinates.
1045 LayoutRect rect(minX, minY, width, height); 1050 LayoutRect rect(minX, minY, width, height);
1046 flipForWritingMode(rect); 1051 flipForWritingMode(rect);
1047 rect.moveBy(accumulatedOffset); 1052 rect.moveBy(accumulatedOffset);
1048 1053
1049 if (visibleToHitTestRequest(result.hitTestRequest()) && locationInContainer. intersects(rect)) { 1054 if (visibleToHitTestRequest(result.hitTestRequest()) && locationInContainer. intersects(rect)) {
1050 layoutObject().updateHitTestResult(result, flipForWritingMode(locationIn Container.point() - toLayoutSize(accumulatedOffset))); // Don't add in m_x or m_ y here, we want coords in the containing block's space. 1055 layoutObject().updateHitTestResult(result, flipForWritingMode(locationIn Container.point() - toLayoutSize(accumulatedOffset)), rect); // Don't add in m_x or m_y here, we want coords in the containing block's space.
1051 if (!result.addNodeToListBasedTestResult(layoutObject().node(), location InContainer, rect)) 1056 if (!result.addNodeToListBasedTestResult(layoutObject().node(), location InContainer, rect))
1052 return true; 1057 return true;
1053 } 1058 }
1059 result.shrinkValidityRect(rect);
1054 1060
1055 return false; 1061 return false;
1056 } 1062 }
1057 1063
1058 void InlineFlowBox::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOf fset, LayoutUnit lineTop, LayoutUnit lineBottom) 1064 void InlineFlowBox::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOf fset, LayoutUnit lineTop, LayoutUnit lineBottom)
1059 { 1065 {
1060 InlineFlowBoxPainter(*this).paint(paintInfo, paintOffset, lineTop, lineBotto m); 1066 InlineFlowBoxPainter(*this).paint(paintInfo, paintOffset, lineTop, lineBotto m);
1061 } 1067 }
1062 1068
1063 bool InlineFlowBox::boxShadowCanBeAppliedToBackground(const FillLayer& lastBackg roundLayer) const 1069 bool InlineFlowBox::boxShadowCanBeAppliedToBackground(const FillLayer& lastBackg roundLayer) const
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 ASSERT(child->prevOnLine() == prev); 1316 ASSERT(child->prevOnLine() == prev);
1311 prev = child; 1317 prev = child;
1312 } 1318 }
1313 ASSERT(prev == m_lastChild); 1319 ASSERT(prev == m_lastChild);
1314 #endif 1320 #endif
1315 } 1321 }
1316 1322
1317 #endif 1323 #endif
1318 1324
1319 } // namespace blink 1325 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698