Start with implementing the new algorithms per the spec. This fixes the
case where the load event should be fired, but only if a src exists and
it is about:blank and it is connected for the very first time.
Part of #31973
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This was the last failure in this directory. To fix it, I had to spelunk
into a couple of places:
1. We shouldn't use the `base_element()` of the document, but select the
first base element, regardless if it has an empty href or not
2. We didn't implement target checking for elements. Only some values
are valid and an empty target (which the test also confusingly uses) is
not valid. Hence, it should fallback to the base element
3. We weren't sanitizing the value in case it contains an ASCII tab or
newline + U+003C. This is true for both the form target as well as for
other link elements.
All in all, added a lot more specification text to figure out what was
going on.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
When a `<link>` element loads a stylesheet then it calls
`ElementStylesheetLoader::new`, followed immediately by
calling `load` on the new loader. This is the only place where these
functions are used, so we can coalesce them together and avoid an
unreachable assertion in the process.
This should have no impact on the end user, it's just a cleanup.
Testing: Regressions should be covered by existing tests
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Leaving the entries sitting around both unnecessarily increases memory
usage and breaks code that looks up window proxies by name and reuses
names for iframes within the same page.
Testing: Newly-passing tests.
Fixes: #15258
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
In addition, clean-up the UA stylesheet for dialogs.
Stylo PR: servo/stylo#301
Testing: change causes several WPT tests to start passing.
Signed-off-by: Luke Warlow <lwarlow@igalia.com>
We weren't removing stylesheets when we should be doing so. This most
notably happens when the stylesheet no longer has a href or its "rel"
changes.
The crash is also fixed, since the issue was that we were passing the
value of the attribute that was changed as if it were an href. However,
if we set the type attribute, then that's not the href.
To fix that, we now retrieve the href inside the method so we always
have the correct value.
Fixes#42259
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
A template element should set the host of a DocumentFragment. However,
it didn't have a host yet. That's because ShadowRoot declares a host
attribute which returns Element, but its property is declared on
DocumentFragment.
Therefore, define the host on DocumentFragment instead and use it in all
relevant points for shadow roots. Then, update the pre-insert validity
check to use the correct host-including variant of inclusive ancestors.
Lastly, set the host of the template to wire it all up.
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This change adds support for the `colorspace` attribute on color inputs
and implements serialization of the input value accordingly.
The color picker from servoshell doesn't yet support non-rgb colorspaces
(and neither does the embedding API), so we convert to and from rgb when
communicating with the embedder.
Testing: New tests start to pass
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Reviewable per commits:
As noted in
https://github.com/servo/servo/pull/42180#discussion_r2749861902
transmuting `&Reflector<AssociatedMemory>` to `&Reflector<()>` will
ignore AssociatedMemory information and thus it will not remove extra
associated memory. By returning `&Reflector<Self::ReflectorType>` from
`DomObject::reflector()` we will preserve this information and thus
correctly handle cases with associated memory. We also do not need
`overrideMemoryUsage` in bindings.conf anymore. 🎉
Instead of removing associated memory in drop code we should do it as
part of finalizers, otherwise we have problems in nested (inherited)
structs, where drop is run for both parent and child, but we only added
associated memory for child (on init_reflector) which already included
size of parent. The only exception here is promise, because it is RCed
and not finalized.
Testing: Tested locally that it fixes speedometer.
Fixes#42269
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This change fixes a crash in options collections due to the fact that a
`<select>` element was being considered an ancestor of itself. This
regression likely introduced in #40776.
This change also fills in the specification text for
`HTMLOptionCollect::Add`.
Testing: This change adds a WPT crash test.
Fixes: #41080.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Make it runs at the correct time and then also performs checks for its
scheme. The CSP check is left for a follow-up PR.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Add support for `:open` pseudo-class. This is supported on dialog,
details and select elements.
Stylo PR: servo/stylo#297
Testing: WPTs but also
`data:text/html,<select><option>123</option></select><style>:open {
background-color: red; }</style>`. There are some tests that now error,
these previously failed due to missing `:open` and now make it further
along hitting test_driver.send_keys() which causes them to error
Fixes: #41277.
---------
Signed-off-by: Luke Warlow <lwarlow@igalia.com>
Ensure that the UA shadow DOM for `<textarea>` is initialized when we
are binding to a tree.
Testing: New WPT.
Fixes: #42231
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
This inserts a cache in painter that keeps data for animating images in
Painter.
We then can send cheap ImageUpdate::UpdateAnimation to just get the
required bytes from the cache.
There are some warts with the current design:
- ImageUpdate::AddImage only adds images in the cache that have the data
in SerializableImageData::Raw. Potentially there could be image
animations in other ways which then for a following
ImageUpdate::UpdateAnimation we do not have the data. We can probably
fix this on the sender side.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Testing: Tested on the usecase in
https://github.com/servo/servo/issues/41818 and WPT test here:
https://github.com/Narfinger/servo/actions/runs/21063721427
Fixes: https://github.com/servo/servo/issues/41818
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
The `HTMLLinkElement::pending_loads` field should only be used to track
outstanding loads for the current generation; any loads from previous
generations can be ignored. This avoids confusion about when to dispatch
load/error events. See
https://github.com/servo/servo/issues/42187#issuecomment-3808888585 for
more details about how the timing of multiple loads for the same
`<link>` element resulted in intermittent timeouts in one WPT test.
Testing: Intermittent failure did not appear within 75 runs; previously
reproduced within 15.
Fixes: #42187
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
We populate the required field for all relevant entrypoints
and set it to `document.base_url` when the url is `about:blank`
or `about:srcdoc`. In all other cases, it uses
`document.about_base_url`.
Testing: WPT
Fixes#41836
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
While adding various spec comments to the parts of `#the-end` (which are
scattered throughout the script crate), I stumbled upon the render
blocking stylesheets implementation. There was a HTML PR to make clear
when it should run and the corresponding WPT tests have been fixed.
Fixes#22715
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This change is a reworking of the shaping code and simplification of the
`GlyphRun` data structure.
The shaper was written between 2012 and 2014 against an early version of
Rust. It was originally written to have a single glyph entry per UTF-8
code point. This is useful when you always need to iterate through
glyphs based on UTF-8 code points. Unfortunately, this required a
tri-level data structure to hold detailed glyphs and meant that CJK
characters took over 3x the memory usage of ASCII characters. In
addition, iterating through glyphs (the most common and basic operation
on shaped text) required doing a lookup involving a binary search for
detailed glyphs (ones that had large advances or mapped to more or less
than a single UTF-8 code point).
The new design of the `GlyphStore` is instead based on `chars` in the
input string. These are tracked during layout so that the resulting
glyph output can be interpreted relatively to its original character
offset in the containing IFC. We are already dealing with IFC text on a
per-character basis for a variety of reasons (such as text
transformation and whitespace collapse). In addition, we will now able
to
implement mapping between the character offsets before and after layout
transformations of the original DOM string.
Now the penalty of more complex glyph iteration is only paid when
transforming glyph offsets to character offsets. Currently this is only
done for selections and clicking in text boxes, both of which are much
less common than layout.
This change does not properly handle selections in RTL text, though
rendering and basic selection and visual movement works (though buggy).
It does not seem like this affects the performance of shaping based on
measurement using the text shaping performance counters. This likely
means that the performance of shaping is dominated on our machines by
HarfBuzz. We noticed no performance degradation in Speedometer when run
on a M3 Mac.
Followup work:
- Properly handle selection in RTL text.
- Support mapping from original DOM character offsets to offsets in
layout after text transformation and whitespace collapse. This is now
possible.
Testing: This causes some tests to pass and a few to fail. This is
likely
due to the fact that we are handling glyphs more consistently while
shaping. Of the new failures:
- `letter-spacing-bengali-yaphala-001.html`,
`letter-spacing-cursive-001.html`, `font-feature-settings-tibetan.html`
where passing before probably because we were not applying letter
spacing to detailed glyphs. These scripts should not have letter spacing
applied to them, because they are cursive -- which we never implemented
properly. It will be handled in a a followup.
- `shaping-arabic-diacritics-001.html`: This was a false pass. The tests
verifies that Arabic diacritics are applied to NBSP. This wasn't
happening before nor after this change, but the results matched anyway.
Now they don't, but before and after are equally broken.
-
Fixes: #216
Part of #35540.
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Parsed and vectorized representations of SVGs in the image cache are
never evicted when SVGs are updated, leading to stale SVGs staying in
the image cache alongside updated ones. This PR:
- adds a stringified uuid field to SVGSVGElement
- adds a map of `SVGSVGElement` uuid to `PendingImageId` in
`ImageCacheImpl`
- adds an optional argument for the uuid to
`ImageCacheImpl::rasterize_vector_image`, which, if provided, removes
any existing parsed svgs associated with the uuid and stores a new entry
of uuid -> `PendingImageId`
- implements `unbind_from_tree` on SVGSVGElement, which clears the
associated images/representations from the image_cache (from
`vector_images`, `rasterized_vector_images`, and `completed_loads`) as
well as from the layout image resolver image cache.
Testing: Each of the following documents should display their (very
flashy) content correctly and memory usage should stay constant
<details>
<summary>Changing SVGSVGElement</summary>
```
<svg height="100" width="100" xmlns="http://www.w3.org/2000/svg">
<circle id="c" r="1" cx="50" cy="50" fill="red" />
</svg>
<script>
let c = document.querySelector("#c");
let r = 1;
setInterval(() => {
r += 1;
c.setAttribute("r", r.toString());
let tmp = document.createTextNode("ignored");
c.parentNode.appendChild(tmp);
tmp.remove();
}, 100);
</script>
```
</details>
<details>
<summary>Unbinding SVGSVGElements</summary>
```
<div id="parent_div">
<svg id="test" height="100" width="100" xmlns="http://www.w3.org/2000/svg">
<circle id="c" r="10" cx="50" cy="50" fill="red" />
</svg>
</div>
<script>
let div = document.querySelector("#parent_div");
let svg_html_string = div.innerHTML;
let svg = document.querySelector("#test");
let r = 10;
setInterval(() => {
svg.remove();
div.innerHTML = svg_html_string;
svg = document.querySelector("#test");
let circle = document.querySelector("#c");
r += 1;
circle.setAttribute("r", r.toString());
}, 100);
</script>
```
</details>
<details>
<summary>Unbinding SVGSVGElements (and rebinding the same SVG)</summary>
This didn't work until I also evicted the associated image from the
layout image resolver image cache and the image cache's
`completed_loads` on SVGSVGElement unbind, so it seems like a useful, if
a bit redundant, test.
```
<div id="parent_div">
<svg id="test" height="100" width="100" xmlns="http://www.w3.org/2000/svg">
<circle id="c" r="10" cx="50" cy="50" fill="red" />
</svg>
</div>
<script>
let div = document.querySelector("#parent_div");
let svg_html_string = div.innerHTML;
let svg = document.querySelector("#test");
let r = 10;
setInterval(() => {
svg.remove();
div.innerHTML = svg_html_string;
svg = document.querySelector("#test");
}, 100);
</script>
```
</details>
Fixes: #41070
---------
Signed-off-by: Tom Cummings <cummings.t287@gmail.com>
Since we use `NetworkError` just for logging reasons, we don't really
need to pass it around; instead lets follow spec more closely and pass a
`None` on network failures.
Make more explicit if a `modulemap` entry is currently fetching or
ready.
Testing: No functional change, covered by existing tests
---------
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
Changed the return type of `ModuleObject::handle()` to the original type
of its contained handle by removing `.into()` call, as requested in the
linked issue.
Additional changes are due to temporary borrows now sharing lifetime
with returned handle reference.
Testing: No new tests needed, as the code is functionally the same after
the changes. Verified with running `./mach test-build` and `./mach
test-unit` successfully.
Fixes: https://github.com/servo/servo/issues/42051
Signed-off-by: Krzysztof Biedroń <arkendil@gmail.com>
This change finishes the big rename associated with the old
`compositing` crates. Long ago, these crates managed a compositor, like
you might find in a traditional web engine. These days, compositing is
done in WebRender so the name has stopped making much sense. Various
structs inside the crates have already been renamed and this is the
final big change necessary for the rename
Testing: This is just a rename so existing tests should cover it.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This better reflects the intention of the code, which is that these
fields are set at most one time.
Testing: No behaviour change expected, so existing tests suffice.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Although these type of inputs do not have an activation behavior (the
behavior of their clicks are up to the page), they should still get the
"active" node state when they are pressed. This allows the `:active`
pseudo-selector to work on them, making press highlights work.
Testing: This fixes two WPT subtests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit remove more unused code from `script_module`,
`inline_module_map` and `dynamic_modules` fields from `GlobalScope` and
the now unused custom interface `DynamicModuleOwner`.
Testing: No functional change, a successful build is enough.
---------
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
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>
Instead of handling selection in text input during box tree / fragment
tree construction, fully handle it during display list construction.
This means that when the selection changes in script, it updates
automatically in the `FragmentTree` and only a new display list is
necessary. This avoids a layout while changing the selection in text
fields.
Testing: This fixes a few rendering issues, but these are very hard
to isolate and test for. It causes one test to start failing, but this
is
because a cursor that wasn't rendered properly now starts showing
up.
Fixes: #41920.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
We only implemented the first part (parser_inserted), but
weren't checking any of the other cases.
Testing: WPT
Part of #22715
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Updates it according to the spec and adds a big explanation why it
differs from the spec. It took me a while to figure out what's going on
here and why the code was actually correct.
Testing: WPT
Part of #22715Fixes#42009
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
Co-authored-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>
These were missing. It also lists why some of these steps are actually
present in the `StylesheetLoader` instead.
Testing: WPT
Part of #22715
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
These changes introduce a new OriginSnapshot type, which is an immutable
version of MutableOrigin (ie. an origin that includes an optional domain
modifier). This is now propagated as part of LoadData's origin, allowing
us to perform the same-origin-domain check for javascript: URLs as
needed.
Testing: Newly-passing tests.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This constructors takes more arguments than it needs to. The three
arguments removed are almost always the default values. The exception is
in the unit tests. In this change those calls are modified to use
`set_max_length` like is done in the actual script code.
Testing: This is just a simplification of the code, so should be covered
by existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This change brings Servo closer to the specification by removing the
unspecified sanitization flags used during parsing of input elements.
Instead we implement the lines of the specification that say to reset
resettable elements after parsing them. This forces a re-sanitization of
the default value (from the `value` attribute), clearing up the
confusion in parser comments.
In addition, specification text is added in the element creation code.
Testing: This just brings our code closer to the specification, so it is
covered by existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Updates the implementation of HTMLIFrameElement::GetContentDocument to
match the latest specification text.
Testing: Since each script thread only contains documents that are
same-origin-domain, I don't think it's possible to construct a testcase
with an observable difference here.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Retrieving the origin from the document's URL means the wrong origin can
be returned for documents like about:blank or about:srcdoc.
Testing: Newly-passing test involving a srcdoc and blob.
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
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>
This change moves all single versus multiline input handling to script.
It didn't really belong in `Rope`. In addition, it ensures that all
insertions into single line text boxes are sanitized by replacing
linebreaks with spaces.
Testing: As pasting is hard to test with a WPT-style test, this changes
includes new unit tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>