mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:12:45 +00:00 
			
		
		
		
	LibWeb: Add simple implementation of Document.createElementNS
This commit is contained in:
		
							parent
							
								
									affb4ef01b
								
							
						
					
					
						commit
						449c6c5604
					
				
					 4 changed files with 14 additions and 3 deletions
				
			
		|  | @ -56,7 +56,7 @@ static String snake_name(const StringView& title_name) | ||||||
| 
 | 
 | ||||||
| static String make_input_acceptable_cpp(const String& input) | static String make_input_acceptable_cpp(const String& input) | ||||||
| { | { | ||||||
|     if (input.is_one_of("class", "template", "for", "default", "char")) { |     if (input.is_one_of("class", "template", "for", "default", "char", "namespace")) { | ||||||
|         StringBuilder builder; |         StringBuilder builder; | ||||||
|         builder.append(input); |         builder.append(input); | ||||||
|         builder.append('_'); |         builder.append('_'); | ||||||
|  | @ -1031,7 +1031,7 @@ static @fully_qualified_name@* impl_from(JS::VM& vm, JS::GlobalObject& global_ob | ||||||
| 
 | 
 | ||||||
|     auto generate_to_cpp = [&](auto& parameter, auto& js_name, const auto& js_suffix, auto cpp_name, bool return_void = false, bool legacy_null_to_empty_string = false, bool optional = false) { |     auto generate_to_cpp = [&](auto& parameter, auto& js_name, const auto& js_suffix, auto cpp_name, bool return_void = false, bool legacy_null_to_empty_string = false, bool optional = false) { | ||||||
|         auto scoped_generator = generator.fork(); |         auto scoped_generator = generator.fork(); | ||||||
|         scoped_generator.set("cpp_name", cpp_name); |         scoped_generator.set("cpp_name", make_input_acceptable_cpp(cpp_name)); | ||||||
|         scoped_generator.set("js_name", js_name); |         scoped_generator.set("js_name", js_name); | ||||||
|         scoped_generator.set("js_suffix", js_suffix); |         scoped_generator.set("js_suffix", js_suffix); | ||||||
|         scoped_generator.set("legacy_null_to_empty_string", legacy_null_to_empty_string ? "true" : "false"); |         scoped_generator.set("legacy_null_to_empty_string", legacy_null_to_empty_string ? "true" : "false"); | ||||||
|  | @ -1109,7 +1109,7 @@ static @fully_qualified_name@* impl_from(JS::VM& vm, JS::GlobalObject& global_ob | ||||||
|         Vector<String> parameter_names; |         Vector<String> parameter_names; | ||||||
|         size_t argument_index = 0; |         size_t argument_index = 0; | ||||||
|         for (auto& parameter : parameters) { |         for (auto& parameter : parameters) { | ||||||
|             parameter_names.append(snake_name(parameter.name)); |             parameter_names.append(make_input_acceptable_cpp(snake_name(parameter.name))); | ||||||
|             arguments_generator.set("argument.index", String::number(argument_index)); |             arguments_generator.set("argument.index", String::number(argument_index)); | ||||||
| 
 | 
 | ||||||
|             arguments_generator.append(R"~~~( |             arguments_generator.append(R"~~~( | ||||||
|  |  | ||||||
|  | @ -566,12 +566,21 @@ JS::Value Document::run_javascript(const StringView& source) | ||||||
|     return result; |     return result; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // https://dom.spec.whatwg.org/#dom-document-createelement
 | ||||||
|  | // FIXME: This only implements step 6 of the algorithm and does not take in options.
 | ||||||
| NonnullRefPtr<Element> Document::create_element(const String& tag_name) | NonnullRefPtr<Element> Document::create_element(const String& tag_name) | ||||||
| { | { | ||||||
|     // FIXME: Let namespace be the HTML namespace, if this is an HTML document or this’s content type is "application/xhtml+xml", and null otherwise.
 |     // FIXME: Let namespace be the HTML namespace, if this is an HTML document or this’s content type is "application/xhtml+xml", and null otherwise.
 | ||||||
|     return DOM::create_element(*this, tag_name, Namespace::HTML); |     return DOM::create_element(*this, tag_name, Namespace::HTML); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // https://dom.spec.whatwg.org/#internal-createelementns-steps
 | ||||||
|  | // FIXME: This only implements step 4 of the algorithm and does not take in options.
 | ||||||
|  | NonnullRefPtr<Element> Document::create_element_ns(const String& namespace_, const String& qualified_name) | ||||||
|  | { | ||||||
|  |     return DOM::create_element(*this, qualified_name, namespace_); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| NonnullRefPtr<DocumentFragment> Document::create_document_fragment() | NonnullRefPtr<DocumentFragment> Document::create_document_fragment() | ||||||
| { | { | ||||||
|     return adopt(*new DocumentFragment(*this)); |     return adopt(*new DocumentFragment(*this)); | ||||||
|  |  | ||||||
|  | @ -146,6 +146,7 @@ public: | ||||||
|     JS::Value run_javascript(const StringView&); |     JS::Value run_javascript(const StringView&); | ||||||
| 
 | 
 | ||||||
|     NonnullRefPtr<Element> create_element(const String& tag_name); |     NonnullRefPtr<Element> create_element(const String& tag_name); | ||||||
|  |     NonnullRefPtr<Element> create_element_ns(const String& namespace_, const String& qualifed_name); | ||||||
|     NonnullRefPtr<DocumentFragment> create_document_fragment(); |     NonnullRefPtr<DocumentFragment> create_document_fragment(); | ||||||
|     NonnullRefPtr<Text> create_text_node(const String& data); |     NonnullRefPtr<Text> create_text_node(const String& data); | ||||||
|     NonnullRefPtr<Comment> create_comment(const String& data); |     NonnullRefPtr<Comment> create_comment(const String& data); | ||||||
|  |  | ||||||
|  | @ -19,6 +19,7 @@ interface Document : Node { | ||||||
|     ArrayFromVector querySelectorAll(DOMString selectors); |     ArrayFromVector querySelectorAll(DOMString selectors); | ||||||
| 
 | 
 | ||||||
|     Element createElement(DOMString tagName); |     Element createElement(DOMString tagName); | ||||||
|  |     Element createElementNS(DOMString? namespace, DOMString qualifiedName); | ||||||
|     DocumentFragment createDocumentFragment(); |     DocumentFragment createDocumentFragment(); | ||||||
|     Text createTextNode(DOMString data); |     Text createTextNode(DOMString data); | ||||||
|     Comment createComment(DOMString data); |     Comment createComment(DOMString data); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Luke
						Luke