Index: Source/web/LinkHighlight.cpp |
diff --git a/Source/web/LinkHighlight.cpp b/Source/web/LinkHighlight.cpp |
index 34aa09d71558e9a25fb4d87b3d5c4cd6e0b13d6d..33fdae2585f9c7789248217318454fef775f85f3 100644 |
--- a/Source/web/LinkHighlight.cpp |
+++ b/Source/web/LinkHighlight.cpp |
@@ -49,6 +49,7 @@ |
#include "public/platform/WebRect.h" |
#include "public/platform/WebSize.h" |
#include "wtf/CurrentTime.h" |
+#include "wtf/Vector.h" |
using namespace WebCore; |
@@ -184,6 +185,38 @@ static void addQuadToPath(const FloatQuad& quad, Path& path) |
path.closeSubpath(); |
} |
+void LinkHighlight::computeQuads(RenderObject* renderer, Vector<FloatQuad>& outQuads) const |
+{ |
+ if (!renderer) |
+ return; |
+ |
+ Vector<FloatQuad> newQuads; |
+ renderer->absoluteQuads(newQuads); |
+ |
+ // As an optimization and to ensure we draw a rounded highlight, ensure we don't add |
+ // any quads that are contained in an existing quad. If there is more than one |
+ // quad returned they won't get rounded (see FIXME in computeHighlightLayerPathAndPosition). |
+ for (unsigned i = 0; i < outQuads.size(); ++i) { |
aelias_OOO_until_Jul13
2014/01/11 00:22:45
Nit: use size_t instead of unsigned
|
+ for (unsigned newIx = newQuads.size(); newIx > 0; --newIx) { |
+ if (outQuads[i].containsQuad(newQuads[newIx - 1])) |
+ newQuads.remove(newIx - 1); |
aelias_OOO_until_Jul13
2014/01/11 00:22:45
removal is an O(n) operation on a Vector. In addi
|
+ } |
+ } |
+ |
+ outQuads.append(newQuads); |
+ |
+ // For inline elements, absoluteQuads will return a line box based on the line-height |
+ // and font metrics, which is technically incorrect as replaced elements like images |
+ // should use their intristic height and expand the linebox as needed. To get an |
+ // appropriately sized highlight we descend into the children and have them add their |
+ // boxes. |
+ if (renderer->isInline()) { |
+ for (RenderObject* child = renderer->firstChild(); child; child = child->nextSibling()) |
+ computeQuads(child, outQuads); |
+ } |
+ |
+} |
+ |
bool LinkHighlight::computeHighlightLayerPathAndPosition(RenderLayer* compositingLayer) |
{ |
if (!m_node || !m_node->renderer() || !m_currentGraphicsLayer) |
@@ -193,7 +226,7 @@ bool LinkHighlight::computeHighlightLayerPathAndPosition(RenderLayer* compositin |
// Get quads for node in absolute coordinates. |
Vector<FloatQuad> quads; |
- m_node->renderer()->absoluteQuads(quads); |
+ computeQuads(m_node->renderer(), quads); |
ASSERT(quads.size()); |
// Adjust for offset between target graphics layer and the node's renderer. |