2024-09-26 13:17:18 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2026-06-04 10:40:32 +02:00
|
|
|
#include <AK/NeverDestroyed.h>
|
2024-09-26 13:17:18 -04:00
|
|
|
#include <LibWeb/HTML/BrowsingContext.h>
|
|
|
|
|
#include <LibWeb/WebDriver/Actions.h>
|
|
|
|
|
#include <LibWeb/WebDriver/InputState.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::WebDriver {
|
|
|
|
|
|
|
|
|
|
// https://w3c.github.io/webdriver/#dfn-browsing-context-input-state-map
|
2026-06-04 10:40:32 +02:00
|
|
|
static HashMap<GC::RawPtr<HTML::BrowsingContext>, InputState>& browsing_context_input_state_map()
|
|
|
|
|
{
|
|
|
|
|
static NeverDestroyed<HashMap<GC::RawPtr<HTML::BrowsingContext>, InputState>> map;
|
|
|
|
|
return *map;
|
|
|
|
|
}
|
2024-09-26 13:17:18 -04:00
|
|
|
|
|
|
|
|
InputState::InputState() = default;
|
|
|
|
|
InputState::~InputState() = default;
|
|
|
|
|
|
|
|
|
|
// https://w3c.github.io/webdriver/#dfn-get-the-input-state
|
|
|
|
|
InputState& get_input_state(HTML::BrowsingContext& browsing_context)
|
|
|
|
|
{
|
|
|
|
|
// 1. Assert: browsing context is a top-level browsing context.
|
|
|
|
|
VERIFY(browsing_context.is_top_level());
|
|
|
|
|
|
|
|
|
|
// 2. Let input state map be session's browsing context input state map.
|
|
|
|
|
// 3. If input state map does not contain browsing context, set input state map[browsing context] to create an input state.
|
2026-06-04 10:40:32 +02:00
|
|
|
auto& input_state = browsing_context_input_state_map().ensure(browsing_context);
|
2024-09-26 13:17:18 -04:00
|
|
|
|
|
|
|
|
// 4. Return input state map[browsing context].
|
|
|
|
|
return input_state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://w3c.github.io/webdriver/#dfn-reset-the-input-state
|
|
|
|
|
void reset_input_state(HTML::BrowsingContext& browsing_context)
|
|
|
|
|
{
|
|
|
|
|
// 1. Assert: browsing context is a top-level browsing context.
|
|
|
|
|
VERIFY(browsing_context.is_top_level());
|
|
|
|
|
|
|
|
|
|
// 2. Let input state map be session's browsing context input state map.
|
|
|
|
|
// 3. If input state map[browsing context] exists, then remove input state map[browsing context].
|
2026-06-04 10:40:32 +02:00
|
|
|
browsing_context_input_state_map().remove(browsing_context);
|
2024-09-26 13:17:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|