1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 12:17:44 +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:
Andreas Kling 2021-03-07 13:46:20 +01:00
parent 6c087480cf
commit 7f9f916470
4 changed files with 21 additions and 15 deletions

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <LibGfx/Painter.h>
#include <LibWeb/Dump.h>
#include <LibWeb/Layout/InitialContainingBlockBox.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)
{
paint_document_background(context);
paint(context, PaintPhase::Background);
paint(context, PaintPhase::Border);
paint(context, PaintPhase::Foreground);