Bläddra i källkod

LibWeb: Allow setting the width & height properties on <canvas> elements

Andreas Kling 3 år sedan
förälder
incheckning
778268b1a5

+ 10 - 0
Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp

@@ -37,6 +37,16 @@ unsigned HTMLCanvasElement::height() const
     return attribute(HTML::AttributeNames::height).to_uint().value_or(150);
 }
 
+void HTMLCanvasElement::set_width(unsigned value)
+{
+    set_attribute(HTML::AttributeNames::width, String::number(value));
+}
+
+void HTMLCanvasElement::set_height(unsigned value)
+{
+    set_attribute(HTML::AttributeNames::height, String::number(value));
+}
+
 RefPtr<Layout::Node> HTMLCanvasElement::create_layout_node()
 {
     auto style = document().style_computer().compute_style(*this);

+ 3 - 0
Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.h

@@ -28,6 +28,9 @@ public:
     unsigned width() const;
     unsigned height() const;
 
+    void set_width(unsigned);
+    void set_height(unsigned);
+
     String to_data_url(const String& type, Optional<double> quality) const;
 
 private:

+ 2 - 2
Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.idl

@@ -1,8 +1,8 @@
 interface HTMLCanvasElement : HTMLElement {
 
     CanvasRenderingContext2D? getContext(DOMString contextId);
-    readonly attribute unsigned long width;
-    readonly attribute unsigned long height;
+    attribute unsigned long width;
+    attribute unsigned long height;
 
     USVString toDataURL(optional DOMString type = "image/png", optional double quality);