mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:02:43 +00:00 
			
		
		
		
	 b37379d489
			
		
	
	
		b37379d489
		
	
	
	
	
		
			
			This patch has no functional changes, but prepares the CMake script to be able to handle LibWeb on Lagom.
		
			
				
	
	
	
	
		
			2.4 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			2.4 KiB
		
	
	
	
	
	
	
	
Adding a new IDL file
Serenity's build system does a lot of work of turning the IDL from a Web spec into code, but there are a few things you'll need to do yourself.
For the sake of example, let's say you're wanting to add the HTMLDetailsElement.
- Create LibWeb/HTML/HTMLDetailsElement.idlwith the contents of the IDL section of the spec. In this case, that would be:
[Exposed=Window]
interface HTMLDetailsElement : HTMLElement {
    [HTMLConstructor] constructor();
    [CEReactions] attribute boolean open;
};
- If the IDL refers to other IDL types, you need to import those. For example, CSSRulehas an attribute that returns aCSSStyleSheet, so that needs to be imported:
#import <CSS/CSSStyleSheet.idl>
interface CSSRule {
    readonly attribute CSSStyleSheet? parentStyleSheet;
};
- 
If the IDL starts with [Exposed=Window], add the following toLibWeb/Bindings/WindowObjectHelper.h:- #include <LibWeb/Bindings/HTMLDetailsElementConstructor.h>and
- #include <LibWeb/Bindings/HTMLDetailsElementPrototype.h>to the includes list.
- ADD_WINDOW_OBJECT_INTERFACE(HTMLDetailsElement) \to the macro at the bottom.
 
- 
Add a libweb_js_wrapper(HTML/HTMLDetailsElement)call toLibWeb/idl_files.cmake
- 
Forward declare the generated classes in LibWeb/Forward.h:- HTMLDetailsElementin its namespace.
- HTMLDetailsElementWrapperin the- Web::Bindingsnamespace.
 
- 
The C++ class equivalent of the IDL interface has a few requirements: - It must inherit from public RefCounted<HTMLDetailsElement>andpublic Bindings::Wrappable
- It must have a public using WrapperType = Bindings::HTMLDetailsElementWrapper;
 
- It must inherit from 
- 
Depending on what kind of thing your interface is, you may need to add it to the WrapperFactoryof that kind:- CSSRules: LibWeb/Bindings/CSSRuleWrapperFactory.cpp
- Events: LibWeb/Bindings/EventWrapperFactory.cpp
- Elements: LibWeb/Bindings/NodeWrapperFactory.cpp
 Open the relevant wrapper factory file, and add #includedirectives and anifstatement for your new type.
- CSSRules: