mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 01:00:05 +00:00
LibWeb: Factor out HTMLOrSVGElement
This is a mixin in the IDL, so let's treat it as a mixin in our code and let both SVGElement and MathMLElement reuse the implementations that we wrote for HTMLElement.
This commit is contained in:
parent
d9124c8058
commit
5f84c2c3af
Notes:
github-actions[bot]
2024-10-31 09:47:30 +00:00
Author: https://github.com/gmta
Commit: 5f84c2c3af
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2036
Reviewed-by: https://github.com/tcl3
14 changed files with 130 additions and 117 deletions
69
Userland/Libraries/LibWeb/HTML/HTMLOrSVGElement.cpp
Normal file
69
Userland/Libraries/LibWeb/HTML/HTMLOrSVGElement.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/Focus.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/HTML/HTMLOrSVGElement.h>
|
||||
#include <LibWeb/MathML/MathMLElement.h>
|
||||
#include <LibWeb/SVG/SVGElement.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-dataset-dev
|
||||
template<typename ElementBase>
|
||||
JS::NonnullGCPtr<DOMStringMap> HTMLOrSVGElement<ElementBase>::dataset()
|
||||
{
|
||||
if (!m_dataset)
|
||||
m_dataset = DOMStringMap::create(*static_cast<ElementBase*>(this));
|
||||
return *m_dataset;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#dom-focus
|
||||
template<typename ElementBase>
|
||||
void HTMLOrSVGElement<ElementBase>::focus()
|
||||
{
|
||||
// FIXME: below are the focus(options) steps, also implement focus()
|
||||
|
||||
// 1. If the element is marked as locked for focus, then return.
|
||||
if (m_locked_for_focus)
|
||||
return;
|
||||
|
||||
// 2. Mark the element as locked for focus.
|
||||
m_locked_for_focus = true;
|
||||
|
||||
// 3. Run the focusing steps for the element.
|
||||
run_focusing_steps(static_cast<ElementBase*>(this));
|
||||
|
||||
// FIXME: 4. If the value of the preventScroll dictionary member of options is false,
|
||||
// then scroll the element into view with scroll behavior "auto",
|
||||
// block flow direction position set to an implementation-defined value,
|
||||
// and inline base direction position set to an implementation-defined value.
|
||||
|
||||
// 5. Unmark the element as locked for focus.
|
||||
m_locked_for_focus = false;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#dom-blur
|
||||
template<typename ElementBase>
|
||||
void HTMLOrSVGElement<ElementBase>::blur()
|
||||
{
|
||||
// The blur() method, when invoked, should run the unfocusing steps for the element on which the method was called.
|
||||
run_unfocusing_steps(static_cast<ElementBase*>(this));
|
||||
|
||||
// User agents may selectively or uniformly ignore calls to this method for usability reasons.
|
||||
}
|
||||
|
||||
template<typename ElementBase>
|
||||
void HTMLOrSVGElement<ElementBase>::visit_edges(JS::Cell::Visitor& visitor)
|
||||
{
|
||||
visitor.visit(m_dataset);
|
||||
}
|
||||
|
||||
template class HTMLOrSVGElement<HTMLElement>;
|
||||
template class HTMLOrSVGElement<MathML::MathMLElement>;
|
||||
template class HTMLOrSVGElement<SVG::SVGElement>;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue