mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
LibWeb: Bring parsing of width/height attributes in canvas up to spec
This commit is contained in:
parent
e6b8c2bd59
commit
22220cf116
Notes:
sideshowbarker
2024-07-17 08:55:54 +09:00
Author: https://github.com/circl-lastname Commit: https://github.com/SerenityOS/serenity/commit/22220cf116 Pull-request: https://github.com/SerenityOS/serenity/pull/20870 Reviewed-by: https://github.com/AtkinsSJ ✅
1 changed files with 11 additions and 2 deletions
|
@ -15,6 +15,7 @@
|
|||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/CanvasRenderingContext2D.h>
|
||||
#include <LibWeb/HTML/HTMLCanvasElement.h>
|
||||
#include <LibWeb/HTML/Numbers.h>
|
||||
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
|
||||
#include <LibWeb/Layout/CanvasBox.h>
|
||||
#include <LibWeb/Platform/EventLoopPlugin.h>
|
||||
|
@ -53,12 +54,20 @@ void HTMLCanvasElement::visit_edges(Cell::Visitor& visitor)
|
|||
|
||||
unsigned HTMLCanvasElement::width() const
|
||||
{
|
||||
return attribute(HTML::AttributeNames::width).to_uint().value_or(300);
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#obtain-numeric-values
|
||||
// The rules for parsing non-negative integers must be used to obtain their numeric values.
|
||||
// If an attribute is missing, or if parsing its value returns an error, then the default value must be used instead.
|
||||
// The width attribute defaults to 300
|
||||
return parse_non_negative_integer(attribute(HTML::AttributeNames::width)).value_or(300);
|
||||
}
|
||||
|
||||
unsigned HTMLCanvasElement::height() const
|
||||
{
|
||||
return attribute(HTML::AttributeNames::height).to_uint().value_or(150);
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#obtain-numeric-values
|
||||
// The rules for parsing non-negative integers must be used to obtain their numeric values.
|
||||
// If an attribute is missing, or if parsing its value returns an error, then the default value must be used instead.
|
||||
// the height attribute defaults to 150
|
||||
return parse_non_negative_integer(attribute(HTML::AttributeNames::height)).value_or(150);
|
||||
}
|
||||
|
||||
void HTMLCanvasElement::reset_context_to_default_state()
|
||||
|
|
Loading…
Add table
Reference in a new issue