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

Side by Side Diff: third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp

Issue 1747223002: Implement mapAncestorToLocal for LayoutSVG{ModelObject,Block} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid potential margin collapsing(?) bug Created 4 years, 9 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 | « third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.h ('k') | no next file » | 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) 2007, 2008 Rob Buis <buis@kde.org> 2 * Copyright (C) 2007, 2008 Rob Buis <buis@kde.org>
3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Google, Inc. All rights reserved. 5 * Copyright (C) 2009 Google, Inc. All rights reserved.
6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 7 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return rect; 109 return rect;
110 } 110 }
111 111
112 LayoutRect rect; 112 LayoutRect rect;
113 const LayoutSVGRoot& svgRoot = mapRectToSVGRootForPaintInvalidation(object, 113 const LayoutSVGRoot& svgRoot = mapRectToSVGRootForPaintInvalidation(object,
114 paintInvalidationRect, rect, strokeWidthForHairlinePadding); 114 paintInvalidationRect, rect, strokeWidthForHairlinePadding);
115 svgRoot.mapToVisibleRectInAncestorSpace(paintInvalidationContainer, rect, pa intInvalidationState); 115 svgRoot.mapToVisibleRectInAncestorSpace(paintInvalidationContainer, rect, pa intInvalidationState);
116 return rect; 116 return rect;
117 } 117 }
118 118
119 static const LayoutSVGRoot& computeTransformToSVGRoot(const LayoutObject& object , AffineTransform& rootBorderBoxTransform)
120 {
121 ASSERT(object.isSVG() && !object.isSVGRoot());
122
123 const LayoutObject* parent;
124 for (parent = &object; !parent->isSVGRoot(); parent = parent->parent())
125 rootBorderBoxTransform.preMultiply(parent->localToParentTransform());
126
127 const LayoutSVGRoot& svgRoot = toLayoutSVGRoot(*parent);
128 rootBorderBoxTransform.preMultiply(svgRoot.localToBorderBoxTransform());
129 return svgRoot;
130 }
131
119 const LayoutSVGRoot& SVGLayoutSupport::mapRectToSVGRootForPaintInvalidation(cons t LayoutObject& object, 132 const LayoutSVGRoot& SVGLayoutSupport::mapRectToSVGRootForPaintInvalidation(cons t LayoutObject& object,
120 const FloatRect& localPaintInvalidationRect, LayoutRect& rect, float strokeW idthForHairlinePadding) 133 const FloatRect& localPaintInvalidationRect, LayoutRect& rect, float strokeW idthForHairlinePadding)
121 { 134 {
122 ASSERT(object.isSVG() && !object.isSVGRoot());
123
124 const LayoutObject* parent;
125 AffineTransform rootBorderBoxTransform; 135 AffineTransform rootBorderBoxTransform;
126 for (parent = &object; !parent->isSVGRoot(); parent = parent->parent()) 136 const LayoutSVGRoot& svgRoot = computeTransformToSVGRoot(object, rootBorderB oxTransform);
127 rootBorderBoxTransform.preMultiply(parent->localToParentTransform());
128
129 const LayoutSVGRoot& svgRoot = toLayoutSVGRoot(*parent);
130 rootBorderBoxTransform.preMultiply(svgRoot.localToBorderBoxTransform());
131 137
132 rect = adjustedEnclosingIntRect(rootBorderBoxTransform.mapRect(localPaintInv alidationRect), 138 rect = adjustedEnclosingIntRect(rootBorderBoxTransform.mapRect(localPaintInv alidationRect),
133 rootBorderBoxTransform, strokeWidthForHairlinePadding); 139 rootBorderBoxTransform, strokeWidthForHairlinePadding);
134
135 return svgRoot; 140 return svgRoot;
136 } 141 }
137 142
138 void SVGLayoutSupport::mapLocalToAncestor(const LayoutObject* object, const Layo utBoxModelObject* ancestor, TransformState& transformState, bool* wasFixed, cons t PaintInvalidationState* paintInvalidationState) 143 void SVGLayoutSupport::mapLocalToAncestor(const LayoutObject* object, const Layo utBoxModelObject* ancestor, TransformState& transformState, bool* wasFixed, cons t PaintInvalidationState* paintInvalidationState)
139 { 144 {
140 transformState.applyTransform(object->localToParentTransform()); 145 transformState.applyTransform(object->localToParentTransform());
141 146
142 if (paintInvalidationState && paintInvalidationState->canMapToContainer(ance stor)) { 147 if (paintInvalidationState && paintInvalidationState->canMapToContainer(ance stor)) {
143 // |svgTransform| contains localToBorderBoxTransform mentioned below. 148 // |svgTransform| contains localToBorderBoxTransform mentioned below.
144 transformState.applyTransform(paintInvalidationState->svgTransform()); 149 transformState.applyTransform(paintInvalidationState->svgTransform());
145 transformState.move(paintInvalidationState->paintOffset()); 150 transformState.move(paintInvalidationState->paintOffset());
146 return; 151 return;
147 } 152 }
148 153
149 LayoutObject* parent = object->parent(); 154 LayoutObject* parent = object->parent();
150 155
151 // At the SVG/HTML boundary (aka LayoutSVGRoot), we apply the localToBorderB oxTransform 156 // At the SVG/HTML boundary (aka LayoutSVGRoot), we apply the localToBorderB oxTransform
152 // to map an element from SVG viewport coordinates to CSS box coordinates. 157 // to map an element from SVG viewport coordinates to CSS box coordinates.
153 // LayoutSVGRoot's mapLocalToAncestor method expects CSS box coordinates. 158 // LayoutSVGRoot's mapLocalToAncestor method expects CSS box coordinates.
154 if (parent->isSVGRoot()) 159 if (parent->isSVGRoot())
155 transformState.applyTransform(toLayoutSVGRoot(parent)->localToBorderBoxT ransform()); 160 transformState.applyTransform(toLayoutSVGRoot(parent)->localToBorderBoxT ransform());
156 161
157 MapCoordinatesFlags mode = UseTransforms; 162 MapCoordinatesFlags mode = UseTransforms;
158 parent->mapLocalToAncestor(ancestor, transformState, mode, wasFixed, paintIn validationState); 163 parent->mapLocalToAncestor(ancestor, transformState, mode, wasFixed, paintIn validationState);
159 } 164 }
160 165
166 void SVGLayoutSupport::mapAncestorToLocal(const LayoutObject& object, const Layo utBoxModelObject* ancestor, TransformState& transformState)
167 {
168 // |object| is either a LayoutSVGModelObject or a LayoutSVGBlock here. In
pdr. 2016/03/01 22:58:39 Can you add an assert for this?
fs 2016/03/02 08:54:30 It's a bit of a handful to express, but sure, adde
169 // the former case, |object| can never be an ancestor while in the latter
170 // the caller is responsible for doing the ancestor check. Because of this,
171 // computing the transform to the SVG root is always what we want to do here .
172 ASSERT(ancestor != &object);
173 AffineTransform localToSVGRoot;
174 const LayoutSVGRoot& svgRoot = computeTransformToSVGRoot(object, localToSVGR oot);
175
176 MapCoordinatesFlags mode = UseTransforms | ApplyContainerFlip;
177 svgRoot.mapAncestorToLocal(ancestor, transformState, mode);
178
179 transformState.applyTransform(localToSVGRoot);
180 }
181
161 const LayoutObject* SVGLayoutSupport::pushMappingToContainer(const LayoutObject* object, const LayoutBoxModelObject* ancestorToStopAt, LayoutGeometryMap& geomet ryMap) 182 const LayoutObject* SVGLayoutSupport::pushMappingToContainer(const LayoutObject* object, const LayoutBoxModelObject* ancestorToStopAt, LayoutGeometryMap& geomet ryMap)
162 { 183 {
163 ASSERT_UNUSED(ancestorToStopAt, ancestorToStopAt != object); 184 ASSERT_UNUSED(ancestorToStopAt, ancestorToStopAt != object);
164 185
165 LayoutObject* parent = object->parent(); 186 LayoutObject* parent = object->parent();
166 187
167 // At the SVG/HTML boundary (aka LayoutSVGRoot), we apply the localToBorderB oxTransform 188 // At the SVG/HTML boundary (aka LayoutSVGRoot), we apply the localToBorderB oxTransform
168 // to map an element from SVG viewport coordinates to CSS box coordinates. 189 // to map an element from SVG viewport coordinates to CSS box coordinates.
169 // LayoutSVGRoot's mapLocalToAncestor method expects CSS box coordinates. 190 // LayoutSVGRoot's mapLocalToAncestor method expects CSS box coordinates.
170 if (parent->isSVGRoot()) { 191 if (parent->isSVGRoot()) {
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 587
567 return closestText; 588 return closestText;
568 } 589 }
569 590
570 LayoutObject* SVGLayoutSupport::findClosestLayoutSVGText(LayoutObject* layoutObj ect, const FloatPoint& point) 591 LayoutObject* SVGLayoutSupport::findClosestLayoutSVGText(LayoutObject* layoutObj ect, const FloatPoint& point)
571 { 592 {
572 return searchTreeForFindClosestLayoutSVGText(layoutObject, point).candidateL ayoutObject; 593 return searchTreeForFindClosestLayoutSVGText(layoutObject, point).candidateL ayoutObject;
573 } 594 }
574 595
575 } // namespace blink 596 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698