Commit Graph

3565 Commits

Author SHA1 Message Date
David Wendt 640763bfda avm2: Also do the same for `int` 2021-11-28 18:40:21 -07:00
David Wendt 593158cb04 avm2: Also allow calling `Number` methods on the prototype in the `public` namespace. 2021-11-28 18:40:21 -07:00
David Wendt 6bfca1af5f avm2: Expose `Boolean` methods in the `public` namespace via prototypes. 2021-11-28 18:40:21 -07:00
David Wendt 3e8f13b70a avm2: `Number.MIN_VALUE` is the machine epsilon, not the lowest possible finite value. 2021-11-28 18:40:21 -07:00
David Wendt 7569994f1f avm2: Impl `Boolean.toString` and `Boolean.valueOf`. 2021-11-28 18:40:21 -07:00
David Wendt aa01a682e1 avm2: Implement `uint`'s various formatting methods, too. 2021-11-28 18:40:21 -07:00
David Wendt e43d18f7b0 avm2: Impl `int` versions of `toFixed`, `toString`, `toExponential`, and `toPrecision` 2021-11-28 18:40:21 -07:00
David Wendt cabfe5e20c avm2: All documented primitive class methods are in the AS3 namespace. 2021-11-28 18:40:21 -07:00
David Wendt 9e62b05157 avm2: Implement `Number.AS3::toString` and `Number.AS3::valueOf`.
This method has an odd flaw that we don't emulate yet. Actually, two:

1. Precision limits that are specific to the chosen radix
2. Occasional and intermittent corruption in the resulting 0 padding; usually manifesting as `x`, `W`, or `°` characters

The first could be emulated, but I've chosen not to... because the second thing listed not only isn't really possible to emulate, but actively prohibits approx-testing the results. So I'm marking the test as ignored and hoping no movies actually rely on the precision limits in `toString`.
2021-11-28 18:40:21 -07:00
David Wendt 4a09dfa3d0 avm2: Implement `Number.toFixed` and `Number.toPrecision` 2021-11-28 18:40:21 -07:00
David Wendt 55a7a1882d avm2: Implement `Number.toExponential` 2021-11-28 18:40:21 -07:00
David Wendt 16597e0d7b avm2: Fill out class constants for `uint`, `int`, and `Number`. 2021-11-28 18:40:21 -07:00
relrelb 2117ad8a4c html: Ignore <p>, <li> and <br> tags in non-multiline mode 2021-11-28 22:57:48 +02:00
relrelb 9cad582e8b html: Do not trim text in `FormatSpans::from_html`
Flash preserves spaces before and after text.

But since now `quick-xml` might emit empty `Text` events, those need
to be explicitly ignored in order to retain the same text format across
tags.
2021-11-28 22:57:48 +02:00
relrelb a027d932e4 html: Use `as_ref()` instead of `clone()`
This should improve performance a bit.
2021-11-28 22:57:48 +02:00
Varun Ramesh 7c87f35d8d
avm2: Implement `flash.display.PixelSnapping` (#5718)
* Add flash.display.PixelSnapping enum class

* Run 'cargo format --all'

* Add 'final' class attribute
2021-11-28 07:31:39 +02:00
Moulins 9701b817f5 core: Replace WStr<'_> and WStrMut<'_> by a single DST type WStr 2021-11-27 11:20:47 -07:00
Moulins fd8bdeb1a8 core: improve f64's FromWStr impl
This avoids converting the string to UTF8 if it can't possibly
be a float
2021-11-27 11:20:47 -07:00
Moulins ee326e31b7 core: Reduce allocations in AvmString::new_utf8
Also remove some useless back-and-forth conversions between
AvmString and String
2021-11-27 11:20:47 -07:00
Moulins fa30e1bc43 chore: rename AvmString::{new -> new_utf8, new_ucs2 -> new} 2021-11-27 11:20:47 -07:00
Moulins 45fe1e86ae core: remove AvmString::as_str, and the extra UTF8 String inside 2021-11-27 11:20:47 -07:00
Moulins e24af59197 core: remove last instances of AvmString::as_str 2021-11-27 11:20:47 -07:00
Moulins 824263d2bc core: adapt TextField, Font & Html handling code to use WStr 2021-11-27 11:20:47 -07:00
Moulins f149c9efce core: remove some AvmString::as_str calls 2021-11-27 11:20:47 -07:00
Moulins 053758d77c avm2: use WString in QName methods 2021-11-27 11:20:47 -07:00
Moulins 5ca911209b core: implement WStr::join 2021-11-27 11:20:47 -07:00
Moulins c496f81f13 avm1: remove AvmString::as_str usage in activation.rs and movie_clip.rs 2021-11-27 11:20:47 -07:00
Moulins 87400b829d core: use WStrings for display object's frame and scene labels 2021-11-27 11:20:47 -07:00
Moulins 84b4e33036 core: implement FromWStr for various enum types 2021-11-27 11:20:47 -07:00
Moulins b894d0c97f avm1: adapt parseInt, escape & unescape to use WStr API 2021-11-27 11:20:47 -07:00
Moulins c2349ae012 xml: use AvmString in xml code
This has the nice side-effect of reducing string cloning, because we can
just pass AvmStrings around instead.
2021-11-27 11:20:47 -07:00
Moulins 5db23ddbf3 avm2: use WStr in date parsing logic 2021-11-27 11:20:47 -07:00
Moulins f49ce49d28 core: add FromWStr trait and WStr::parse 2021-11-27 11:20:47 -07:00
Moulins 8863b54db0 avm1: don't use &str for activation's path & variable logic 2021-11-27 11:20:47 -07:00
Moulins 1d9d7e6942 avm1: don't use &str methods when parsing enum parameters in MovieClip 2021-11-27 11:20:47 -07:00
Moulins d850085d2b avm1: partially rewrite Value::primitive_as_number 2021-11-27 11:20:47 -07:00
Moulins 4a09088d42 avm2: rewrite regexp module to not rely on AvmString::as_str
This is a little tricky, because we have to map the utf8 indices
returned by the regex engine to utf16 indices usable by Ruffle.

To limit the impact on performance, the regex, the string we're
currently matching on, and the last known (utf8, utf16) positions
are cached, avoiding extra utf8 conversions in common use cases
where a single string is repeatedly searched with increasing
`lastIndex`.
2021-11-27 11:20:47 -07:00
Moulins 23cbe4c2fd core: Add `string::Pattern` trait, based on `std::str::Pattern`
This allows `Str::{find, rfind, split}` to accept multiple types
2021-11-27 11:20:47 -07:00
Moulins 110f568aa4 core: Remove some useless utf8<->utf16 conv. in {avm1,avm2}/activation.rs 2021-11-27 11:20:47 -07:00
Moulins 8885175550 core: Replace string::utils *_ignore_case functions by methods on WStr 2021-11-27 11:20:47 -07:00
Moulins 79d47a9863 avm1: Requires a WStr<'_> to access PropertyMap 2021-11-27 11:20:47 -07:00
Moulins 7f4af210b8 core: Reimplement AVM string methods using our UCS2 API
This generally means that methods are more efficient, as we
don't need to encode to UTF16 on-the-fly to have correct indices.

This also fix some bugs:
 - charCode now properly handle surrogate pairs
 - calling lastIndexOf with the empty pattern and an OoB index now
properly returns the string length

Still missing is AVM2's String.match
2021-11-27 11:20:47 -07:00
Moulins 32fa20b857 core: Make AvmString "two-headed" by storing a UTF8 and an UCS2 string
This is only temporary; once all code paths use the ruffle `WString` API
instead of dereferencing to a string, the UTF8 `String` will be removed.
2021-11-27 11:20:47 -07:00
Moulins 3d20c4acc7 core: Add owned string::WString type 2021-11-27 11:20:47 -07:00
Moulins c1ccd3a3ac core: Introduce `WStr` and `WStrMut` types, for representing Flash strings
These types represent an UCS2 string (UTF-16 with unpaired surrogates).

The string is stored either as a sequence of u8s (Bytes) or u16s (Wide);
the type of string is tracked by setting the high bit of the length of
its fat pointer.
2021-11-27 11:20:47 -07:00
relrelb b32ec3cf6c audio: Calculate sound transform values using 30-bit integers
The fix in #5218 wasn't sufficient; 30-bit arithmetic should be used
along all the way when calculating an effective sound transform.

For example, a sound transform composited by volumes `-0x80000000` and
`25` should end up as effectively 0, whereas previously it would have
been calculated as `-0x80000000 * 25 / 100 = -0x20000000`, which is a
30-bit integer that hasn't been truncated.

Fixes #5655.
2021-11-27 12:09:33 +02:00
relrelb e2b821e92f chore: Replace `min` + `max` with `clamp`
`clamp` is a bit more efficient, in both runtime and size terms.
2021-11-26 20:54:48 +02:00
relrelb 41eb215b02 chore: Avoid using `std::char`
Use the `char` primitive type instead.
2021-11-26 10:45:30 +02:00
relrelb dc6d4804ff core: Avoid odd import 2021-11-26 10:45:30 +02:00
relrelb 0a3ede31dc core: Remove unused `Downcast` 2021-11-26 10:45:30 +02:00
relrelb 79a0ba31ae avm1: Use `.unwrap_or(&Value::Undefined)` in more places 2021-11-26 10:45:30 +02:00
Adrian Wielgosik f35b2666a3 build: Use the 'union' SmallVec feature for minor memory savings 2021-11-26 00:45:09 +01:00
relrelb 79deba87f3 avm1: Small cleanup in `start_drag` 2021-11-25 07:35:33 +02:00
relrelb a2aeadf9e1 core: Small cleanups in `Player::handle_event`
* Use `match` for AVM debug key combos.
* Remove redundant `if let Some(button_event)` inside an `if button_event.is_some()`.
2021-11-25 07:35:33 +02:00
relrelb cbce91365c desktop: Track `keys_down` by `KeyCode`
This makes `DesktopUiBackend::is_key_down` a simple one-line check.
Also unify the handling code of `ElementState::Pressed` and `ElementState::Released`,
which had a lot of common code.
2021-11-25 07:35:33 +02:00
Adrian Wielgosik da4ed75bc8 avm2: Compare QNames by local name first 2021-11-22 17:59:00 -07:00
Adrian Wielgosik c2d521df41 avm2: refactor: Merge has-setter-and-no-getter into one lookup 2021-11-22 17:59:00 -07:00
Adrian Wielgosik 370186dc3c avm2: refactor: Make trait lookups return a single item 2021-11-22 17:59:00 -07:00
TÖRÖK Attila 0e4d2d48f5 video/vp6: Don't throw an error on skip frames, reuse the last frame instead 2021-11-22 17:08:31 +01:00
relrelb 56b5183262 avm1: Refactor and fix `BitmapData::compare` 2021-11-20 14:11:14 +02:00
bbb651 687069ba7d avm1: Added BitmapData::compare 2021-11-20 14:11:14 +02:00
relrelb 3760e0e275 core: De-duplicate `round_to_even` function
Put a single implementation in `ecma_conversions.rs`.
Need to consider what to do with the similar implementation in `matrix.rs`.
2021-11-20 13:36:06 +02:00
relrelb 7c6d006862 avm2: Correct `TextFormat` properties coercion 2021-11-20 13:36:06 +02:00
relrelb 10b7c69719 avm1: Correct `TextFormat` properties coercion 2021-11-20 13:36:06 +02:00
David Wendt 068e7acc6f avm2: Remove the need for `lazy_static` 2021-11-19 20:43:53 -07:00
David Wendt dda8a73899 avm2: Refactor so we don't need to rebox and unbox the numbers into values.
Also, use an actual constant table for the ellipsises.
2021-11-19 20:43:53 -07:00
David Wendt 4665a6c210 avm2: None of `Graphics`' methods need to be `pub`. 2021-11-19 20:43:53 -07:00
David Wendt c719e69693 avm2: Also implement `drawEllipse` using `drawRoundRect`. 2021-11-19 20:43:53 -07:00
David Wendt ef46d780ba avm2: Implement `Graphics.drawCircle` using `drawRoundRect` 2021-11-19 20:43:53 -07:00
David Wendt b318eb9969 avm2: Implement `Graphics.drawRoundRect` 2021-11-19 20:43:53 -07:00
relrelb 24db13ae1e html: Handle self-closing tags
"br" and "sbr" tags can appear in a self-closing form (i.e. `<br />`).
Commit 3cab464026 forgot to handle this.
2021-11-15 23:28:51 +02:00
relrelb 855bc721a8 html: Restore handling of "br" tags
This fully reverts commit 2119ce9.
Seems like Flash does handle "br" tags, but ignores them under some
unknown circumstances (e.g. setting `htmlText` in AVM1).
For now handle "br" tags unconditionally.
2021-11-15 23:28:51 +02:00
relrelb 73f5982cad avm1: Fix `Sound.setVolume()` and `Sound.setPan()` with no arguments
Instead of coercing `undefined` into `f64` (which results `NaN` in SWF7+),
treat the missing value argument as `0`.
2021-11-14 20:25:45 +02:00
relrelb df514f319a html: Restore handling of "sbr" tags
This partially reverts commit 2119ce9821,
only restoring "sbr" tags handling because Flash seems to ignore only
"br" tags.
2021-11-13 12:11:48 +02:00
relrelb 2119ce9821 html: Remove handling of "br" and "sbr" tags
Seems like Flash just ignores them.
2021-11-13 10:21:41 +02:00
relrelb 12e8d3a82f html: Fix typo 2021-11-13 10:21:41 +02:00
David Wendt c0874f445d avm2: Functions are functions. 2021-11-11 17:12:49 -07:00
David Wendt 7dd9776d40 avm2: Implement `uint`, `Number`, and `Boolean`'s constructors, too. 2021-11-11 16:34:11 -07:00
David Wendt 7cc7f0fe7f avm2: Impl `int`'s instance initializer. 2021-11-11 16:34:11 -07:00
David Wendt be3e126ebb avm2: Stub the `Sprite` constructor as just creating a `MovieClip`. 2021-11-11 16:33:33 -07:00
Tal Hayon 7ed38850fd core: implement displayState for Stage in avm1/2 2021-11-11 16:20:05 -07:00
relrelb 7b95441874 core: Re-use `EditText::html_text` in `EditText::propagate_text_binding` 2021-11-11 08:05:33 +02:00
relrelb cf05137c1f core: `EditText::html_text` cannot fail 2021-11-11 08:05:33 +02:00
relrelb 848b721165 xml: Remove `XmlNode::walk` 2021-11-11 08:05:33 +02:00
relrelb c4729d733c core: Avoid one usage of `FormatSpans::replace_text`
Use `FormatSpans::from_text` instead.
2021-11-11 08:05:33 +02:00
relrelb 3cab464026 core: Use `quick-xml` directly when creating `FormatSpans` 2021-11-11 08:05:33 +02:00
relrelb 8c64951b15 core: Remove unused `EditText::document` 2021-11-11 08:05:33 +02:00
relrelb a900aae63e core: Make `EditText::set_html_text` accept a `&str` 2021-11-11 08:05:33 +02:00
relrelb 0787662079 core: Make `EditText::set_text` accept a `&str` 2021-11-11 08:05:33 +02:00
David Wendt 67e7526517 avm2: `EventDispatcher` contains an undocumented `toString` method. 2021-11-10 18:16:26 -07:00
David Wendt 360ae1f044 avm2: Private classes in different scripts are allowed to share the same name without conflicting. 2021-11-10 17:43:02 -07:00
David Wendt 60eb88b326 avm2: Note currently incorrect behavior intended to be fixed in a future PR. 2021-11-09 17:28:33 -07:00
David Wendt 4cfa3253d5 avm2: Impl `Proxy`'s enumeration-related methods. 2021-11-09 17:28:33 -07:00
David Wendt 4289f89350 avm2: Split out enumerant values into a separate method as well. 2021-11-09 17:28:33 -07:00
David Wendt 297526269c avm2: Allow objects to assign arbitrary enumerant indexes, by having objects drive the enumeration process rather than just counting from one 2021-11-09 17:28:33 -07:00
David Wendt 1170385c3b avm2: Implement `Proxy.hasproperty` 2021-11-09 17:28:33 -07:00
David Wendt 427b2bf17a avm2: Implement `Proxy.deleteproperty` 2021-11-09 17:28:33 -07:00
David Wendt 503dc08594 avm2: Refactor `Object.delete_property` to work similar to get/set 2021-11-09 17:28:33 -07:00
David Wendt e67ca1afe0 avm2: Implement `Proxy.callproperty` 2021-11-09 17:28:33 -07:00
David Wendt 301fd1020f avm2: Implement `Proxy.setproperty` 2021-11-09 17:28:33 -07:00