These three methods date back from the very early history of Servo and
are no longer necessary:
1. `Window.debug`: `console.log` is a better replacement for this method
now. A manual test that tests the very basics of JavaScript used
this. This test is removed as well.
2. `Window.gc`: This can be replaced with `TestUtils.gc`, which is part
of a W3C specification.
3. `Window.js_backtrace`: This method is moved to `ServoTestUtils`.
Testing: Tests are updated to reflect these changes.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This introduces a new `ServoTestUtils` namespace with a `forceLayout()`
function. This `forceLayout()` function returns an object which
currently has an array of the phases ran by layout. Also moves
`panic()`, `crashHard()` and `advanceClock()` from `TestBinding` to this
new namespace. `TestBinding` is meant to test the bindings generation,
but these are more generic helpers for Servo-only tests.
Testing: This change adds a series of Servo-only tests that verify the
behavior of the new `forceLayout()` function. Tests that rely on the
moved interfaces are updated and should continue to pass.
Signed-off-by: Luke Warlow <lwarlow@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Indexeddb: transaction lifecycle
Testing: more Indexeddb test should pass
part of #40983
---------
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
This continues #41916
Changelog:
- Upstream:
360787fff5...7cd2a178d3
- Servo fixups:
e4d50e905e...d9831d464b
Stylo tracking issue: https://github.com/servo/stylo/issues/305
In particular, this adds support for `alignment-baseline` and
`baseline-shift`, and turns `vertical-align` into a shorthand of them.
This also introduces `vertical-align: center`.
Testing: Various tests improve. Some internal tests are updated because
they were wrong. And some fail because we don't support presentation
attributes on SVG elements.
---------
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Servo does not yet calculate the ink overflow area, as this sort of
thing is usually a result of `contain: paint` which Servo does not
support yet. We just need to ensure that text clipping is large
enough to contain the ink of all of the glyphs in the run. This change
just expands the rectangle based on glyph advances by 2 times the
largest advance, which should be big enough for most glyphs.
This is a big of a workaround until we have support for `contain:
paint`.
Testing:
- This change adds a Servo-specific test to ensure glyphs are fully
inked. While this test would run just fine in other browsers, it isn't
very
useful to them as this is test is very specific to the way that Servo
draws
glyphs.
- This also fixes a variety of existing WPT tests.
Fixes: #41413.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
There was a bug where characters were not properly counted when
segmeting IFC text. Immediately incrementing the
`current_character_index` meant that the count was always one character
off. This character count is mainly used for drawing selections and
really matters when multiple text segments are in a single IFC. This
change fixes that by counting characters in the same way we were
counting byte indices for the text.
Testing: This change adds a Servo-specific WPT-style test. As it is
quite
difficult to reproduce the correct display in a different way, a
mismatch test
is used. Since this is mainly about appearance and is very specific to
our
implementation the test is Servo-specific.
Fixes: #42354.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
When doing a Stylo upgrade, it may happen that a commit imported from
upstream accidentally enables a CSS property on Servo. That is even more
likely after https://phabricator.services.mozilla.com/D280900, since the
new default is that properties are enabled everywhere.
Therefore, this test will help detect these accidents. Ideally, the test
would only track CSS properties exposed to stable, but that requires
running the test without experimental features, or using internal APIs.
So for now, the test will also track experimental properties.
Testing: just adding a new test, no behavior change
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
User activation is a concept used to prevents annoying usage of specific
API (Fullscreen API, Virtual Keyboard) to the user by states that the
API needs to have in order to process. This PR implements the
`UserActivation` interface and keep track of the last user interaction.
Each `Window` will keep track the [last activation time
stamp](https://html.spec.whatwg.org/multipage/interaction.html#last-activation-timestamp),
which will be set if there are a triggering input event firing in the
`Window` and propagating across the browsing contexts ancestors and
descendants. These timestamp could be consumed, and the timestamp will
be set to negative infinite.
It is then used to gate some APIs within browser that is determined as
transient activation consuming-gated APIs, which needs transient
activation to be true and consumes the activation. For the purpose of
testing, this PR would implement this behavior on fullscreen API which
is used to test activation consuming behavior.
Spec:
https://html.spec.whatwg.org/multipage/interaction.html#the-useractivation-interface
Testing: Existing WPT
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
This change adds support for the unspecified `-webkit-text-security`
property. All major browsers support this property. The benefit of
adding this property is that the first addition of a prefixed CSS
property will allow us to start running MotionMark.
This depends on servo/stylo#295.
Testing: Three new Servo-specific tests are added for this change. There
are a few `-webkit-text-security` tests in WPT, but they do not seem
to test basic functionality.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This change makes a variety of changes to form controls to improve their
appearance. In general, they now look more similar to Chrome and
Firefox:
- Padding is added everywhere
- Checkboxes and radio buttons are more centered in their containers
and they no longer affect the baseline of their surroundings.
- Buttons react when hovered and clicked.
- Form control styles are organized a bit.
- More controls have a style making it obvious they are disabled.
There's more work to do here, but it is saved for followup changes
- Checkbox checks are not well positioned -- they should likely be an
image.
- More work is necessary to ensure that the controls look consistent at
all font sizes and that font sizes from the surrounding content do not
leak in.
Testing: This change causes some WPT tests to start passing some to
start failing,
due to the fact that we do not properly implement all of the behavior of
form controls.
Failures:
- `/css/css-flexbox/stretch-flex-item-checkbox-input.html` and
`/css/css-flexbox/stretch-flex-item-checkbox-input.html`: These test the
behavior of checkboxes and radio buttons in flex containers, but since
we do not have a Shadow DOM or custom rendering for our controls, we
must limit the height and width of the controls. Further refinement
is necessary here to get this working properly, though it only affects
controls in flex.
- `/css/css-grid/subgrid/subgrid-button.html`,
`/css/css-transforms/transform-input-002.html`,
`/html/rendering/widgets/button-layout/scrollbars.html`: These two seem
to be
minor subpixel variations in the output.
-
`/html/rendering/widgets/baseline-alignment-and-overflow.tentative.html`:
This tests uspecified behavior about where baselines come from in
controls.
We do not implement this yet.
-
`/pointerevents/pointerevent_lostpointercapture_for_disconnected_shadow_host.html`:
We do not support the `lostpointercapture` event so I suspect this is
just
timing out in a slightly different way.
Fixes: #34969.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This PR targets on adding JSON to `IDL` to show all supported values in
JS API.
This was missed during implementation. Screenshot Attached for JS API
Testing: `components/servo/tests/largest_contentful_paint.rs`
Fixes: None, this is just an refinement.
<img width="772" height="360" alt="Screenshot from 2026-01-19 17-13-20"
src="https://github.com/user-attachments/assets/1730f3f6-423c-466c-b0d4-976d35d82827"
/>
---------
Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
This change adds basic support for selecting text via dragging the mouse
in text inputs. This is currently handled entirely inside of text
inputs, but will be integrated into a more global drag handler when that
is implemented in the `DocumentEventHandler`. This means that events
that happen outside of the text input currently don't update the
selection.
Testing: This adds Servo-specific WPT-style tests. There are WPT tests
that test this sort of behavior, but I believe they rely on selection
events, which we have no implemented yet (we will soon).
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
winit on macOS seems to send a mousemove event right before mouse button
up events. This interferes with interactive use of text boxes -- for
instance double-clicking to select the hovered word. This change makes
it so
that mouse move events that do not change the cursor location are
ignored.
Testing: This change adds a Servo-specific WPT-style test.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
In text inputs, the edit point can be equal to a non-`None` selection
origin for a variety of reasons such as when the selection is set by a
DOM API or when a composition event inserts a zero length string. In
both of these cases, we should treat the selection as collapsed. It is
important to do this because for the purposes of arrow key movement and
context menu entries, we should think of the text input as not having a
selection at all.
Testing: This change adds a Servo-specific WPT test, as key press
behavior is
platform specific.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Previously it was only possible to set width and height of SVG elements
in pixels. These changes allow parsing other units like em using a CSS
parser in SVGSVGElement and resolving them to computed values in the
layout code.
Testing: Tested manually
Fixes: -
---------
Signed-off-by: Rodion Borovyk <rodion.borovyk@gmail.com>
This change makes it so that tranforms (including CSS transform and
scrolling) are properly accounted for when calculating glyph indices.
Containing block sizes are moved to `BaseFragment`. This should reduce
the size of the StackingContextTree a little.
Testing: A Servo-specific WPT-style test is added for this change.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
We should not move the text cursor or change the text selection when
non-primary (such as the right) mouse buttons are pressed. Doing so
interferes with the common operations:
1. Select text
2. Open context menu
3. Copy text
This change fixes that.
Testing: New WPT-style tests are added.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This change adds support for updating the selection when double and
triple clicking in text fields. Double clicking selects the most
relevant word while triple clicking selects the entire line.
Testing: This change adds unit tests for `Rope` as well as a
Servo-specific WPT style test. These behaviors are platform
dependent.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Make it so that clicking past the end of the text of a multiline input,
moves the edit point to the end of that line. Now we evaluate all
potential target `TextFragment`s and find the most appropriate one,
putting the edit point there.
Testing: This updates expected test results for the `<textarea>`
clicking tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This change updates and implements the old `query_text_index` layout
query to properly look for the glyph index of a point within a node's
`Fragment`s. This should work properly with the shadow DOM of both
`<input>` and `<textarea>` elements. In particular, multiple lines are
supported.
Caveats:
- `<input>` and `<textarea>` that are transformed are currently not
supported. This will happen in a followup.
- For multi-line inputs, we should be finding the text offset of the
nearest line that is within the block range of the click. This will
happen in a followup.
Testing: This change adds two Servo-specific WPT-style tests. These are
Servo-specific because the behavior of clicking in text fields isn't
fully specified.
Fixes: #35432Fixes: #10083
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
There is currently no way to disable canvas on the whole in Servo, so
one canvas backend must be enabled for the build to succeed. Currently,
the Vello GPU backend is much slower than the CPU backend, as it
downloads pixels to CPU memory before reuploading them and displaying
them. Fixing that requires allowing rendering Vello GPU contents to a
OpenGL texture or some kind of surface that can be represented by an
OpenGL texture during display.
Historically, the approach that other browsers have taken with regard to
GPU canvas is that CPU canvas is used as a fallback until the GPU
version can be counted on to be reliably faster. I think that Servo
should take the same approach. We should always expose a CPU version of
canvas and a GPU version. Embedders should not care about how these are
implemented, just that they work as expected and perform well.
Testing: This change just adjusts the build configuration option, so no
tests are necessary.
Fixes: #40779
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This change improves the counting of clicks for mouse button events by
ensuring that `detail` property of those events includes the click
count. This `detail` differs from that of `dblclick` events where the
`detail` is always 2. In addition, it ensures that the click count can
increase for mouse buttons that do not cause `click` and `dblclick`
events (such as the right mouse button).
Testing: This change adds two Servo-specific WPT-style tests. While this
behavior is specified a bit, the details are implementation specific.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
The tests were performing exact string matching on the contents of the
request body, so this change allows them to match.
Testing: Newly passing tests.
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Fixes caret rendering when the caret is placed a the start of a line
```
Hello,
{here}World!
```
Also adds a utility function to the `range` crate.
Note that the rendering of the caret on many non-empty lines is still
broken due to the presence of several other bugs
Testing: I ran unit tests. Add a new reftest
Fixes: Part of #40839
---------
Signed-off-by: Freya Arbjerg <git@arbjerg.dev>
lot of RefCell already borrowed crashes are because of code like this:
```
if let Some(index) = self
.array
.borrow()
.iter()
.position(|p| &**p == r_p)
{
self.array.borrow_mut().remove(index);
}
```
this will always panic whenever the position() finds an index, because
the immutable borrow from borrow() is still alive when we call
borrow_mut().
Fix by ensuring the borrow is dropped before taking a mutable borrow (by
computing the index in a separate scope / temporary), then remove
safely.
Testing: added crash test.
Fixes: #41260
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
There are two flavours of the mozjs `TypedArray<T>` wrapper for typed
array objects: one stores a `Box<Heap<*mut JSObject>>`, while the other
just has a bare `*mut JSObject`. The second one must only be stored
inside the `CustomAutoRoot` rooting values, but we were using it in many
other places like WebIDL dictionaries without rooting it safely. These
changes make our typed array APIs always use
`RootedTraceableBox<TypedArray<T>>` with the `Box<Heap<*mut JSObject>>`
flavour, which ensures that the JS object stored inside the typed array
wrapper is always visible to the SpiderMonkey GC.
Testing: Adds a new test that crashes without these changes.
Fixes: #41206
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Currently when we call a `Focus` we always scroll a focusable element to
the center of the container. However, this would causes a different
behavior where UAs wouldn't scroll when a focus is called to a visible
element. This PR add implementations following the behavior of Firefox
[nsFocusManager::ScrollIntoView](e613f4df35/dom/base/nsFocusManager.cpp (L3121)),
where we are scrolling to the element if it is not visible.
This would enhance the user experience of focusing an input element,
where we should avoid moving the element if it is visible.
Incidentally fix a calculation bug for the calculation of
`ScrollIntoView` with `nearest` block or inline option.
Testing: Private WPT for the implementation defined behavior and public
WPT for the bug.
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Fix RefCell already borrowed panic in
HTMLMediaElement::set_audio_renderer
Testing: new crash test should pass.
Fixes: #40720
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
The result of a predicate can depend on the position of the node in its
set, and this position is dependent on the axis that the node set came
from. This is specified in
https://www.w3.org/TR/1999/REC-xpath-19991116/#predicates.
Additionally, this change fixes a small bug in the implementation of
`preceding::` (https://github.com/servo/servo/pull/40588) where the root
of a subtree would be included twice. That wasn't discovered earlier
because nodes are deduplicated at the end of the evaluation.
Testing: New tests start to pass, this change adds more tests
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
The test query `//L/*` is present twice in the xpathmark-FT test suite.
Our WPT harness was complaining about that, so I've removed the second
test instance.
Depends on https://github.com/servo/servo/pull/40564
Testing: The relevant test is now `OK`
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Use `InputEvent` for text input and set appropriate values for the
`composed`, `data`, `isComposing`, and `inputType` attributes. Use a
placeholder for `dataTransfer` attribute and `getTargetRanges` function,
as they are only applicable to contenteditable, which isn't implemented.
Testing: I added two tests under `tests/wpt/mozilla/tests/input-events`
based on the similarly named ones for contenteditable under
`tests/wpt/tests/input-events`.
Fixes: https://github.com/servo/servo/issues/36398
---------
Signed-off-by: Excitable Snowball <excitablesnowball@gmail.com>
Instead of having the `ImageCache` return the broken image icon for
failed loads, have `HTMLImageElement` explicitly request it. This means
that the image is loaded on demand (reducing the usage of resources) and
also simplifying the interface of the `ImageCache` greatly.
In addition, the display of the broken image icon is improved, more
closely matching other browsers. A test for this display (which was
falsely passing before) is updated to reflect the new display of the
broken image icon.
Testing: There is a Servo-specific test for this change. Some WPT tests
start to fail as well. Before these were not properly loading the broken
image icon so they were failing before, just in a hidden way.
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This change fixes the Servo-specific FileAPI tests which need the
special `SelectFiles` API. In addition, file selection is now totally
asynchronous, so update the tests to handle this.
Testing: This change fixes some tests.
Fixes: #40348.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
The patch implements Compression (https://compression.spec.whatwg.org/)
with the compression and decompression provided by the `flate2` crate
(https://crates.io/crates/flate2).
`flate2` supports several different backends, controlled through the
crate's features. By default, it uses `miniz_oxide`
(https://crates.io/crates/miniz_oxide).
`flate2` provides three modules `read`, `write` and `bufread` which work
on instances of the `std::io::Read`, `std::io::Write` and
`std::io::Bufread` traits, respectively. The `write` module is chosen in
the patch since it matches the streaming model in the specification.
Testing: Enable WPT for Compression API, and introduce WPT expectation.
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
`evaluate_internal` is the common code path used when evaluating an
expression, so any verification that always applies must happen there.
Testing: This change adds a test
Fixes https://github.com/servo/servo/issues/40104
Part of #34527
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
When the provided xpath result type is `XPathResult.ANY_TYPE` then we
need to infer the result type from the result value. Previously we were
doing this in the XPathResult constructor, but that isn't being called
when we reuse a result. Instead, we move the inferring to right after we
evaluate an expression.
Testing: This change adds a new test
Fixes https://github.com/servo/servo/issues/39955
Part of #34527
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
When one unbinds an iframe from the tree, its browsing context is
destroyed, however if script keeps a reference to the window, it can
still try to open an auxiliary, resulting in a crash because the
constellation has already removed the browsing context. This adds a
non-intermittent test for the problem, and addresses it in a seemingly
ad-hoc way by checking whether the browsing context has already been
discarded, and if so doing an early return, as part of the window open
steps.
Testing: Added a crash test in the mozilla wpt folder.
Fixes: https://github.com/servo/servo/issues/39716
---------
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
Without the `test-wait` class the testharness won't wait until the
actual test executes.
I'm not sure if this is the reason for
https://github.com/servo/servo/issues/39473 (I don't understand how that
could cause the test to time out), but it's definitely *a* bug. The test
is not intermittent locally. Let's do a couple try runs and then see
where we go from there.
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>