فهرست منبع

LibWeb: Improve HTMLImageElement::{width,height}()

With this change, it will correctly return the width/height when the
image element has an assigned width/height attribute.
Igor Pissolati 3 سال پیش
والد
کامیت
ae519c6fef
1فایلهای تغییر یافته به همراه10 افزوده شده و 0 حذف شده
  1. 10 0
      Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp

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

@@ -101,6 +101,11 @@ unsigned HTMLImageElement::width() const
     if (auto* paint_box = this->paint_box())
     if (auto* paint_box = this->paint_box())
         return paint_box->content_width();
         return paint_box->content_width();
 
 
+    // NOTE: This step seems to not be in the spec, but all browsers do it.
+    auto width_attr = get_attribute(HTML::AttributeNames::width);
+    if (auto converted = width_attr.to_uint(); converted.has_value())
+        return *converted;
+
     // ...or else the density-corrected intrinsic width and height of the image, in CSS pixels,
     // ...or else the density-corrected intrinsic width and height of the image, in CSS pixels,
     // if the image has intrinsic dimensions and is available but not being rendered.
     // if the image has intrinsic dimensions and is available but not being rendered.
     if (m_image_loader.has_image())
     if (m_image_loader.has_image())
@@ -124,6 +129,11 @@ unsigned HTMLImageElement::height() const
     if (auto* paint_box = this->paint_box())
     if (auto* paint_box = this->paint_box())
         return paint_box->content_height();
         return paint_box->content_height();
 
 
+    // NOTE: This step seems to not be in the spec, but all browsers do it.
+    auto height_attr = get_attribute(HTML::AttributeNames::height);
+    if (auto converted = height_attr.to_uint(); converted.has_value())
+        return *converted;
+
     // ...or else the density-corrected intrinsic height and height of the image, in CSS pixels,
     // ...or else the density-corrected intrinsic height and height of the image, in CSS pixels,
     // if the image has intrinsic dimensions and is available but not being rendered.
     // if the image has intrinsic dimensions and is available but not being rendered.
     if (m_image_loader.has_image())
     if (m_image_loader.has_image())