Created
February 1, 2012 13:17
-
-
Save kenchris/1716934 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ManualTests/qt/tap-highlighting-images.html b/ManualTests/qt/tap-highlighting-images.html | |
index bbeea1a..a5e2bf8 100644 | |
--- a/ManualTests/qt/tap-highlighting-images.html | |
+++ b/ManualTests/qt/tap-highlighting-images.html | |
@@ -1,6 +1,6 @@ | |
<body style="background-color: green"> | |
<p>Two anchors, one around a pure image, the other around an image embedded in a div.</p> | |
- <a href=""><img src="../resources/apple.jpg"></a> | |
- <a href=""><div style="background-color: blue;"><img style="display: block; margin-left: auto; margin-right: auto;" src="../resources/apple.jpg"></div></a> | |
+ <a href=""><img src="../resources/apple.jpg"></a><br><br> | |
+ <a href=""><div style="width: 400px; background-color: blue;"><img style="display: block; margin-left: auto; margin-right: auto;" src="../resources/apple.jpg"></div></a> | |
</body> | |
diff --git a/Source/WebCore/page/GestureTapHighlighter.cpp b/Source/WebCore/page/GestureTapHighlighter.cpp | |
index 7548abe..32a12d1 100644 | |
--- a/Source/WebCore/page/GestureTapHighlighter.cpp | |
+++ b/Source/WebCore/page/GestureTapHighlighter.cpp | |
@@ -42,6 +42,8 @@ | |
#include "RenderLayer.h" | |
#include "RenderObject.h" | |
+#include <QtDebug> | |
+ | |
namespace WebCore { | |
namespace { | |
@@ -81,39 +83,6 @@ AffineTransform localToAbsoluteTransform(const RenderObject* o) | |
return transform; | |
} | |
-Path pathForRenderBox(RenderBox* o) | |
-{ | |
- ASSERT(o); | |
- const int rounding = 4; | |
- | |
- LayoutRect contentBox; | |
- LayoutRect paddingBox; | |
- LayoutRect borderBox; | |
- | |
- contentBox = o->contentBoxRect(); | |
- paddingBox = LayoutRect( | |
- contentBox.x() - o->paddingLeft(), | |
- contentBox.y() - o->paddingTop(), | |
- contentBox.width() + o->paddingLeft() + o->paddingRight(), | |
- contentBox.height() + o->paddingTop() + o->paddingBottom()); | |
- borderBox = LayoutRect( | |
- paddingBox.x() - o->borderLeft(), | |
- paddingBox.y() - o->borderTop(), | |
- paddingBox.width() + o->borderLeft() + o->borderRight(), | |
- paddingBox.height() + o->borderTop() + o->borderBottom()); | |
- | |
- FloatRect rect(borderBox); | |
- rect.inflate(rounding); | |
- | |
- rect.move(toLayoutSize(ownerFrameToMainFrameOffset(o))); | |
- | |
- Path path; | |
- FloatSize rounded(rounding * 1.8, rounding * 1.8); | |
- path.addRoundedRect(rect, rounded); | |
- | |
- return path; | |
-} | |
- | |
void addRectWithRoundedCorners(Path& path, const LayoutRect& rect, bool topLeft, bool topRight, bool bottomLeft, bool bottomRight) | |
{ | |
const int rounding = 4; | |
@@ -135,20 +104,54 @@ inline bool contains(LayoutRect rect, int x) | |
return !rect.isEmpty() && x >= rect.x() && x <= rect.maxX(); | |
} | |
-Path pathForRenderInline(RenderInline* o) | |
+Path pathForRenderer(RenderObject* o) | |
{ | |
ASSERT(o); | |
Path path; | |
Vector<LayoutRect> rects; | |
- o->absoluteRects(rects, /* acc. offset */ ownerFrameToMainFrameOffset(o)); | |
+ o->addFocusRingRects(rects, /* acc. offset */ ownerFrameToMainFrameOffset(o)); | |
+ | |
+ if (!rects.size()) | |
+ return path; | |
+ | |
+ int end = rects.size() - 1; | |
+ int begin = 0; | |
+ | |
+ LayoutRect first; | |
+ for ( ; begin <= end; ++begin) { | |
+ LayoutRect cur = rects.at(begin); | |
+ if (cur.isEmpty()) | |
+ continue; | |
+ | |
+ if (!first.isEmpty() && !first.intersects(cur)) | |
+ break; | |
+ | |
+ first.unite(cur); | |
+ } | |
+ | |
+ LayoutRect last; | |
+ for ( ; end >= begin; --end) { | |
+ LayoutRect cur = rects.at(end); | |
+ if (cur.isEmpty()) | |
+ continue; | |
+ | |
+ if (!last.isEmpty() && !first.intersects(cur)) | |
+ break; | |
+ | |
+ last.unite(cur); | |
+ } | |
- LayoutRect first = rects.size() ? rects.first() : LayoutRect(); | |
- LayoutRect last = rects.size() > 1 ? rects.last() : LayoutRect(); | |
LayoutRect middle; | |
- for (int i = 1; i < rects.size() - 1; ++i) | |
- middle.uniteIfNonZero(rects.at(i)); | |
+ for ( ; begin <= end; ++begin) { | |
+ LayoutRect cur = rects.at(begin); | |
+ if (cur.isEmpty()) | |
+ continue; | |
+ middle.unite(cur); | |
+ } | |
+ | |
+ // Adjust middle to boundaries of first and last. | |
if (!middle.isEmpty()) { | |
int leftSide = middle.x(); | |
int rightSide = middle.maxX(); | |
@@ -199,12 +202,9 @@ Path pathForNodeHighlight(const Node* node) | |
if (!renderer || (!renderer->isBox() && !renderer->isRenderInline())) | |
return path; | |
- if (renderer->isBox()) | |
- path = pathForRenderBox(toRenderBox(renderer)); | |
- else | |
- path = pathForRenderInline(toRenderInline(renderer)); | |
- | |
+ path = pathForRenderer(renderer); | |
path.transform(localToAbsoluteTransform(renderer)); | |
+ | |
return path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment