• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef ImageBitmap_h
6 #define ImageBitmap_h
7 
8 #include "bindings/v8/ScriptWrappable.h"
9 #include "core/html/HTMLImageElement.h"
10 #include "core/html/canvas/CanvasImageSource.h"
11 #include "platform/geometry/IntRect.h"
12 #include "platform/graphics/Image.h"
13 #include "platform/heap/Handle.h"
14 #include "wtf/PassRefPtr.h"
15 #include "wtf/RefCounted.h"
16 
17 namespace WebCore {
18 
19 class HTMLCanvasElement;
20 class HTMLVideoElement;
21 class ImageData;
22 
23 class ImageBitmap FINAL : public RefCountedWillBeGarbageCollectedFinalized<ImageBitmap>, public ScriptWrappable, public ImageLoaderClient, public CanvasImageSource {
24     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ImageBitmap);
25 public:
26     static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLImageElement*, const IntRect&);
27     static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLVideoElement*, const IntRect&);
28     static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLCanvasElement*, const IntRect&);
29     static PassRefPtrWillBeRawPtr<ImageBitmap> create(ImageData*, const IntRect&);
30     static PassRefPtrWillBeRawPtr<ImageBitmap> create(ImageBitmap*, const IntRect&);
31     static PassRefPtrWillBeRawPtr<ImageBitmap> create(Image*, const IntRect&);
32 
33     PassRefPtr<Image> bitmapImage() const;
imageElement()34     PassRefPtrWillBeRawPtr<HTMLImageElement> imageElement() const { return m_imageElement; }
35 
bitmapRect()36     IntRect bitmapRect() const { return m_bitmapRect; }
37 
width()38     int width() const { return m_cropRect.width(); }
height()39     int height() const { return m_cropRect.height(); }
size()40     IntSize size() const { return m_cropRect.size(); }
41 
42     virtual ~ImageBitmap();
43 
44     // CanvasImageSource implementation
45     virtual PassRefPtr<Image> getSourceImageForCanvas(SourceImageMode, SourceImageStatus*) const OVERRIDE;
wouldTaintOrigin(SecurityOrigin *)46     virtual bool wouldTaintOrigin(SecurityOrigin*) const OVERRIDE { return false; };
47     virtual void adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const OVERRIDE;
48     virtual FloatSize sourceSize() const OVERRIDE;
49 
50     virtual void trace(Visitor*);
51 
52 private:
53     ImageBitmap(HTMLImageElement*, const IntRect&);
54     ImageBitmap(HTMLVideoElement*, const IntRect&);
55     ImageBitmap(HTMLCanvasElement*, const IntRect&);
56     ImageBitmap(ImageData*, const IntRect&);
57     ImageBitmap(ImageBitmap*, const IntRect&);
58     ImageBitmap(Image*, const IntRect&);
59 
60     // ImageLoaderClient
61     virtual void notifyImageSourceChanged() OVERRIDE;
requestsHighLiveResourceCachePriority()62     virtual bool requestsHighLiveResourceCachePriority() OVERRIDE { return true; }
63 
64     // ImageBitmaps constructed from HTMLImageElements hold a reference to the HTMLImageElement until
65     // the image source changes.
66     RefPtrWillBeMember<HTMLImageElement> m_imageElement;
67     RefPtr<Image> m_bitmap;
68 
69     IntRect m_bitmapRect; // The rect where the underlying Image should be placed in reference to the ImageBitmap.
70     IntRect m_cropRect;
71 
72     // The offset by which the desired Image is stored internally.
73     // ImageBitmaps constructed from HTMLImageElements reference the entire ImageResource and may have a non-zero bitmap offset.
74     // ImageBitmaps not constructed from HTMLImageElements always pre-crop and store the image at (0, 0).
75     IntPoint m_bitmapOffset;
76 
77 };
78 
79 } // namespace WebCore
80 
81 #endif // ImageBitmap_h
82