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

Side by Side Diff: Source/core/html/HTMLImageElement.cpp

Issue 181693006: Refactoring source image usage in CanvasRenderingContext2D (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | 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 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed.
5 * Copyright (C) 2010 Google Inc. All rights reserved. 5 * Copyright (C) 2010 Google Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 13 matching lines...) Expand all
24 #include "core/html/HTMLImageElement.h" 24 #include "core/html/HTMLImageElement.h"
25 25
26 #include "CSSPropertyNames.h" 26 #include "CSSPropertyNames.h"
27 #include "HTMLNames.h" 27 #include "HTMLNames.h"
28 #include "RuntimeEnabledFeatures.h" 28 #include "RuntimeEnabledFeatures.h"
29 #include "bindings/v8/ScriptEventListener.h" 29 #include "bindings/v8/ScriptEventListener.h"
30 #include "core/dom/Attribute.h" 30 #include "core/dom/Attribute.h"
31 #include "core/events/ThreadLocalEventNames.h" 31 #include "core/events/ThreadLocalEventNames.h"
32 #include "core/fetch/ImageResource.h" 32 #include "core/fetch/ImageResource.h"
33 #include "core/html/HTMLAnchorElement.h" 33 #include "core/html/HTMLAnchorElement.h"
34 #include "core/html/HTMLCanvasElement.h"
34 #include "core/html/HTMLFormElement.h" 35 #include "core/html/HTMLFormElement.h"
36 #include "core/html/canvas/CanvasRenderingContext.h"
35 #include "core/html/parser/HTMLParserIdioms.h" 37 #include "core/html/parser/HTMLParserIdioms.h"
36 #include "core/html/parser/HTMLSrcsetParser.h" 38 #include "core/html/parser/HTMLSrcsetParser.h"
37 #include "core/rendering/RenderImage.h" 39 #include "core/rendering/RenderImage.h"
38 40
39 using namespace std; 41 using namespace std;
40 42
41 namespace WebCore { 43 namespace WebCore {
42 44
43 using namespace HTMLNames; 45 using namespace HTMLNames;
44 46
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 return 0; 405 return 0;
404 406
405 return m_imageLoader.image()->image(); 407 return m_imageLoader.image()->image();
406 } 408 }
407 409
408 bool HTMLImageElement::isInteractiveContent() const 410 bool HTMLImageElement::isInteractiveContent() const
409 { 411 {
410 return fastHasAttribute(usemapAttr); 412 return fastHasAttribute(usemapAttr);
411 } 413 }
412 414
415 PassRefPtr<Image> HTMLImageElement::getSourceImageForCanvas(HTMLCanvasElement* c anvas, ExceptionState& exceptionState, CanvasImageSourceUsage usage, bool* isVol atile) const
416 {
417 if (isVolatile)
418 *isVolatile = false;
419 if (cachedImage() && cachedImage()->errorOccurred()) {
420 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageElemen t provided is in the 'broken' state.");
421 return nullptr;
422 }
423
424 if (!complete()) {
425 return nullptr;
426 }
427
428 if (!cachedImage()) {
429 return usage == DrawCanvasImageSourceUsage ? Image::nullImage() : PassRe fPtr<Image>();
430 }
431
432 RefPtr<Image> sourceImage = cachedImage()->imageForRenderer(renderer());
433
434 // We need to synthesize a container size if a renderer is not available to provide one.
435 if (!renderer() && sourceImage->usesContainerSize())
436 sourceImage->setContainerSize(sourceImage->size());
437
438 return sourceImage.release();
413 } 439 }
440
441 bool HTMLImageElement::wouldTaintOrigin(CanvasRenderingContext* dst) const
Stephen White 2014/02/27 18:53:41 It seems unfortunate to add a dependency on Canvas
442 {
443 ImageResource* image = cachedImage();
444 if (!image)
445 return false;
446 return !image->isAccessAllowed(dst->canvas()->securityOrigin());
447 }
448
449 FloatSize HTMLImageElement::sourceSize() const
450 {
451 ImageResource* image = cachedImage();
452 if (!image)
453 return FloatSize();
454 LayoutSize size;
455 size = image->imageSizeForRenderer(renderer(), 1.0f); // FIXME: Not sure abo ut this.
456
457 return size;
458 }
459
460 FloatSize HTMLImageElement::defaultDestinationSize() const
461 {
462 ImageResource* image = cachedImage();
463 if (!image)
464 return FloatSize();
465 LayoutSize size;
466 size = image->imageSizeForRenderer(renderer(), 1.0f); // FIXME: Not sure abo ut this.
467 if (renderer() && renderer()->isRenderImage() && image->image() && !image->i mage()->hasRelativeWidth())
468 size.scale(toRenderImage(renderer())->imageDevicePixelRatio());
469 return size;
470 }
471
472 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698