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

Side by Side Diff: third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp

Issue 2035113002: Implement ImageBitmapOptions resize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 if (value.isBlob()) 79 if (value.isBlob())
80 return value.getAsBlob(); 80 return value.getAsBlob();
81 if (value.isImageData()) 81 if (value.isImageData())
82 return value.getAsImageData(); 82 return value.getAsImageData();
83 if (value.isImageBitmap()) 83 if (value.isImageBitmap())
84 return value.getAsImageBitmap(); 84 return value.getAsImageBitmap();
85 ASSERT_NOT_REACHED(); 85 ASSERT_NOT_REACHED();
86 return nullptr; 86 return nullptr;
87 } 87 }
88 88
89 ScriptPromise ImageBitmapFactories::createImageBitmapFromBlob(ScriptState* scrip tState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, const IntRect & cropRect, const ImageBitmapOptions& options) 89 ScriptPromise ImageBitmapFactories::createImageBitmapFromBlob(ScriptState* scrip tState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, const IntRect & cropRect, const ImageBitmapOptions& options, ExceptionState& exceptionState)
90 { 90 {
91 if (!ImageBitmap::isResizeOptionValid(options, exceptionState))
92 return ScriptPromise();
91 Blob* blob = static_cast<Blob*>(bitmapSource); 93 Blob* blob = static_cast<Blob*>(bitmapSource);
92 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create( from(eventTarget), cropRect, options, scriptState); 94 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create( from(eventTarget), cropRect, options, scriptState);
93 ScriptPromise promise = loader->promise(); 95 ScriptPromise promise = loader->promise();
94 from(eventTarget).addLoader(loader); 96 from(eventTarget).addLoader(loader);
95 loader->loadBlobAsync(eventTarget.getExecutionContext(), blob); 97 loader->loadBlobAsync(eventTarget.getExecutionContext(), blob);
96 return promise; 98 return promise;
97 } 99 }
98 100
99 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, const Imag eBitmapOptions& options, ExceptionState& exceptionState) 101 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, const Imag eBitmapOptions& options, ExceptionState& exceptionState)
100 { 102 {
101 UseCounter::Feature feature = UseCounter::CreateImageBitmap; 103 UseCounter::Feature feature = UseCounter::CreateImageBitmap;
102 UseCounter::count(scriptState->getExecutionContext(), feature); 104 UseCounter::count(scriptState->getExecutionContext(), feature);
103 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, false); 105 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, false);
104 if (!bitmapSourceInternal) 106 if (!bitmapSourceInternal)
105 return ScriptPromise(); 107 return ScriptPromise();
106 if (bitmapSourceInternal->isBlob()) 108 if (bitmapSourceInternal->isBlob())
107 return createImageBitmapFromBlob(scriptState, eventTarget, bitmapSourceI nternal, IntRect(), options); 109 return createImageBitmapFromBlob(scriptState, eventTarget, bitmapSourceI nternal, IntRect(), options, exceptionState);
108 IntSize srcSize = bitmapSourceInternal->bitmapSourceSize(); 110 IntSize srcSize = bitmapSourceInternal->bitmapSourceSize();
109 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0, 0, srcSize.width(), srcSize.height(), options, exceptionState); 111 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0, 0, srcSize.width(), srcSize.height(), options, exceptionState);
110 } 112 }
111 113
112 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, in t sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& excepti onState) 114 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, in t sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& excepti onState)
113 { 115 {
114 UseCounter::Feature feature = UseCounter::CreateImageBitmap; 116 UseCounter::Feature feature = UseCounter::CreateImageBitmap;
115 UseCounter::count(scriptState->getExecutionContext(), feature); 117 UseCounter::count(scriptState->getExecutionContext(), feature);
116 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, true); 118 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, true);
117 if (!bitmapSourceInternal) 119 if (!bitmapSourceInternal)
118 return ScriptPromise(); 120 return ScriptPromise();
119 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx, sy, sw, sh, options, exceptionState); 121 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx, sy, sw, sh, options, exceptionState);
120 } 122 }
121 123
122 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int s w, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) 124 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int s w, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState)
123 { 125 {
124 if (bitmapSource->isBlob()) { 126 if (bitmapSource->isBlob()) {
125 if (!sw || !sh) { 127 if (!ImageBitmap::isSWSHValid(sw, sh, exceptionState))
126 exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width"));
127 return ScriptPromise(); 128 return ScriptPromise();
128 } 129 return createImageBitmapFromBlob(scriptState, eventTarget, bitmapSource, IntRect(sx, sy, sw, sh), options, exceptionState);
129 return createImageBitmapFromBlob(scriptState, eventTarget, bitmapSource, IntRect(sx, sy, sw, sh), options);
130 } 130 }
131 131
132 return bitmapSource->createImageBitmap(scriptState, eventTarget, sx, sy, sw, sh, options, exceptionState); 132 return bitmapSource->createImageBitmap(scriptState, eventTarget, sx, sy, sw, sh, options, exceptionState);
133 } 133 }
134 134
135 const char* ImageBitmapFactories::supplementName() 135 const char* ImageBitmapFactories::supplementName()
136 { 136 {
137 return "ImageBitmapFactories"; 137 return "ImageBitmapFactories";
138 } 138 }
139 139
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 m_factory->didFinishLoading(this); 268 m_factory->didFinishLoading(this);
269 } 269 }
270 270
271 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) 271 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader)
272 { 272 {
273 visitor->trace(m_factory); 273 visitor->trace(m_factory);
274 visitor->trace(m_resolver); 274 visitor->trace(m_resolver);
275 } 275 }
276 276
277 } // namespace blink 277 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698