mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 11:00:29 +00:00
LibWeb: Make property_initial_value() return a NonnullRefPtr
The finale! Users can now be sure that the value is valid, which makes things simpler.
This commit is contained in:
parent
4d42915485
commit
e52f987020
Notes:
sideshowbarker
2024-07-18 01:18:23 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/e52f987020b Pull-request: https://github.com/SerenityOS/serenity/pull/10862 Reviewed-by: https://github.com/awesomekling
3 changed files with 7 additions and 17 deletions
|
@ -169,7 +169,7 @@ bool is_inherited_property(PropertyID property_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<StyleValue> property_initial_value(PropertyID property_id)
|
NonnullRefPtr<StyleValue> property_initial_value(PropertyID property_id)
|
||||||
{
|
{
|
||||||
static HashMap<PropertyID, NonnullRefPtr<StyleValue>> initial_values;
|
static HashMap<PropertyID, NonnullRefPtr<StyleValue>> initial_values;
|
||||||
if (initial_values.is_empty()) {
|
if (initial_values.is_empty()) {
|
||||||
|
@ -219,10 +219,7 @@ RefPtr<StyleValue> property_initial_value(PropertyID property_id)
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = initial_values.find(property_id);
|
return *initial_values.find(property_id)->value;
|
||||||
if (it == initial_values.end())
|
|
||||||
return nullptr;
|
|
||||||
return it->value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool property_has_quirk(PropertyID property_id, Quirk quirk)
|
bool property_has_quirk(PropertyID property_id, Quirk quirk)
|
||||||
|
|
|
@ -45,6 +45,7 @@ int main(int argc, char** argv)
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/NonnullRefPtr.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Traits.h>
|
#include <AK/Traits.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
@ -104,7 +105,7 @@ PropertyID property_id_from_camel_case_string(StringView);
|
||||||
PropertyID property_id_from_string(const StringView&);
|
PropertyID property_id_from_string(const StringView&);
|
||||||
const char* string_from_property_id(PropertyID);
|
const char* string_from_property_id(PropertyID);
|
||||||
bool is_inherited_property(PropertyID);
|
bool is_inherited_property(PropertyID);
|
||||||
RefPtr<StyleValue> property_initial_value(PropertyID);
|
NonnullRefPtr<StyleValue> property_initial_value(PropertyID);
|
||||||
|
|
||||||
bool property_accepts_value(PropertyID, StyleValue&);
|
bool property_accepts_value(PropertyID, StyleValue&);
|
||||||
size_t property_maximum_value_count(PropertyID);
|
size_t property_maximum_value_count(PropertyID);
|
||||||
|
|
|
@ -635,18 +635,10 @@ void StyleComputer::compute_cascaded_values(StyleProperties& style, DOM::Element
|
||||||
// FIXME: Transition declarations [css-transitions-1]
|
// FIXME: Transition declarations [css-transitions-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
static NonnullRefPtr<StyleValue> get_initial_value(CSS::PropertyID property_id)
|
|
||||||
{
|
|
||||||
auto value = property_initial_value(property_id);
|
|
||||||
if (!value)
|
|
||||||
return InitialStyleValue::the();
|
|
||||||
return value.release_nonnull();
|
|
||||||
};
|
|
||||||
|
|
||||||
static NonnullRefPtr<StyleValue> get_inherit_value(CSS::PropertyID property_id, DOM::Element const* element)
|
static NonnullRefPtr<StyleValue> get_inherit_value(CSS::PropertyID property_id, DOM::Element const* element)
|
||||||
{
|
{
|
||||||
if (!element || !element->parent_element() || !element->parent_element()->specified_css_values())
|
if (!element || !element->parent_element() || !element->parent_element()->specified_css_values())
|
||||||
return get_initial_value(property_id);
|
return property_initial_value(property_id);
|
||||||
auto& map = element->parent_element()->specified_css_values()->properties();
|
auto& map = element->parent_element()->specified_css_values()->properties();
|
||||||
auto it = map.find(property_id);
|
auto it = map.find(property_id);
|
||||||
VERIFY(it != map.end());
|
VERIFY(it != map.end());
|
||||||
|
@ -662,12 +654,12 @@ void StyleComputer::compute_defaulted_property_value(StyleProperties& style, DOM
|
||||||
if (is_inherited_property(property_id))
|
if (is_inherited_property(property_id))
|
||||||
style.m_property_values.set(property_id, get_inherit_value(property_id, element));
|
style.m_property_values.set(property_id, get_inherit_value(property_id, element));
|
||||||
else
|
else
|
||||||
style.m_property_values.set(property_id, get_initial_value(property_id));
|
style.m_property_values.set(property_id, property_initial_value(property_id));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it->value->is_initial()) {
|
if (it->value->is_initial()) {
|
||||||
it->value = get_initial_value(property_id);
|
it->value = property_initial_value(property_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue