mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:02:44 +00:00 
			
		
		
		
	LibWeb: Add element adjust_computed_style and move set_property() to it
This commit is contained in:
		
							parent
							
								
									928287b782
								
							
						
					
					
						commit
						69e4f924b7
					
				
					 9 changed files with 30 additions and 23 deletions
				
			
		|  | @ -1 +1 @@ | ||||||
|    56,20 |    10,20 | ||||||
|  |  | ||||||
|  | @ -2250,6 +2250,9 @@ RefPtr<StyleProperties> StyleComputer::compute_style_impl(DOM::Element& element, | ||||||
|     // 7. Resolve effective overflow values
 |     // 7. Resolve effective overflow values
 | ||||||
|     resolve_effective_overflow_values(style); |     resolve_effective_overflow_values(style); | ||||||
| 
 | 
 | ||||||
|  |     // 8. Let the element adjust computed style
 | ||||||
|  |     element.adjust_computed_style(style); | ||||||
|  | 
 | ||||||
|     return style; |     return style; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -212,6 +212,7 @@ public: | ||||||
|     JS::NonnullGCPtr<Geometry::DOMRectList> get_client_rects() const; |     JS::NonnullGCPtr<Geometry::DOMRectList> get_client_rects() const; | ||||||
| 
 | 
 | ||||||
|     virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>); |     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_receive_focus() { } | ||||||
|     virtual void did_lose_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) |     if (type_state() == TypeAttributeState::RadioButton) | ||||||
|         return heap().allocate_without_realm<Layout::RadioButton>(document(), *this, move(style)); |         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`.
 |     // AD-HOC: We rewrite `display: inline` to `display: inline-block`.
 | ||||||
|     //         This is required for the internal shadow tree to work correctly in layout.
 |     //         This is required for the internal shadow tree to work correctly in layout.
 | ||||||
|     if (style->display().is_inline_outside() && style->display().is_flow_inside()) |     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))); |         style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock))); | ||||||
| 
 | 
 | ||||||
|     if (type_state() != TypeAttributeState::FileUpload) { |     if (type_state() != TypeAttributeState::FileUpload) { | ||||||
|         if (style->property(CSS::PropertyID::Width)->has_auto()) |         if (style.property(CSS::PropertyID::Width)->has_auto()) | ||||||
|             style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(size(), CSS::Length::Type::Ch))); |             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) | void HTMLInputElement::set_checked(bool checked, ChangeSource change_source) | ||||||
|  |  | ||||||
|  | @ -58,6 +58,7 @@ public: | ||||||
|     virtual ~HTMLInputElement() override; |     virtual ~HTMLInputElement() override; | ||||||
| 
 | 
 | ||||||
|     virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override; |     virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override; | ||||||
|  |     virtual void adjust_computed_style(CSS::StyleProperties&) override; | ||||||
| 
 | 
 | ||||||
|     enum class TypeAttributeState { |     enum class TypeAttributeState { | ||||||
| #define __ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(_, state) state, | #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); |     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`.
 |     // AD-HOC: We rewrite `display: inline` to `display: inline-block`.
 | ||||||
|     //         This is required for the internal shadow tree to work correctly in layout.
 |     //         This is required for the internal shadow tree to work correctly in layout.
 | ||||||
|     if (style->display().is_inline_outside() && style->display().is_flow_inside()) |     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))); |         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); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options
 | // https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options
 | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ class HTMLSelectElement final | ||||||
| public: | public: | ||||||
|     virtual ~HTMLSelectElement() override; |     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(); |     JS::GCPtr<HTMLOptionsCollection> const& options(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -31,19 +31,17 @@ HTMLTextAreaElement::HTMLTextAreaElement(DOM::Document& document, DOM::Qualified | ||||||
| 
 | 
 | ||||||
| HTMLTextAreaElement::~HTMLTextAreaElement() = default; | 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`.
 |     // AD-HOC: We rewrite `display: inline` to `display: inline-block`.
 | ||||||
|     //         This is required for the internal shadow tree to work correctly in layout.
 |     //         This is required for the internal shadow tree to work correctly in layout.
 | ||||||
|     if (style->display().is_inline_outside() && style->display().is_flow_inside()) |     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))); |         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()) |     if (style.property(CSS::PropertyID::Width)->has_auto()) | ||||||
|         style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(cols(), CSS::Length::Type::Ch))); |         style.set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(cols(), CSS::Length::Type::Ch))); | ||||||
|     if (style->property(CSS::PropertyID::Height)->has_auto()) |     if (style.property(CSS::PropertyID::Height)->has_auto()) | ||||||
|         style->set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length(rows(), CSS::Length::Type::Lh))); |         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); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void HTMLTextAreaElement::initialize(JS::Realm& realm) | void HTMLTextAreaElement::initialize(JS::Realm& realm) | ||||||
|  |  | ||||||
|  | @ -28,7 +28,7 @@ class HTMLTextAreaElement final | ||||||
| public: | public: | ||||||
|     virtual ~HTMLTextAreaElement() override; |     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 |     String const& type() const | ||||||
|     { |     { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Bastiaan van der Plaat
						Bastiaan van der Plaat