mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
LibWeb: Move painting of background images to common location
For now, painting of background color is kept separate. The ICB needs to perform a "translate" call between painting the color and background, whereas other divs must not make that call.
This commit is contained in:
parent
1333fa7cf7
commit
735829f694
3 changed files with 32 additions and 43 deletions
|
@ -48,25 +48,9 @@ void Box::paint(PaintContext& context, PaintPhase phase)
|
||||||
if (phase == PaintPhase::Background && !is_body()) {
|
if (phase == PaintPhase::Background && !is_body()) {
|
||||||
auto background_rect = enclosing_int_rect(padded_rect);
|
auto background_rect = enclosing_int_rect(padded_rect);
|
||||||
context.painter().fill_rect(background_rect, computed_values().background_color());
|
context.painter().fill_rect(background_rect, computed_values().background_color());
|
||||||
if (background_image() && background_image()->bitmap()) {
|
|
||||||
switch (computed_values().background_repeat()) {
|
|
||||||
case CSS::Repeat::Repeat:
|
|
||||||
// The background rect is already sized to align with 'repeat'.
|
|
||||||
break;
|
|
||||||
case CSS::Repeat::RepeatX:
|
|
||||||
background_rect.set_height(background_image()->bitmap()->height());
|
|
||||||
break;
|
|
||||||
case CSS::Repeat::RepeatY:
|
|
||||||
background_rect.set_width(background_image()->bitmap()->width());
|
|
||||||
break;
|
|
||||||
case CSS::Repeat::NoRepeat:
|
|
||||||
default: // FIXME: Support 'round' and 'square'
|
|
||||||
background_rect.set_width(background_image()->bitmap()->width());
|
|
||||||
background_rect.set_height(background_image()->bitmap()->height());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.painter().blit_tiled(background_rect, *background_image()->bitmap(), background_image()->bitmap()->rect());
|
if (background_image() && background_image()->bitmap()) {
|
||||||
|
paint_background_image(context, *background_image()->bitmap(), computed_values().background_repeat(), move(background_rect));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +84,32 @@ void Box::paint(PaintContext& context, PaintPhase phase)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Box::paint_background_image(
|
||||||
|
PaintContext& context,
|
||||||
|
const Gfx::Bitmap& background_image,
|
||||||
|
CSS::Repeat background_repeat,
|
||||||
|
Gfx::IntRect background_rect)
|
||||||
|
{
|
||||||
|
switch (background_repeat) {
|
||||||
|
case CSS::Repeat::Repeat:
|
||||||
|
// The background rect is already sized to align with 'repeat'.
|
||||||
|
break;
|
||||||
|
case CSS::Repeat::RepeatX:
|
||||||
|
background_rect.set_height(background_image.height());
|
||||||
|
break;
|
||||||
|
case CSS::Repeat::RepeatY:
|
||||||
|
background_rect.set_width(background_image.width());
|
||||||
|
break;
|
||||||
|
case CSS::Repeat::NoRepeat:
|
||||||
|
default: // FIXME: Support 'round' and 'square'
|
||||||
|
background_rect.set_width(background_image.width());
|
||||||
|
background_rect.set_height(background_image.height());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.painter().blit_tiled(background_rect, background_image, background_image.rect());
|
||||||
|
}
|
||||||
|
|
||||||
HitTestResult Box::hit_test(const Gfx::IntPoint& position, HitTestType type) const
|
HitTestResult Box::hit_test(const Gfx::IntPoint& position, HitTestType type) const
|
||||||
{
|
{
|
||||||
// FIXME: It would be nice if we could confidently skip over hit testing
|
// FIXME: It would be nice if we could confidently skip over hit testing
|
||||||
|
|
|
@ -153,6 +153,8 @@ protected:
|
||||||
|
|
||||||
virtual void did_set_rect() { }
|
virtual void did_set_rect() { }
|
||||||
|
|
||||||
|
void paint_background_image(PaintContext&, const Gfx::Bitmap&, CSS::Repeat, Gfx::IntRect);
|
||||||
|
|
||||||
Vector<LineBox> m_line_boxes;
|
Vector<LineBox> m_line_boxes;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -68,31 +68,8 @@ void InitialContainingBlockBox::paint_document_background(PaintContext& context)
|
||||||
context.painter().translate(-context.viewport_rect().location());
|
context.painter().translate(-context.viewport_rect().location());
|
||||||
|
|
||||||
if (auto background_bitmap = document().background_image()) {
|
if (auto background_bitmap = document().background_image()) {
|
||||||
int painted_image_width = 0;
|
Gfx::IntRect background_rect = { 0, 0, context.viewport_rect().x() + context.viewport_rect().width(), context.viewport_rect().y() + context.viewport_rect().height() };
|
||||||
int painted_image_height = 0;
|
paint_background_image(context, *background_bitmap, document().background_repeat(), move(background_rect));
|
||||||
|
|
||||||
switch (document().background_repeat()) {
|
|
||||||
case CSS::Repeat::Repeat:
|
|
||||||
painted_image_width = context.viewport_rect().x() + context.viewport_rect().width();
|
|
||||||
painted_image_height = context.viewport_rect().y() + context.viewport_rect().height();
|
|
||||||
break;
|
|
||||||
case CSS::Repeat::RepeatX:
|
|
||||||
painted_image_width = context.viewport_rect().x() + context.viewport_rect().width();
|
|
||||||
painted_image_height = background_bitmap->rect().height();
|
|
||||||
break;
|
|
||||||
case CSS::Repeat::RepeatY:
|
|
||||||
painted_image_width = background_bitmap->rect().width();
|
|
||||||
painted_image_height = context.viewport_rect().y() + context.viewport_rect().height();
|
|
||||||
break;
|
|
||||||
case CSS::Repeat::NoRepeat:
|
|
||||||
default: // FIXME: Support 'round' and 'square'
|
|
||||||
painted_image_width = background_bitmap->rect().width();
|
|
||||||
painted_image_height = background_bitmap->rect().height();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Gfx::IntRect background_rect { 0, 0, painted_image_width, painted_image_height };
|
|
||||||
context.painter().blit_tiled(background_rect, *background_bitmap, background_bitmap->rect());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue