1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 23:58:11 +00:00

LibWebView+WebConent: Add an IPC to get an element's selected state

This commit is contained in:
Timothy Flynn 2022-11-03 17:04:24 -04:00 committed by Tim Flynn
parent d907fb304e
commit 4067138702
5 changed files with 31 additions and 0 deletions

View file

@ -28,6 +28,8 @@
#include <LibWeb/Geometry/DOMRect.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/FormAssociatedElement.h>
#include <LibWeb/HTML/HTMLInputElement.h>
#include <LibWeb/HTML/HTMLOptionElement.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h>
#include <LibWeb/HTML/Storage.h>
#include <LibWeb/HTML/Window.h>
@ -501,6 +503,27 @@ static Optional<Web::DOM::Element&> find_element_by_id(i32 element_id)
return verify_cast<Web::DOM::Element>(*node);
}
Messages::WebContentServer::IsElementSelectedResponse ConnectionFromClient::is_element_selected(i32 element_id)
{
auto element = find_element_by_id(element_id);
if (!element.has_value())
return { false };
bool selected = false;
if (is<Web::HTML::HTMLInputElement>(*element)) {
auto& input = dynamic_cast<Web::HTML::HTMLInputElement&>(*element);
using enum Web::HTML::HTMLInputElement::TypeAttributeState;
if (input.type_state() == Checkbox || input.type_state() == RadioButton)
selected = input.checked();
} else if (is<Web::HTML::HTMLOptionElement>(*element)) {
selected = dynamic_cast<Web::HTML::HTMLOptionElement&>(*element).selected();
}
return { selected };
}
Messages::WebContentServer::GetElementAttributeResponse ConnectionFromClient::get_element_attribute(i32 element_id, String const& name)
{
auto element = find_element_by_id(element_id);