mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-26 20:55:35 +03:00
LibWeb: Add element adjust_computed_style and move set_property() to it
This commit is contained in:
parent
928287b782
commit
69e4f924b7
Notes:
sideshowbarker
2024-07-17 08:34:29 +09:00
Author: https://github.com/bplaat Commit: https://github.com/SerenityOS/serenity/commit/69e4f924b7 Pull-request: https://github.com/SerenityOS/serenity/pull/23512
@ -1 +1 @@
|
||||
56,20
|
||||
10,20
|
||||
|
@ -2250,6 +2250,9 @@ RefPtr<StyleProperties> StyleComputer::compute_style_impl(DOM::Element& element,
|
||||
// 7. Resolve effective overflow values
|
||||
resolve_effective_overflow_values(style);
|
||||
|
||||
// 8. Let the element adjust computed style
|
||||
element.adjust_computed_style(style);
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
|
@ -212,6 +212,7 @@ public:
|
||||
JS::NonnullGCPtr<Geometry::DOMRectList> get_client_rects() const;
|
||||
|
||||
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>);
|
||||
virtual void adjust_computed_style(CSS::StyleProperties&) { }
|
||||
|
||||
virtual void did_receive_focus() { }
|
||||
virtual void did_lose_focus() { }
|
||||
|
@ -97,17 +97,23 @@ JS::GCPtr<Layout::Node> HTMLInputElement::create_layout_node(NonnullRefPtr<CSS::
|
||||
if (type_state() == TypeAttributeState::RadioButton)
|
||||
return heap().allocate_without_realm<Layout::RadioButton>(document(), *this, move(style));
|
||||
|
||||
return Element::create_layout_node_for_display_type(document(), style->display(), style, this);
|
||||
}
|
||||
|
||||
void HTMLInputElement::adjust_computed_style(CSS::StyleProperties& style)
|
||||
{
|
||||
if (type_state() == TypeAttributeState::Hidden || type_state() == TypeAttributeState::SubmitButton || type_state() == TypeAttributeState::Button || type_state() == TypeAttributeState::ResetButton || type_state() == TypeAttributeState::ImageButton || type_state() == TypeAttributeState::Checkbox || type_state() == TypeAttributeState::RadioButton)
|
||||
return;
|
||||
|
||||
// AD-HOC: We rewrite `display: inline` to `display: inline-block`.
|
||||
// This is required for the internal shadow tree to work correctly in layout.
|
||||
if (style->display().is_inline_outside() && style->display().is_flow_inside())
|
||||
style->set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock)));
|
||||
if (style.display().is_inline_outside() && style.display().is_flow_inside())
|
||||
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock)));
|
||||
|
||||
if (type_state() != TypeAttributeState::FileUpload) {
|
||||
if (style->property(CSS::PropertyID::Width)->has_auto())
|
||||
style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(size(), CSS::Length::Type::Ch)));
|
||||
if (style.property(CSS::PropertyID::Width)->has_auto())
|
||||
style.set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(size(), CSS::Length::Type::Ch)));
|
||||
}
|
||||
|
||||
return Element::create_layout_node_for_display_type(document(), style->display(), style, this);
|
||||
}
|
||||
|
||||
void HTMLInputElement::set_checked(bool checked, ChangeSource change_source)
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
virtual ~HTMLInputElement() override;
|
||||
|
||||
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
|
||||
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
||||
|
||||
enum class TypeAttributeState {
|
||||
#define __ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(_, state) state,
|
||||
|
@ -48,14 +48,12 @@ void HTMLSelectElement::visit_edges(Cell::Visitor& visitor)
|
||||
visitor.visit(m_chevron_icon_element);
|
||||
}
|
||||
|
||||
JS::GCPtr<Layout::Node> HTMLSelectElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
|
||||
void HTMLSelectElement::adjust_computed_style(CSS::StyleProperties& style)
|
||||
{
|
||||
// AD-HOC: We rewrite `display: inline` to `display: inline-block`.
|
||||
// This is required for the internal shadow tree to work correctly in layout.
|
||||
if (style->display().is_inline_outside() && style->display().is_flow_inside())
|
||||
style->set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock)));
|
||||
|
||||
return Element::create_layout_node_for_display_type(document(), style->display(), style, this);
|
||||
if (style.display().is_inline_outside() && style.display().is_flow_inside())
|
||||
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock)));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options
|
||||
|
@ -25,7 +25,7 @@ class HTMLSelectElement final
|
||||
public:
|
||||
virtual ~HTMLSelectElement() override;
|
||||
|
||||
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
|
||||
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
||||
|
||||
JS::GCPtr<HTMLOptionsCollection> const& options();
|
||||
|
||||
|
@ -31,19 +31,17 @@ HTMLTextAreaElement::HTMLTextAreaElement(DOM::Document& document, DOM::Qualified
|
||||
|
||||
HTMLTextAreaElement::~HTMLTextAreaElement() = default;
|
||||
|
||||
JS::GCPtr<Layout::Node> HTMLTextAreaElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
|
||||
void HTMLTextAreaElement::adjust_computed_style(CSS::StyleProperties& style)
|
||||
{
|
||||
// AD-HOC: We rewrite `display: inline` to `display: inline-block`.
|
||||
// This is required for the internal shadow tree to work correctly in layout.
|
||||
if (style->display().is_inline_outside() && style->display().is_flow_inside())
|
||||
style->set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock)));
|
||||
if (style.display().is_inline_outside() && style.display().is_flow_inside())
|
||||
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock)));
|
||||
|
||||
if (style->property(CSS::PropertyID::Width)->has_auto())
|
||||
style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(cols(), CSS::Length::Type::Ch)));
|
||||
if (style->property(CSS::PropertyID::Height)->has_auto())
|
||||
style->set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length(rows(), CSS::Length::Type::Lh)));
|
||||
|
||||
return Element::create_layout_node_for_display_type(document(), style->display(), style, this);
|
||||
if (style.property(CSS::PropertyID::Width)->has_auto())
|
||||
style.set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(cols(), CSS::Length::Type::Ch)));
|
||||
if (style.property(CSS::PropertyID::Height)->has_auto())
|
||||
style.set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length(rows(), CSS::Length::Type::Lh)));
|
||||
}
|
||||
|
||||
void HTMLTextAreaElement::initialize(JS::Realm& realm)
|
||||
|
@ -28,7 +28,7 @@ class HTMLTextAreaElement final
|
||||
public:
|
||||
virtual ~HTMLTextAreaElement() override;
|
||||
|
||||
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
|
||||
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
||||
|
||||
String const& type() const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user