script: Expose node helpers as NodeTraits and give more descriptive names (#34832)

This puts a few commonly used `Node` helpers into a trait (`NodeTraits`)
and gives them more descriptive names and documentation. The renames:

- `document_from_node` -> `NodeTraits::owner_document`
- `window_from_node` -> `NodeTraits::owner_window`
- `stylesheets_owner_from_node<T:` -> `NodeTraits::stylesheet_list_owner`
- `containing_shadow_root` -> `NodeTraits::containing_shadow_root`

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-01-03 19:55:01 +01:00 committed by GitHub
parent 621ddd749c
commit e8f75c9aea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 415 additions and 426 deletions

View file

@ -57,7 +57,7 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::element::cors_setting_for_element;
use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::htmlcanvaselement::{utils as canvas_utils, LayoutCanvasRenderingContextHelpers};
use crate::dom::node::{document_from_node, window_from_node, Node, NodeDamage};
use crate::dom::node::{Node, NodeDamage, NodeTraits};
use crate::dom::promise::Promise;
use crate::dom::vertexarrayobject::VertexAttribData;
use crate::dom::webgl_extensions::WebGLExtensions;
@ -551,8 +551,7 @@ impl WebGLRenderingContext {
match self.canvas {
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(ref canvas) => {
canvas.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
let document = document_from_node(&**canvas);
document.add_dirty_webgl_canvas(self);
canvas.owner_document().add_dirty_webgl_canvas(self);
},
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(_) => {},
}
@ -665,7 +664,7 @@ impl WebGLRenderingContext {
TexImageSource::HTMLImageElement(image) => {
let document = match self.canvas {
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(ref canvas) => {
document_from_node(&**canvas)
canvas.owner_document()
},
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(ref _canvas) => {
// TODO: Support retrieving image pixels here for OffscreenCanvas
@ -683,7 +682,7 @@ impl WebGLRenderingContext {
let window = match self.canvas {
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(ref canvas) => {
window_from_node(&**canvas)
canvas.owner_window()
},
// This is marked as unreachable as we should have returned already
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(_) => unreachable!(),