| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-09-03 11:14:37 +01:00
										 |  |  |  * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-28 14:20:12 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 16:27:10 +01:00
										 |  |  | #include <AK/JsonObject.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-06 20:33:02 +01:00
										 |  |  | #include <LibGUI/Model.h>
 | 
					
						
							| 
									
										
										
										
											2021-01-21 20:55:37 +01:00
										 |  |  | #include <LibWeb/CSS/StyleProperties.h>
 | 
					
						
							| 
									
										
										
										
											2020-01-03 04:15:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | namespace Web { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | class StylePropertiesModel final : public GUI::Model { | 
					
						
							| 
									
										
										
										
											2020-01-03 04:15:50 +01:00
										 |  |  | public: | 
					
						
							|  |  |  |     enum Column { | 
					
						
							|  |  |  |         PropertyName, | 
					
						
							|  |  |  |         PropertyValue, | 
					
						
							|  |  |  |         __Count | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 16:27:10 +01:00
										 |  |  |     static NonnullRefPtr<StylePropertiesModel> create(StringView properties) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-11-15 01:46:51 +01:00
										 |  |  |         auto json_or_error = JsonValue::from_string(properties).release_value_but_fixme_should_propagate_errors(); | 
					
						
							|  |  |  |         return adopt_ref(*new StylePropertiesModel(json_or_error.as_object())); | 
					
						
							| 
									
										
										
										
											2021-08-24 16:27:10 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual ~StylePropertiesModel() override; | 
					
						
							| 
									
										
										
										
											2020-01-03 04:15:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 16:27:10 +01:00
										 |  |  |     virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override; | 
					
						
							|  |  |  |     virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return Column::__Count; } | 
					
						
							| 
									
										
										
										
											2020-01-03 04:15:50 +01:00
										 |  |  |     virtual String column_name(int) const override; | 
					
						
							| 
									
										
										
										
											2021-08-24 16:27:10 +01:00
										 |  |  |     virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole) const override; | 
					
						
							| 
									
										
										
										
											2022-02-17 18:20:20 +01:00
										 |  |  |     virtual bool is_searchable() const override { return true; } | 
					
						
							|  |  |  |     virtual Vector<GUI::ModelIndex> matches(StringView, unsigned flags, GUI::ModelIndex const&) override; | 
					
						
							| 
									
										
										
										
											2020-01-03 04:15:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2021-08-24 16:27:10 +01:00
										 |  |  |     explicit StylePropertiesModel(JsonObject); | 
					
						
							| 
									
										
										
										
											2020-01-03 04:15:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 16:27:10 +01:00
										 |  |  |     JsonObject m_properties; | 
					
						
							| 
									
										
										
										
											2020-01-03 04:15:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     struct Value { | 
					
						
							|  |  |  |         String name; | 
					
						
							|  |  |  |         String value; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     Vector<Value> m_values; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |