mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57:35 +00:00
LibWeb: Flesh out implementation of ResizeObserver interfaces
Adds the initial implementation for interfaces defined in the ResizeObserver specification. These interfaces will be used to construct and send observation events in the upcoming changes.
This commit is contained in:
parent
fb4c632309
commit
fb8edcea00
15 changed files with 494 additions and 13 deletions
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Heap/Heap.h>
|
||||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/Painting/PaintableBox.h>
|
||||
#include <LibWeb/ResizeObserver/ResizeObservation.h>
|
||||
|
||||
namespace Web::ResizeObserver {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(ResizeObservation);
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<ResizeObservation>> ResizeObservation::create(JS::Realm& realm, DOM::Element& target, Bindings::ResizeObserverBoxOptions observed_box)
|
||||
{
|
||||
return realm.heap().allocate<ResizeObservation>(realm, realm, target, observed_box);
|
||||
}
|
||||
|
||||
ResizeObservation::ResizeObservation(JS::Realm& realm, DOM::Element& target, Bindings::ResizeObserverBoxOptions observed_box)
|
||||
: m_realm(realm)
|
||||
, m_target(target)
|
||||
, m_observed_box(observed_box)
|
||||
{
|
||||
auto computed_size = realm.heap().allocate<ResizeObserverSize>(realm, realm);
|
||||
m_last_reported_sizes.append(computed_size);
|
||||
}
|
||||
|
||||
void ResizeObservation::visit_edges(JS::Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_target);
|
||||
for (auto& size : m_last_reported_sizes)
|
||||
visitor.visit(size);
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/resize-observer-1/#dom-resizeobservation-isactive
|
||||
bool ResizeObservation::is_active()
|
||||
{
|
||||
// 1. Set currentSize by calculate box size given target and observedBox.
|
||||
auto current_size = ResizeObserverSize::calculate_box_size(m_realm, m_target, m_observed_box);
|
||||
|
||||
// 2. Return true if currentSize is not equal to the first entry in this.lastReportedSizes.
|
||||
VERIFY(!m_last_reported_sizes.is_empty());
|
||||
if (!m_last_reported_sizes.first()->equals(*current_size))
|
||||
return true;
|
||||
|
||||
// 3. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue