• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 AsyncImageResizer_h
32 #define AsyncImageResizer_h
33 
34 #if ENABLE(IMAGE_RESIZER)
35 
36 #include "Blob.h"
37 #include "CachedResourceClient.h"
38 #include "IntSize.h"
39 #include "ScriptValue.h"
40 
41 namespace WebCore {
42 
43 class CachedImage;
44 class ImageResizerThread;
45 
46 // AsyncImageResizer waits for the CachedImage that is passed in to load completely,
47 // then starts an ImageResizerThread to resize the image. Once created, ImageResizerThread
48 // becomes in charge of its own lifetime and that of AsyncImageResizer. After the callbacks
49 // occur, both objects are destroyed. If the document is destroyed during resizing,
50 // AsyncImageResizer will receive a notification and subsequently block the callbacks from
51 // occurring.
52 class AsyncImageResizer : public CachedResourceClient, public RefCounted<AsyncImageResizer> {
53 public:
54     struct CallbackInfo {
CallbackInfoCallbackInfo55         CallbackInfo(PassRefPtr<AsyncImageResizer> asyncImageResizer)
56             : asyncImageResizer(asyncImageResizer)
57             , blob(0)
58         {
59         }
60 
61         RefPtr<AsyncImageResizer> asyncImageResizer;
62         RefPtr<Blob> blob;
63     };
64 
65     enum OutputType {
66         JPEG,
67         PNG
68     };
69 
70     enum AspectRatioOption {
71         PreserveAspectRatio,
72         IgnoreAspectRatio
73     };
74 
75     enum OrientationOption {
76         CorrectOrientation,
77         IgnoreOrientation
78     };
79 
80     static PassRefPtr<AsyncImageResizer> create(CachedImage*, OutputType, IntSize desiredBounds, ScriptValue successCallback, ScriptValue errorCallback, float quality, AspectRatioOption, OrientationOption);
81     ~AsyncImageResizer();
82 
83     // FIXME: Insert override function for notification of document destruction (change m_callbacksOk).
84 
resizeComplete(RefPtr<Blob>)85     void resizeComplete(RefPtr<Blob>) { /* FIXME: Not yet implemented. */ }
resizeError()86     void resizeError() { /* FIXME: Not yet implemented. */ }
87 
88 private:
89     AsyncImageResizer(CachedImage*, OutputType, IntSize desiredBounds, ScriptValue successCallback, ScriptValue errorCallback, float quality, AspectRatioOption, OrientationOption);
90     virtual void notifyFinished(CachedResource*);
91 
92     CachedImage* m_cachedImage;
93     ScriptValue m_successCallback;
94     ScriptValue m_errorCallback;
95 
96     // Parameters to pass into ImageResizerThread.
97     OutputType m_outputType;
98     IntSize m_desiredBounds;
99     float m_quality;
100     AspectRatioOption m_aspectRatioOption;
101     OrientationOption m_orientationOption;
102 };
103 
104 } // namespace WebCore
105 
106 #endif // ENABLE(IMAGE_RESIZER)
107 
108 #endif // AsyncImageResizer_h
109