Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #ifndef SVGImageForContainer_h |
| 27 | #define SVGImageForContainer_h |
| 28 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 29 | #include "core/platform/graphics/FloatRect.h" |
| 30 | #include "core/platform/graphics/FloatSize.h" |
| 31 | #include "core/platform/graphics/Image.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 32 | #include "core/svg/graphics/SVGImage.h" |
| 33 | |
| 34 | namespace WebCore { |
| 35 | |
| 36 | class SVGImageForContainer : public Image { |
| 37 | public: |
| 38 | static PassRefPtr<SVGImageForContainer> create(SVGImage* image, const FloatSize& containerSize, float zoom) |
| 39 | { |
| 40 | return adoptRef(new SVGImageForContainer(image, containerSize, zoom)); |
| 41 | } |
| 42 | |
| 43 | virtual bool isSVGImage() const OVERRIDE { return true; } |
| 44 | |
| 45 | virtual IntSize size() const OVERRIDE; |
| 46 | |
| 47 | virtual bool usesContainerSize() const OVERRIDE { return m_image->usesContainerSize(); } |
| 48 | virtual bool hasRelativeWidth() const OVERRIDE { return m_image->hasRelativeWidth(); } |
| 49 | virtual bool hasRelativeHeight() const OVERRIDE { return m_image->hasRelativeHeight(); } |
| 50 | virtual void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio) OVERRIDE |
| 51 | { |
| 52 | m_image->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio); |
| 53 | } |
| 54 | |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 55 | virtual void draw(GraphicsContext*, const FloatRect&, const FloatRect&, CompositeOperator, BlendMode) OVERRIDE; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 56 | |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 57 | virtual void drawPattern(GraphicsContext*, const FloatRect&, const FloatSize&, const FloatPoint&, CompositeOperator, const FloatRect&, BlendMode) OVERRIDE; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 58 | |
| 59 | // FIXME: Implement this to be less conservative. |
| 60 | virtual bool currentFrameKnownToBeOpaque() OVERRIDE { return false; } |
| 61 | |
| 62 | virtual PassNativeImagePtr nativeImageForCurrentFrame() OVERRIDE; |
| 63 | |
| 64 | private: |
| 65 | SVGImageForContainer(SVGImage* image, const FloatSize& containerSize, float zoom) |
| 66 | : m_image(image) |
| 67 | , m_containerSize(containerSize) |
| 68 | , m_zoom(zoom) |
| 69 | { |
| 70 | } |
| 71 | |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 72 | virtual void destroyDecodedData() OVERRIDE { } |
| 73 | virtual unsigned decodedSize() const OVERRIDE { return 0; } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 74 | |
| 75 | SVGImage* m_image; |
| 76 | const FloatSize m_containerSize; |
| 77 | const float m_zoom; |
| 78 | }; |
| 79 | } |
| 80 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 81 | #endif // SVGImageForContainer_h |