2016-01-19 11:49:10 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
use app_units::Au;
|
2016-11-07 08:26:08 +03:00
|
|
|
use cssparser::Parser;
|
2016-05-05 04:37:26 +03:00
|
|
|
use env_logger;
|
2016-01-19 11:49:10 +03:00
|
|
|
use euclid::Size2D;
|
2016-10-04 19:58:56 +03:00
|
|
|
use parking_lot::RwLock;
|
2016-11-04 07:42:06 +03:00
|
|
|
use std::fmt::Write;
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] 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 refactoring
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 10:58:34 +03:00
|
|
|
use std::mem::transmute;
|
2016-02-04 20:55:09 +03:00
|
|
|
use std::sync::{Arc, Mutex};
|
2016-07-11 15:11:48 +03:00
|
|
|
use style::arc_ptr_eq;
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] 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 refactoring
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 10:58:34 +03:00
|
|
|
use style::context::{LocalStyleContextCreationInfo, ReflowGoal, SharedStyleContext};
|
2016-10-26 14:36:06 +03:00
|
|
|
use style::dom::{NodeInfo, StylingMode, TElement, TNode};
|
2016-01-19 11:49:10 +03:00
|
|
|
use style::error_reporting::StdoutErrorReporter;
|
2016-09-26 10:36:05 +03:00
|
|
|
use style::gecko::data::{NUM_THREADS, PerDocumentStyleData};
|
|
|
|
use style::gecko::selector_impl::{GeckoSelectorImpl, PseudoElement};
|
|
|
|
use style::gecko::snapshot::GeckoElementSnapshot;
|
|
|
|
use style::gecko::traversal::RecalcStyleOnly;
|
|
|
|
use style::gecko::wrapper::{GeckoElement, GeckoNode};
|
2016-10-18 08:51:14 +03:00
|
|
|
use style::gecko::wrapper::DUMMY_BASE_URL;
|
2016-09-26 10:36:05 +03:00
|
|
|
use style::gecko_bindings::bindings::{RawGeckoElementBorrowed, RawGeckoNodeBorrowed};
|
2016-10-18 08:51:14 +03:00
|
|
|
use style::gecko_bindings::bindings::{RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockStrong};
|
2016-09-26 10:36:05 +03:00
|
|
|
use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
|
|
|
|
use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
|
|
|
|
use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
|
|
|
|
use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder};
|
2016-11-04 07:42:06 +03:00
|
|
|
use style::gecko_bindings::bindings::{nsACString, nsAString};
|
2016-10-09 16:53:28 +03:00
|
|
|
use style::gecko_bindings::bindings::Gecko_Utf8SliceToString;
|
2016-10-18 08:51:14 +03:00
|
|
|
use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
|
2016-09-26 10:36:05 +03:00
|
|
|
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
|
|
|
|
use style::gecko_bindings::structs::ServoElementSnapshot;
|
|
|
|
use style::gecko_bindings::structs::nsRestyleHint;
|
2016-10-09 16:53:28 +03:00
|
|
|
use style::gecko_bindings::structs::nsString;
|
2016-09-26 10:36:05 +03:00
|
|
|
use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasBoxFFI};
|
|
|
|
use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong};
|
2016-10-14 06:31:20 +03:00
|
|
|
use style::gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
|
2016-02-04 20:55:09 +03:00
|
|
|
use style::parallel;
|
2016-10-09 16:53:28 +03:00
|
|
|
use style::parser::{ParserContext, ParserContextExtraData};
|
2016-10-27 04:14:04 +03:00
|
|
|
use style::properties::{CascadeFlags, ComputedValues, Importance, PropertyDeclaration};
|
2016-10-09 16:53:28 +03:00
|
|
|
use style::properties::{PropertyDeclarationParseResult, PropertyDeclarationBlock};
|
2016-11-06 01:11:24 +03:00
|
|
|
use style::properties::{apply_declarations, parse_one_declaration};
|
2016-08-09 20:02:55 +03:00
|
|
|
use style::selector_impl::PseudoElementCascadeType;
|
2016-07-06 04:55:36 +03:00
|
|
|
use style::sequential;
|
2016-09-26 10:36:05 +03:00
|
|
|
use style::string_cache::Atom;
|
2016-09-09 06:19:19 +03:00
|
|
|
use style::stylesheets::{Origin, Stylesheet};
|
2016-07-20 21:38:31 +03:00
|
|
|
use style::timer::Timer;
|
2016-11-07 08:26:08 +03:00
|
|
|
use style_traits::ToCss;
|
2016-02-04 20:55:09 +03:00
|
|
|
use url::Url;
|
2016-09-26 10:36:05 +03:00
|
|
|
|
2016-01-19 11:49:10 +03:00
|
|
|
/*
|
|
|
|
* For Gecko->Servo function calls, we need to redeclare the same signature that was declared in
|
|
|
|
* the C header in Gecko. In order to catch accidental mismatches, we run rust-bindgen against
|
|
|
|
* those signatures as well, giving us a second declaration of all the Servo_* functions in this
|
|
|
|
* crate. If there's a mismatch, LLVM will assert and abort, which is a rather awful thing to
|
|
|
|
* depend on but good enough for our purposes.
|
|
|
|
*/
|
|
|
|
|
2016-05-05 04:37:26 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_Initialize() -> () {
|
|
|
|
// Enable standard Rust logging.
|
|
|
|
//
|
|
|
|
// See https://doc.rust-lang.org/log/env_logger/index.html for instructions.
|
|
|
|
env_logger::init().unwrap();
|
2016-08-04 04:20:21 +03:00
|
|
|
|
|
|
|
// Allocate our default computed values.
|
|
|
|
unsafe { ComputedValues::initialize(); }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_Shutdown() -> () {
|
|
|
|
// Destroy our default computed values.
|
|
|
|
unsafe { ComputedValues::shutdown(); }
|
2016-05-05 04:37:26 +03:00
|
|
|
}
|
|
|
|
|
2016-10-30 01:14:10 +03:00
|
|
|
fn restyle_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed) {
|
2016-04-04 17:41:29 +03:00
|
|
|
// Force the creation of our lazily-constructed initial computed values on
|
2016-05-05 04:37:26 +03:00
|
|
|
// the main thread, since it's not safe to call elsewhere.
|
|
|
|
//
|
|
|
|
// FIXME(bholley): this should move into Servo_Initialize as soon as we get
|
|
|
|
// rid of the HackilyFindSomeDeviceContext stuff that happens during
|
|
|
|
// initial_values computation, since that stuff needs to be called further
|
|
|
|
// along in startup than the sensible place to call Servo_Initialize.
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] 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 refactoring
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 10:58:34 +03:00
|
|
|
ComputedValues::initial_values();
|
2016-04-04 17:41:29 +03:00
|
|
|
|
2016-07-29 05:56:20 +03:00
|
|
|
// The stylist consumes stylesheets lazily.
|
2016-10-11 20:03:29 +03:00
|
|
|
let mut per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2016-07-29 05:56:20 +03:00
|
|
|
per_doc_data.flush_stylesheets();
|
2016-07-02 00:12:54 +03:00
|
|
|
|
|
|
|
let local_context_data =
|
|
|
|
LocalStyleContextCreationInfo::new(per_doc_data.new_animations_sender.clone());
|
2016-01-19 11:49:10 +03:00
|
|
|
|
|
|
|
let shared_style_context = SharedStyleContext {
|
2016-10-09 16:53:28 +03:00
|
|
|
// FIXME (bug 1303229): Use the actual viewport size here
|
2016-01-19 11:49:10 +03:00
|
|
|
viewport_size: Size2D::new(Au(0), Au(0)),
|
|
|
|
screen_size_changed: false,
|
|
|
|
generation: 0,
|
|
|
|
goal: ReflowGoal::ForScriptQuery,
|
2016-07-02 00:12:54 +03:00
|
|
|
stylist: per_doc_data.stylist.clone(),
|
|
|
|
running_animations: per_doc_data.running_animations.clone(),
|
|
|
|
expired_animations: per_doc_data.expired_animations.clone(),
|
2016-01-19 11:49:10 +03:00
|
|
|
error_reporter: Box::new(StdoutErrorReporter),
|
2016-07-02 00:12:54 +03:00
|
|
|
local_context_creation_data: Mutex::new(local_context_data),
|
2016-07-20 21:38:31 +03:00
|
|
|
timer: Timer::new(),
|
2016-01-19 11:49:10 +03:00
|
|
|
};
|
|
|
|
|
2016-10-30 01:14:10 +03:00
|
|
|
if element.styling_mode() == StylingMode::Stop {
|
2016-10-26 14:36:06 +03:00
|
|
|
error!("Unnecessary call to restyle_subtree");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-26 09:46:16 +03:00
|
|
|
if per_doc_data.num_threads == 1 || per_doc_data.work_queue.is_none() {
|
2016-10-30 01:14:10 +03:00
|
|
|
sequential::traverse_dom::<_, RecalcStyleOnly>(element.as_node(), &shared_style_context);
|
2016-07-28 01:56:26 +03:00
|
|
|
} else {
|
2016-10-30 01:14:10 +03:00
|
|
|
parallel::traverse_dom::<_, RecalcStyleOnly>(element.as_node(), &shared_style_context,
|
|
|
|
per_doc_data.work_queue.as_mut().unwrap());
|
2016-01-19 11:49:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-26 00:26:11 +03:00
|
|
|
#[no_mangle]
|
2016-09-03 06:42:21 +03:00
|
|
|
pub extern "C" fn Servo_RestyleSubtree(node: RawGeckoNodeBorrowed,
|
2016-10-11 20:03:29 +03:00
|
|
|
raw_data: RawServoStyleSetBorrowed) -> () {
|
2016-09-03 06:42:21 +03:00
|
|
|
let node = GeckoNode(node);
|
2016-10-30 01:14:10 +03:00
|
|
|
if let Some(element) = node.as_element() {
|
|
|
|
restyle_subtree(element, raw_data);
|
|
|
|
}
|
2016-05-26 00:26:11 +03:00
|
|
|
}
|
|
|
|
|
2016-10-09 16:53:28 +03:00
|
|
|
#[no_mangle]
|
2016-10-18 08:51:14 +03:00
|
|
|
pub extern "C" fn Servo_RestyleWithAddedDeclaration(declarations: RawServoDeclarationBlockBorrowed,
|
2016-10-09 16:53:28 +03:00
|
|
|
previous_style: ServoComputedValuesBorrowed)
|
|
|
|
-> ServoComputedValuesStrong
|
|
|
|
{
|
2016-11-06 01:11:24 +03:00
|
|
|
let previous_style = ComputedValues::as_arc(&previous_style);
|
2016-10-18 08:51:14 +03:00
|
|
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
2016-11-06 01:11:24 +03:00
|
|
|
|
|
|
|
let guard = declarations.read();
|
|
|
|
|
|
|
|
let declarations = || {
|
|
|
|
guard.declarations.iter().rev().map(|&(ref decl, _importance)| decl)
|
2016-10-18 08:51:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// FIXME (bug 1303229): Use the actual viewport size here
|
2016-11-06 01:11:24 +03:00
|
|
|
let computed = apply_declarations(Size2D::new(Au(0), Au(0)),
|
|
|
|
/* is_root_element = */ false,
|
|
|
|
declarations,
|
|
|
|
previous_style,
|
|
|
|
None,
|
|
|
|
Box::new(StdoutErrorReporter),
|
|
|
|
CascadeFlags::empty());
|
2016-10-18 08:51:14 +03:00
|
|
|
Arc::new(computed).into_strong()
|
2016-10-09 16:53:28 +03:00
|
|
|
}
|
|
|
|
|
2016-07-06 04:55:36 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_StyleWorkerThreadCount() -> u32 {
|
|
|
|
*NUM_THREADS as u32
|
|
|
|
}
|
|
|
|
|
2016-01-19 11:49:10 +03:00
|
|
|
#[no_mangle]
|
2016-09-24 13:17:29 +03:00
|
|
|
pub extern "C" fn Servo_Node_ClearNodeData(node: RawGeckoNodeBorrowed) -> () {
|
2016-10-30 01:14:10 +03:00
|
|
|
if let Some(element) = GeckoNode(node).as_element() {
|
|
|
|
element.clear_data();
|
|
|
|
}
|
2016-01-19 11:49:10 +03:00
|
|
|
}
|
2016-02-04 20:55:09 +03:00
|
|
|
|
|
|
|
#[no_mangle]
|
2016-10-25 12:09:19 +03:00
|
|
|
pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(data: *const nsACString,
|
|
|
|
mode: SheetParsingMode,
|
|
|
|
base_url: *const nsACString,
|
|
|
|
base: *mut ThreadSafeURIHolder,
|
|
|
|
referrer: *mut ThreadSafeURIHolder,
|
|
|
|
principal: *mut ThreadSafePrincipalHolder)
|
|
|
|
-> RawServoStyleSheetStrong {
|
|
|
|
let input = unsafe { data.as_ref().unwrap().as_str_unchecked() };
|
2016-02-04 20:55:09 +03:00
|
|
|
|
2016-04-30 00:27:16 +03:00
|
|
|
let origin = match mode {
|
|
|
|
SheetParsingMode::eAuthorSheetFeatures => Origin::Author,
|
|
|
|
SheetParsingMode::eUserSheetFeatures => Origin::User,
|
|
|
|
SheetParsingMode::eAgentSheetFeatures => Origin::UserAgent,
|
|
|
|
};
|
|
|
|
|
2016-10-25 12:09:19 +03:00
|
|
|
let base_str = unsafe { base_url.as_ref().unwrap().as_str_unchecked() };
|
2016-08-02 20:56:11 +03:00
|
|
|
let url = Url::parse(base_str).unwrap();
|
2016-10-14 06:31:20 +03:00
|
|
|
let extra_data = unsafe { ParserContextExtraData {
|
2016-05-25 00:41:04 +03:00
|
|
|
base: Some(GeckoArcURI::new(base)),
|
|
|
|
referrer: Some(GeckoArcURI::new(referrer)),
|
|
|
|
principal: Some(GeckoArcPrincipal::new(principal)),
|
2016-10-14 06:31:20 +03:00
|
|
|
}};
|
2016-05-25 00:41:04 +03:00
|
|
|
let sheet = Arc::new(Stylesheet::from_str(input, url, origin, Box::new(StdoutErrorReporter),
|
|
|
|
extra_data));
|
2016-02-04 20:55:09 +03:00
|
|
|
unsafe {
|
|
|
|
transmute(sheet)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2016-10-11 20:03:29 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_AppendStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
2016-08-24 16:16:05 +03:00
|
|
|
raw_sheet: RawServoStyleSheetBorrowed) {
|
2016-10-11 20:03:29 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2016-09-03 06:42:21 +03:00
|
|
|
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
|
|
|
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
|
|
|
data.stylesheets.push(sheet.clone());
|
|
|
|
data.stylesheets_changed = true;
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2016-10-11 20:03:29 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_PrependStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
2016-08-24 16:16:05 +03:00
|
|
|
raw_sheet: RawServoStyleSheetBorrowed) {
|
2016-10-11 20:03:29 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2016-09-03 06:42:21 +03:00
|
|
|
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
|
|
|
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
|
|
|
data.stylesheets.insert(0, sheet.clone());
|
|
|
|
data.stylesheets_changed = true;
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
2016-04-29 08:37:40 +03:00
|
|
|
#[no_mangle]
|
2016-10-11 20:03:29 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_InsertStyleSheetBefore(raw_data: RawServoStyleSetBorrowed,
|
2016-08-24 16:16:05 +03:00
|
|
|
raw_sheet: RawServoStyleSheetBorrowed,
|
|
|
|
raw_reference: RawServoStyleSheetBorrowed) {
|
2016-10-11 20:03:29 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2016-09-03 06:42:21 +03:00
|
|
|
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
|
|
|
let reference = HasArcFFI::as_arc(&raw_reference);
|
|
|
|
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
|
|
|
let index = data.stylesheets.iter().position(|x| arc_ptr_eq(x, reference)).unwrap();
|
|
|
|
data.stylesheets.insert(index, sheet.clone());
|
|
|
|
data.stylesheets_changed = true;
|
2016-04-29 08:37:40 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 20:55:09 +03:00
|
|
|
#[no_mangle]
|
2016-10-11 20:03:29 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_RemoveStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
2016-08-24 16:16:05 +03:00
|
|
|
raw_sheet: RawServoStyleSheetBorrowed) {
|
2016-10-11 20:03:29 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2016-09-03 06:42:21 +03:00
|
|
|
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
|
|
|
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
|
|
|
data.stylesheets_changed = true;
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2016-08-24 16:16:05 +03:00
|
|
|
pub extern "C" fn Servo_StyleSheet_HasRules(raw_sheet: RawServoStyleSheetBorrowed) -> bool {
|
2016-09-03 06:42:21 +03:00
|
|
|
!Stylesheet::as_arc(&raw_sheet).rules.is_empty()
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 00:57:33 +03:00
|
|
|
#[no_mangle]
|
2016-08-24 16:16:05 +03:00
|
|
|
pub extern "C" fn Servo_StyleSheet_AddRef(sheet: RawServoStyleSheetBorrowed) -> () {
|
2016-08-17 15:35:43 +03:00
|
|
|
unsafe { Stylesheet::addref(sheet) };
|
2016-03-25 00:57:33 +03:00
|
|
|
}
|
2016-02-04 20:55:09 +03:00
|
|
|
|
|
|
|
#[no_mangle]
|
2016-08-24 16:16:05 +03:00
|
|
|
pub extern "C" fn Servo_StyleSheet_Release(sheet: RawServoStyleSheetBorrowed) -> () {
|
2016-08-17 15:35:43 +03:00
|
|
|
unsafe { Stylesheet::release(sheet) };
|
2016-03-25 00:57:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2016-09-03 06:42:21 +03:00
|
|
|
pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed)
|
2016-08-17 15:35:43 +03:00
|
|
|
-> ServoComputedValuesStrong {
|
2016-09-09 10:00:13 +03:00
|
|
|
let node = GeckoNode(node);
|
2016-10-30 01:14:10 +03:00
|
|
|
|
|
|
|
// Gecko erroneously calls this function from ServoRestyleManager::RecreateStyleContexts.
|
|
|
|
// We plan to fix that, but just support it for now until that code gets rewritten.
|
|
|
|
if node.is_text_node() {
|
|
|
|
error!("Don't call Servo_ComputedValue_Get() for text nodes");
|
|
|
|
let parent = node.parent_node().unwrap().as_element().unwrap();
|
|
|
|
let parent_cv = parent.borrow_data().map_or_else(|| Arc::new(ComputedValues::initial_values().clone()),
|
|
|
|
|x| x.get_current_styles().unwrap()
|
|
|
|
.primary.clone());
|
|
|
|
return ComputedValues::inherit_from(&parent_cv).into_strong();
|
|
|
|
}
|
|
|
|
|
|
|
|
let element = node.as_element().unwrap();
|
|
|
|
let data = element.borrow_data();
|
2016-10-21 23:50:48 +03:00
|
|
|
let arc_cv = match data.as_ref().and_then(|x| x.get_current_styles()) {
|
|
|
|
Some(styles) => styles.primary.clone(),
|
2016-05-07 14:25:31 +03:00
|
|
|
None => {
|
|
|
|
// FIXME(bholley): This case subverts the intended semantics of this
|
|
|
|
// function, and exists only to make stylo builds more robust corner-
|
|
|
|
// cases where Gecko wants the style for a node that Servo never
|
|
|
|
// traversed. We should remove this as soon as possible.
|
|
|
|
error!("stylo: encountered unstyled node, substituting default values.");
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] 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 refactoring
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 10:58:34 +03:00
|
|
|
Arc::new(ComputedValues::initial_values().clone())
|
2016-05-07 14:25:31 +03:00
|
|
|
},
|
|
|
|
};
|
2016-09-03 06:42:21 +03:00
|
|
|
arc_cv.into_strong()
|
2016-03-25 00:57:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2016-09-03 06:42:21 +03:00
|
|
|
pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: ServoComputedValuesBorrowedOrNull,
|
2016-04-30 00:27:16 +03:00
|
|
|
pseudo_tag: *mut nsIAtom,
|
2016-10-11 20:03:29 +03:00
|
|
|
raw_data: RawServoStyleSetBorrowed)
|
2016-08-17 15:35:43 +03:00
|
|
|
-> ServoComputedValuesStrong {
|
2016-07-29 05:56:20 +03:00
|
|
|
// The stylist consumes stylesheets lazily.
|
2016-10-11 20:03:29 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2016-07-29 05:56:20 +03:00
|
|
|
data.flush_stylesheets();
|
2016-04-30 00:27:16 +03:00
|
|
|
|
2016-08-16 20:50:29 +03:00
|
|
|
let atom = Atom::from(pseudo_tag);
|
|
|
|
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ true);
|
2016-04-30 00:27:16 +03:00
|
|
|
|
|
|
|
|
2016-10-05 08:59:56 +03:00
|
|
|
let maybe_parent = ComputedValues::arc_from_borrowed(&parent_style_or_null);
|
2016-11-06 01:11:24 +03:00
|
|
|
let new_computed = data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent, false)
|
|
|
|
.map(|(computed, _rule_node)| computed);
|
2016-09-03 06:42:21 +03:00
|
|
|
new_computed.map_or(Strong::null(), |c| c.into_strong())
|
2016-03-25 00:57:33 +03:00
|
|
|
}
|
|
|
|
|
2016-05-04 13:42:23 +03:00
|
|
|
#[no_mangle]
|
2016-08-24 16:16:05 +03:00
|
|
|
pub extern "C" fn Servo_ComputedValues_GetForPseudoElement(parent_style: ServoComputedValuesBorrowed,
|
2016-09-03 06:42:21 +03:00
|
|
|
match_element: RawGeckoElementBorrowed,
|
|
|
|
pseudo_tag: *mut nsIAtom,
|
2016-10-11 20:03:29 +03:00
|
|
|
raw_data: RawServoStyleSetBorrowed,
|
2016-09-03 06:42:21 +03:00
|
|
|
is_probe: bool)
|
2016-08-17 15:35:43 +03:00
|
|
|
-> ServoComputedValuesStrong {
|
2016-09-03 06:42:21 +03:00
|
|
|
debug_assert!(!(match_element as *const _).is_null());
|
2016-05-04 13:42:23 +03:00
|
|
|
|
|
|
|
let parent_or_null = || {
|
|
|
|
if is_probe {
|
2016-09-03 06:42:21 +03:00
|
|
|
Strong::null()
|
2016-05-04 13:42:23 +03:00
|
|
|
} else {
|
2016-09-03 06:42:21 +03:00
|
|
|
ComputedValues::as_arc(&parent_style).clone().into_strong()
|
2016-05-04 13:42:23 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-16 20:50:29 +03:00
|
|
|
let atom = Atom::from(pseudo_tag);
|
|
|
|
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ false);
|
2016-05-04 13:42:23 +03:00
|
|
|
|
2016-07-29 05:56:20 +03:00
|
|
|
// The stylist consumes stylesheets lazily.
|
2016-10-11 20:03:29 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2016-07-29 05:56:20 +03:00
|
|
|
data.flush_stylesheets();
|
2016-05-04 13:42:23 +03:00
|
|
|
|
2016-09-09 10:00:13 +03:00
|
|
|
let element = GeckoElement(match_element);
|
2016-05-04 13:42:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
match GeckoSelectorImpl::pseudo_element_cascade_type(&pseudo) {
|
|
|
|
PseudoElementCascadeType::Eager => {
|
2016-10-30 01:14:10 +03:00
|
|
|
let maybe_computed = element.get_pseudo_style(&pseudo);
|
2016-09-03 06:42:21 +03:00
|
|
|
maybe_computed.map_or_else(parent_or_null, FFIArcHelpers::into_strong)
|
2016-05-04 13:42:23 +03:00
|
|
|
}
|
|
|
|
PseudoElementCascadeType::Lazy => {
|
2016-09-03 06:42:21 +03:00
|
|
|
let parent = ComputedValues::as_arc(&parent_style);
|
|
|
|
data.stylist
|
|
|
|
.lazily_compute_pseudo_element_style(&element, &pseudo, parent)
|
2016-11-06 01:11:24 +03:00
|
|
|
.map(|(c, _rule_node)| c)
|
2016-09-03 06:42:21 +03:00
|
|
|
.map_or_else(parent_or_null, FFIArcHelpers::into_strong)
|
2016-05-04 13:42:23 +03:00
|
|
|
}
|
|
|
|
PseudoElementCascadeType::Precomputed => {
|
|
|
|
unreachable!("Anonymous pseudo found in \
|
|
|
|
Servo_GetComputedValuesForPseudoElement");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 14:30:47 +03:00
|
|
|
#[no_mangle]
|
2016-09-03 06:42:21 +03:00
|
|
|
pub extern "C" fn Servo_ComputedValues_Inherit(parent_style: ServoComputedValuesBorrowedOrNull)
|
2016-08-17 15:35:43 +03:00
|
|
|
-> ServoComputedValuesStrong {
|
2016-10-05 08:59:56 +03:00
|
|
|
let maybe_arc = ComputedValues::arc_from_borrowed(&parent_style);
|
|
|
|
let style = if let Some(reference) = maybe_arc.as_ref() {
|
|
|
|
ComputedValues::inherit_from(reference)
|
2016-08-04 04:20:21 +03:00
|
|
|
} else {
|
2016-10-05 08:59:56 +03:00
|
|
|
Arc::new(ComputedValues::initial_values().clone())
|
2016-08-04 04:20:21 +03:00
|
|
|
};
|
2016-09-03 06:42:21 +03:00
|
|
|
style.into_strong()
|
2016-05-06 14:30:47 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 00:57:33 +03:00
|
|
|
#[no_mangle]
|
2016-08-24 16:16:05 +03:00
|
|
|
pub extern "C" fn Servo_ComputedValues_AddRef(ptr: ServoComputedValuesBorrowed) -> () {
|
2016-08-17 15:35:43 +03:00
|
|
|
unsafe { ComputedValues::addref(ptr) };
|
2016-03-25 00:57:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2016-08-24 16:16:05 +03:00
|
|
|
pub extern "C" fn Servo_ComputedValues_Release(ptr: ServoComputedValuesBorrowed) -> () {
|
2016-08-17 15:35:43 +03:00
|
|
|
unsafe { ComputedValues::release(ptr) };
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2016-09-03 06:42:21 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_Init() -> RawServoStyleSetOwned {
|
2016-02-04 20:55:09 +03:00
|
|
|
let data = Box::new(PerDocumentStyleData::new());
|
2016-09-03 06:42:21 +03:00
|
|
|
data.into_ffi()
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2016-09-03 06:42:21 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) -> () {
|
|
|
|
let _ = data.into_box::<PerDocumentStyleData>();
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
2016-06-24 05:46:25 +03:00
|
|
|
|
2016-10-09 16:53:28 +03:00
|
|
|
|
|
|
|
#[no_mangle]
|
2016-10-25 12:09:19 +03:00
|
|
|
pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const nsACString,
|
|
|
|
base_url: *const nsACString, base: *mut ThreadSafeURIHolder,
|
2016-10-09 16:53:28 +03:00
|
|
|
referrer: *mut ThreadSafeURIHolder,
|
|
|
|
principal: *mut ThreadSafePrincipalHolder)
|
2016-10-18 08:51:14 +03:00
|
|
|
-> RawServoDeclarationBlockStrong {
|
2016-10-25 12:09:19 +03:00
|
|
|
let name = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
|
|
|
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
|
|
|
let base_str = unsafe { base_url.as_ref().unwrap().as_str_unchecked() };
|
2016-10-09 16:53:28 +03:00
|
|
|
let base_url = Url::parse(base_str).unwrap();
|
2016-10-14 06:31:20 +03:00
|
|
|
let extra_data = unsafe { ParserContextExtraData {
|
2016-10-09 16:53:28 +03:00
|
|
|
base: Some(GeckoArcURI::new(base)),
|
|
|
|
referrer: Some(GeckoArcURI::new(referrer)),
|
|
|
|
principal: Some(GeckoArcPrincipal::new(principal)),
|
2016-10-14 06:31:20 +03:00
|
|
|
}};
|
2016-10-09 16:53:28 +03:00
|
|
|
|
|
|
|
let context = ParserContext::new_with_extra_data(Origin::Author, &base_url,
|
|
|
|
Box::new(StdoutErrorReporter),
|
|
|
|
extra_data);
|
|
|
|
|
|
|
|
let mut results = vec![];
|
2016-10-25 12:09:19 +03:00
|
|
|
match PropertyDeclaration::parse(name, &context, &mut Parser::new(value),
|
2016-10-09 16:53:28 +03:00
|
|
|
&mut results, false) {
|
|
|
|
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration => {},
|
2016-10-18 08:51:14 +03:00
|
|
|
_ => return RawServoDeclarationBlockStrong::null(),
|
2016-10-09 16:53:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let results = results.into_iter().map(|r| (r, Importance::Normal)).collect();
|
|
|
|
|
2016-10-18 08:51:14 +03:00
|
|
|
Arc::new(RwLock::new(PropertyDeclarationBlock {
|
|
|
|
declarations: results,
|
|
|
|
important_count: 0,
|
|
|
|
})).into_strong()
|
2016-10-09 16:53:28 +03:00
|
|
|
}
|
2016-10-18 08:51:14 +03:00
|
|
|
|
2016-06-24 05:46:25 +03:00
|
|
|
#[no_mangle]
|
2016-10-25 12:09:19 +03:00
|
|
|
pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString) -> RawServoDeclarationBlockStrong {
|
|
|
|
let value = unsafe { data.as_ref().unwrap().as_str_unchecked() };
|
2016-10-18 08:51:14 +03:00
|
|
|
Arc::new(RwLock::new(GeckoElement::parse_style_attribute(value))).into_strong()
|
2016-06-24 05:46:25 +03:00
|
|
|
}
|
|
|
|
|
2016-11-04 07:42:06 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_CreateEmpty() -> RawServoDeclarationBlockStrong {
|
|
|
|
Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: vec![], important_count: 0 })).into_strong()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_Clone(declarations: RawServoDeclarationBlockBorrowed)
|
|
|
|
-> RawServoDeclarationBlockStrong {
|
|
|
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
Arc::new(RwLock::new(declarations.read().clone())).into_strong()
|
|
|
|
}
|
|
|
|
|
2016-06-24 05:46:25 +03:00
|
|
|
#[no_mangle]
|
2016-10-18 08:51:14 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_AddRef(declarations: RawServoDeclarationBlockBorrowed) {
|
|
|
|
unsafe { RwLock::<PropertyDeclarationBlock>::addref(declarations) };
|
2016-06-24 05:46:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2016-10-18 08:51:14 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_Release(declarations: RawServoDeclarationBlockBorrowed) {
|
|
|
|
unsafe { RwLock::<PropertyDeclarationBlock>::release(declarations) };
|
2016-08-23 05:12:23 +03:00
|
|
|
}
|
|
|
|
|
2016-10-09 16:53:28 +03:00
|
|
|
#[no_mangle]
|
2016-10-18 08:51:14 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_Equals(a: RawServoDeclarationBlockBorrowed,
|
|
|
|
b: RawServoDeclarationBlockBorrowed)
|
2016-10-09 16:53:28 +03:00
|
|
|
-> bool {
|
2016-10-18 08:51:14 +03:00
|
|
|
*RwLock::<PropertyDeclarationBlock>::as_arc(&a).read() == *RwLock::<PropertyDeclarationBlock>::as_arc(&b).read()
|
2016-06-24 05:46:25 +03:00
|
|
|
}
|
2016-07-19 07:25:31 +03:00
|
|
|
|
2016-11-04 07:42:06 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_GetCssText(declarations: RawServoDeclarationBlockBorrowed,
|
|
|
|
result: *mut nsAString) {
|
|
|
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
declarations.read().to_css(unsafe { result.as_mut().unwrap() }).unwrap();
|
|
|
|
}
|
|
|
|
|
2016-10-09 16:53:28 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
|
2016-10-18 08:51:14 +03:00
|
|
|
declarations: RawServoDeclarationBlockBorrowed,
|
2016-10-09 16:53:28 +03:00
|
|
|
buffer: *mut nsString)
|
|
|
|
{
|
|
|
|
let mut string = String::new();
|
|
|
|
|
2016-10-18 08:51:14 +03:00
|
|
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
declarations.read().to_css(&mut string).unwrap();
|
|
|
|
// FIXME: We are expecting |declarations| to be a declaration block with either a single
|
|
|
|
// longhand property-declaration or a series of longhand property-declarations that make
|
|
|
|
// up a single shorthand property. As a result, it should be possible to serialize
|
|
|
|
// |declarations| as a single declaration. However, we only want to return the *value* from
|
|
|
|
// that single declaration. For now, we just manually strip the property name, colon,
|
|
|
|
// leading spacing, and trailing space. In future we should find a more robust way to do
|
|
|
|
// this.
|
|
|
|
//
|
|
|
|
// See https://github.com/servo/servo/issues/13423
|
|
|
|
debug_assert!(string.find(':').is_some());
|
|
|
|
let position = string.find(':').unwrap();
|
|
|
|
// Get the value after the first colon and any following whitespace.
|
|
|
|
let value = &string[(position + 1)..].trim_left();
|
|
|
|
debug_assert!(value.ends_with(';'));
|
|
|
|
let length = value.len() - 1; // Strip last semicolon.
|
|
|
|
|
|
|
|
// FIXME: Once we have nsString bindings for Servo (bug 1294742), we should be able to drop
|
|
|
|
// this and fill in |buffer| directly.
|
|
|
|
unsafe {
|
|
|
|
Gecko_Utf8SliceToString(buffer, value.as_ptr(), length);
|
2016-10-09 16:53:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 07:42:06 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_Count(declarations: RawServoDeclarationBlockBorrowed) -> u32 {
|
|
|
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
declarations.read().declarations.len() as u32
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(declarations: RawServoDeclarationBlockBorrowed,
|
|
|
|
index: u32, result: *mut nsAString) -> bool {
|
|
|
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
if let Some(&(ref decl, _)) = declarations.read().declarations.get(index as usize) {
|
|
|
|
let result = unsafe { result.as_mut().unwrap() };
|
|
|
|
write!(result, "{}", decl.name()).unwrap();
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME Methods of PropertyDeclarationBlock should take atoms directly.
|
|
|
|
// This function is just a temporary workaround before that finishes.
|
|
|
|
fn get_property_name_from_atom(atom: *mut nsIAtom, is_custom: bool) -> String {
|
|
|
|
let atom = Atom::from(atom);
|
|
|
|
if !is_custom {
|
|
|
|
atom.to_string()
|
|
|
|
} else {
|
|
|
|
let mut result = String::with_capacity(atom.len() as usize + 2);
|
|
|
|
write!(result, "--{}", atom).unwrap();
|
|
|
|
result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_GetPropertyValue(declarations: RawServoDeclarationBlockBorrowed,
|
|
|
|
property: *mut nsIAtom, is_custom: bool,
|
|
|
|
value: *mut nsAString) {
|
|
|
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
let property = get_property_name_from_atom(property, is_custom);
|
|
|
|
declarations.read().property_value_to_css(&property, unsafe { value.as_mut().unwrap() }).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_GetPropertyIsImportant(declarations: RawServoDeclarationBlockBorrowed,
|
|
|
|
property: *mut nsIAtom, is_custom: bool) -> bool {
|
|
|
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
let property = get_property_name_from_atom(property, is_custom);
|
|
|
|
declarations.read().property_priority(&property).important()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDeclarationBlockBorrowed,
|
|
|
|
property: *mut nsIAtom, is_custom: bool,
|
|
|
|
value: *mut nsACString, is_important: bool) -> bool {
|
|
|
|
let property = get_property_name_from_atom(property, is_custom);
|
|
|
|
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
|
|
|
// FIXME Needs real URL and ParserContextExtraData.
|
|
|
|
let base_url = &*DUMMY_BASE_URL;
|
|
|
|
let extra_data = ParserContextExtraData::default();
|
|
|
|
if let Ok(decls) = parse_one_declaration(&property, value, &base_url,
|
|
|
|
Box::new(StdoutErrorReporter), extra_data) {
|
|
|
|
let mut declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations).write();
|
|
|
|
let importance = if is_important { Importance::Important } else { Importance::Normal };
|
|
|
|
for decl in decls.into_iter() {
|
|
|
|
declarations.set_parsed_declaration(decl, importance);
|
|
|
|
}
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_RemoveProperty(declarations: RawServoDeclarationBlockBorrowed,
|
|
|
|
property: *mut nsIAtom, is_custom: bool) {
|
|
|
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
let property = get_property_name_from_atom(property, is_custom);
|
|
|
|
declarations.write().remove_property(&property);
|
|
|
|
}
|
|
|
|
|
2016-07-19 07:25:31 +03:00
|
|
|
#[no_mangle]
|
2016-10-25 12:09:19 +03:00
|
|
|
pub extern "C" fn Servo_CSSSupports(property: *const nsACString, value: *const nsACString) -> bool {
|
|
|
|
let property = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
|
|
|
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
2016-07-19 07:25:31 +03:00
|
|
|
|
|
|
|
let base_url = &*DUMMY_BASE_URL;
|
|
|
|
let extra_data = ParserContextExtraData::default();
|
|
|
|
|
|
|
|
match parse_one_declaration(&property, &value, &base_url, Box::new(StdoutErrorReporter), extra_data) {
|
|
|
|
Ok(decls) => !decls.is_empty(),
|
|
|
|
Err(()) => false,
|
|
|
|
}
|
|
|
|
}
|
2016-07-22 00:54:34 +03:00
|
|
|
|
|
|
|
#[no_mangle]
|
2016-09-03 06:42:21 +03:00
|
|
|
pub extern "C" fn Servo_ComputeRestyleHint(element: RawGeckoElementBorrowed,
|
2016-07-22 00:54:34 +03:00
|
|
|
snapshot: *mut ServoElementSnapshot,
|
2016-09-03 06:42:21 +03:00
|
|
|
raw_data: RawServoStyleSetBorrowed) -> nsRestyleHint {
|
2016-10-11 20:03:29 +03:00
|
|
|
let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2016-07-22 00:54:34 +03:00
|
|
|
let snapshot = unsafe { GeckoElementSnapshot::from_raw(snapshot) };
|
2016-09-09 10:00:13 +03:00
|
|
|
let element = GeckoElement(element);
|
2016-07-22 00:54:34 +03:00
|
|
|
|
|
|
|
// NB: This involves an FFI call, we can get rid of it easily if needed.
|
|
|
|
let current_state = element.get_state();
|
|
|
|
|
|
|
|
let hint = per_doc_data.stylist
|
|
|
|
.compute_restyle_hint(&element, &snapshot,
|
|
|
|
current_state);
|
|
|
|
|
|
|
|
// NB: Binary representations match.
|
|
|
|
unsafe { transmute(hint.bits() as u32) }
|
|
|
|
}
|