Browse Source

LibWeb: Set size of canvas used to take WebDriver screenshots explicitly

The default canvas size is 300x150 pixels. If the element or document
we are trying to screenshot for the WebDriver is not at least that size,
then we will create a canvas that is wider or taller than the actual
element we are painting, resulting in a bunch of transparent pixels
falling off the end.

This fixes 14 WPT css/CSS2/floats tests that we run in CI, and
presumably a ton of other reftests in the WPT test suite.
Andrew Kaster 1 năm trước cách đây
mục cha
commit
cb68c6eaf1
1 tập tin đã thay đổi với 4 bổ sung0 xóa
  1. 4 0
      Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp

+ 4 - 0
Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp

@@ -61,6 +61,10 @@ Response capture_element_screenshot(Painter const& painter, Page& page, DOM::Ele
         auto canvas_element = DOM::create_element(element.document(), HTML::TagNames::canvas, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
         auto& canvas = verify_cast<HTML::HTMLCanvasElement>(*canvas_element);
 
+        // FIXME: Handle DevicePixelRatio in HiDPI mode.
+        MUST(canvas.set_width(rect.width()));
+        MUST(canvas.set_height(rect.height()));
+
         if (!canvas.create_bitmap(rect.width(), rect.height())) {
             encoded_string_or_error = Error::from_code(ErrorCode::UnableToCaptureScreen, "Unable to create a screenshot bitmap"sv);
             return;