This moves Servo closer to the focus parts of the HTML specification.
The behavior should be the same as before, but now the code in `script`
matches the structure of the specification.
The main goal is to set us up for:
- Firing focus events in the right order on nested documents
- A proper implementation of the unfocusing steps.
Testing: This should not change behavior so is covered by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@fastmail.fm>
Co-authored-by: Martin Robinson <mrobinson@fastmail.fm>
Depends on #42251 for the overflow query.
Use containing block queries to implement the iteration of step [3.2.7.
Compute the Intersection of a Target Element and the
Root](https://w3c.github.io/IntersectionObserver/#compute-the-intersection)
within `IntersectionObserver` algorithm.
Contrary to the algorithm in the spec that maps the coordinate space of
the element for each iteration, we uses bounding client rect queries to
get the appropriate clip rect. And, to handle the mapping between
different coordinate spaces of iframes, we use a simple translation.
Due to the platform limitation, currently it would only handle the same
`ScriptThread` browsing context. Therefore innaccuracy any usage with
cross origin iframes is expected.
Testing: Existing and new WPTs.
Part of: https://github.com/servo/servo/issues/35767
Co-authored-by: Josh Matthews
[josh@joshmatthews.net](josh@joshmatthews.net)
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
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>
\`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>
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>
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>
`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>
There are two times that Servo needs to ask other `Document`s to either
focus or blur.
- During processing of the "focusing steps". When a new element gains
focus this may cause focus to be lost or gained in parent `<iframe>`s.
- When calling `focus()` on a DOM Window from another origin.
In both of these cases we need to request that a `Document` gain or lose
focus via the Constellation, but in the second case we may have a
`BrowsingContextId` of the `<iframe>` gaining focus and a
`FocusSequence`. This change splits those cases into two kinds of
messages.
Finally, run the entire focusing steps when calling `window.focus()`
instead of going to the constellation immediately. This will be
important in a followup changes where messaging order is made more
consistent.
Testing: This should not change behavior so is covered by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This implements MallocSizeOf for a couple more types and removes some
"ignore_malloc_size_of" throughout the codebase.
- std::path::PathBuf
- tokio::sync::oneshot::Sender
- http::HeaderMap (with a reasonable approximation of iterating over all
headers)
- data_url::Mime by looking at the inner type
- http::Method: Is an enum internally
- urlpattern::Urlpattern: Iterating over all public fields that are
strings as an approximation.
Testing: We cannot test if MallocSizeOf is correct currently.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Initialize unminified_css_dir directly in Window::new instead of storing
a separate unminify_css bool and lazily setting the dir in
init_document.
Testing: Ran ```./mach run --unminify-css google.com``` also checked
```ls unminified-css/``` result was ```www.google.com www.gstatic.com```
Fixes: #43730
Signed-off-by: Sabb <sarafaabbas@gmail.com>
Also move the related `navigate_to_fragment` method next to it.
Part of #40600
Testing: It compiles
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This is the first step toward implementing the Web Animations
specification. It adds support for the `AnimationTimeline` and
`DocumentTimeline` specification concepts. Note that there was already
an `AnimationTimeline`, but it did not implement the specification.
Testing: Various WPT start to pass or no longer error / timeout.
Signed-off-by: Martin Robinson <mrobinson@abandonedwig.info>
Co-authored-by: Martin Robinson <mrobinson@abandonedwig.info>
Both `Window::load_url` and `ScriptThread::navigate` implement parts of
the same navigate algorithm from the HTML spec
(https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate).
`ScriptThread::navigate` had only one caller: `Window::load_url`.
This merges both methods into a single `navigate` function in
`navigation.rs`, which is the appropriate home for navigation logic. All
previous callers of `Window::load_url` now call `navigation::navigate`
directly.
Testing: This is a pure refactor with no behaviour changes, so no new
tests are needed. Existing tests cover the navigation paths affected.
Fixes: #43494
---------
Signed-off-by: thebabalola <t.babalolajoseph@gmail.com>
The commit contains several related changes:
* iframes that load javascript: URLs as part of the initial insertion
(ie. `<iframe src='javascript:...'>`) get a synchronous load event
dispatched
* javascript: URL evaluation that does not result in a string no longer
treated like a 204 response
* iframes that perform a javascript: URL navigation that does not result
in a new document no longer block the parent document load event
Testing: Lots of new tests passing.
Fixes: #24901
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
- canvas
- constellation_traits
- canvas_traits
- constellation
Testing: This should not change any behaviour.
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Follow up of #43526. This addresses Nico's comment:
https://github.com/servo/servo/pull/43526#issuecomment-4104953308
- `bluetooth_traits` -> `servo_bluetooth_traits`
- `base` -> `servo_base`
- `bluetooth` -> `servo_bluetooth`
- `background_hang_monitor` -> `servo_background_hang_monitor`
Testing: This should not change any behaviour.
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
We now check for this header and corresponding logic. The WPT tests
mostly pass, but rely on the `contentDocument` of the iframe to be
`null`. This is not something we did before, which means that iframes
were able to access the contents of error pages.
Instead, we now mark the document as internal with an opaque origin
according to the spec [1]. We shouldn't do this post-fact, but is
required since we first need to construct the document and enter its
realm, before we determine that it is an invalid document.
Fixes#16103
[1]:
https://html.spec.whatwg.org/multipage/document-lifecycle.html#navigate-ua-inline
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This change implements the `scrollend` event. Since there is no support
for asynchronous / smooth scrolling, with this change all `scroll`
events simply send a `scrollend` event in a way that looks a bit like
what the specification says. Note that there are currently some serious
issues (w3c/csswg-drafts#8396) with specification, so things are still a
bit weird overall.
In addition, this organizes and reduces duplication in some of the
existing scroll event code.
Testing: This causes some WPT tests to start passing or to stop timing
out.
---------
Signed-off-by: abdelrahman1234567 <abdelrahman.hossameldin.awadalla@huawei.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: abdelrahman1234567 <abdelrahman.hossameldin.awadalla@huawei.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
On visual viewport scroll, fire the scroll event to the `VisualViewport`
instances. Incidentaly, fix a bug where the pinch zoom update should be
propagated to the script.
Testing: New unit test and manual WPT.
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Pass `&mut JSContext` to `ReadableStream::cancel`, in preparation of
porting the remaining `BlobMethods`.
Testing: Just a refactor, ./mach test-unit still passes.
Fixes: Part of #42638
Signed-off-by: Uiniel <174327181+uiniel@users.noreply.github.com>
Also moves some relevant methods from GlobalScope that were only used
within ReportingObserver.
Part of #38901
Testing: It compiles
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
The spec expects us to check for render blocking (among some other
state) before we start procesing a document. Therefore, add those checks
and also check in the
stylesheet loader that we should only do so when we are allowed to do
so.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Servo side of https://github.com/servo/stylo/pull/322.
Update the WPT expectation following the changes to make `::placeholder`
public and adding property restriction to `::placeholder` and
`::marker`. Additionally ensure that `getComputedStyle` works for
`::placeholder`.
Testing: Existing WPTs
Fixes: #43034Fixes: #43035Fixes: #19808
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Accepting the name of the event as a `DOMString` means that when events
are constructed from within Servo (for instance via input event
handling), the static strings are converted to an owned `String`
wrapped in a `DOMString` and then finally converted to an `Atom` in
`Event`. This makes it so that all non-generated `Event` constructors
accept `Atom`, which can avoid a conversion entirely when the atom
already exists on the Stylo atoms list and eliminate one in-memory copy
in the case that it isn't on the atom list.
Eventually, all event names can be on the atom list and we can eliminate
all copies. This is a tiny optimization, but also makes the code much
friendlier everywhere.
Testing: This should not change behavior so should be covered by
existing test.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
In layout calculation within script, Instead of relying on the computed
values for overflow, query the overflow from layout for its used value
to accurately reflect whether an element establish a scroll container.
This query will be used for `IntersectionObserver` as well.
Testing: There are new `IntersectionObserver` WPT failures:
- `intersection-observer/isIntersecting-change-events.html`
- `intersection-observer/containing-block.html`
The failures are more than likely a false positive because intersection
observation steps wasn't supposed to trigger a reflow, but it was
before. It could be caused by the implementation of
`IntersectionObserver` in major UAs being a little bit different from
the spec in the calculation of `threshold` and `isIntersecting` .
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Since `evaluate_js_on_global` called `enter_realm` and there were
already some callee that did it, I've actually passed `&mut
CurrentRealm`.
Also converted `Window::WebdriverException` to pass `&mut JSContext`
inside `javascript_error_info_from_error_info`.
Testing: A successful build is enough
Part of #40600
---------
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
Now `ServoTestUtils.forceLayout()` will provide the number of fragments
that have been restyled and rebuilt. This will be useful to test that
incremental layout works well.
Testing: Adds a test using this new API
---------
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
I only wanted to get `&mut JSContext` in microtask chunk and checkpoint,
but this in turn needed `&mut JSContext` in servoparser, which then
caused need for even more changes in script.
I tried to limit the size by putting some `temp_cx` in:
- drops of `LoadBlocker`, `GenericAutoEntryScript`
- methods of `VirtualMethods`
- methods of `FetchResponseListener`
Testing: Just refactor, but should be covered by WPT tests.
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
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 is a first step to compile scripts using `&mut JSContext`.
Testing: Refactor, covered by existing WPT tests.
Part of #40600
---------
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
We implemented many more MallocSizeOf tests (even if some such as
channels are zero).
Meaning we can not ignore more of it making the code cleaner.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Testing: Compilation is the test.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Instead of immediately looking for the top-level browsing context's
`Document` in the `ScriptThread`, check whether `Window` is top-level
beforehand. This is a small optimization.
Testing: Existing WPTs (no behavior changes)
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Profiling a speedometer run showed significant time spent in some layout
function in vector allocations. The main change is to switch the result
of `query_box_areas()` from a Vec<T> to and iterator.
Testing: refactoring with no expected test changes
Signed-off-by: webbeef <me@webbeef.org>
The patch adds the following functionality to the per-WebView
`UserContentManager` API.
- Removing a `UserScript` at that was previously added.
- Adding a new `UserStyleSheet` representing a user-origin style sheet.
allow removing user script
- Removing a previously added `UserStyleSheet`.
There might be scope for some improvements in the API:
- `UserScript` and `UserStyleSheet` have different ways of representing
the source location - a `PathBuf` and `Url` respectively. This is due to
how those values are used by the underlying evaluation APIs in script
and stylo. More investigation is needed here and could be addressed in
future patches.
Testing: New unit tests are added for the user stylesheet APIs. Existing
tests have been updated to test the removal of user scripts.