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

Side by Side Diff: Source/web/LinkHighlight.cpp

Issue 129643002: Fix link highlights on links that contain images. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 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/web/LinkHighlight.h ('k') | Source/web/WebViewImpl.cpp » ('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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "core/rendering/style/ShadowData.h" 42 #include "core/rendering/style/ShadowData.h"
43 #include "platform/graphics/Color.h" 43 #include "platform/graphics/Color.h"
44 #include "public/platform/Platform.h" 44 #include "public/platform/Platform.h"
45 #include "public/platform/WebAnimationCurve.h" 45 #include "public/platform/WebAnimationCurve.h"
46 #include "public/platform/WebCompositorSupport.h" 46 #include "public/platform/WebCompositorSupport.h"
47 #include "public/platform/WebFloatAnimationCurve.h" 47 #include "public/platform/WebFloatAnimationCurve.h"
48 #include "public/platform/WebFloatPoint.h" 48 #include "public/platform/WebFloatPoint.h"
49 #include "public/platform/WebRect.h" 49 #include "public/platform/WebRect.h"
50 #include "public/platform/WebSize.h" 50 #include "public/platform/WebSize.h"
51 #include "wtf/CurrentTime.h" 51 #include "wtf/CurrentTime.h"
52 #include "wtf/Vector.h"
52 53
53 using namespace WebCore; 54 using namespace WebCore;
54 55
55 namespace blink { 56 namespace blink {
56 57
57 class WebViewImpl; 58 class WebViewImpl;
58 59
59 PassOwnPtr<LinkHighlight> LinkHighlight::create(Node* node, WebViewImpl* owningW ebViewImpl) 60 PassOwnPtr<LinkHighlight> LinkHighlight::create(Node* node, WebViewImpl* owningW ebViewImpl)
60 { 61 {
61 return adoptPtr(new LinkHighlight(node, owningWebViewImpl)); 62 return adoptPtr(new LinkHighlight(node, owningWebViewImpl));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 static void addQuadToPath(const FloatQuad& quad, Path& path) 178 static void addQuadToPath(const FloatQuad& quad, Path& path)
178 { 179 {
179 // FIXME: Make this create rounded quad-paths, just like the axis-aligned ca se. 180 // FIXME: Make this create rounded quad-paths, just like the axis-aligned ca se.
180 path.moveTo(quad.p1()); 181 path.moveTo(quad.p1());
181 path.addLineTo(quad.p2()); 182 path.addLineTo(quad.p2());
182 path.addLineTo(quad.p3()); 183 path.addLineTo(quad.p3());
183 path.addLineTo(quad.p4()); 184 path.addLineTo(quad.p4());
184 path.closeSubpath(); 185 path.closeSubpath();
185 } 186 }
186 187
188 void LinkHighlight::computeQuads(RenderObject* renderer, Vector<FloatQuad>& outQ uads) const
189 {
190 if (!renderer)
191 return;
192
193 Vector<FloatQuad> newQuads;
194 renderer->absoluteQuads(newQuads);
195
196 // As an optimization and to ensure we draw a rounded highlight, ensure we d on't add
197 // any quads that are contained in an existing quad. If there is more than o ne
198 // quad returned they won't get rounded (see FIXME in computeHighlightLayerP athAndPosition).
199 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
200 for (unsigned newIx = newQuads.size(); newIx > 0; --newIx) {
201 if (outQuads[i].containsQuad(newQuads[newIx - 1]))
202 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
203 }
204 }
205
206 outQuads.append(newQuads);
207
208 // For inline elements, absoluteQuads will return a line box based on the li ne-height
209 // and font metrics, which is technically incorrect as replaced elements lik e images
210 // should use their intristic height and expand the linebox as needed. To g et an
211 // appropriately sized highlight we descend into the children and have them add their
212 // boxes.
213 if (renderer->isInline()) {
214 for (RenderObject* child = renderer->firstChild(); child; child = child- >nextSibling())
215 computeQuads(child, outQuads);
216 }
217
218 }
219
187 bool LinkHighlight::computeHighlightLayerPathAndPosition(RenderLayer* compositin gLayer) 220 bool LinkHighlight::computeHighlightLayerPathAndPosition(RenderLayer* compositin gLayer)
188 { 221 {
189 if (!m_node || !m_node->renderer() || !m_currentGraphicsLayer) 222 if (!m_node || !m_node->renderer() || !m_currentGraphicsLayer)
190 return false; 223 return false;
191 224
192 ASSERT(compositingLayer); 225 ASSERT(compositingLayer);
193 226
194 // Get quads for node in absolute coordinates. 227 // Get quads for node in absolute coordinates.
195 Vector<FloatQuad> quads; 228 Vector<FloatQuad> quads;
196 m_node->renderer()->absoluteQuads(quads); 229 computeQuads(m_node->renderer(), quads);
197 ASSERT(quads.size()); 230 ASSERT(quads.size());
198 231
199 // Adjust for offset between target graphics layer and the node's renderer. 232 // Adjust for offset between target graphics layer and the node's renderer.
200 FloatPoint positionAdjust = IntPoint(m_currentGraphicsLayer->offsetFromRende rer()); 233 FloatPoint positionAdjust = IntPoint(m_currentGraphicsLayer->offsetFromRende rer());
201 234
202 Path newPath; 235 Path newPath;
203 for (unsigned quadIndex = 0; quadIndex < quads.size(); ++quadIndex) { 236 for (unsigned quadIndex = 0; quadIndex < quads.size(); ++quadIndex) {
204 FloatQuad absoluteQuad = quads[quadIndex]; 237 FloatQuad absoluteQuad = quads[quadIndex];
205 absoluteQuad.move(-positionAdjust.x(), -positionAdjust.y()); 238 absoluteQuad.move(-positionAdjust.x(), -positionAdjust.y());
206 239
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Make sure we update geometry on the next callback from WebViewImpl::layou t(). 366 // Make sure we update geometry on the next callback from WebViewImpl::layou t().
334 m_geometryNeedsUpdate = true; 367 m_geometryNeedsUpdate = true;
335 } 368 }
336 369
337 WebLayer* LinkHighlight::layer() 370 WebLayer* LinkHighlight::layer()
338 { 371 {
339 return clipLayer(); 372 return clipLayer();
340 } 373 }
341 374
342 } // namespace WeKit 375 } // namespace WeKit
OLDNEW
« no previous file with comments | « Source/web/LinkHighlight.h ('k') | Source/web/WebViewImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698