mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:27:45 +00:00
LibWeb: Create a basic layout node for HTMLVideoElement
This commit is contained in:
parent
725d7c3699
commit
f156d3d5e5
10 changed files with 338 additions and 0 deletions
50
Userland/Libraries/LibWeb/Painting/VideoPaintable.cpp
Normal file
50
Userland/Libraries/LibWeb/Painting/VideoPaintable.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/HTMLVideoElement.h>
|
||||
#include <LibWeb/Layout/VideoBox.h>
|
||||
#include <LibWeb/Painting/BorderRadiusCornerClipper.h>
|
||||
#include <LibWeb/Painting/VideoPaintable.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
||||
JS::NonnullGCPtr<VideoPaintable> VideoPaintable::create(Layout::VideoBox const& layout_box)
|
||||
{
|
||||
return layout_box.heap().allocate_without_realm<VideoPaintable>(layout_box);
|
||||
}
|
||||
|
||||
VideoPaintable::VideoPaintable(Layout::VideoBox const& layout_box)
|
||||
: PaintableBox(layout_box)
|
||||
{
|
||||
}
|
||||
|
||||
Layout::VideoBox const& VideoPaintable::layout_box() const
|
||||
{
|
||||
return static_cast<Layout::VideoBox const&>(layout_node());
|
||||
}
|
||||
|
||||
void VideoPaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||
{
|
||||
if (!is_visible())
|
||||
return;
|
||||
|
||||
// FIXME: This should be done at a different level.
|
||||
if (is_out_of_view(context))
|
||||
return;
|
||||
|
||||
PaintableBox::paint(context, phase);
|
||||
|
||||
if (phase != PaintPhase::Foreground)
|
||||
return;
|
||||
|
||||
if (auto const& bitmap = layout_box().dom_node().current_frame()) {
|
||||
auto image_rect = context.rounded_device_rect(absolute_rect());
|
||||
ScopedCornerRadiusClip corner_clip { context, context.painter(), image_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
|
||||
context.painter().draw_scaled_bitmap(image_rect.to_type<int>(), *bitmap, bitmap->rect(), 1.0f, to_gfx_scaling_mode(computed_values().image_rendering()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
28
Userland/Libraries/LibWeb/Painting/VideoPaintable.h
Normal file
28
Userland/Libraries/LibWeb/Painting/VideoPaintable.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/Painting/PaintableBox.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
||||
class VideoPaintable final : public PaintableBox {
|
||||
JS_CELL(VideoPaintable, PaintableBox);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<VideoPaintable> create(Layout::VideoBox const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
Layout::VideoBox const& layout_box() const;
|
||||
|
||||
private:
|
||||
VideoPaintable(Layout::VideoBox const&);
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue