mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:47:47 +00:00
LibWeb: Make tiled backgrounds scroll with content
Previously the page background was always draw relative to the viewport instead of following with the content. This should eventually become an opt-in mode (via CSS "background-attachment") but for now let's have the default behavior be that backgrounds scroll with content. Also take this opportunity to move the background painting code from the two web views to a shared location in InitialContainingBlockBox.
This commit is contained in:
parent
6c087480cf
commit
7f9f916470
4 changed files with 21 additions and 15 deletions
|
@ -262,14 +262,7 @@ void InProcessWebView::paint_event(GUI::PaintEvent& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.fill_rect(event.rect(), document()->background_color(palette()));
|
|
||||||
|
|
||||||
if (auto background_bitmap = document()->background_image()) {
|
|
||||||
painter.draw_tiled_bitmap(event.rect(), *background_bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
painter.translate(frame_thickness(), frame_thickness());
|
painter.translate(frame_thickness(), frame_thickness());
|
||||||
painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
|
|
||||||
|
|
||||||
PaintContext context(painter, palette(), { horizontal_scrollbar().value(), vertical_scrollbar().value() });
|
PaintContext context(painter, palette(), { horizontal_scrollbar().value(), vertical_scrollbar().value() });
|
||||||
context.set_should_show_line_box_borders(m_should_show_line_box_borders);
|
context.set_should_show_line_box_borders(m_should_show_line_box_borders);
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibGfx/Painter.h>
|
||||||
#include <LibWeb/Dump.h>
|
#include <LibWeb/Dump.h>
|
||||||
#include <LibWeb/Layout/InitialContainingBlockBox.h>
|
#include <LibWeb/Layout/InitialContainingBlockBox.h>
|
||||||
#include <LibWeb/Page/Frame.h>
|
#include <LibWeb/Page/Frame.h>
|
||||||
|
@ -61,8 +62,26 @@ void InitialContainingBlockBox::build_stacking_context_tree()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InitialContainingBlockBox::paint_document_background(PaintContext& context)
|
||||||
|
{
|
||||||
|
context.painter().fill_rect(Gfx::IntRect { {}, context.viewport_rect().size() }, document().background_color(context.palette()));
|
||||||
|
context.painter().translate(-context.viewport_rect().location());
|
||||||
|
|
||||||
|
if (auto background_bitmap = document().background_image()) {
|
||||||
|
Gfx::IntRect background_rect {
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
context.viewport_rect().x() + context.viewport_rect().width(),
|
||||||
|
context.viewport_rect().y() + context.viewport_rect().height()
|
||||||
|
};
|
||||||
|
context.painter().blit_tiled(background_rect, *background_bitmap, background_bitmap->rect());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void InitialContainingBlockBox::paint_all_phases(PaintContext& context)
|
void InitialContainingBlockBox::paint_all_phases(PaintContext& context)
|
||||||
{
|
{
|
||||||
|
paint_document_background(context);
|
||||||
|
|
||||||
paint(context, PaintPhase::Background);
|
paint(context, PaintPhase::Background);
|
||||||
paint(context, PaintPhase::Border);
|
paint(context, PaintPhase::Border);
|
||||||
paint(context, PaintPhase::Foreground);
|
paint(context, PaintPhase::Foreground);
|
||||||
|
|
|
@ -41,6 +41,8 @@ public:
|
||||||
void paint_all_phases(PaintContext&);
|
void paint_all_phases(PaintContext&);
|
||||||
virtual void paint(PaintContext&, PaintPhase) override;
|
virtual void paint(PaintContext&, PaintPhase) override;
|
||||||
|
|
||||||
|
void paint_document_background(PaintContext&);
|
||||||
|
|
||||||
virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override;
|
virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override;
|
||||||
|
|
||||||
const LayoutRange& selection() const { return m_selection; }
|
const LayoutRange& selection() const { return m_selection; }
|
||||||
|
|
|
@ -84,14 +84,6 @@ void PageHost::paint(const Gfx::IntRect& content_rect, Gfx::Bitmap& target)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.fill_rect(bitmap_rect, layout_root->document().background_color(palette()));
|
|
||||||
|
|
||||||
if (auto background_bitmap = layout_root->document().background_image()) {
|
|
||||||
painter.draw_tiled_bitmap(bitmap_rect, *background_bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
painter.translate(-content_rect.x(), -content_rect.y());
|
|
||||||
|
|
||||||
Web::PaintContext context(painter, palette(), content_rect.top_left());
|
Web::PaintContext context(painter, palette(), content_rect.top_left());
|
||||||
context.set_should_show_line_box_borders(m_should_show_line_box_borders);
|
context.set_should_show_line_box_borders(m_should_show_line_box_borders);
|
||||||
context.set_viewport_rect(content_rect);
|
context.set_viewport_rect(content_rect);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue