OLD | NEW |
(Empty) | |
| 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 are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #ifndef ImageBitmapFactories_h |
| 32 #define ImageBitmapFactories_h |
| 33 |
| 34 #include "bindings/v8/ScriptPromiseResolver.h" |
| 35 #include "bindings/v8/ScriptState.h" |
| 36 #include "core/fileapi/FileReaderLoader.h" |
| 37 #include "core/fileapi/FileReaderLoaderClient.h" |
| 38 #include "core/platform/Supplementable.h" |
| 39 #include "core/platform/graphics/IntRect.h" |
| 40 #include "wtf/Forward.h" |
| 41 #include "wtf/HashSet.h" |
| 42 |
| 43 namespace WebCore { |
| 44 |
| 45 class Blob; |
| 46 class CanvasRenderingContext2D; |
| 47 class EventTarget; |
| 48 class ExceptionState; |
| 49 class HTMLCanvasElement; |
| 50 class HTMLImageElement; |
| 51 class HTMLVideoElement; |
| 52 class ImageBitmap; |
| 53 class ImageData; |
| 54 class ScriptExecutionContext; |
| 55 |
| 56 class ImageBitmapFactories : public Supplement<DOMWindow> { |
| 57 |
| 58 class ImageBitmapLoader; |
| 59 |
| 60 public: |
| 61 static ScriptObject createImageBitmap(EventTarget*, HTMLImageElement*, Excep
tionState&); |
| 62 static ScriptObject createImageBitmap(EventTarget*, HTMLImageElement*, int s
x, int sy, int sw, int sh, ExceptionState&); |
| 63 static ScriptObject createImageBitmap(EventTarget*, HTMLVideoElement*, Excep
tionState&); |
| 64 static ScriptObject createImageBitmap(EventTarget*, HTMLVideoElement*, int s
x, int sy, int sw, int sh, ExceptionState&); |
| 65 static ScriptObject createImageBitmap(EventTarget*, CanvasRenderingContext2D
*, ExceptionState&); |
| 66 static ScriptObject createImageBitmap(EventTarget*, CanvasRenderingContext2D
*, int sx, int sy, int sw, int sh, ExceptionState&); |
| 67 static ScriptObject createImageBitmap(EventTarget*, HTMLCanvasElement*, Exce
ptionState&); |
| 68 static ScriptObject createImageBitmap(EventTarget*, HTMLCanvasElement*, int
sx, int sy, int sw, int sh, ExceptionState&); |
| 69 static ScriptObject createImageBitmap(EventTarget*, Blob*, ExceptionState&); |
| 70 static ScriptObject createImageBitmap(EventTarget*, Blob*, int sx, int sy, i
nt sw, int sh, ExceptionState&); |
| 71 static ScriptObject createImageBitmap(EventTarget*, ImageData*, ExceptionSta
te&); |
| 72 static ScriptObject createImageBitmap(EventTarget*, ImageData*, int sx, int
sy, int sw, int sh, ExceptionState&); |
| 73 static ScriptObject createImageBitmap(EventTarget*, ImageBitmap*, ExceptionS
tate&); |
| 74 static ScriptObject createImageBitmap(EventTarget*, ImageBitmap*, int sx, in
t sy, int sw, int sh, ExceptionState&); |
| 75 |
| 76 void didStartLoading(PassRefPtr<ImageBitmapLoader>); |
| 77 void didFinishLoading(PassRefPtr<ImageBitmapLoader>); |
| 78 |
| 79 virtual ~ImageBitmapFactories() { } |
| 80 static ImageBitmapFactories* from(DOMWindow*); |
| 81 |
| 82 private: |
| 83 class ImageBitmapLoader : public RefCounted<ImageBitmapLoader>, public FileR
eaderLoaderClient { |
| 84 public: |
| 85 static PassRefPtr<ImageBitmapLoader> create(ImageBitmapFactories* factor
y, PassRefPtr<ScriptPromiseResolver> resolver, const IntRect& cropRect) |
| 86 { |
| 87 return adoptRef(new ImageBitmapLoader(factory, resolver, cropRect)); |
| 88 } |
| 89 |
| 90 void loadBlobAsync(ScriptExecutionContext*, Blob*); |
| 91 |
| 92 ~ImageBitmapLoader() { } |
| 93 |
| 94 private: |
| 95 ImageBitmapLoader(ImageBitmapFactories*, PassRefPtr<ScriptPromiseResolve
r>, const IntRect&); |
| 96 |
| 97 void rejectPromise(); |
| 98 |
| 99 // FileReaderLoaderClient |
| 100 virtual void didStartLoading() OVERRIDE { } |
| 101 virtual void didReceiveData() OVERRIDE { } |
| 102 virtual void didFinishLoading() OVERRIDE; |
| 103 virtual void didFail(FileError::ErrorCode) OVERRIDE; |
| 104 |
| 105 ScriptState* m_scriptState; |
| 106 FileReaderLoader m_loader; |
| 107 ImageBitmapFactories* m_factory; |
| 108 RefPtr<ScriptPromiseResolver> m_resolver; |
| 109 IntRect m_cropRect; |
| 110 }; |
| 111 |
| 112 static const char* supplementName(); |
| 113 |
| 114 HashSet<RefPtr<ImageBitmapLoader> > m_pendingLoaders; |
| 115 }; |
| 116 |
| 117 } // namespace WebCore |
| 118 |
| 119 #endif // ImageBitmapFactories_h |
OLD | NEW |