mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 20:25:07 +00:00

Instead of doing layout synchronously whenever something changes, we now use a basic event loop timer to defer and coalesce relayouts. If you did something that requires a relayout of the page, make sure to call Document::set_needs_layout() and it will get coalesced with all the other layout updates. There's lots of room for improvement here, but this already makes many web pages significantly snappier. :^) Also, note that this exposes a number of layout bugs where we have been relying on multiple relayouts to calculate the correct dimensions for things. Now that we only do a single layout in many cases, these kind of problems are much more noticeable. That should also make them easier to figure out and fix. :^)
55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
#include <LibWeb/DOM/Event.h>
|
|
#include <LibWeb/DOM/ShadowRoot.h>
|
|
#include <LibWeb/DOMParsing/InnerHTML.h>
|
|
#include <LibWeb/Layout/BlockBox.h>
|
|
|
|
namespace Web::DOM {
|
|
|
|
ShadowRoot::ShadowRoot(Document& document, Element& host)
|
|
: DocumentFragment(document)
|
|
{
|
|
set_host(host);
|
|
}
|
|
|
|
// https://dom.spec.whatwg.org/#ref-for-get-the-parent%E2%91%A6
|
|
EventTarget* ShadowRoot::get_parent(const Event& event)
|
|
{
|
|
if (!event.composed()) {
|
|
auto& events_first_invocation_target = verify_cast<Node>(*event.path().first().invocation_target);
|
|
if (&events_first_invocation_target.root() == this)
|
|
return nullptr;
|
|
}
|
|
|
|
return host();
|
|
}
|
|
|
|
RefPtr<Layout::Node> ShadowRoot::create_layout_node()
|
|
{
|
|
return adopt_ref(*new Layout::BlockBox(document(), this, CSS::ComputedValues {}));
|
|
}
|
|
|
|
// https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
|
|
String ShadowRoot::inner_html() const
|
|
{
|
|
return serialize_fragment(/* FIXME: Providing true for the require well-formed flag (which may throw) */);
|
|
}
|
|
|
|
// https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
|
|
ExceptionOr<void> ShadowRoot::set_inner_html(String const& markup)
|
|
{
|
|
auto result = DOMParsing::InnerHTML::inner_html_setter(*this, markup);
|
|
if (result.is_exception())
|
|
return result.exception();
|
|
|
|
set_needs_style_update(true);
|
|
return {};
|
|
}
|
|
|
|
}
|