html_sys/scripting/
canvas.rs

1/// The HTML `<canvas>` element
2///
3/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas)
4#[doc(alias = "canvas")]
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct Canvas {
8    pub data_map: crate::DataMap,
9    global_attrs: crate::GlobalAttributes,
10    /// Horizontal dimension
11    pub width: std::option::Option<i64>,
12    /// Vertical dimension
13    pub height: std::option::Option<i64>,
14    /// Describes the role(s) the current element plays in the context of the document.
15    pub role: std::option::Option<std::borrow::Cow<'static, str>>,
16    /// Identifies the currently active element when DOM focus is on a composite widget, combobox, textbox, group, or application.
17    pub aria_active_descendant_element: std::option::Option<
18        std::borrow::Cow<'static, str>,
19    >,
20    /// Indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute.
21    pub aria_atomic: bool,
22    /// Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for a combobox, searchbox, or textbox and specifies how predictions would be presented if they were made.
23    pub aria_auto_complete: std::option::Option<std::borrow::Cow<'static, str>>,
24    /// Defines a string value that labels the current element, which is intended to be converted into Braille. See related aria-label.
25    pub aria_braille_label: std::option::Option<std::borrow::Cow<'static, str>>,
26    /// Defines a human-readable, author-localized abbreviated description for the role of an element, which is intended to be converted into Braille. See related aria-roledescription.
27    pub aria_braille_role_description: std::option::Option<
28        std::borrow::Cow<'static, str>,
29    >,
30    /// Indicates an element is being modified and that assistive technologies could wait until the modifications are complete before exposing them to the user.
31    pub aria_busy: bool,
32    /// Indicates the current "checked" state of checkboxes, radio buttons, and other widgets. See related aria-pressed and aria-selected.
33    pub aria_checked: std::option::Option<std::borrow::Cow<'static, str>>,
34    /// Defines the total number of columns in a table, grid, or treegrid. See related aria-colindex.
35    pub aria_col_count: std::option::Option<i64>,
36    /// Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid. See related aria-colindextext, aria-colcount, and aria-colspan.
37    pub aria_col_index: std::option::Option<i64>,
38    /// Defines a human readable text alternative of aria-colindex. See related aria-rowindextext.
39    pub aria_col_index_text: std::option::Option<std::borrow::Cow<'static, str>>,
40    /// Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid. See related aria-colindex and aria-rowspan.
41    pub aria_col_span: std::option::Option<i64>,
42    /// Identifies the element (or elements) whose contents or presence are controlled by the current element. See related aria-owns.
43    pub aria_controls_elements: std::option::Option<std::borrow::Cow<'static, str>>,
44    /// Indicates the element that represents the current item within a container or set of related elements.
45    pub aria_current: std::option::Option<std::borrow::Cow<'static, str>>,
46    /// Identifies the element (or elements) that describes the object. See related aria-labelledby and aria-description.
47    pub aria_described_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
48    /// Defines a string value that describes or annotates the current element. See related aria-describedby.
49    pub aria_description: std::option::Option<std::borrow::Cow<'static, str>>,
50    /// Identifies the element (or elements) that provide additional information related to the object. See related aria-describedby.
51    pub aria_details_elements: std::option::Option<std::borrow::Cow<'static, str>>,
52    /// Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. See related aria-hidden and aria-readonly.
53    pub aria_disabled: bool,
54    /// [Deprecated in ARIA 1.1] Indicates what functions can be performed when a dragged object is released on the drop target.
55    pub aria_drop_effect: std::option::Option<std::borrow::Cow<'static, str>>,
56    /// Identifies the element (or elements) that provides an error message for an object. See related aria-invalid and aria-describedby.
57    pub aria_error_message_elements: std::option::Option<std::borrow::Cow<'static, str>>,
58    /// Indicates whether a grouping element owned or controlled by this element is expanded or collapsed.
59    pub aria_expanded: bool,
60    /// Identifies the next element (or elements) in an alternate reading order of content which, at the user's discretion, allows assistive technology to override the general default of reading in document source order.
61    pub aria_flow_to_elements: std::option::Option<std::borrow::Cow<'static, str>>,
62    /// [Deprecated in ARIA 1.1] Indicates an element's "grabbed" state in a drag-and-drop operation.
63    pub aria_grabbed: bool,
64    /// Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
65    pub aria_has_popup: std::option::Option<std::borrow::Cow<'static, str>>,
66    /// Indicates whether the element is exposed to an accessibility API. See related aria-disabled.
67    pub aria_hidden: bool,
68    /// Indicates the entered value does not conform to the format expected by the application. See related aria-errormessage.
69    pub aria_invalid: std::option::Option<std::borrow::Cow<'static, str>>,
70    /// Defines keyboard shortcuts that an author has implemented to activate or give focus to an element.
71    pub aria_key_shortcuts: std::option::Option<std::borrow::Cow<'static, str>>,
72    /// Defines a string value that labels the current element. See related aria-labelledby.
73    pub aria_label: std::option::Option<std::borrow::Cow<'static, str>>,
74    /// Identifies the element (or elements) that labels the current element. See related aria-label and aria-describedby.
75    pub aria_labelled_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
76    /// Defines the hierarchical level of an element within a structure.
77    pub aria_level: std::option::Option<i64>,
78    /// Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.
79    pub aria_live: std::option::Option<std::borrow::Cow<'static, str>>,
80    /// Indicates whether an element is modal when displayed.
81    pub aria_modal: bool,
82    /// Indicates whether a text box accepts multiple lines of input or only a single line.
83    pub aria_multi_line: bool,
84    /// Indicates that the user can select more than one item from the current selectable descendants.
85    pub aria_multi_selectable: bool,
86    /// Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous.
87    pub aria_orientation: std::option::Option<std::borrow::Cow<'static, str>>,
88    /// Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship between DOM elements where the DOM hierarchy cannot be used to represent the relationship. See related aria-controls.
89    pub aria_owns_elements: std::option::Option<std::borrow::Cow<'static, str>>,
90    /// Defines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. A hint could be a sample value or a brief description of the expected format.
91    pub aria_placeholder: std::option::Option<std::borrow::Cow<'static, str>>,
92    /// Defines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. See related aria-setsize.
93    pub aria_pos_in_set: std::option::Option<i64>,
94    /// Indicates the current "pressed" state of toggle buttons. See related aria-checked and aria-selected.
95    pub aria_pressed: std::option::Option<std::borrow::Cow<'static, str>>,
96    ///  Indicates that the element is not editable, but is otherwise operable. See related aria-disabled.
97    pub aria_read_only: bool,
98    /// Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. See related aria-atomic.
99    pub aria_relevant: std::option::Option<std::borrow::Cow<'static, str>>,
100    /// Indicates that user input is required on the element before a form can be submitted.
101    pub aria_required: bool,
102    /// Defines a human-readable, author-localized description for the role of an element.
103    pub aria_role_description: std::option::Option<std::borrow::Cow<'static, str>>,
104    /// Defines the total number of rows in a table, grid, or treegrid. See related aria-rowindex.
105    pub aria_row_count: std::option::Option<i64>,
106    /// Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid. See related aria-rowindextext, aria-rowcount, and aria-rowspan.
107    pub aria_row_index: std::option::Option<i64>,
108    /// Defines a human readable text alternative of aria-rowindex. See related aria-colindextext.
109    pub aria_row_index_text: std::option::Option<std::borrow::Cow<'static, str>>,
110    /// Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid. See related aria-rowindex and aria-colspan.
111    pub aria_row_span: std::option::Option<i64>,
112    /// Indicates the current "selected" state of various widgets. See related aria-checked and aria-pressed.
113    pub aria_selected: bool,
114    /// Defines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. See related aria-posinset.
115    pub aria_set_size: std::option::Option<i64>,
116    /// Indicates if items in a table or grid are sorted in ascending or descending order.
117    pub aria_sort: std::option::Option<std::borrow::Cow<'static, str>>,
118    /// Defines the maximum allowed value for a range widget.
119    pub aria_value_max: std::option::Option<f64>,
120    /// Defines the minimum allowed value for a range widget.
121    pub aria_value_min: std::option::Option<f64>,
122    /// Defines the current value for a range widget. See related aria-valuetext.
123    pub aria_value_now: std::option::Option<f64>,
124    /// Defines the human readable text alternative of aria-valuenow for a range widget.
125    pub aria_value_text: std::option::Option<std::borrow::Cow<'static, str>>,
126}
127impl crate::RenderElement for Canvas {
128    fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
129        write!(writer, "<canvas")?;
130        if let Some(field) = self.width.as_ref() {
131            write!(writer, r#" width="{field}""#)?;
132        }
133        if let Some(field) = self.height.as_ref() {
134            write!(writer, r#" height="{field}""#)?;
135        }
136        if let Some(field) = self.role.as_ref() {
137            write!(writer, r#" role="{field}""#)?;
138        }
139        if let Some(field) = self.aria_active_descendant_element.as_ref() {
140            write!(writer, r#" aria-activedescendant="{field}""#)?;
141        }
142        if self.aria_atomic {
143            write!(writer, r#" aria-atomic"#)?;
144        }
145        if let Some(field) = self.aria_auto_complete.as_ref() {
146            write!(writer, r#" aria-autocomplete="{field}""#)?;
147        }
148        if let Some(field) = self.aria_braille_label.as_ref() {
149            write!(writer, r#" aria-braillelabel="{field}""#)?;
150        }
151        if let Some(field) = self.aria_braille_role_description.as_ref() {
152            write!(writer, r#" aria-brailleroledescription="{field}""#)?;
153        }
154        if self.aria_busy {
155            write!(writer, r#" aria-busy"#)?;
156        }
157        if let Some(field) = self.aria_checked.as_ref() {
158            write!(writer, r#" aria-checked="{field}""#)?;
159        }
160        if let Some(field) = self.aria_col_count.as_ref() {
161            write!(writer, r#" aria-colcount="{field}""#)?;
162        }
163        if let Some(field) = self.aria_col_index.as_ref() {
164            write!(writer, r#" aria-colindex="{field}""#)?;
165        }
166        if let Some(field) = self.aria_col_index_text.as_ref() {
167            write!(writer, r#" aria-colindextext="{field}""#)?;
168        }
169        if let Some(field) = self.aria_col_span.as_ref() {
170            write!(writer, r#" aria-colspan="{field}""#)?;
171        }
172        if let Some(field) = self.aria_controls_elements.as_ref() {
173            write!(writer, r#" aria-controls="{field}""#)?;
174        }
175        if let Some(field) = self.aria_current.as_ref() {
176            write!(writer, r#" aria-current="{field}""#)?;
177        }
178        if let Some(field) = self.aria_described_by_elements.as_ref() {
179            write!(writer, r#" aria-describedby="{field}""#)?;
180        }
181        if let Some(field) = self.aria_description.as_ref() {
182            write!(writer, r#" aria-description="{field}""#)?;
183        }
184        if let Some(field) = self.aria_details_elements.as_ref() {
185            write!(writer, r#" aria-details="{field}""#)?;
186        }
187        if self.aria_disabled {
188            write!(writer, r#" aria-disabled"#)?;
189        }
190        if let Some(field) = self.aria_drop_effect.as_ref() {
191            write!(writer, r#" aria-dropeffect="{field}""#)?;
192        }
193        if let Some(field) = self.aria_error_message_elements.as_ref() {
194            write!(writer, r#" aria-errormessage="{field}""#)?;
195        }
196        if self.aria_expanded {
197            write!(writer, r#" aria-expanded"#)?;
198        }
199        if let Some(field) = self.aria_flow_to_elements.as_ref() {
200            write!(writer, r#" aria-flowto="{field}""#)?;
201        }
202        if self.aria_grabbed {
203            write!(writer, r#" aria-grabbed"#)?;
204        }
205        if let Some(field) = self.aria_has_popup.as_ref() {
206            write!(writer, r#" aria-haspopup="{field}""#)?;
207        }
208        if self.aria_hidden {
209            write!(writer, r#" aria-hidden"#)?;
210        }
211        if let Some(field) = self.aria_invalid.as_ref() {
212            write!(writer, r#" aria-invalid="{field}""#)?;
213        }
214        if let Some(field) = self.aria_key_shortcuts.as_ref() {
215            write!(writer, r#" aria-keyshortcuts="{field}""#)?;
216        }
217        if let Some(field) = self.aria_label.as_ref() {
218            write!(writer, r#" aria-label="{field}""#)?;
219        }
220        if let Some(field) = self.aria_labelled_by_elements.as_ref() {
221            write!(writer, r#" aria-labelledby="{field}""#)?;
222        }
223        if let Some(field) = self.aria_level.as_ref() {
224            write!(writer, r#" aria-level="{field}""#)?;
225        }
226        if let Some(field) = self.aria_live.as_ref() {
227            write!(writer, r#" aria-live="{field}""#)?;
228        }
229        if self.aria_modal {
230            write!(writer, r#" aria-modal"#)?;
231        }
232        if self.aria_multi_line {
233            write!(writer, r#" aria-multiline"#)?;
234        }
235        if self.aria_multi_selectable {
236            write!(writer, r#" aria-multiselectable"#)?;
237        }
238        if let Some(field) = self.aria_orientation.as_ref() {
239            write!(writer, r#" aria-orientation="{field}""#)?;
240        }
241        if let Some(field) = self.aria_owns_elements.as_ref() {
242            write!(writer, r#" aria-owns="{field}""#)?;
243        }
244        if let Some(field) = self.aria_placeholder.as_ref() {
245            write!(writer, r#" aria-placeholder="{field}""#)?;
246        }
247        if let Some(field) = self.aria_pos_in_set.as_ref() {
248            write!(writer, r#" aria-posinset="{field}""#)?;
249        }
250        if let Some(field) = self.aria_pressed.as_ref() {
251            write!(writer, r#" aria-pressed="{field}""#)?;
252        }
253        if self.aria_read_only {
254            write!(writer, r#" aria-readonly"#)?;
255        }
256        if let Some(field) = self.aria_relevant.as_ref() {
257            write!(writer, r#" aria-relevant="{field}""#)?;
258        }
259        if self.aria_required {
260            write!(writer, r#" aria-required"#)?;
261        }
262        if let Some(field) = self.aria_role_description.as_ref() {
263            write!(writer, r#" aria-roledescription="{field}""#)?;
264        }
265        if let Some(field) = self.aria_row_count.as_ref() {
266            write!(writer, r#" aria-rowcount="{field}""#)?;
267        }
268        if let Some(field) = self.aria_row_index.as_ref() {
269            write!(writer, r#" aria-rowindex="{field}""#)?;
270        }
271        if let Some(field) = self.aria_row_index_text.as_ref() {
272            write!(writer, r#" aria-rowindextext="{field}""#)?;
273        }
274        if let Some(field) = self.aria_row_span.as_ref() {
275            write!(writer, r#" aria-rowspan="{field}""#)?;
276        }
277        if self.aria_selected {
278            write!(writer, r#" aria-selected"#)?;
279        }
280        if let Some(field) = self.aria_set_size.as_ref() {
281            write!(writer, r#" aria-setsize="{field}""#)?;
282        }
283        if let Some(field) = self.aria_sort.as_ref() {
284            write!(writer, r#" aria-sort="{field}""#)?;
285        }
286        if let Some(field) = self.aria_value_max.as_ref() {
287            write!(writer, r#" aria-valuemax="{field}""#)?;
288        }
289        if let Some(field) = self.aria_value_min.as_ref() {
290            write!(writer, r#" aria-valuemin="{field}""#)?;
291        }
292        if let Some(field) = self.aria_value_now.as_ref() {
293            write!(writer, r#" aria-valuenow="{field}""#)?;
294        }
295        if let Some(field) = self.aria_value_text.as_ref() {
296            write!(writer, r#" aria-valuetext="{field}""#)?;
297        }
298        write!(writer, "{}", self.global_attrs)?;
299        write!(writer, "{}", self.data_map)?;
300        write!(writer, ">")?;
301        Ok(())
302    }
303    #[allow(unused_variables)]
304    fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
305        write!(writer, "</canvas>")?;
306        Ok(())
307    }
308}
309impl std::fmt::Display for Canvas {
310    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
311        use crate::RenderElement;
312        self.write_opening_tag(writer)?;
313        self.write_closing_tag(writer)?;
314        Ok(())
315    }
316}
317impl std::ops::Deref for Canvas {
318    type Target = crate::GlobalAttributes;
319    fn deref(&self) -> &Self::Target {
320        &self.global_attrs
321    }
322}
323impl std::ops::DerefMut for Canvas {
324    fn deref_mut(&mut self) -> &mut Self::Target {
325        &mut self.global_attrs
326    }
327}