mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:07:44 +00:00
LibWeb: Port HTMLCanvasElement interface from DeprecatedString to String
This commit is contained in:
parent
7206f1777a
commit
76af9d434c
4 changed files with 13 additions and 13 deletions
|
@ -153,7 +153,7 @@ JS::ThrowCompletionOr<HTMLCanvasElement::HasOrCreatedContext> HTMLCanvasElement:
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-getcontext
|
// https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-getcontext
|
||||||
JS::ThrowCompletionOr<HTMLCanvasElement::RenderingContext> HTMLCanvasElement::get_context(DeprecatedString const& type, JS::Value options)
|
JS::ThrowCompletionOr<HTMLCanvasElement::RenderingContext> HTMLCanvasElement::get_context(String const& type, JS::Value options)
|
||||||
{
|
{
|
||||||
// 1. If options is not an object, then set options to null.
|
// 1. If options is not an object, then set options to null.
|
||||||
if (!options.is_object())
|
if (!options.is_object())
|
||||||
|
@ -246,14 +246,14 @@ static ErrorOr<SerializeBitmapResult> serialize_bitmap(Gfx::Bitmap const& bitmap
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-todataurl
|
// https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-todataurl
|
||||||
DeprecatedString HTMLCanvasElement::to_data_url(DeprecatedString const& type, Optional<double> quality) const
|
String HTMLCanvasElement::to_data_url(StringView type, Optional<double> quality) const
|
||||||
{
|
{
|
||||||
// FIXME: 1. If this canvas element's bitmap's origin-clean flag is set to false, then throw a "SecurityError" DOMException.
|
// FIXME: 1. If this canvas element's bitmap's origin-clean flag is set to false, then throw a "SecurityError" DOMException.
|
||||||
|
|
||||||
// 2. If this canvas element's bitmap has no pixels (i.e. either its horizontal dimension or its vertical dimension is zero)
|
// 2. If this canvas element's bitmap has no pixels (i.e. either its horizontal dimension or its vertical dimension is zero)
|
||||||
// then return the string "data:,". (This is the shortest data: URL; it represents the empty string in a text/plain resource.)
|
// then return the string "data:,". (This is the shortest data: URL; it represents the empty string in a text/plain resource.)
|
||||||
if (!m_bitmap)
|
if (!m_bitmap)
|
||||||
return "data:,";
|
return "data:,"_string;
|
||||||
|
|
||||||
// 3. Let file be a serialization of this canvas element's bitmap as a file, passing type and quality if given.
|
// 3. Let file be a serialization of this canvas element's bitmap as a file, passing type and quality if given.
|
||||||
auto file = serialize_bitmap(*m_bitmap, type, move(quality));
|
auto file = serialize_bitmap(*m_bitmap, type, move(quality));
|
||||||
|
@ -261,19 +261,19 @@ DeprecatedString HTMLCanvasElement::to_data_url(DeprecatedString const& type, Op
|
||||||
// 4. If file is null then return "data:,".
|
// 4. If file is null then return "data:,".
|
||||||
if (file.is_error()) {
|
if (file.is_error()) {
|
||||||
dbgln("HTMLCanvasElement: Failed to encode canvas bitmap to {}: {}", type, file.error());
|
dbgln("HTMLCanvasElement: Failed to encode canvas bitmap to {}: {}", type, file.error());
|
||||||
return "data:,";
|
return "data:,"_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Return a data: URL representing file. [RFC2397]
|
// 5. Return a data: URL representing file. [RFC2397]
|
||||||
auto base64_encoded_or_error = encode_base64(file.value().buffer);
|
auto base64_encoded_or_error = encode_base64(file.value().buffer);
|
||||||
if (base64_encoded_or_error.is_error()) {
|
if (base64_encoded_or_error.is_error()) {
|
||||||
return "data:,";
|
return "data:,"_string;
|
||||||
}
|
}
|
||||||
return AK::URL::create_with_data(file.value().mime_type, base64_encoded_or_error.release_value(), true).to_deprecated_string();
|
return MUST(AK::URL::create_with_data(file.value().mime_type, base64_encoded_or_error.release_value(), true).to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-toblob
|
// https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-toblob
|
||||||
WebIDL::ExceptionOr<void> HTMLCanvasElement::to_blob(JS::NonnullGCPtr<WebIDL::CallbackType> callback, DeprecatedString const& type, Optional<double> quality)
|
WebIDL::ExceptionOr<void> HTMLCanvasElement::to_blob(JS::NonnullGCPtr<WebIDL::CallbackType> callback, StringView type, Optional<double> quality)
|
||||||
{
|
{
|
||||||
// FIXME: 1. If this canvas element's bitmap's origin-clean flag is set to false, then throw a "SecurityError" DOMException.
|
// FIXME: 1. If this canvas element's bitmap's origin-clean flag is set to false, then throw a "SecurityError" DOMException.
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
Gfx::Bitmap* bitmap() { return m_bitmap; }
|
Gfx::Bitmap* bitmap() { return m_bitmap; }
|
||||||
bool create_bitmap(size_t minimum_width = 0, size_t minimum_height = 0);
|
bool create_bitmap(size_t minimum_width = 0, size_t minimum_height = 0);
|
||||||
|
|
||||||
JS::ThrowCompletionOr<RenderingContext> get_context(DeprecatedString const& type, JS::Value options);
|
JS::ThrowCompletionOr<RenderingContext> get_context(String const& type, JS::Value options);
|
||||||
|
|
||||||
unsigned width() const;
|
unsigned width() const;
|
||||||
unsigned height() const;
|
unsigned height() const;
|
||||||
|
@ -33,8 +33,8 @@ public:
|
||||||
WebIDL::ExceptionOr<void> set_width(unsigned);
|
WebIDL::ExceptionOr<void> set_width(unsigned);
|
||||||
WebIDL::ExceptionOr<void> set_height(unsigned);
|
WebIDL::ExceptionOr<void> set_height(unsigned);
|
||||||
|
|
||||||
DeprecatedString to_data_url(DeprecatedString const& type, Optional<double> quality) const;
|
String to_data_url(StringView type, Optional<double> quality) const;
|
||||||
WebIDL::ExceptionOr<void> to_blob(JS::NonnullGCPtr<WebIDL::CallbackType> callback, DeprecatedString const& type, Optional<double> quality);
|
WebIDL::ExceptionOr<void> to_blob(JS::NonnullGCPtr<WebIDL::CallbackType> callback, StringView type, Optional<double> quality);
|
||||||
|
|
||||||
void present();
|
void present();
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
typedef (CanvasRenderingContext2D or WebGLRenderingContext) RenderingContext;
|
typedef (CanvasRenderingContext2D or WebGLRenderingContext) RenderingContext;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/semantics.html#htmlcanvaselement
|
// https://html.spec.whatwg.org/multipage/semantics.html#htmlcanvaselement
|
||||||
[Exposed=Window, UseDeprecatedAKString]
|
[Exposed=Window]
|
||||||
interface HTMLCanvasElement : HTMLElement {
|
interface HTMLCanvasElement : HTMLElement {
|
||||||
|
|
||||||
[HTMLConstructor] constructor();
|
[HTMLConstructor] constructor();
|
||||||
|
|
|
@ -36,11 +36,11 @@ static Response encode_canvas_element(HTML::HTMLCanvasElement const& canvas)
|
||||||
auto data_url = canvas.to_data_url("image/png"sv, {});
|
auto data_url = canvas.to_data_url("image/png"sv, {});
|
||||||
|
|
||||||
// 5. Let index be the index of "," in data url.
|
// 5. Let index be the index of "," in data url.
|
||||||
auto index = data_url.find(',');
|
auto index = data_url.find_byte_offset(',');
|
||||||
VERIFY(index.has_value());
|
VERIFY(index.has_value());
|
||||||
|
|
||||||
// 6. Let encoded string be a substring of data url using (index + 1) as the start argument.
|
// 6. Let encoded string be a substring of data url using (index + 1) as the start argument.
|
||||||
auto encoded_string = data_url.substring(*index + 1);
|
auto encoded_string = MUST(data_url.substring_from_byte_offset(*index + 1));
|
||||||
|
|
||||||
// 7. Return success with data encoded string.
|
// 7. Return success with data encoded string.
|
||||||
return JsonValue { move(encoded_string) };
|
return JsonValue { move(encoded_string) };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue