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

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

Issue 1032823003: Refactor HitTestResult to store the HitTestRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated as per review comments Created 5 years, 8 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 | « Source/core/layout/line/InlineFlowBox.h ('k') | Source/core/layout/line/InlineTextBox.h » ('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) 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 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 // the transition to LayoutUnit-based types is complete (crbug.com/321237) 960 // the transition to LayoutUnit-based types is complete (crbug.com/321237)
961 LayoutRect frameBox = frameRectIncludingLineHeight(lineTop, lineBottom).encl osingLayoutRect(); 961 LayoutRect frameBox = frameRectIncludingLineHeight(lineTop, lineBottom).encl osingLayoutRect();
962 962
963 LayoutRect layoutOverflow(isHorizontal() ? logicalLayoutOverflow : logicalLa youtOverflow.transposedRect()); 963 LayoutRect layoutOverflow(isHorizontal() ? logicalLayoutOverflow : logicalLa youtOverflow.transposedRect());
964 setLayoutOverflow(layoutOverflow, frameBox); 964 setLayoutOverflow(layoutOverflow, frameBox);
965 965
966 LayoutRect visualOverflow(isHorizontal() ? logicalVisualOverflow : logicalVi sualOverflow.transposedRect()); 966 LayoutRect visualOverflow(isHorizontal() ? logicalVisualOverflow : logicalVi sualOverflow.transposedRect());
967 setVisualOverflow(visualOverflow, frameBox); 967 setVisualOverflow(visualOverflow, frameBox);
968 } 968 }
969 969
970 bool InlineFlowBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& re sult, const HitTestLocation& locationInContainer, const LayoutPoint& accumulated Offset, LayoutUnit lineTop, LayoutUnit lineBottom) 970 bool InlineFlowBox::nodeAtPoint(HitTestResult& result, const HitTestLocation& lo cationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, Lay outUnit lineBottom)
971 { 971 {
972 LayoutRect overflowRect(visualOverflowRect(lineTop, lineBottom)); 972 LayoutRect overflowRect(visualOverflowRect(lineTop, lineBottom));
973 flipForWritingMode(overflowRect); 973 flipForWritingMode(overflowRect);
974 overflowRect.moveBy(accumulatedOffset); 974 overflowRect.moveBy(accumulatedOffset);
975 if (!locationInContainer.intersects(overflowRect)) 975 if (!locationInContainer.intersects(overflowRect))
976 return false; 976 return false;
977 977
978 // Check children first. 978 // Check children first.
979 // We need to account for culled inline parents of the hit-tested nodes, so that they may also get included in area-based hit-tests. 979 // We need to account for culled inline parents of the hit-tested nodes, so that they may also get included in area-based hit-tests.
980 LayoutObject* culledParent = 0; 980 LayoutObject* culledParent = 0;
981 for (InlineBox* curr = lastChild(); curr; curr = curr->prevOnLine()) { 981 for (InlineBox* curr = lastChild(); curr; curr = curr->prevOnLine()) {
982 if (curr->layoutObject().isText() || !curr->boxModelObject()->hasSelfPai ntingLayer()) { 982 if (curr->layoutObject().isText() || !curr->boxModelObject()->hasSelfPai ntingLayer()) {
983 LayoutObject* newParent = 0; 983 LayoutObject* newParent = 0;
984 // Culled parents are only relevant for area-based hit-tests, so ign ore it in point-based ones. 984 // Culled parents are only relevant for area-based hit-tests, so ign ore it in point-based ones.
985 if (locationInContainer.isRectBasedTest()) { 985 if (locationInContainer.isRectBasedTest()) {
986 newParent = curr->layoutObject().parent(); 986 newParent = curr->layoutObject().parent();
987 if (newParent == layoutObject()) 987 if (newParent == layoutObject())
988 newParent = 0; 988 newParent = 0;
989 } 989 }
990 // Check the culled parent after all its children have been checked, to do this we wait until 990 // Check the culled parent after all its children have been checked, to do this we wait until
991 // we are about to test an element with a different parent. 991 // we are about to test an element with a different parent.
992 if (newParent != culledParent) { 992 if (newParent != culledParent) {
993 if (!newParent || !newParent->isDescendantOf(culledParent)) { 993 if (!newParent || !newParent->isDescendantOf(culledParent)) {
994 while (culledParent && culledParent != layoutObject() && cul ledParent != newParent) { 994 while (culledParent && culledParent != layoutObject() && cul ledParent != newParent) {
995 if (culledParent->isLayoutInline() && toLayoutInline(cul ledParent)->hitTestCulledInline(request, result, locationInContainer, accumulate dOffset)) 995 if (culledParent->isLayoutInline() && toLayoutInline(cul ledParent)->hitTestCulledInline(result, locationInContainer, accumulatedOffset))
996 return true; 996 return true;
997 culledParent = culledParent->parent(); 997 culledParent = culledParent->parent();
998 } 998 }
999 } 999 }
1000 culledParent = newParent; 1000 culledParent = newParent;
1001 } 1001 }
1002 if (curr->nodeAtPoint(request, result, locationInContainer, accumula tedOffset, lineTop, lineBottom)) { 1002 if (curr->nodeAtPoint(result, locationInContainer, accumulatedOffset , lineTop, lineBottom)) {
1003 layoutObject().updateHitTestResult(result, locationInContainer.p oint() - toLayoutSize(accumulatedOffset)); 1003 layoutObject().updateHitTestResult(result, locationInContainer.p oint() - toLayoutSize(accumulatedOffset));
1004 return true; 1004 return true;
1005 } 1005 }
1006 } 1006 }
1007 } 1007 }
1008 // Check any culled ancestor of the final children tested. 1008 // Check any culled ancestor of the final children tested.
1009 while (culledParent && culledParent != layoutObject()) { 1009 while (culledParent && culledParent != layoutObject()) {
1010 if (culledParent->isLayoutInline() && toLayoutInline(culledParent)->hitT estCulledInline(request, result, locationInContainer, accumulatedOffset)) 1010 if (culledParent->isLayoutInline() && toLayoutInline(culledParent)->hitT estCulledInline(result, locationInContainer, accumulatedOffset))
1011 return true; 1011 return true;
1012 culledParent = culledParent->parent(); 1012 culledParent = culledParent->parent();
1013 } 1013 }
1014 1014
1015 // Now check ourselves. Pixel snap hit testing. 1015 // Now check ourselves. Pixel snap hit testing.
1016 LayoutRect frameRect(roundedFrameRect()); 1016 LayoutRect frameRect(roundedFrameRect());
1017 LayoutUnit minX = frameRect.x(); 1017 LayoutUnit minX = frameRect.x();
1018 LayoutUnit minY = frameRect.y(); 1018 LayoutUnit minY = frameRect.y();
1019 LayoutUnit width = frameRect.width(); 1019 LayoutUnit width = frameRect.width();
1020 LayoutUnit height = frameRect.height(); 1020 LayoutUnit height = frameRect.height();
1021 1021
1022 // Constrain our hit testing to the line top and bottom if necessary. 1022 // Constrain our hit testing to the line top and bottom if necessary.
1023 bool noQuirksMode = layoutObject().document().inNoQuirksMode(); 1023 bool noQuirksMode = layoutObject().document().inNoQuirksMode();
1024 if (!noQuirksMode && !hasTextChildren() && !(descendantsHaveSameLineHeightAn dBaseline() && hasTextDescendants())) { 1024 if (!noQuirksMode && !hasTextChildren() && !(descendantsHaveSameLineHeightAn dBaseline() && hasTextDescendants())) {
1025 RootInlineBox& rootBox = root(); 1025 RootInlineBox& rootBox = root();
1026 LayoutUnit& top = isHorizontal() ? minY : minX; 1026 LayoutUnit& top = isHorizontal() ? minY : minX;
1027 LayoutUnit& logicalHeight = isHorizontal() ? height : width; 1027 LayoutUnit& logicalHeight = isHorizontal() ? height : width;
1028 LayoutUnit bottom = std::min(rootBox.lineBottom(), top + logicalHeight); 1028 LayoutUnit bottom = std::min(rootBox.lineBottom(), top + logicalHeight);
1029 top = std::max(rootBox.lineTop(), top); 1029 top = std::max(rootBox.lineTop(), top);
1030 logicalHeight = bottom - top; 1030 logicalHeight = bottom - top;
1031 } 1031 }
1032 1032
1033 // Move x/y to our coordinates. 1033 // Move x/y to our coordinates.
1034 LayoutRect rect(minX, minY, width, height); 1034 LayoutRect rect(minX, minY, width, height);
1035 flipForWritingMode(rect); 1035 flipForWritingMode(rect);
1036 rect.moveBy(accumulatedOffset); 1036 rect.moveBy(accumulatedOffset);
1037 1037
1038 if (visibleToHitTestRequest(request) && locationInContainer.intersects(rect) ) { 1038 if (visibleToHitTestRequest(result.hitTestRequest()) && locationInContainer. intersects(rect)) {
1039 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. 1039 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.
1040 if (!result.addNodeToListBasedTestResult(layoutObject().node(), request, locationInContainer, rect)) 1040 if (!result.addNodeToListBasedTestResult(layoutObject().node(), location InContainer, rect))
1041 return true; 1041 return true;
1042 } 1042 }
1043 1043
1044 return false; 1044 return false;
1045 } 1045 }
1046 1046
1047 void InlineFlowBox::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOf fset, LayoutUnit lineTop, LayoutUnit lineBottom) 1047 void InlineFlowBox::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOf fset, LayoutUnit lineTop, LayoutUnit lineBottom)
1048 { 1048 {
1049 InlineFlowBoxPainter(*this).paint(paintInfo, paintOffset, lineTop, lineBotto m); 1049 InlineFlowBoxPainter(*this).paint(paintInfo, paintOffset, lineTop, lineBotto m);
1050 } 1050 }
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 ASSERT(child->prevOnLine() == prev); 1299 ASSERT(child->prevOnLine() == prev);
1300 prev = child; 1300 prev = child;
1301 } 1301 }
1302 ASSERT(prev == m_lastChild); 1302 ASSERT(prev == m_lastChild);
1303 #endif 1303 #endif
1304 } 1304 }
1305 1305
1306 #endif 1306 #endif
1307 1307
1308 } // namespace blink 1308 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/line/InlineFlowBox.h ('k') | Source/core/layout/line/InlineTextBox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698