diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index e7564af1bd..a9d40b2f72 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -77,6 +77,9 @@ bool Node::establishes_stacking_context() const auto position = computed_values().position(); if (position == CSS::Position::Absolute || position == CSS::Position::Relative || position == CSS::Position::Fixed || position == CSS::Position::Sticky) return true; + auto opacity = computed_values().opacity(); + if (opacity.has_value() && opacity.value() != 1.0f) + return true; return false; } diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index 7ff683e8b6..3db4556ac8 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -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 // 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); } +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 result; diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.h b/Userland/Libraries/LibWeb/Painting/StackingContext.h index 687e887b49..1e8142718b 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.h +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.h @@ -35,6 +35,8 @@ private: Box& m_box; StackingContext* const m_parent { nullptr }; Vector m_children; + + void paint_internal(PaintContext&); }; }