mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:17:45 +00:00
LibWeb: Draw elements with opacity in a separate stacking context
This commit is contained in:
parent
0e6ba6e1d3
commit
f567414f65
3 changed files with 27 additions and 1 deletions
|
@ -77,6 +77,9 @@ bool Node::establishes_stacking_context() const
|
||||||
auto position = computed_values().position();
|
auto position = computed_values().position();
|
||||||
if (position == CSS::Position::Absolute || position == CSS::Position::Relative || position == CSS::Position::Fixed || position == CSS::Position::Sticky)
|
if (position == CSS::Position::Absolute || position == CSS::Position::Relative || position == CSS::Position::Fixed || position == CSS::Position::Sticky)
|
||||||
return true;
|
return true;
|
||||||
|
auto opacity = computed_values().opacity();
|
||||||
|
if (opacity.has_value() && opacity.value() != 1.0f)
|
||||||
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
#include <LibGfx/Painter.h>
|
||||||
#include <LibWeb/DOM/Node.h>
|
#include <LibWeb/DOM/Node.h>
|
||||||
#include <LibWeb/Layout/Box.h>
|
#include <LibWeb/Layout/Box.h>
|
||||||
#include <LibWeb/Layout/InitialContainingBlockBox.h>
|
#include <LibWeb/Layout/InitialContainingBlockBox.h>
|
||||||
|
@ -71,7 +72,7 @@ void StackingContext::paint_descendants(PaintContext& context, Node& box, Stacki
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void StackingContext::paint(PaintContext& context)
|
void StackingContext::paint_internal(PaintContext& context)
|
||||||
{
|
{
|
||||||
// For a more elaborate description of the algorithm, see CSS 2.1 Appendix E
|
// For a more elaborate description of the algorithm, see CSS 2.1 Appendix E
|
||||||
// Draw the background and borders for the context root (steps 1, 2)
|
// Draw the background and borders for the context root (steps 1, 2)
|
||||||
|
@ -101,6 +102,26 @@ void StackingContext::paint(PaintContext& context)
|
||||||
paint_descendants(context, m_box, StackingContextPaintPhase::FocusAndOverlay);
|
paint_descendants(context, m_box, StackingContextPaintPhase::FocusAndOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StackingContext::paint(PaintContext& context)
|
||||||
|
{
|
||||||
|
auto opacity = m_box.computed_values().opacity();
|
||||||
|
if (opacity.has_value() && opacity.value() == 0.0f)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (opacity.has_value() && opacity.value() != 1.0f) {
|
||||||
|
auto bitmap = context.painter().target();
|
||||||
|
auto new_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, bitmap->size());
|
||||||
|
if (!new_bitmap)
|
||||||
|
return;
|
||||||
|
Gfx::Painter painter(*new_bitmap);
|
||||||
|
PaintContext paint_context(painter, context.palette(), context.scroll_offset());
|
||||||
|
paint_internal(paint_context);
|
||||||
|
context.painter().blit(Gfx::IntPoint(m_box.absolute_position()), *new_bitmap, Gfx::IntRect(m_box.absolute_rect()), opacity.value());
|
||||||
|
} else {
|
||||||
|
paint_internal(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestType type) const
|
HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestType type) const
|
||||||
{
|
{
|
||||||
HitTestResult result;
|
HitTestResult result;
|
||||||
|
|
|
@ -35,6 +35,8 @@ private:
|
||||||
Box& m_box;
|
Box& m_box;
|
||||||
StackingContext* const m_parent { nullptr };
|
StackingContext* const m_parent { nullptr };
|
||||||
Vector<StackingContext*> m_children;
|
Vector<StackingContext*> m_children;
|
||||||
|
|
||||||
|
void paint_internal(PaintContext&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue