mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
LibWeb: Bring parsing of width/height attributes in canvas up to spec
This commit is contained in:
parent
e6b8c2bd59
commit
22220cf116
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
Add a link
Reference in a new issue