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

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

Issue 2802813002: Adds SVGImageElement as a ImageBitmapSource (Closed)
Patch Set: test Created 3 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Rob Buis <buis@kde.org>
4 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 4 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 */ 20 */
21 21
22 #include "core/svg/SVGImageElement.h" 22 #include "core/svg/SVGImageElement.h"
23 23
24 #include "core/CSSPropertyNames.h" 24 #include "core/CSSPropertyNames.h"
25 #include "core/dom/StyleChangeReason.h" 25 #include "core/dom/StyleChangeReason.h"
26 #include "core/frame/ImageBitmap.h"
27 #include "core/frame/LocalDOMWindow.h"
26 #include "core/layout/LayoutImageResource.h" 28 #include "core/layout/LayoutImageResource.h"
27 #include "core/layout/svg/LayoutSVGImage.h" 29 #include "core/layout/svg/LayoutSVGImage.h"
28 30
29 namespace blink { 31 namespace blink {
30 32
31 inline SVGImageElement::SVGImageElement(Document& document) 33 inline SVGImageElement::SVGImageElement(Document& document)
32 : SVGGraphicsElement(SVGNames::imageTag, document), 34 : SVGGraphicsElement(SVGNames::imageTag, document),
33 SVGURIReference(this), 35 SVGURIReference(this),
34 m_x(SVGAnimatedLength::create(this, 36 m_x(SVGAnimatedLength::create(this,
35 SVGNames::xAttr, 37 SVGNames::xAttr,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 if (isConnected()) 142 if (isConnected())
141 imageLoader().updateFromElement(ImageLoader::UpdateIgnorePreviousError); 143 imageLoader().updateFromElement(ImageLoader::UpdateIgnorePreviousError);
142 else 144 else
143 m_needsLoaderURIUpdate = true; 145 m_needsLoaderURIUpdate = true;
144 return; 146 return;
145 } 147 }
146 148
147 SVGGraphicsElement::svgAttributeChanged(attrName); 149 SVGGraphicsElement::svgAttributeChanged(attrName);
148 } 150 }
149 151
152 IntSize SVGImageElement::bitmapSourceSize() const {
153 ImageResourceContent* image = cachedImage();
154 if (!image)
155 return IntSize();
156 LayoutSize lSize = image->imageSize(
157 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f);
158 DCHECK(lSize.fraction().isZero());
159 return IntSize(lSize.width().toInt(), lSize.height().toInt());
160 }
161
162 ScriptPromise SVGImageElement::createImageBitmap(
163 ScriptState* scriptState,
164 EventTarget& eventTarget,
165 Optional<IntRect> cropRect,
166 const ImageBitmapOptions& options,
167 ExceptionState& exceptionState) {
168 DCHECK(eventTarget.toLocalDOMWindow());
169 if ((cropRect &&
170 !ImageBitmap::isSourceSizeValid(cropRect->width(), cropRect->height(),
171 exceptionState)) ||
172 !ImageBitmap::isSourceSizeValid(bitmapSourceSize().width(),
173 bitmapSourceSize().height(),
174 exceptionState))
175 return ScriptPromise();
176 if (!ImageBitmap::isResizeOptionValid(options, exceptionState))
177 return ScriptPromise();
178 return ImageBitmapSource::fulfillImageBitmap(
179 scriptState,
180 ImageBitmap::create(this, cropRect,
181 eventTarget.toLocalDOMWindow()->document(), options));
fs 2017/04/06 16:48:12 I was a bit puzzled by this until I saw what it wa
fserb 2017/04/06 20:06:16 For the first thing, you are right. For the second
182 }
183
150 bool SVGImageElement::selfHasRelativeLengths() const { 184 bool SVGImageElement::selfHasRelativeLengths() const {
151 return m_x->currentValue()->isRelative() || 185 return m_x->currentValue()->isRelative() ||
152 m_y->currentValue()->isRelative() || 186 m_y->currentValue()->isRelative() ||
153 m_width->currentValue()->isRelative() || 187 m_width->currentValue()->isRelative() ||
154 m_height->currentValue()->isRelative(); 188 m_height->currentValue()->isRelative();
155 } 189 }
156 190
157 LayoutObject* SVGImageElement::createLayoutObject(const ComputedStyle&) { 191 LayoutObject* SVGImageElement::createLayoutObject(const ComputedStyle&) {
158 return new LayoutSVGImage(this); 192 return new LayoutSVGImage(this);
159 } 193 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 const AtomicString SVGImageElement::imageSourceURL() const { 240 const AtomicString SVGImageElement::imageSourceURL() const {
207 return AtomicString(hrefString()); 241 return AtomicString(hrefString());
208 } 242 }
209 243
210 void SVGImageElement::didMoveToNewDocument(Document& oldDocument) { 244 void SVGImageElement::didMoveToNewDocument(Document& oldDocument) {
211 imageLoader().elementDidMoveToNewDocument(); 245 imageLoader().elementDidMoveToNewDocument();
212 SVGGraphicsElement::didMoveToNewDocument(oldDocument); 246 SVGGraphicsElement::didMoveToNewDocument(oldDocument);
213 } 247 }
214 248
215 } // namespace blink 249 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698