mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-18 09:50:27 +00:00
Instead of using a custom paintable to draw the controls for video and audio elements, we build them out of plain old HTML elements within a shadow root. This required a few hacks in the previous commits in order to allow a replaced element to host children within a shadow root, but it's fairly self-contained. A big benefit is that we can drive all the UI updates off of plain old DOM events (except the play button overlay on videos, which uses the video element representation), so we can test our media and input event handling more thoroughly. :^) The control bar visibility is now more similar to how other browsers handle it. It will show upon hovering over the element, but if the cursor is kept still for more than a second, it will hide again. While dragging, the controls remain visible, and will then hide after the mouse button is released. The icons have been redesigned from scratch, and the mute icon now visualizes the volume level along with indicating the mute state.
41 lines
1,013 B
C++
41 lines
1,013 B
C++
/*
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/HTML/HTMLAudioElement.h>
|
|
#include <LibWeb/Layout/AudioBox.h>
|
|
#include <LibWeb/Painting/PaintableBox.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
GC_DEFINE_ALLOCATOR(AudioBox);
|
|
|
|
AudioBox::AudioBox(DOM::Document& document, DOM::Element& element, GC::Ref<CSS::ComputedProperties> style)
|
|
: ReplacedBox(document, element, style)
|
|
{
|
|
}
|
|
|
|
HTML::HTMLAudioElement& AudioBox::dom_node()
|
|
{
|
|
return static_cast<HTML::HTMLAudioElement&>(*ReplacedBox::dom_node());
|
|
}
|
|
|
|
HTML::HTMLAudioElement const& AudioBox::dom_node() const
|
|
{
|
|
return static_cast<HTML::HTMLAudioElement const&>(*ReplacedBox::dom_node());
|
|
}
|
|
|
|
bool AudioBox::can_have_children() const
|
|
{
|
|
// If we allow children when controls are disabled, innerText may be non-empty.
|
|
return dom_node().shadow_root() != nullptr;
|
|
}
|
|
|
|
GC::Ptr<Painting::Paintable> AudioBox::create_paintable() const
|
|
{
|
|
return Painting::PaintableBox::create(*this);
|
|
}
|
|
|
|
}
|