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

Side by Side Diff: third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp

Issue 1458083002: Support fragment URLs for more kinds of SVG images (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplification wasn't simple enough Created 5 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org> 2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 intrinsicSize = rootElement->currentViewBoxRect().size(); 187 intrinsicSize = rootElement->currentViewBoxRect().size();
188 188
189 if (!intrinsicSize.isEmpty()) 189 if (!intrinsicSize.isEmpty())
190 return expandedIntSize(intrinsicSize); 190 return expandedIntSize(intrinsicSize);
191 191
192 // As last resort, use CSS replaced element fallback size. 192 // As last resort, use CSS replaced element fallback size.
193 return IntSize(300, 150); 193 return IntSize(300, 150);
194 } 194 }
195 195
196 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl oatSize containerSize, float zoom, const FloatRect& dstRect, 196 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl oatSize containerSize, float zoom, const FloatRect& dstRect,
197 const FloatRect& srcRect) 197 const FloatRect& srcRect, const KURL& url)
198 { 198 {
199 if (!m_page) 199 if (!m_page)
200 return; 200 return;
201 201
202 // Temporarily disable the image observer to prevent changeInRect() calls du e re-laying out the image. 202 // Temporarily disable the image observer to prevent changeInRect() calls du e re-laying out the image.
203 ImageObserverDisabler imageObserverDisabler(this); 203 ImageObserverDisabler imageObserverDisabler(this);
204 204
205 IntSize roundedContainerSize = roundedIntSize(containerSize); 205 IntSize roundedContainerSize = roundedIntSize(containerSize);
206 setContainerSize(roundedContainerSize); 206 setContainerSize(roundedContainerSize);
207 207
208 FloatRect scaledSrc = srcRect; 208 FloatRect scaledSrc = srcRect;
209 scaledSrc.scale(1 / zoom); 209 scaledSrc.scale(1 / zoom);
210 210
211 // Compensate for the container size rounding by adjusting the source rect. 211 // Compensate for the container size rounding by adjusting the source rect.
212 FloatSize adjustedSrcSize = scaledSrc.size(); 212 FloatSize adjustedSrcSize = scaledSrc.size();
213 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height()); 213 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height());
214 scaledSrc.setSize(adjustedSrcSize); 214 scaledSrc.setSize(adjustedSrcSize);
215 215
216 draw(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation, ClampI mageToSourceRect); 216 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation , ClampImageToSourceRect, url);
217 } 217 }
218 218
219 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame() 219 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame()
220 { 220 {
221 if (!m_page) 221 if (!m_page)
222 return nullptr; 222 return nullptr;
223 223
224 SkPictureRecorder recorder; 224 SkPictureRecorder recorder;
225 SkCanvas* canvas = recorder.beginRecording(width(), height()); 225 SkCanvas* canvas = recorder.beginRecording(width(), height());
226 drawForContainer(canvas, SkPaint(), FloatSize(size()), 1, rect(), rect()); 226 drawForContainer(canvas, SkPaint(), FloatSize(size()), 1, rect(), rect(), KU RL());
227 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); 227 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
228 228
229 return adoptRef( 229 return adoptRef(
230 SkImage::NewFromPicture(picture.get(), SkISize::Make(width(), height()), nullptr, nullptr)); 230 SkImage::NewFromPicture(picture.get(), SkISize::Make(width(), height()), nullptr, nullptr));
231 } 231 }
232 232
233 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize, 233 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize,
234 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa tPoint& phase, 234 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa tPoint& phase,
235 SkXfermode::Mode compositeOp, const FloatRect& dstRect, 235 SkXfermode::Mode compositeOp, const FloatRect& dstRect,
236 const IntSize& repeatSpacing) 236 const IntSize& repeatSpacing, const KURL& url)
237 { 237 {
238 // Tile adjusted for scaling/stretch. 238 // Tile adjusted for scaling/stretch.
239 FloatRect tile(srcRect); 239 FloatRect tile(srcRect);
240 tile.scale(tileScale.width(), tileScale.height()); 240 tile.scale(tileScale.width(), tileScale.height());
241 241
242 // Expand the tile to account for repeat spacing. 242 // Expand the tile to account for repeat spacing.
243 FloatRect spacedTile(tile); 243 FloatRect spacedTile(tile);
244 spacedTile.expand(FloatSize(repeatSpacing)); 244 spacedTile.expand(FloatSize(repeatSpacing));
245 245
246 SkPictureBuilder patternPicture(spacedTile, nullptr, context); 246 SkPictureBuilder patternPicture(spacedTile, nullptr, context);
247 if (!DrawingRecorder::useCachedDrawingIfPossible(patternPicture.context(), * this, DisplayItem::Type::SVGImage)) { 247 if (!DrawingRecorder::useCachedDrawingIfPossible(patternPicture.context(), * this, DisplayItem::Type::SVGImage)) {
248 DrawingRecorder patternPictureRecorder(patternPicture.context(), *this, DisplayItem::Type::SVGImage, spacedTile); 248 DrawingRecorder patternPictureRecorder(patternPicture.context(), *this, DisplayItem::Type::SVGImage, spacedTile);
249 // When generating an expanded tile, make sure we don't draw into the sp acing area. 249 // When generating an expanded tile, make sure we don't draw into the sp acing area.
250 if (tile != spacedTile) 250 if (tile != spacedTile)
251 patternPicture.context().clip(tile); 251 patternPicture.context().clip(tile);
252 SkPaint paint; 252 SkPaint paint;
253 drawForContainer(patternPicture.context().canvas(), paint, containerSize , zoom, tile, srcRect); 253 drawForContainer(patternPicture.context().canvas(), paint, containerSize , zoom, tile, srcRect, url);
254 } 254 }
255 RefPtr<const SkPicture> tilePicture = patternPicture.endRecording(); 255 RefPtr<const SkPicture> tilePicture = patternPicture.endRecording();
256 256
257 SkMatrix patternTransform; 257 SkMatrix patternTransform;
258 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced Tile.y()); 258 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced Tile.y());
259 RefPtr<SkShader> patternShader = adoptRef(SkShader::CreatePictureShader( 259 RefPtr<SkShader> patternShader = adoptRef(SkShader::CreatePictureShader(
260 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod e, 260 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod e,
261 &patternTransform, nullptr)); 261 &patternTransform, nullptr));
262 262
263 SkPaint paint; 263 SkPaint paint;
(...skipping 10 matching lines...) Expand all
274 274
275 SkXfermode::Mode xfermode; 275 SkXfermode::Mode xfermode;
276 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { 276 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) {
277 if (xfermode != SkXfermode::kSrcOver_Mode) 277 if (xfermode != SkXfermode::kSrcOver_Mode)
278 return true; 278 return true;
279 } 279 }
280 280
281 return false; 281 return false;
282 } 282 }
283 283
284 void SVGImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dst Rect, const FloatRect& srcRect, RespectImageOrientationEnum, ImageClampingMode) 284 void SVGImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dst Rect, const FloatRect& srcRect,
285 RespectImageOrientationEnum shouldRespectImageOrientation, ImageClampingMode clampMode)
285 { 286 {
286 if (!m_page) 287 if (!m_page)
287 return; 288 return;
288 289
290 drawInternal(canvas, paint, dstRect, srcRect, shouldRespectImageOrientation, clampMode, KURL());
291 }
292
293 void SVGImage::drawInternal(SkCanvas* canvas, const SkPaint& paint, const FloatR ect& dstRect, const FloatRect& srcRect,
294 RespectImageOrientationEnum, ImageClampingMode, const KURL& url)
295 {
289 FrameView* view = frameView(); 296 FrameView* view = frameView();
290 view->resize(containerSize()); 297 view->resize(containerSize());
291 298
292 // Always call processUrlFragment, even if the url is empty, because 299 // Always call processUrlFragment, even if the url is empty, because
293 // there may have been a previous url/fragment that needs to be reset. 300 // there may have been a previous url/fragment that needs to be reset.
294 view->processUrlFragment(m_url); 301 view->processUrlFragment(url);
295 302
296 SkPictureBuilder imagePicture(dstRect); 303 SkPictureBuilder imagePicture(dstRect);
297 { 304 {
298 ClipRecorder clipRecorder(imagePicture.context(), *this, DisplayItem::Cl ipNodeImage, LayoutRect(enclosingIntRect(dstRect))); 305 ClipRecorder clipRecorder(imagePicture.context(), *this, DisplayItem::Cl ipNodeImage, LayoutRect(enclosingIntRect(dstRect)));
299 306
300 // We can only draw the entire frame, clipped to the rect we want. So co mpute where the top left 307 // We can only draw the entire frame, clipped to the rect we want. So co mpute where the top left
301 // of the image would be if we were drawing without clipping, and transl ate accordingly. 308 // of the image would be if we were drawing without clipping, and transl ate accordingly.
302 FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / sr cRect.height()); 309 FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / sr cRect.height());
303 FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect. location().y() * scale.height()); 310 FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect. location().y() * scale.height());
304 FloatPoint destOffset = dstRect.location() - topLeftOffset; 311 FloatPoint destOffset = dstRect.location() - topLeftOffset;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 507
501 return m_page; 508 return m_page;
502 } 509 }
503 510
504 String SVGImage::filenameExtension() const 511 String SVGImage::filenameExtension() const
505 { 512 {
506 return "svg"; 513 return "svg";
507 } 514 }
508 515
509 } 516 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698