mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +00:00

Since there is currently no easy way to handle rotations and skews with LibGfx this only implements translation and scaling by first constructing a general 4x4 transformation matrix like outlined in the css-transforms-1 specification. This is then downgraded to a Gfx::AffineTransform in order to transform the destination rectangle used with draw_scaled_bitmap() While rotation would be nice this already looks pretty good :^)
50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Vector.h>
|
|
#include <LibGfx/Matrix4x4.h>
|
|
#include <LibWeb/Layout/Node.h>
|
|
#include <LibWeb/Painting/Paintable.h>
|
|
|
|
namespace Web::Painting {
|
|
|
|
class StackingContext {
|
|
public:
|
|
StackingContext(Layout::Box&, StackingContext* parent);
|
|
|
|
StackingContext* parent() { return m_parent; }
|
|
const StackingContext* parent() const { return m_parent; }
|
|
|
|
enum class StackingContextPaintPhase {
|
|
BackgroundAndBorders,
|
|
Floats,
|
|
BackgroundAndBordersForInlineLevelAndReplaced,
|
|
Foreground,
|
|
FocusAndOverlay,
|
|
};
|
|
|
|
void paint_descendants(PaintContext&, Layout::Node&, StackingContextPaintPhase) const;
|
|
void paint(PaintContext&) const;
|
|
HitTestResult hit_test(Gfx::IntPoint const&, HitTestType) const;
|
|
|
|
void dump(int indent = 0) const;
|
|
|
|
void sort();
|
|
|
|
private:
|
|
Layout::Box& m_box;
|
|
StackingContext* const m_parent { nullptr };
|
|
Vector<StackingContext*> m_children;
|
|
|
|
void paint_internal(PaintContext&) const;
|
|
Gfx::FloatMatrix4x4 get_transformation_matrix(CSS::Transformation const& transformation) const;
|
|
Gfx::FloatMatrix4x4 combine_transformations(Vector<CSS::Transformation> const& transformations) const;
|
|
Gfx::AffineTransform combine_transformations_2d(Vector<CSS::Transformation> const& transformations) const;
|
|
};
|
|
|
|
}
|