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

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: spec is clear, patch is now ready 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 ((options.hasResizeWidth() && options.resizeWidth() <= 0) || (options.has ResizeHeight() && options.resizeHeight() <= 0)) {
jbroman 2016/07/07 19:18:00 Is checking for negative values necessary? I think
xidachen 2016/07/07 20:43:29 Done. Now it is a static method in ImageBitmap cal
92 exceptionState.throwDOMException(InvalidStateError, "The resizeWidth or/ and resizeHeight is less than or equals to 0.");
93 return ScriptPromise();
94 }
91 Blob* blob = static_cast<Blob*>(bitmapSource); 95 Blob* blob = static_cast<Blob*>(bitmapSource);
92 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create( from(eventTarget), cropRect, options, scriptState); 96 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create( from(eventTarget), cropRect, options, scriptState);
93 ScriptPromise promise = loader->promise(); 97 ScriptPromise promise = loader->promise();
94 from(eventTarget).addLoader(loader); 98 from(eventTarget).addLoader(loader);
95 loader->loadBlobAsync(eventTarget.getExecutionContext(), blob); 99 loader->loadBlobAsync(eventTarget.getExecutionContext(), blob);
96 return promise; 100 return promise;
97 } 101 }
98 102
99 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, const Imag eBitmapOptions& options, ExceptionState& exceptionState) 103 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, const Imag eBitmapOptions& options, ExceptionState& exceptionState)
100 { 104 {
101 UseCounter::Feature feature = UseCounter::CreateImageBitmap; 105 UseCounter::Feature feature = UseCounter::CreateImageBitmap;
102 UseCounter::count(scriptState->getExecutionContext(), feature); 106 UseCounter::count(scriptState->getExecutionContext(), feature);
103 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, false); 107 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, false);
104 if (!bitmapSourceInternal) 108 if (!bitmapSourceInternal)
105 return ScriptPromise(); 109 return ScriptPromise();
106 if (bitmapSourceInternal->isBlob()) 110 if (bitmapSourceInternal->isBlob())
107 return createImageBitmapFromBlob(scriptState, eventTarget, bitmapSourceI nternal, IntRect(), options); 111 return createImageBitmapFromBlob(scriptState, eventTarget, bitmapSourceI nternal, IntRect(), options, exceptionState);
108 IntSize srcSize = bitmapSourceInternal->bitmapSourceSize(); 112 IntSize srcSize = bitmapSourceInternal->bitmapSourceSize();
109 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0, 0, srcSize.width(), srcSize.height(), options, exceptionState); 113 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0, 0, srcSize.width(), srcSize.height(), options, exceptionState);
110 } 114 }
111 115
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) 116 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 { 117 {
114 UseCounter::Feature feature = UseCounter::CreateImageBitmap; 118 UseCounter::Feature feature = UseCounter::CreateImageBitmap;
115 UseCounter::count(scriptState->getExecutionContext(), feature); 119 UseCounter::count(scriptState->getExecutionContext(), feature);
116 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, true); 120 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, true);
117 if (!bitmapSourceInternal) 121 if (!bitmapSourceInternal)
118 return ScriptPromise(); 122 return ScriptPromise();
119 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx, sy, sw, sh, options, exceptionState); 123 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx, sy, sw, sh, options, exceptionState);
120 } 124 }
121 125
122 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int s w, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) 126 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int s w, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState)
123 { 127 {
124 if (bitmapSource->isBlob()) { 128 if (bitmapSource->isBlob()) {
125 if (!sw || !sh) { 129 if (!sw || !sh) {
126 exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width")); 130 exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width"));
127 return ScriptPromise(); 131 return ScriptPromise();
128 } 132 }
129 return createImageBitmapFromBlob(scriptState, eventTarget, bitmapSource, IntRect(sx, sy, sw, sh), options); 133 return createImageBitmapFromBlob(scriptState, eventTarget, bitmapSource, IntRect(sx, sy, sw, sh), options, exceptionState);
130 } 134 }
131 135
132 return bitmapSource->createImageBitmap(scriptState, eventTarget, sx, sy, sw, sh, options, exceptionState); 136 return bitmapSource->createImageBitmap(scriptState, eventTarget, sx, sy, sw, sh, options, exceptionState);
133 } 137 }
134 138
135 const char* ImageBitmapFactories::supplementName() 139 const char* ImageBitmapFactories::supplementName()
136 { 140 {
137 return "ImageBitmapFactories"; 141 return "ImageBitmapFactories";
138 } 142 }
139 143
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 m_factory->didFinishLoading(this); 272 m_factory->didFinishLoading(this);
269 } 273 }
270 274
271 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) 275 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader)
272 { 276 {
273 visitor->trace(m_factory); 277 visitor->trace(m_factory);
274 visitor->trace(m_resolver); 278 visitor->trace(m_resolver);
275 } 279 }
276 280
277 } // namespace blink 281 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698