The code was doing repetitive work by checking if `compiled_script` is
null and then assigning and expecting the same, combined and replaced
with condition based working
Testing: The flow remains the same no new tests needed
Fixes: #44210
Signed-off-by: Rover track <rishan.pgowda@gmail.com>
This introduces a `ScriptToEmbedderChan` property on `LayoutThread`,
which is used to send accessibility updates directly to the embedder.
Follow-up to https://github.com/servo/servo/pull/42338.
Testing: Covered by existing tests.
Signed-off-by: Alice Boxhall <alice@igalia.com>
Remove the `WebGLCommandSender` wrapper and return `Option<WebGLChan>`
directly from the `webgl_chan` method.
Testing: no tests required as runtime behavior is not affected
Fixes: #44193
Signed-off-by: Niya Gupta <niyabits@disroot.org>
This change introduces the `accessibility_tree` module, containing code
to build an in-memory representation of a very basic accessibility tree
for web contents. Currently, the tree for a given document contains:
- a `RootWebArea` which has the document root node as its sole child,
- an `Unknown` node for the root DOM node,
- a `GenericContainer` node for each DOM element, and
- a `TextRun` node for each text node.
This allows us to make basic assertions about the tree contents in the
`accessibility` test by doing a tree walk to find text nodes and
checking their contents.
Right now, the tree is rebuilt from scratch when accessibility is
enabled and when a navigation occurs (via
`Constellation::set_frame_tree_for_webview()` sending
`ScriptThreadMessage::SetAccessibilityActive`); it's not responsive to
changes in the page.
This change also changes the way we handle updating the graft node
between the webview's accessibility tree and its top level pipeline's
accessibility tree.
Previously, `Constellation::set_frame_tree_for_webview()` would send a
`ConstellationToEmbedderMsg::DocumentAccessibilityTreeIdChange` method
informing the webview of the accesskit TreeId of the top-level pipeline.
However, this resulted in flaky timing as we couldn't depend on that
message being handled before the message containing the TreeUpdate from
the WebContents, which would lead to a panic as the new TreeId wasn't
grafted into the combined tree yet.
This change introduces an epoch value which flows from the
ConstellationWebview, where it's updated every time the
`active_top_level_pipeline_id` changes, to the layout accessibility
tree, and finally to the webview with each TreeUpdate. Whenever a
TreeUpdate arrives at the webview which has a newer epoch than the last
known epoch, the webview-to-contents graft node is updated before the
TreeUpdate is forwarded. If a TreeUpdate arrives at the webview with an
epoch _older_ than the last known epoch, it's dropped, as it must be for
a no-longer-active pipeline.
Fixes: Part of #4344
---------
Signed-off-by: delan azabani <dazabani@igalia.com>
Signed-off-by: Alice Boxhall <alice@igalia.com>
Co-authored-by: delan azabani <dazabani@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
Previously the code was computing a prefix sum over the number of
preceding elements in tree order to get the index that the node should
be inserted in.
That's not great if the DOM tree is big. Instead, we can compare two
nodes individually by looking at their ancestor chain and then find the
correct position with binary search.
On https://262.ecma-international.org/16.0/index.html, this reduces the
time it takes for content to appear from around 33s to 16s.
Part of https://github.com/servo/servo/issues/44113
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
The main goal here is to have layout not depend on `ServoLayoutElement`
directly and instead use the layout DOM interface exposed by
`layout-api`.
This change allows layout to determine if replaced content
is the root of a user agent widget without having to access
`ServoDangerousStyleShadowRoot` which isn't really safe to use in layout
code. `LayoutElement::shadow_root()` is now no longer exposed to layout.
Testing: This should not change behavior, so should be covered by
existing test.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This returns the `PerformanceMark` object from Performance.mark()
Testing: More WPT tests passed
---------
Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
This change is a minor cleanup of the way that layout flushes the
stylesheets of shadow roots. This avoids exposing so many public methods
in our and gradually to stop using Stylo's `TShadowRoot` in layout
entirely.
Testing: This should not change behavior, so should be covered by
existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This puts in most of the required machinery for underline. There are
still remaining test failures, but tackling these in separate PR's to
keep things manageable.
Part of #25005
Testing: WPT
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
In https://github.com/servo/servo/pull/43600, we introduce the new
`CoreResourceMsg::GetCookiesForUrl`.
However after some updates, it is exactly the same with an existing one
`CoreResourceMsg::GetCookiesDataForUrl` which is used by `webdriver`.
This PR removes the duplication.
Signed-off-by: batu_hoang <longvatrong111@gmail.com>
Refactor AudioContext methods to use &mut JSContext
Testing: Just refactor.
Fixes: Part of #42638
---------
Signed-off-by: Emmanuel Paul Elom <elomemmanuel007@gmail.com>
When mutating window-reflecting event handler attributes on <body>,
HTMLBodyElement::attribute_mutated forwarded handlers to owner_window()
even for documents without a browsing context.
This caused handlers such as onload to be attached to the wrong window
in cases involving createHTMLDocument() and node cloning.
Only forward these handlers when the owner document has a browsing
context. This matches the has_browsing_context() check used by
window_event_handlers!(ForwardToWindow) and the spec algorithm.
The Range WPT expectations added for this issue are removed, as those
tests now pass. The onerroreventhandler.html test is marked as TIMEOUT
as its failure is a separate issue tracked in #44157 .
Testing:
- ./mach fmt
- ./mach test-tidy
- ./mach test-wpt -r dom/ranges
- ./mach test-wpt -r
html/webappapis/scripting/events/onerroreventhandler.html
- ./mach try linux-wpt ( Try run
[#24328414549](https://github.com/arabson99/servo/actions/runs/24328414549))
Reproduced locally with the parent.html/child.html testcase from #36561.
Before this change, Servo logged "foo is not defined".
After this change, the error no longer appears.
Fixes: #36561
Signed-off-by: arabson99 <arabiusman99@gmail.com>
I noticed that those links' fragments are all "off-by-one". This is due
to https://github.com/KhronosGroup/WebGL/pull/3762, that added a section
at the top of the specification. This patch fixes those links.
Testing: This is a comment-only change, so not covered by any automated
test. I manually navigated to a random subset of those links and checked
they do take to the correct section.
Signed-off-by: Simon Martin <simon@nasilyan.com>
\`has_sent_idle_message\` was declared and initialized in \`Window\` but
never read anywhere. Removed the field and its initialization.
Fixes#44151
Signed-off-by: thebabalola <t.babalolajoseph@gmail.com>
The parsed relations of a element don't depend on its position in the
DOM tree at all, so this does nothing.
Testing: This should not change observable behaviour, WPT should catch
regressions
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
It fixes two new tests, but also regresses 4. That's because we don't
handle xx-small (we shouldn't, at least browsers are inconsistent on
what to do with that) and pre-existing issues where a `<font>` element
is already present as parent of the selected node. These are
pre-existing issues that are now correctly exposed.
Part of #25005
Testing: WPT
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Servo has had two implementations of `selectors::Element`, one used
during layout and one used for `Element#matches()` and
`Element#closest()`. The DOM APIs can trivially use the version that's
exposed to the layout interface, which allows removing the duplicated
implementation. This will eliminate code and prevent the two
implementations from drifting apart.
Testing: This should not change behavior in a testable way so should
be covered by existing tests.
Signed-off-by: Martin Robinson <mrobinson@fastmail.fm>
Co-authored-by: Martin Robinson <mrobinson@fastmail.fm>
This should be done for CopyTexImage2D, like it is already done for
TexImage2D and CompressedTexImage2D.
Testing: Regular testsuite. I was unable to add a dedicated case because
all I could think of it check the bound buffer's status before and after
copyTexImage2D, but I could not find a way to change it from say
complete to something else.
Fixes: #23264
---------
Signed-off-by: Simon Martin <simon@nasilyan.com>
Signed-off-by: Martin Robinson <martin@abandonedwig.info>
Co-authored-by: Martin Robinson <martin@abandonedwig.info>
Moved devtools_wants_updates from GlobalScope to Window
Testing: Compiles cleanly. ```./mach test-devtools``` gives different
results each time, ```./mach test-devtools
test_sources_list_with_data_inline_classic_script``` always pass though.
Fixes: #44106
Signed-off-by: Sabb <sarafaabbas@gmail.com>
Signed-off-by: Abbas Olanrewaju Sarafa <109840351+sabbCodes@users.noreply.github.com>
This change reworks the layout DOM wrappers so that they are simpler and
easier to reason about. The main changes here:
**Combine layout wrappers into one interface:**
- `LayoutNode`/`ThreadSafeLayoutNode` is combined into `LayoutNode`:
The idea here is that `LayoutNode` is always thread-safe when used in
layout as long as no `unsafe` calls are used. These interfaces
only expose what is necessary for layout.
- `LayoutElement`/`ThreadSafeLayoutElement` is combined into
`LayoutElement`: See above.
**Expose two new interfaces to be used *only* with `stylo` and
`selectors`:**
`DangerousStyleNode` and `DangerousStyleElement`. `stylo`
and `selectors` have a different way of ensuring safety that is
incompatible with Servo's layout (access all of the DOM tree anywhere,
but ensure that writing only happens from a single-thread). These types
only implement things like `TElement`, `TNode` and are not intended to
be used by layout at all.
All traits and implementations are moved to files that are named after
the struct or trait inside them, in order to better understand what one
is looking at.
The main goals here are:
- Make it easier to reason about the safe use of the DOM APIs.
- Remove the interdependencies between the `stylo` and `selectors`
interface implementations and the layout interface. This helps
with the first point as well and makes it simpler to know where
a method is implemented.
- Reduce the amount of code.
- Make it possible to eliminate `TrustedNodeAddress` in the future.
- Document and bring the method naming up to modern Rust conventions.
This is a lot of code changes, but is very well tested by the WPT tests.
Unfortunately, it is difficult to make a change like this iteratively.
In addition, this new design comes with new documentation at
servo/book#225.
Testing: This should not change behavior so should be covered by
existing
WPT tests.
Signed-off-by: Martin Robinson <mrobinson@fastmail.fm>
Fixes: #44105
moved member and initialization of crypto in Globlalscope to window and
workerGlobalScope
Testing: required tests passed
`
web-platform-test
Ran 80 checks (78 subtests, 2 tests)
Expected results: 80
Unexpected results: 0
OK
`
Signed-off-by: Rover track <rishan.pgowda@gmail.com>
This file was getting way too big and too cluttered. Instead, split it
up into multiple files in a dedicated folder.
Part of #25005
Part of #43709
Testing: It compiles
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Implementing Drop for DOM types is being forbidden. This change moves
the shader deletion logic into a separate DroppableWebGLShader struct,
allowing WebGLShader to comply with this restriction while still
ensuring GPU resources are released when the object is finalized.
Testing: Covered by existing WebGL tests.
Fixes: #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Many things are nodes, such as `CharacterData` and attributes. They
don't need style data at all. This saves 16 bytes on every attribute and
text node.
Testing: This should not change testable behavior (only save some
memory),
so it should be covered by existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Changes all the uses of `ServoUrl` to `ImmutableOrigin` in
`WebStorageThreadMsg`
Testing: Adds a test case as described in the issue.
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<main>
<h1>Tab and Program crashes!</h1>
<iframe srcdoc="
<body>
<p>Hello Web users! <br/> I am an iframe, <br /> I set a key and then retreive it. </p>
<script>
for (let i = 0; i < 1000; i++) {
window.localStorage.setItem('truth', 'Servo is awesome! 🌐')
const example = window.localStorage.getItem('truth')
console.log(example === 'Servo is awesome! 🌐')
}
</script>
</body>
"></iframe>
</main>
</body>
</html>
```
Fixes: #44001
---------
Signed-off-by: Niya Gupta <niyabits@disroot.org>
`dom_count` was used to determine whether it is worth it to run layout
parallel algorithm.
Now this is based on `layout_threads` pref.
Testing: Just removing dead code.
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Adjust event targeting for keyboard events when a shadow host is
involved. This is needed to not interfere with keyboard default action
like tabindex focusing.
Testing: Updated WPT tests expectations
Fixes: #43809
---------
Signed-off-by: webbeef <me@webbeef.org>
Make Servo match the focus bits of the HTML specification a bit more by
storing a `FocusableArea` as the currently focused thing in a
`Document` instead of an optional `Element`. There is always a focused
area of a `Document`, defaulting to the viewport. This is important to
support the case of focused navigables and image maps parts in the
future.
Some focus chain debugging code has been removed as the focus chain
concept needs to be reworked to match the specification more closely.
Testing: This should not change behavior so existing tests should
suffice.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
I noticed that the transferFromImageBitmap() was running without errors
but the canvas stayed blank and this was becacuse of two issues:
The mark_as_dirty was empty meaning the canvas never knew it needed to
repaint
The BitmapRenderer context had no rendering pipeline as such no ImageKey
was allocated and update_rendering always returned false, so the way I
fixed it is by
1. Implemented mark_as_dirty to call self.canvas.mark_as_dirty()
2. Allocated an ImageKey for BitmapRenderer contexts
3.Implemented set_image_key and update_rendering that sends the bitmap's
pixel data to WebRender via the paint API
4, Calling mark_as_dirty after set_bitmap in TransferFromImageBitmap
Now the reason we are setting an ImageKey on the
ImageBitmaRenderingContext is because it needs one to render to the
screen and without it the canvas was always blank
Also I noticed that for some reasons I don't understand yet, the
createImageBitmap hangs or is slow to render but after loading servo on
an open tab, if I then go ahead and open another tab and paste the file
link there, the previous tab which had the bitmap image now renders
properly
Fixes: #43565
<img width="383" height="238" alt="Screenshot from 2026-04-06 13-44-28"
src="https://github.com/user-attachments/assets/4c5096ba-ee84-4e7a-a3c6-673cc12276c4"
/>
<img width="389" height="292" alt="Screenshot from 2026-04-06 15-38-55"
src="https://github.com/user-attachments/assets/43b45e60-61d8-48de-b53e-6da5ab988768"
/>
Signed-off-by: Messi002 <rostandmessi2@gmail.com>
Servo has lots of `LayoutXYZHelper` traits that are used to define
additional methods on `LayoutDom<XYZ>`. We can replace them with `impl
LayoutDom<XYZ>` blocks, reducing the number of LoC and making it easier
to add or modify methods.
Testing: These should be covered by existing tests
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This is another part of moving more operations safely to unrooted
iterators.
- Some uses of inclusively_*_siblings
- Some uses of children()
- Some uses of child_elements()
Testing: Compilation is the test as we only use previously made iterator
functions.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Calling `compressedTexSubImage2D` without a prior `compressedTexImage2D`
for the same texture target and level caused the panic at
`tex_image_2d.rs:633` because `image_info_for_target` returned `None`
and `.unwrap()` was called on it.
Per the WebGL spec, this should generate `GL_INVALID_OPERATION` instead
of panicking. So this PR replaces the unwrap with proper error handling.
And also includes a WPT crash test that reproduces the original panic.
Fixes#43527
---------
Signed-off-by: thebabalola <t.babalolajoseph@gmail.com>
Several more TODO's are now implemented:
1. We correctly restore values for fontsize now
2. We implement relevant logic in wrap_node_list
3. We implement simple modifiable
4. We clear overrides whenever the selection changes
(which is triggered for both the selection itself and
any containing ranges).
Part of #25005
Testing: WPT
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This change allows users to pass a mark like `"navigationStart"` to
`Performance.measure` and that will resolve to the value of
`navigationStart` on the `PerformanceTiming` interface.
Testing: New tests start to pass
Part of https://github.com/servo/servo/issues/43821 - we no longer throw
an exception in the case above.
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>