diff options
8 files changed, 24 insertions, 13 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp b/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp index ca81eaa4b0..ce92931b24 100644 --- a/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp +++ b/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp @@ -50,7 +50,7 @@ void InitialContainingBlock::paint_all_phases(PaintContext& context) { build_stacking_context_tree_if_needed(); context.painter().fill_rect(enclosing_int_rect(paint_box()->absolute_rect()), document().background_color(context.palette())); - context.painter().translate(-context.viewport_rect().location()); + context.painter().translate(-context.device_viewport_rect().location().to_type<int>()); paint_box()->stacking_context()->paint(context); } diff --git a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp index 67c5767f3a..64a4722d44 100644 --- a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> - * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org> * Copyright (c) 2022, MacDue <macdue@dueutil.tech> * * SPDX-License-Identifier: BSD-2-Clause @@ -315,7 +315,7 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet while (image_x < clip_rect.right()) { image_rect.set_x(image_x); auto int_image_rect = image_rect.to_rounded<int>(); - if (int_image_rect != last_int_image_rect && int_image_rect.intersects(context.viewport_rect())) + if (int_image_rect != last_int_image_rect && int_image_rect.intersects(context.device_viewport_rect().to_type<int>())) image.paint(context, int_image_rect, image_rendering); last_int_image_rect = int_image_rect; if (!repeat_x) diff --git a/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.cpp b/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.cpp index 42043452a1..e03e2cca64 100644 --- a/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.cpp @@ -47,15 +47,15 @@ void NestedBrowsingContextPaintable::paint(PaintContext& context, PaintPhase pha return; context.painter().save(); - auto old_viewport_rect = context.viewport_rect(); + auto old_viewport_rect = context.device_viewport_rect(); context.painter().add_clip_rect(clip_rect); context.painter().translate(absolute_x(), absolute_y()); - context.set_viewport_rect({ {}, layout_box().dom_node().nested_browsing_context()->size() }); + context.set_device_viewport_rect({ {}, layout_box().dom_node().nested_browsing_context()->size() }); const_cast<Layout::InitialContainingBlock*>(hosted_layout_tree)->paint_all_phases(context); - context.set_viewport_rect(old_viewport_rect); + context.set_device_viewport_rect(old_viewport_rect); context.painter().restore(); if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) { diff --git a/Userland/Libraries/LibWeb/Painting/PaintContext.cpp b/Userland/Libraries/LibWeb/Painting/PaintContext.cpp index 9dd49be010..c418d0fe5e 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintContext.cpp @@ -34,6 +34,16 @@ void PaintContext::clear_svg_context() m_svg_context.clear(); } +CSSPixelRect PaintContext::css_viewport_rect() const +{ + return { + m_device_viewport_rect.x().value() / m_device_pixels_per_css_pixel, + m_device_viewport_rect.y().value() / m_device_pixels_per_css_pixel, + m_device_viewport_rect.width().value() / m_device_pixels_per_css_pixel, + m_device_viewport_rect.height().value() / m_device_pixels_per_css_pixel + }; +} + DevicePixels PaintContext::rounded_device_pixels(CSSPixels css_pixels) const { return roundf(css_pixels.value() * m_device_pixels_per_css_pixel); diff --git a/Userland/Libraries/LibWeb/Painting/PaintContext.h b/Userland/Libraries/LibWeb/Painting/PaintContext.h index 511a789287..32128bbc57 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintContext.h +++ b/Userland/Libraries/LibWeb/Painting/PaintContext.h @@ -31,8 +31,9 @@ public: bool should_show_line_box_borders() const { return m_should_show_line_box_borders; } void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; } - Gfx::IntRect viewport_rect() const { return m_viewport_rect; } - void set_viewport_rect(Gfx::IntRect const& rect) { m_viewport_rect = rect; } + DevicePixelRect device_viewport_rect() const { return m_device_viewport_rect; } + void set_device_viewport_rect(DevicePixelRect const& rect) { m_device_viewport_rect = rect; } + CSSPixelRect css_viewport_rect() const; bool has_focus() const { return m_focus; } void set_has_focus(bool focus) { m_focus = focus; } @@ -51,7 +52,7 @@ public: PaintContext clone(Gfx::Painter& painter) const { auto clone = PaintContext(painter, m_palette, m_device_pixels_per_css_pixel); - clone.m_viewport_rect = m_viewport_rect; + clone.m_device_viewport_rect = m_device_viewport_rect; clone.m_should_show_line_box_borders = m_should_show_line_box_borders; clone.m_focus = m_focus; clone.m_svg_context = m_svg_context; @@ -63,7 +64,7 @@ private: Palette m_palette; Optional<SVGContext> m_svg_context; float m_device_pixels_per_css_pixel; - Gfx::IntRect m_viewport_rect; + DevicePixelRect m_device_viewport_rect; bool m_should_show_line_box_borders { false }; bool m_focus { false }; }; diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 4e320a74f9..677c50eb16 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -249,7 +249,7 @@ void PaintableBox::paint_background(PaintContext& context) const if (layout_box().is_root_element()) { // CSS 2.1 Appendix E.2: If the element is a root element, paint the background over the entire canvas. - background_rect = context.viewport_rect().to_type<float>(); + background_rect = context.device_viewport_rect().to_type<int>().to_type<float>(); // Section 2.11.2: If the computed value of background-image on the root element is none and its background-color is transparent, // user agents must instead propagate the computed values of the background properties from that element’s first HTML BODY child element. diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp index be54d02a85..c1b6f4c6bc 100644 --- a/Userland/Services/WebContent/PageHost.cpp +++ b/Userland/Services/WebContent/PageHost.cpp @@ -120,7 +120,7 @@ void PageHost::paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap& targ Web::PaintContext context(painter, palette(), device_pixels_per_css_pixel()); context.set_should_show_line_box_borders(m_should_show_line_box_borders); - context.set_viewport_rect(content_rect.to_type<int>()); + context.set_device_viewport_rect(content_rect); context.set_has_focus(m_has_focus); layout_root->paint_all_phases(context); } diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 162df70b6b..c1aaa5c869 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -89,7 +89,7 @@ public: Web::PaintContext context(painter, palette(), device_pixels_per_css_pixel()); context.set_should_show_line_box_borders(false); - context.set_viewport_rect(content_rect.to_type<int>()); + context.set_device_viewport_rect(content_rect); context.set_has_focus(true); layout_root->paint_all_phases(context); } |