mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 00:17:45 +00:00
Browser+WebContent+WebDriver: Move Get Element CSS Value to WebContent
This commit is contained in:
parent
3c00d0e92b
commit
06f1b8825c
16 changed files with 39 additions and 121 deletions
|
@ -20,7 +20,6 @@
|
|||
#include <LibJS/Runtime/ConsoleObject.h>
|
||||
#include <LibJS/Runtime/JSONObject.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/Cookie/ParsedCookie.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/NodeList.h>
|
||||
|
@ -495,44 +494,6 @@ void ConnectionFromClient::scroll_element_into_view(i32 element_id)
|
|||
element->scroll_into_view(options);
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetActiveDocumentsTypeResponse ConnectionFromClient::get_active_documents_type()
|
||||
{
|
||||
auto* active_document = page().top_level_browsing_context().active_document();
|
||||
|
||||
if (!active_document)
|
||||
return { "" };
|
||||
|
||||
auto type = active_document->document_type();
|
||||
|
||||
switch (type) {
|
||||
case Web::DOM::Document::Type::HTML:
|
||||
return { "html" };
|
||||
break;
|
||||
case Web::DOM::Document::Type::XML:
|
||||
return { "xml" };
|
||||
break;
|
||||
}
|
||||
|
||||
return { "" };
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetComputedValueForElementResponse ConnectionFromClient::get_computed_value_for_element(i32 element_id, String const& property_name)
|
||||
{
|
||||
auto element = find_element_by_id(element_id);
|
||||
if (!element.has_value())
|
||||
return { "" };
|
||||
|
||||
auto property_id = Web::CSS::property_id_from_string(property_name);
|
||||
|
||||
auto computed_values = element->computed_css_values();
|
||||
if (!computed_values)
|
||||
return { "" };
|
||||
|
||||
auto style_value = computed_values->property(property_id);
|
||||
|
||||
return { style_value->to_string() };
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetElementTextResponse ConnectionFromClient::get_element_text(i32 element_id)
|
||||
{
|
||||
auto element = find_element_by_id(element_id);
|
||||
|
|
|
@ -84,8 +84,6 @@ private:
|
|||
virtual void js_console_request_messages(i32) override;
|
||||
|
||||
virtual void scroll_element_into_view(i32 element_id) override;
|
||||
virtual Messages::WebContentServer::GetActiveDocumentsTypeResponse get_active_documents_type() override;
|
||||
virtual Messages::WebContentServer::GetComputedValueForElementResponse get_computed_value_for_element(i32 element_id, String const& property_name) override;
|
||||
virtual Messages::WebContentServer::GetElementTextResponse get_element_text(i32 element_id) override;
|
||||
virtual Messages::WebContentServer::GetElementTagNameResponse get_element_tag_name(i32 element_id) override;
|
||||
virtual Messages::WebContentServer::GetElementRectResponse get_element_rect(i32 element_id) override;
|
||||
|
|
|
@ -43,8 +43,6 @@ endpoint WebContentServer
|
|||
js_console_request_messages(i32 start_index) =|
|
||||
|
||||
scroll_element_into_view(i32 element_id) => ()
|
||||
get_active_documents_type() => (String type)
|
||||
get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value)
|
||||
get_element_text(i32 element_id) => (String text)
|
||||
get_element_tag_name(i32 element_id) => (String tag_name)
|
||||
get_element_rect(i32 element_id) => (Gfx::IntRect rect)
|
||||
|
|
|
@ -16,4 +16,5 @@ endpoint WebDriverClient {
|
|||
is_element_selected(String element_id) => (Web::WebDriver::Response response)
|
||||
get_element_attribute(String element_id, String name) => (Web::WebDriver::Response response)
|
||||
get_element_property(String element_id, String name) => (Web::WebDriver::Response response)
|
||||
get_element_css_value(String element_id, String name) => (Web::WebDriver::Response response)
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
#include <AK/JsonValue.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/StyleProperties.h>
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/HTML/AttributeNames.h>
|
||||
|
@ -555,6 +558,38 @@ Messages::WebDriverClient::GetElementPropertyResponse WebDriverConnection::get_e
|
|||
return make_success_response({});
|
||||
}
|
||||
|
||||
// 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value
|
||||
Messages::WebDriverClient::GetElementCssValueResponse WebDriverConnection::get_element_css_value(String const& element_id, String const& name)
|
||||
{
|
||||
// 1. If the current browsing context is no longer open, return error with error code no such window.
|
||||
TRY(ensure_open_top_level_browsing_context());
|
||||
|
||||
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
||||
|
||||
// 3. Let element be the result of trying to get a known connected element with url variable element id.
|
||||
auto* element = TRY(get_known_connected_element(element_id));
|
||||
|
||||
// 4. Let computed value be the result of the first matching condition:
|
||||
String computed_value;
|
||||
|
||||
// -> current browsing context’s active document’s type is not "xml"
|
||||
if (!m_page_host.page().top_level_browsing_context().active_document()->is_xml_document()) {
|
||||
// computed value of parameter property name from element’s style declarations. property name is obtained from url variables.
|
||||
auto property = Web::CSS::property_id_from_string(name);
|
||||
|
||||
if (auto* computed_values = element->computed_css_values())
|
||||
computed_value = computed_values->property(property)->to_string();
|
||||
}
|
||||
// -> Otherwise
|
||||
else {
|
||||
// "" (empty string)
|
||||
computed_value = String::empty();
|
||||
}
|
||||
|
||||
// 5. Return success with data computed value.
|
||||
return make_success_response(move(computed_value));
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-no-longer-open
|
||||
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
|
||||
{
|
||||
|
|
|
@ -46,6 +46,7 @@ private:
|
|||
virtual Messages::WebDriverClient::IsElementSelectedResponse is_element_selected(String const& element_id) override;
|
||||
virtual Messages::WebDriverClient::GetElementAttributeResponse get_element_attribute(String const& element_id, String const& name) override;
|
||||
virtual Messages::WebDriverClient::GetElementPropertyResponse get_element_property(String const& element_id, String const& name) override;
|
||||
virtual Messages::WebDriverClient::GetElementCssValueResponse get_element_css_value(String const& element_id, String const& name) override;
|
||||
|
||||
ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context();
|
||||
void restore_the_window();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue