gecko-dev/servo/ports/geckolib/stylesheet_loader.rs
Michael Partheil 3ff096ba27 servo: Merge #17775 - Replace all uses of the style::stylearc alias with servo_arc (from michael-p:rename-stylearc-to-servo-arc); r=emilio
The `stylearc` alias is left there temporarilly and will be removed completely in a later commit/PR where also `components/style/gecko/generated/structs_{debug|release}.rs` are re-generated (they still use the old alias).

---
<!-- 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 #17768  (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because no new features / only refactoring

Source-Repo: https://github.com/servo/servo
Source-Revision: 31228c18499d1c7f68b6b64b559354c768e81215

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 4d7b64e8a000a80d9daf9b1a511682416f456ff5
2017-07-19 06:03:17 -07:00

62 lines
2.5 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 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 cssparser::SourceLocation;
use servo_arc::Arc;
use style::gecko::data::GeckoStyleSheet;
use style::gecko_bindings::bindings::Gecko_LoadStyleSheet;
use style::gecko_bindings::structs::{Loader, ServoStyleSheet, LoaderReusableStyleSheets};
use style::gecko_bindings::sugar::ownership::FFIArcHelpers;
use style::media_queries::MediaList;
use style::parser::ParserContext;
use style::shared_lock::{Locked, SharedRwLock};
use style::stylesheets::{ImportRule, StylesheetLoader as StyleStylesheetLoader};
use style::stylesheets::import_rule::ImportSheet;
use style::values::specified::url::SpecifiedUrl;
pub struct StylesheetLoader(*mut Loader, *mut ServoStyleSheet, *mut LoaderReusableStyleSheets);
impl StylesheetLoader {
pub fn new(loader: *mut Loader,
parent: *mut ServoStyleSheet,
reusable_sheets: *mut LoaderReusableStyleSheets) -> Self {
StylesheetLoader(loader, parent, reusable_sheets)
}
}
impl StyleStylesheetLoader for StylesheetLoader {
fn request_stylesheet(
&self,
url: SpecifiedUrl,
source_location: SourceLocation,
_context: &ParserContext,
lock: &SharedRwLock,
media: Arc<Locked<MediaList>>,
) -> Arc<Locked<ImportRule>> {
// After we get this raw pointer ImportRule will be moved into a lock and Arc
// and so the Arc<Url> pointer inside will also move,
// but the Url it points to or the allocating backing the String inside that Url wont,
// so this raw pointer will still be valid.
let child_sheet = unsafe {
let (spec_bytes, spec_len) = url.as_slice_components();
let base_url_data = url.extra_data.get();
Gecko_LoadStyleSheet(self.0,
self.1,
self.2,
base_url_data,
spec_bytes,
spec_len as u32,
media.into_strong())
};
debug_assert!(!child_sheet.is_null(),
"Import rules should always have a strong sheet");
let stylesheet = unsafe {
ImportSheet(GeckoStyleSheet::from_addrefed(child_sheet))
};
Arc::new(lock.wrap(ImportRule { url, source_location, stylesheet }))
}
}