2021-10-03 16:32:01 -04:00
# Adding a new IDL file
2024-11-22 10:33:33 -05:00
Ladybird'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.
2021-10-03 16:32:01 -04:00
For the sake of example, let's say you're wanting to add the `HTMLDetailsElement` .
1. Create `LibWeb/HTML/HTMLDetailsElement.idl` with the contents of the IDL section of the spec. In this case, that would be:
```webidl
[Exposed=Window]
interface HTMLDetailsElement : HTMLElement {
[HTMLConstructor] constructor();
[CEReactions] attribute boolean open;
};
```
2022-04-22 15:18:16 -04:00
2. If the IDL refers to other IDL types, you need to import those. For example, `CSSRule` has an attribute that returns a `CSSStyleSheet` , so that needs to be imported:
```webidl
#import <CSS/CSSStyleSheet.idl>
interface CSSRule {
readonly attribute CSSStyleSheet? parentStyleSheet;
};
```
2024-11-09 12:25:08 -05:00
3. Add a `libweb_js_bindings(HTML/HTMLDetailsElement)` call to [`LibWeb/idl_files.cmake` ](../Libraries/LibWeb/idl_files.cmake )
2021-10-03 16:32:01 -04:00
2024-11-09 12:25:08 -05:00
4. Forward declare the generated class in [`LibWeb/Forward.h` ](../Libraries/LibWeb/Forward.h ):
2021-10-03 16:32:01 -04:00
- `HTMLDetailsElement` in its namespace.
2022-04-22 15:18:16 -04:00
2024-10-22 10:30:16 -04:00
5. If your type isn't an Event or Element, you will need to add it to [`is_platform_object()` ](../Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp )
2022-08-11 12:46:13 -04:00
so that it can be accepted as an IDL parameter, attribute or return type.