Commit graph

145 commits

Author SHA1 Message Date
Emilio Cobos Álvarez
1263075776
stylo: Fix StyleSheetInner/Stylesheet mapping
The key of this patch is the split between Stylesheet and StylesheetContents.

Gecko will use StylesheetContents, which maps to a ServoStyleSheetInner.
2017-07-02 15:49:40 +02:00
Hiroyuki Ikezoe
8bfed4cb3c Move ParsingMode into style_traits. 2017-06-14 09:51:36 +09:00
Xidorn Quan
cdc537f23e Bug 1331291 part 1 - Set stylesheet url_data correctly for import rule. 2017-06-13 10:07:06 +10:00
Simon Sapin
d2be5239f5 Avoid returning / passing around a huge ParsedDeclaration type
This enum type used to contain the result of parsing
one CSS source declaration (`name: value;`) and expanding shorthands.
Enum types are as big as the biggest of their variant (plus discriminant),
which was quite big because some shorthands
expand to many longhand properties.
This type was returned through many functions and methods,
wrapped and rewrapped in `Result` with different error types.
This presumably caused significant `memmove` traffic.

Instead, we now allocate an `ArrayVec` on the stack
and pass `&mut` references to it for various functions to push into it.
This type is also very big, but we never move it.

We still use an intermediate data structure because we sometimes decide
after shorthand expansion that a declaration is invalid after all
and that we’re gonna drop it.
Only later do we push to a `PropertyDeclarationBlock`,
with an entire `ArrayVec` or nothing.

In future work we can try to avoid a large stack-allocated array,
and instead writing directly to the heap allocation
of the `Vec` inside `PropertyDeclarationBlock`.
However this is tricky:
we need to preserve this "all or nothing" aspect
of parsing one source declaration,
and at the same time we want to make it as little error-prone as possible
for the various call sites.
`PropertyDeclarationBlock` curently does property deduplication
incrementally: as each `PropertyDeclaration` is pushed,
we check if an existing declaration of the same property exists
and if so overwrite it.
To get rid of the stack allocated array we’d need to somehow
deduplicate separately after pushing multiple `PropertyDeclaration`.
2017-05-19 18:53:25 +02:00
Hiroyuki Ikezoe
b6b3187efa Make ParsingMode bitflags.
assert_parsing_mode_match() is mostly the same as
assert_restyle_hints_match().
2017-05-14 07:15:19 +09:00
Hiroyuki Ikezoe
fcc50ea421 Rename LengthParsingMode to ParsingMode and LengthParsingMode::SVG to PasingMode::AllowUnitlessLength.
We need another flag that represents allow-negative-number for SMIL, so
this enum will also comprise the another parsing mode that allows negative number.
2017-05-14 07:15:19 +09:00
Bobby Holley
7b0679848b Fix up script and layout. 2017-05-02 17:35:45 -07:00
Anthony Ramine
f68e2fded9 Propagate quirks mode all the way to ParserContext
The quirks mode is still not properly propagated in geckolib.
2017-04-27 10:41:55 +02:00
J. Ryan Stinnett
8144aa1163 Expose CSS length mode in Stylo glue
Add length mode args to Stylo glue functions so that Gecko can enable the
special SVG mode as needed.

MozReview-Commit-ID: 1luM13MFEXX
2017-04-14 17:22:16 +08:00
Xidorn Quan
37585309e9 Use a UrlExtraData type alias to unify url handling logic. 2017-04-03 21:57:16 +10:00
Simon Sapin
4f2b9a33fe Replace ParsedDeclaration::expand with non-generic method
... to reduce its code size impact.

https://bugzilla.mozilla.org/show_bug.cgi?id=1351737
2017-03-29 20:28:25 +02:00
Simon Sapin
1bacd0eb15 Move all PropertyDeclarationBlock from RwLock<_> to Locked<_> 2017-03-19 22:30:38 +01:00
Simon Sapin
f70a49974a Make PropertyDeclarationBlock fields private 2017-03-07 23:37:32 +01:00
Simon Sapin
da4e5146e9 Make PropertyDeclarationBlock::important_count private. 2017-03-07 23:37:31 +01:00
Simon Sapin
9d663ea7af Make PropertyDeclaration::parse return an enum rather than push to a Vec. 2017-03-07 23:37:29 +01:00
Xidorn Quan
4f07826837 Return true in set_property only when declaration block is changed 2017-03-06 22:21:59 +11:00
Simon Sapin
958c33a95f Remove unnecessary ref in some patterns 2017-02-26 19:02:54 +01:00
Anthony Ramine
31e9d81c0f Make #[dom_struct] a proc_macro attribute 2017-02-24 01:50:51 +01:00
Emilio Cobos Álvarez
31ecc9b692
script: Don't avoid all the mutation notification methods when the style attribute changes.
Styling was correct because of the explicit dirtiness, but still not fun.

Some things, like dynamic updates to with things like [style~="color"] ~ foo
selectors, were pretty broken, because we didn't take snapshots of those
attributes.
2017-01-30 19:24:42 +01:00
Emilio Cobos Álvarez
684545b396
script: Also do so for element owners. 2017-01-28 14:47:10 +01:00
Emilio Cobos Álvarez
9b06932535
script: Fix base url for style-rule-owned declarations. 2017-01-28 14:47:10 +01:00
Emilio Cobos Álvarez
dd90366775
script: Refactor CSSStyleDeclaration and fix some bugs in the way. 2017-01-28 14:47:09 +01:00
Manish Goregaokar
b5cb401aef Reduce allocator churn when parsing property declaration blocks (fixes #15060) 2017-01-18 16:31:46 -08:00
Keith Yeung
18567ce7a8 Implement CSSKeyframeRule.style 2017-01-07 22:18:04 -08:00
Keith Yeung
4738ce1af5 Implement CSSStyleRule.style 2016-12-17 23:03:40 -08:00
Simon Sapin
dbc9fcc2de Use PropertyId in per-property CSSStyleDeclaration accessors. 2016-12-09 17:06:52 -10:00
Simon Sapin
433c33c4df Match on PropertyId (not strings) to parse a declaration. 2016-12-09 17:06:51 -10:00
Simon Sapin
58d452fa4e Use PropertyId instead of Atom for CSSStyleDeclaration::get_computed_style 2016-12-09 17:06:50 -10:00
Simon Sapin
137e30b825 Introduce enums for identifying CSS properties.
* `LonghandId` and `ShorthandId` are C-like enums
* `Atom` is used for the name of custom properties.
* `PropertyDeclarationId` is the identifier for `PropertyDeclaration`,
  after parsing and shorthand expansion. (Longhand or custom property.)
* `PropertyId` represents any CSS property, e.g. in CSSOM.
  (Longhand, shorthand, or custom.)

Using these instead of strings avoids some memory allocations and copies.
2016-12-09 10:56:22 -10:00
Simon Sapin
b203ab2419 Rename selector_impl.rs to selector_parser.rs
This makes it consistent with an upcoming update of the selectors crate.
2016-11-20 15:30:37 +01:00
Ravi Shankar
6061985898 Prefer Servo-specific ToCss for all types 2016-11-07 09:14:22 +05:30
Simon Sapin
53b638c0e2 Update to string-cache 0.3 2016-11-03 16:23:05 +01:00
Simon Sapin
0eed39c198 Move CSSStyleDeclaration.SetPropertyPriority logic to style 2016-10-10 16:48:23 +02:00
Simon Sapin
c740a76410 Move (some) CSSStyleDeclaration.SetProperty logic to style 2016-10-10 16:42:23 +02:00
Simon Sapin
bd4a4c38c8 Move CSSStyleDeclaration.RemoveProperty logic to style 2016-10-10 16:20:44 +02:00
Simon Sapin
fc6a536b3a Move CSSStyleDeclaration.GetPropertyPriority logic to style 2016-10-10 16:01:23 +02:00
Simon Sapin
bd37f4e694 Move CSSStyleDeclaration.GetPropertyValue logic to style 2016-10-10 15:54:24 +02:00
Anthony Ramine
fcb59d3057 Make reflect_dom_object take a &GlobalScope 2016-10-06 20:59:09 +02:00
Simon Sapin
89a29a7f12 Use parking_lot::RwLock instead of DOMRefCell for PropertyDeclarationBlock 2016-10-04 18:34:59 +02:00
Simon Sapin
d986fd2d2f Use PropertyDeclarationBlock in a DOMRefCell everywhere. 2016-10-04 18:34:57 +02:00
bors-servo
bbfe38e35f Auto merge of #13134 - servo:archery, r=emilio
Add lots of Arc’s in style, and prepare for using DOMRefCell

<!-- Please describe your changes on the following line: -->

`DOMRefCell` usage is not there year because of thread-safety questions, but I have this much already that I’d like to land before it bitrots.

r? @emilio

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactor

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13134)
<!-- Reviewable:end -->
2016-08-31 16:30:56 -05:00
Simon Sapin
acc38aa8c2 Use Arc<PropertyDeclarationBlock> everwhere it’s appropriate. 2016-08-31 02:34:07 +02:00
Simon Sapin
ec723057b2 Make DOMRefCell use style’s copy of RefCell 2016-08-31 02:34:04 +02:00
Anthony Ramine
7dfb336be8 Use Option<T> to return from getters
This removes the cumbersome &mut bool argument and offers overall
a more readable code.
2016-08-30 19:07:19 +02:00
Simon Sapin
16bbc2f26e Merge normal and important declarations in style rules.
Have a single Vec instead of two. Fix #3426
2016-08-21 03:40:35 +02:00
Simon Sapin
24fbb26475 Add an Importance enum replacing booleans to indicate !important. 2016-08-21 00:30:22 +02:00
Simon Sapin
8218b463fb Revert "Simplify CSSStyleDeclaration::GetPropertyValue"
This reverts commit 1637b0ba8a.

* As far as I know, `fn` pointers don’t necessarily inline well
* Upcoming commits are gonna change this mapping to be less trivial,
  so this would at least need a new `fn` declaration, making this
  less of a simplification.
2016-08-21 00:28:48 +02:00
Anthony Ramine
1637b0ba8a Simplify CSSStyleDeclaration::GetPropertyValue
While Fn(_) -> _ isn't Clone, fn(_) -> _ is.
2016-08-14 19:06:18 +02:00
bors-servo
09e6f4ac54 Auto merge of #11428 - g-k:csstext, r=SimonSapin
csstext

- [x] These changes fix #4431.
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy --faster` reports one error for the `css_properties_accessors!` macro not having a spec link

```
$ git log -1 --format=oneline
91fb9bf1d3 fixup! implement cssText
$ ./mach build -d
   Compiling style v0.0.1 (file:///Users/greg/servo/components/style)
   Compiling gfx v0.0.1 (file:///Users/greg/servo/components/gfx)
   Compiling script v0.0.1 (file:///Users/greg/servo/components/script)
   Compiling layout_traits v0.0.1 (file:///Users/greg/servo/components/layout_traits)
   Compiling compositing v0.0.1 (file:///Users/greg/servo/components/compositing)
   Compiling glutin_app v0.0.1 (file:///Users/greg/servo/ports/glutin)
   Compiling constellation v0.0.1 (file:///Users/greg/servo/components/constellation)
   Compiling layout v0.0.1 (file:///Users/greg/servo/components/layout)
   Compiling servo v0.0.1 (file:///Users/greg/servo/components/servo)
Build completed in 0:05:11.475584
$ ./mach test-tidy --faster
Checking files for tidiness...
./components/script/dom/cssstyledeclaration.rs:386: method declared in webidl is missing a comment with a specification link
  Progress: 100% (12/12)
```

- [x] There are tests for these changes.  More CSSOM tests pass, but others fail that probably shouldn't:

* `./mach test-css tests/wpt/css-tests/cssom-1_dev/html/index-002.htm` and a bunch of the other tests in `/css-tests/cssom-1_dev/html/ crash when run individually
* `./mach test-css tests/wpt/css-tests/cssom-1_dev/html/cssom-cssText-serialize.htm` fails to strip a trailing semicolon (`left: 10px` vs `left: 10px;`)
* `./mach test-css tests/wpt/css-tests/cssom-1_dev/html/index-001.htm` shared shorthand values aren't coalesced (`margin: 20px` vs. `margin: 20px 20px 20px 20px`)
* `./mach test-css tests/wpt/css-tests/cssom-1_dev/html/cssstyledeclaration-csstext.htm` also crashes and fails for `color: red;` vs. `color: RED;`,  preserving declaration insertion order, whitespace in the value, and setting an unknown style property.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11428)
<!-- Reviewable:end -->
2016-06-01 01:59:12 -05:00
Glenn Watson
ff995d739c implement cssText 2016-05-31 19:32:30 -04:00