Commit Graph

521 Commits

Author SHA1 Message Date
wsxarcher 7d1373368b core,web: Add the ability to load TTF/OTF/OTC as default fonts for the extension 2024-09-13 22:22:38 +02:00
Kamil Jarosz cbb1af7825 core: Use proper sandbox type per SWF
It's the first step of implementing the security sandbox and its
filesystem/network separation policy.
Before that Ruffle assigned `localTrusted` sandbox type for
all movies except web, where `remote` was used.
The sandbox type also was assigned to the player,
and not SWFs as it should.
This patch does not introduce any sandbox policies based
on the sandbox type, just the proper sandbox type detection.
It is also not possible to specify trusted movies,
and AIR applications don't use the `application` type yet.
2024-09-13 17:30:31 +02:00
Kamil Jarosz 6053fc586d core: Move SandboxType from avm1 to sandbox module 2024-09-13 17:30:31 +02:00
Kamil Jarosz 898db260a3 core: Add support for wider range of key codes
This patch changes the definition of KeyCode from an enum,
which was constraining the possible key codes, to a struct with
a u32 field, which covers all possible cases of a key code.

Key codes in Flash are not related to the physical buttons,
but rather to logical button values.
For instance, typing a non-ASCII key produces a key code related
to that character, and using a non-ANSI keyboard or a layout different
from US QWERTY also produces results matching that assumption.
2024-09-01 21:02:34 +02:00
Tom Schuster d824a02664 web: Fix deprecation warnings 2024-08-20 21:18:36 +02:00
Tom Schuster 0ac25b5808 chore: Update web-sys and js-sys 2024-08-20 21:18:36 +02:00
Kamil Jarosz 3253c9c964 web: Ensure focus is not lost when copying text
Copying text creates a temporary textarea which is selected and focused.
In order to preserve the focus of Ruffle, we need to move the focus
into the container before removing the temporary textarea.
2024-08-20 16:17:42 +02:00
TÖRÖK Attila 9239cb8a5d chore: A couple typo fixes in comments here and there 2024-08-12 21:36:51 +02:00
Moulins 47030b4f5b core: remove UpdateContext's unused lifetime and reborrow method 2024-08-10 22:53:27 +02:00
Nathan Adams 2f7db41f9f web: Move all of the actual player logic out from RufflePlayer and into InnerPlayer 2024-08-05 04:10:43 +02:00
Kamil Jarosz 96173b0501 web: Improve virtual keyboard support
This patch integrates the virtual keyboard with the newly added focus
management and removes Android-specific code, instead using generic
logic which takes advantage of improved focus support in SWFs.
2024-07-27 21:32:35 +02:00
Kamil Jarosz 53d2d16162 core: Add UiBackend::close_virtual_keyboard
This method may be used by backends that require explicit virtual
keyboard closing.
2024-07-27 21:32:35 +02:00
Kamil Jarosz e18ae830c1 web: Use browser focus events for focus management
This patch changes how the player focus is managed.

Before this patch, `instance.has_focus` was unrelated
to the current focus managed by the browser.
When the user clicked anywhere on the window, it was set to `false`,
and when the user clicked on the player, it was set to `true`.
This had two major issues.
1. When the user clicked on the player, `has_focus` was set to `false`,
   and then again to `true`. That was problematic when listening
   to focus change events.
2. Not using browser's focus makes it harder to integrate with Ruffle,
   i.e. tab out of Ruffle.

This patch uses browser's focus management to detect focus
and listen to focus events:
1. on `focusin` – FocusGained event is fired,
2. on `focusout` – FocusLost event is fired, and
3. on `pointerdown` – focus is manually set to the canvas.
The container has `tabindex` set to -1 in order to be focusable.

Virtual keyboard on web is represented as an input inside the container.
In order to preserve player focus when virtual keyboard is open,
this patch ensures that the container is focused and not the canvas.
This way, when the input is focused, the container does not lose its focus.
2024-07-27 21:32:35 +02:00
Kamil Jarosz 3cb798e818 Revert "web: Use browser focus events for focus management"
This reverts commit 5441749e3e.
2024-07-18 23:11:32 +02:00
Aaron Hill 6e93927f63 web: Check for locked 'Player' mutex and reschedule with setTimeout
We use 'wasm-bindgen-futures' as our futures executor on web, which
in turn uses 'queueMicroTask'. This can result in the browser executing
one of our futures while we're still inside our `requestAnimationFrame`
callback (in particular, while we still have the `Player` mutex locked).

We now detect this condition by attempting the lock the Player mutex
inside of our `spawn_local` future. If this fails, we `await`
a `setTimeout`-based promise, which ensures that our code runs in
a new top-level `setTimeout` javascript 'task' (outside of our
`requestAnimationFrame` callback).
2024-07-15 22:46:22 +02:00
Nathan Adams ed66cf036c web: Add firefox testing, + a fix for ExternalConnection on Firefox when called from the test harness
Turns out that an object isn't 'instanceof Object' in Firefox, if it was made from another window/process/tab/whatever. In this case, that meant that Ruffle always thought it was null because wasm-bindgen relies on 'instanceof Object'
2024-07-14 18:04:14 +02:00
Kamil Jarosz 6685c987ac web: Do not show context menu when right click event is consumed 2024-07-12 15:41:08 +02:00
Kamil Jarosz 5441749e3e web: Use browser focus events for focus management
This patch changes how the player focus is managed.

Before this patch, `instance.has_focus` was unrelated
to the current focus managed by the browser.
When the user clicked anywhere on the window, it was set to `false`,
and when the user clicked on the player, it was set to `true`.
This had two major issues.
1. When the user clicked on the player, `has_focus` was set to `false`,
   and then again to `true`. That was problematic when listening
   to focus change events.
2. Not using browser's focus makes it harder to integrate with Ruffle,
   i.e. tab out of Ruffle.

This patch uses browser's focus management to detect focus
and listen to focus events:
1. on `focusin` – FocusGained event is fired,
2. on `focusout` – FocusLost event is fired, and
3. on `pointerdown` – focus is manually set to the canvas.
The canvas has `tabindex` set to -1 in order to be focusable.
2024-07-12 14:20:35 +02:00
Kamil Jarosz 9f9d462381 core: Add click index to PlayerEvent::MouseDown 2024-07-06 18:32:10 +02:00
Kornelius Rohrschneider 0b30b7fdda core: Use HTTP response encoding if existing
If System#useCodepage has been set to true, the form loader now uses the
encoding specified in the HTTP response content type field, if existing,
to decode remote text files. chardetng is now (only) used if the HTTP
response doesn't specify any encoding or if the file is local.
2024-06-26 02:37:44 +02:00
Kamil Jarosz b36a6b792b web: Implement pasting text using Clipboard API
Ruffle does not have direct clipboard access on web, so the current
paste implementation from the context menu does not work.
This patch intercepts the paste context menu callback,
and uses the Clipboard API to ask the browser for the clipboard
and update it before calling the callback.
When the Clipboard API is not available or the user denies
clipboard permission, a modal informing the user about
cut, copy, paste shortcuts is displayed.
2024-06-19 00:15:07 +02:00
Kamil Jarosz 60ee0379b7 web: Add clipboard modal informing about shortcuts
This modal informs the user that they can use shortcuts
for copy, cut, and paste instead of using the context menu.
This modal is meant to be displayed when the browser
does not support reading the clipboard,
or the user denies permission to the clipboard.
2024-06-19 00:15:07 +02:00
Nathan Adams c3f1a18d20 web: SocketProxy doesn't need serde 2024-06-13 00:22:33 +02:00
Kamil Jarosz c23ec0782a core: Prevent pasting empty string when the clipboard is empty 2024-06-09 15:38:35 +02:00
Nathan Adams 0ded7c61ea web: Remove jszip, use rust 2024-06-08 21:53:07 +02:00
Nathan Adams dabdcd63ad web: Fix japanese font registration in rust side, and rename them to camelCase for consistency (not a breaking change as it didn't actually work prior to this...) 2024-06-08 08:42:04 +02:00
Nathan Adams 5cb46b1f9b web: Fixed italicnes in font registration 2024-06-08 08:42:04 +02:00
Nathan Adams 17d9d01d6b web: Builder is now responsible for making the actual Player 2024-06-08 08:42:04 +02:00
Nathan Adams 8ce7e82a0d web: Add create_storage_backend to builder 2024-06-08 08:42:04 +02:00
Nathan Adams b727610cc4 web: Add create_navigator to builder 2024-06-08 08:42:04 +02:00
Nathan Adams 70fca6fa0a web: Add create_audio to builder 2024-06-08 08:42:04 +02:00
Nathan Adams 77a65be5a2 web: Move create_renderer to builder 2024-06-08 08:42:04 +02:00
Nathan Adams a6ab799e1f web: Create a RuffleInstanceBuilder::create_log_subscriber 2024-06-08 08:42:04 +02:00
Nathan Adams c18520bd70 web: Create a global_init function, move our 'do this if first instance' stuff there 2024-06-08 08:42:04 +02:00
Nathan Adams 85ca0aeff8 web: Move font registration to builder, not after we've made the instance 2024-06-08 08:42:04 +02:00
Nathan Adams aa804e520b web: Store StageQuality in builder, do the defaulting in JS 2024-06-08 08:42:04 +02:00
Nathan Adams af71ef3276 web: Store StageScaleMode directly in builder, not Option<> 2024-06-08 08:42:04 +02:00
Nathan Adams 7c340f5b6c web: Store CompatibilityRules in builder, remove a bit of abstraction 2024-06-08 08:42:04 +02:00
Nathan Adams 3fa8735e97 web: Don't parse config in Rust, do it in Typescript with some tests 2024-06-08 08:42:04 +02:00
Nathan Adams f9f7ece8e3 web: Support ExternalInterface.call("function(){....}") 2024-06-07 16:58:57 +02:00
Nathan Adams f887a56bcc web: Remove wrong dead_code annotation 2024-06-03 21:50:20 +02:00
Nathan Adams cf9eded421 web: Swap JsCallback closure and is_capture args, to put closure last 2024-06-03 21:50:20 +02:00
Nathan Adams cf2f16f4b4 web: Make JsCallback take a FnMut, and do the Closure internally, to reduce boilerplate 2024-06-03 21:50:20 +02:00
Nathan Adams a9c5928b62 web: Inline all the Closures for JsCallback::register 2024-06-03 21:50:20 +02:00
Nathan Adams e7fc1a7a4d web: Dedupe a whole bunch of callback related code, by making a struct with Drop impl 2024-06-03 21:50:20 +02:00
Nathan Adams b04d12877e web: Use RuffleHandle as a custom key type, not a wrapper over DefaultKey 2024-06-01 20:34:10 +02:00
Nathan Adams dda9058f07 web: Rename Ruffle to RuffleHandle 2024-06-01 20:34:10 +02:00
Nathan Adams ad2f1dc1a5 web: Move some ExternalInterface util methods out of lib.rs 2024-06-01 20:34:10 +02:00
Nathan Adams 1e3511c7b0 web: Move some input util methods out of lib.rs 2024-06-01 20:34:10 +02:00
Nathan Adams 381b0897c9 avm2: Implement ExternalInterface.objectID 2024-05-26 23:00:33 +02:00