mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 00:17:45 +00:00
LibWeb: Split PaintContext::viewport_rect() into device/css variants
For now, everyone uses `device_viewport_rect()`, until I convert them.
This commit is contained in:
parent
0be479dcfb
commit
4440af0870
8 changed files with 24 additions and 13 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue