Changeset 126204 in webkit
- Timestamp:
- Aug 21, 2012 4:06:06 PM (12 years ago)
- Location:
- trunk/Source/WebKit/chromium
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/chromium/ChangeLog
r126202 r126204 1 2012-08-21 Leandro Gracia Gil <leandrogracia@chromium.org> 2 3 [Chromium] Find-in-page coordinates should use containingBlock 4 https://bugs.webkit.org/show_bug.cgi?id=94343 5 6 Reviewed by Julien Chaffraix. 7 8 The current implementation uses the container method to climb the render tree. 9 However, it would be more correct and convenient to use containingBlock instead. 10 Also, this patch introduces new tests for find-in-page coordinates in tables. 11 12 * src/FindInPageCoordinates.cpp: 13 (WebKit::toNormalizedRect): use containingBlock and get rid of the output parameter as it's not required now. 14 (WebKit::findInPageRectFromAbsoluteRect): use containingBlock introduce some simplifications. 15 * tests/WebFrameTest.cpp: add new tests for tables. 16 * tests/data/find_in_page.html: 17 * tests/data/find_in_page_frame.html: new tests for tables. 18 1 19 2012-08-21 Alexandre Elias <aelias@google.com> 2 20 -
trunk/Source/WebKit/chromium/src/FindInPageCoordinates.cpp
r126074 r126204 39 39 #include "Node.h" 40 40 #include "Range.h" 41 #include "RenderBlock.h" 41 42 #include "RenderBox.h" 42 43 #include "RenderObject.h" … … 49 50 namespace WebKit { 50 51 51 static FloatRect toNormalizedRect(const FloatRect& absoluteRect, const RenderObject* renderer , FloatRect& containerBoundingBox)52 static FloatRect toNormalizedRect(const FloatRect& absoluteRect, const RenderObject* renderer) 52 53 { 53 54 ASSERT(renderer); 54 55 55 const Render Object* container = renderer->container();56 if (!container) {57 containerBoundingBox = FloatRect();56 const RenderBlock* container = renderer->containingBlock(); 57 ASSERT(container || renderer->isRenderView()); 58 if (!container) 58 59 return FloatRect(); 59 }60 60 61 FloatRect normalizedRect = absoluteRect;62 FloatRect containerRect = container->absoluteBoundingBoxRect();63 containerBoundingBox = containerRect;61 // We want to normalize by the max layout overflow size instead of only the visible bounding box. 62 // Quads and their enclosing bounding boxes need to be used in order to keep results transform-friendly. 63 FloatPoint scrolledOrigin; 64 64 65 // For RenderBoxes we want to normalize by the max layout overflow size instead of only the visible bounding box. 66 // Quads and their enclosing bounding boxes need to be used in order to keep results transform-friendly. 67 if (container->isBox()) { 68 const RenderBox* containerBox = toRenderBox(container); 69 FloatPoint scrolledOrigin; 65 // For overflow:scroll we need to get where the actual origin is independently of the scroll. 66 if (container->hasOverflowClip()) 67 scrolledOrigin = -IntPoint(container->scrolledContentOffset()); 70 68 71 // For overflow:scroll we need to get where the actual origin is independently of the scroll. 72 if (container->hasOverflowClip()) 73 scrolledOrigin = -IntPoint(containerBox->scrolledContentOffset()); 74 75 FloatRect overflowRect(scrolledOrigin, containerBox->maxLayoutOverflow()); 76 containerRect = containerBox->localToAbsoluteQuad(FloatQuad(overflowRect), false).enclosingBoundingBox(); 77 } 69 FloatRect overflowRect(scrolledOrigin, container->maxLayoutOverflow()); 70 FloatRect containerRect = container->localToAbsoluteQuad(FloatQuad(overflowRect), false).enclosingBoundingBox(); 78 71 79 72 if (containerRect.isEmpty()) … … 82 75 // Make the coordinates relative to the container enclosing bounding box. 83 76 // Since we work with rects enclosing quad unions this is still transform-friendly. 77 FloatRect normalizedRect = absoluteRect; 84 78 normalizedRect.moveBy(-containerRect.location()); 85 79 … … 90 84 91 85 normalizedRect.scale(1 / containerRect.width(), 1 / containerRect.height()); 92 93 86 return normalizedRect; 94 87 } 95 88 96 FloatRect findInPageRectFromAbsoluteRect(const FloatRect& inputRect, const RenderObject* renderer)89 FloatRect findInPageRectFromAbsoluteRect(const FloatRect& inputRect, const RenderObject* baseRenderer) 97 90 { 98 if (! renderer || inputRect.isEmpty())91 if (!baseRenderer || inputRect.isEmpty()) 99 92 return FloatRect(); 100 93 101 // Normalize the input rect to its container, saving the container bounding box for the incoming loop. 102 FloatRect rendererBoundingBox; 103 FloatRect normalizedRect = toNormalizedRect(inputRect, renderer, rendererBoundingBox); 104 renderer = renderer->container(); 94 // Normalize the input rect to its container block. 95 FloatRect normalizedRect = toNormalizedRect(inputRect, baseRenderer); 105 96 106 97 // Go up across frames. 107 while (renderer) {98 for (const RenderObject* renderer = baseRenderer->containingBlock(); renderer; ) { 108 99 109 100 // Go up the render tree until we reach the root of the current frame (the RenderView). 110 for (const RenderObject* container = renderer->container(); container; renderer = container, container = container->container()) { 101 for (const RenderBlock* container = renderer->containingBlock(); container; 102 renderer = container, container = container->containingBlock()) { 111 103 112 // Compose the normalized rects. The absolute bounding box of the container is calculated in toNormalizedRect 113 // and can be reused for the next iteration of the loop. 114 FloatRect normalizedBoxRect = toNormalizedRect(rendererBoundingBox, renderer, rendererBoundingBox); 104 // Compose the normalized rects. 105 FloatRect normalizedBoxRect = toNormalizedRect(renderer->absoluteBoundingBoxRect(), renderer); 115 106 normalizedRect.scale(normalizedBoxRect.width(), normalizedBoxRect.height()); 116 107 normalizedRect.moveBy(normalizedBoxRect.location()); … … 123 114 ASSERT(renderer->isRenderView()); 124 115 renderer = renderer->frame() ? renderer->frame()->ownerRenderer() : 0; 125 126 // Update the absolute coordinates to the new frame.127 if (renderer)128 rendererBoundingBox = renderer->absoluteBoundingBoxRect();129 116 } 130 117 -
trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp
r125581 r126204 892 892 static const char* kFindString = "result"; 893 893 static const int kFindIdentifier = 12345; 894 static const int kNumResults = 1 0;894 static const int kNumResults = 16; 895 895 896 896 WebFindOptions options; … … 919 919 Range* result = mainFrame->activeMatchFrame()->activeMatch(); 920 920 ASSERT_TRUE(result); 921 result->setEnd(result->endContainer(), result->endOffset() + 2);922 EXPECT_EQ(result->text(), String::format("%s % d", kFindString, resultIndex));921 result->setEnd(result->endContainer(), result->endOffset() + 3); 922 EXPECT_EQ(result->text(), String::format("%s %02d", kFindString, resultIndex)); 923 923 924 924 // Verify that the expected match rect also matches the currently active match. … … 950 950 EXPECT_TRUE(webMatchRects[7].y < webMatchRects[8].y); 951 951 EXPECT_TRUE(webMatchRects[8].y < webMatchRects[9].y); 952 953 // Results 11, 12, 13 and 14 should be between results 10 and 15, as they are inside the table. 954 EXPECT_TRUE(webMatchRects[11].y > webMatchRects[10].y); 955 EXPECT_TRUE(webMatchRects[12].y > webMatchRects[10].y); 956 EXPECT_TRUE(webMatchRects[13].y > webMatchRects[10].y); 957 EXPECT_TRUE(webMatchRects[14].y > webMatchRects[10].y); 958 EXPECT_TRUE(webMatchRects[11].y < webMatchRects[15].y); 959 EXPECT_TRUE(webMatchRects[12].y < webMatchRects[15].y); 960 EXPECT_TRUE(webMatchRects[13].y < webMatchRects[15].y); 961 EXPECT_TRUE(webMatchRects[14].y < webMatchRects[15].y); 962 963 // Result 11 should be above 12, 13 and 14 as it's in the table header. 964 EXPECT_TRUE(webMatchRects[11].y < webMatchRects[12].y); 965 EXPECT_TRUE(webMatchRects[11].y < webMatchRects[13].y); 966 EXPECT_TRUE(webMatchRects[11].y < webMatchRects[14].y); 967 968 // Result 11 should also be right to 12, 13 and 14 because of the colspan. 969 EXPECT_TRUE(webMatchRects[11].x > webMatchRects[12].x); 970 EXPECT_TRUE(webMatchRects[11].x > webMatchRects[13].x); 971 EXPECT_TRUE(webMatchRects[11].x > webMatchRects[14].x); 972 973 // Result 12 should be left to results 11, 13 and 14 in the table layout. 974 EXPECT_TRUE(webMatchRects[12].x < webMatchRects[11].x); 975 EXPECT_TRUE(webMatchRects[12].x < webMatchRects[13].x); 976 EXPECT_TRUE(webMatchRects[12].x < webMatchRects[14].x); 977 978 // Results 13, 12 and 14 should be one above the other in that order because of the rowspan 979 // and vertical-align: middle by default. 980 EXPECT_TRUE(webMatchRects[13].y < webMatchRects[12].y); 981 EXPECT_TRUE(webMatchRects[12].y < webMatchRects[14].y); 952 982 953 983 // Resizing should update the rects version. -
trunk/Source/WebKit/chromium/tests/data/find_in_page.html
r125379 r126204 6 6 <body> 7 7 This a find-in-page match rect test.</br> 8 result 0 </br>8 result 00</br> 9 9 <iframe src="find_in_page_frame.html" height="300" scrolling="yes"></iframe> 10 10 </br> 11 result 111 result 01 12 12 </body> 13 13 </html> -
trunk/Source/WebKit/chromium/tests/data/find_in_page_frame.html
r125379 r126204 37 37 </br></br> 38 38 </br></br> 39 result 239 result 02 40 40 <div class="transform"> 41 result 341 result 03 42 42 </div> 43 result 443 result 04 44 44 <div class="fixed"> 45 result 545 result 05 46 46 </div> 47 result 647 result 06 48 48 <div class="scroll"> 49 result 749 result 07 50 50 Foo bar. 51 51 </br></br> 52 52 </br></br> 53 53 </br></br> 54 result 854 result 08 55 55 </div> 56 result 9 56 result 09 57 </br></br> 58 result 10 59 <table border="1" cellpadding="10" cellspacing="10"> 60 <tr> 61 <th>Foo</th> 62 <th>Bar</th> 63 <th>result 11</th> 64 </tr> 65 <tr> 66 <td rowspan="2">result 12</td> 67 <td colspan="2">result 13</td> 68 </tr> 69 <tr> 70 <td colspan="2">result 14</td> 71 </tr> 72 </table> 73 result 15 57 74 </body> 58 75 </html>
Note: See TracChangeset
for help on using the changeset viewer.