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

Side by Side Diff: Source/core/rendering/RenderObject.cpp

Issue 492053002: Use LayoutRect during addFocusRingRects to avoid loss of precision (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com) 5 * (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2009 Google Inc. All rights reserved. 7 * Copyright (C) 2009 Google Inc. All rights reserved.
8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 quad[3] = FloatPoint(x2, y1 + std::max(-adjacentWidth1, 0)); 1210 quad[3] = FloatPoint(x2, y1 + std::max(-adjacentWidth1, 0));
1211 break; 1211 break;
1212 } 1212 }
1213 1213
1214 graphicsContext->drawConvexPolygon(4, quad, antialias); 1214 graphicsContext->drawConvexPolygon(4, quad, antialias);
1215 graphicsContext->setStrokeStyle(oldStrokeStyle); 1215 graphicsContext->setStrokeStyle(oldStrokeStyle);
1216 } 1216 }
1217 1217
1218 void RenderObject::paintFocusRing(PaintInfo& paintInfo, const LayoutPoint& paint Offset, RenderStyle* style) 1218 void RenderObject::paintFocusRing(PaintInfo& paintInfo, const LayoutPoint& paint Offset, RenderStyle* style)
1219 { 1219 {
1220 Vector<IntRect> focusRingRects; 1220 Vector<LayoutRect> focusRingRects;
1221 addFocusRingRects(focusRingRects, paintOffset, paintInfo.paintContainer()); 1221 addFocusRingRects(focusRingRects, paintOffset, paintInfo.paintContainer());
1222 if (style->outlineStyleIsAuto()) 1222 if (style->outlineStyleIsAuto()) {
1223 paintInfo.context->drawFocusRing(focusRingRects, style->outlineWidth(), style->outlineOffset(), resolveColor(style, CSSPropertyOutlineColor)); 1223 Vector<IntRect> focusRingIntRects;
1224 else 1224 for (size_t i = 0; i < focusRingRects.size(); ++i)
1225 addPDFURLRect(paintInfo.context, unionRect(focusRingRects)); 1225 focusRingIntRects.append(pixelSnappedIntRect(focusRingRects[i]));
Julien - ping for review 2014/08/20 22:12:31 We talked about this O(N) loop and while it should
Xianzhu 2014/09/04 00:29:12 Previously the computation of the loop was distrib
1226 paintInfo.context->drawFocusRing(focusRingIntRects, style->outlineWidth( ), style->outlineOffset(), resolveColor(style, CSSPropertyOutlineColor));
1227 return;
1228 }
1229 addPDFURLRect(paintInfo.context, unionRect(focusRingRects));
1226 } 1230 }
1227 1231
1228 void RenderObject::addPDFURLRect(GraphicsContext* context, const LayoutRect& rec t) 1232 void RenderObject::addPDFURLRect(GraphicsContext* context, const LayoutRect& rec t)
1229 { 1233 {
1230 if (rect.isEmpty()) 1234 if (rect.isEmpty())
1231 return; 1235 return;
1232 Node* n = node(); 1236 Node* n = node();
1233 if (!n || !n->isLink() || !n->isElementNode()) 1237 if (!n || !n->isLink() || !n->isElementNode())
1234 return; 1238 return;
1235 const AtomicString& href = toElement(n)->getAttribute(hrefAttr); 1239 const AtomicString& href = toElement(n)->getAttribute(hrefAttr);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 1311
1308 drawLineForBoxSide(graphicsContext, leftOuter, topOuter, leftInner, bottomOu ter, BSLeft, outlineColor, outlineStyle, outlineWidth, outlineWidth); 1312 drawLineForBoxSide(graphicsContext, leftOuter, topOuter, leftInner, bottomOu ter, BSLeft, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1309 drawLineForBoxSide(graphicsContext, leftOuter, topOuter, rightOuter, topInne r, BSTop, outlineColor, outlineStyle, outlineWidth, outlineWidth); 1313 drawLineForBoxSide(graphicsContext, leftOuter, topOuter, rightOuter, topInne r, BSTop, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1310 drawLineForBoxSide(graphicsContext, rightInner, topOuter, rightOuter, bottom Outer, BSRight, outlineColor, outlineStyle, outlineWidth, outlineWidth); 1314 drawLineForBoxSide(graphicsContext, rightInner, topOuter, rightOuter, bottom Outer, BSRight, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1311 drawLineForBoxSide(graphicsContext, leftOuter, bottomInner, rightOuter, bott omOuter, BSBottom, outlineColor, outlineStyle, outlineWidth, outlineWidth); 1315 drawLineForBoxSide(graphicsContext, leftOuter, bottomInner, rightOuter, bott omOuter, BSBottom, outlineColor, outlineStyle, outlineWidth, outlineWidth);
1312 1316
1313 if (useTransparencyLayer) 1317 if (useTransparencyLayer)
1314 graphicsContext->endLayer(); 1318 graphicsContext->endLayer();
1315 } 1319 }
1316 1320
1317 void RenderObject::addChildFocusRingRects(Vector<IntRect>& rects, const LayoutPo int& additionalOffset, const RenderLayerModelObject* paintContainer) const 1321 void RenderObject::addChildFocusRingRects(Vector<LayoutRect>& rects, const Layou tPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const
1318 { 1322 {
1319 for (RenderObject* current = slowFirstChild(); current; current = current->n extSibling()) { 1323 for (RenderObject* current = slowFirstChild(); current; current = current->n extSibling()) {
1320 if (current->isText() || current->isListMarker()) 1324 if (current->isText() || current->isListMarker())
1321 continue; 1325 continue;
1322 1326
1323 if (current->isBox()) { 1327 if (current->isBox()) {
1324 RenderBox* box = toRenderBox(current); 1328 RenderBox* box = toRenderBox(current);
1325 if (box->hasLayer()) { 1329 if (box->hasLayer()) {
1326 Vector<IntRect> layerFocusRingRects; 1330 Vector<LayoutRect> layerFocusRingRects;
1327 box->addFocusRingRects(layerFocusRingRects, LayoutPoint(), box); 1331 box->addFocusRingRects(layerFocusRingRects, LayoutPoint(), box);
1328 for (size_t i = 0; i < layerFocusRingRects.size(); ++i) { 1332 for (size_t i = 0; i < layerFocusRingRects.size(); ++i) {
1329 FloatQuad quadInBox = box->localToContainerQuad(FloatRect(la yerFocusRingRects[i]), paintContainer); 1333 FloatQuad quadInBox = box->localToContainerQuad(FloatQuad(la yerFocusRingRects[i]), paintContainer);
1330 rects.append(pixelSnappedIntRect(LayoutRect(quadInBox.boundi ngBox()))); 1334 LayoutRect rect = LayoutRect(quadInBox.boundingBox());
1335 if (!rect.isEmpty())
1336 rects.append(rect);
1331 } 1337 }
1332 } else { 1338 } else {
1333 FloatPoint pos(additionalOffset); 1339 box->addFocusRingRects(rects, additionalOffset + box->locationOf fset(), paintContainer);
1334 pos.move(box->locationOffset()); // FIXME: Snap offsets? crbug.c om/350474
1335 box->addFocusRingRects(rects, flooredIntPoint(pos), paintContain er);
1336 } 1340 }
1337 } else { 1341 } else {
1338 current->addFocusRingRects(rects, additionalOffset, paintContainer); 1342 current->addFocusRingRects(rects, additionalOffset, paintContainer);
1339 } 1343 }
1340 } 1344 }
1341 } 1345 }
1342 1346
1343 LayoutPoint RenderObject::positionFromPaintInvalidationContainer(const RenderLay erModelObject* paintInvalidationContainer, const PaintInvalidationState* paintIn validationState) const 1347 LayoutPoint RenderObject::positionFromPaintInvalidationContainer(const RenderLay erModelObject* paintInvalidationContainer, const PaintInvalidationState* paintIn validationState) const
1344 { 1348 {
1345 ASSERT(containerForPaintInvalidation() == paintInvalidationContainer); 1349 ASSERT(containerForPaintInvalidation() == paintInvalidationContainer);
(...skipping 30 matching lines...) Expand all
1376 return IntRect(); 1380 return IntRect();
1377 1381
1378 LayoutRect result = rects[0]; 1382 LayoutRect result = rects[0];
1379 for (size_t i = 1; i < n; ++i) 1383 for (size_t i = 1; i < n; ++i)
1380 result.unite(rects[i]); 1384 result.unite(rects[i]);
1381 return pixelSnappedIntRect(result); 1385 return pixelSnappedIntRect(result);
1382 } 1386 }
1383 1387
1384 void RenderObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads) 1388 void RenderObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads)
1385 { 1389 {
1386 Vector<IntRect> rects; 1390 Vector<LayoutRect> rects;
1387 const RenderLayerModelObject* container = containerForPaintInvalidation(); 1391 const RenderLayerModelObject* container = containerForPaintInvalidation();
1388 addFocusRingRects(rects, LayoutPoint(localToContainerPoint(FloatPoint(), con tainer)), container); 1392 addFocusRingRects(rects, LayoutPoint(localToContainerPoint(FloatPoint(), con tainer)), container);
1389 size_t count = rects.size(); 1393 size_t count = rects.size();
1390 for (size_t i = 0; i < count; ++i) 1394 for (size_t i = 0; i < count; ++i)
1391 quads.append(container->localToAbsoluteQuad(FloatQuad(rects[i]))); 1395 quads.append(container->localToAbsoluteQuad(FloatQuad(rects[i])));
1392 } 1396 }
1393 1397
1394 FloatRect RenderObject::absoluteBoundingBoxRectForRange(const Range* range) 1398 FloatRect RenderObject::absoluteBoundingBoxRectForRange(const Range* range)
1395 { 1399 {
1396 if (!range || !range->startContainer()) 1400 if (!range || !range->startContainer())
(...skipping 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after
3474 { 3478 {
3475 if (object1) { 3479 if (object1) {
3476 const blink::RenderObject* root = object1; 3480 const blink::RenderObject* root = object1;
3477 while (root->parent()) 3481 while (root->parent())
3478 root = root->parent(); 3482 root = root->parent();
3479 root->showRenderTreeAndMark(object1, "*", object2, "-", 0); 3483 root->showRenderTreeAndMark(object1, "*", object2, "-", 0);
3480 } 3484 }
3481 } 3485 }
3482 3486
3483 #endif 3487 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698