mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
style: Refactor preference stylesheet prefs to not require a pres context.
We really only have two sets of prefs, one for chrome-like documents (stuff in chrome docshells + chrome-origin images), and one for the rest. Differential Revision: https://phabricator.services.mozilla.com/D20946
This commit is contained in:
parent
33814a9afe
commit
4e3e4c106a
4 changed files with 20 additions and 15 deletions
|
@ -150,7 +150,7 @@ impl PerDocumentStyleData {
|
||||||
// right now not always honored, see bug 1405543...
|
// right now not always honored, see bug 1405543...
|
||||||
//
|
//
|
||||||
// Should we just force XBL Stylists to be NoQuirks?
|
// Should we just force XBL Stylists to be NoQuirks?
|
||||||
let quirks_mode = unsafe { (*device.pres_context().mDocument.mRawPtr).mCompatMode };
|
let quirks_mode = device.document().mCompatMode;
|
||||||
|
|
||||||
PerDocumentStyleData(AtomicRefCell::new(PerDocumentStyleDataImpl {
|
PerDocumentStyleData(AtomicRefCell::new(PerDocumentStyleDataImpl {
|
||||||
stylist: Stylist::new(device, quirks_mode.into()),
|
stylist: Stylist::new(device, quirks_mode.into()),
|
||||||
|
@ -191,8 +191,7 @@ impl PerDocumentStyleDataImpl {
|
||||||
/// Returns whether visited styles are enabled.
|
/// Returns whether visited styles are enabled.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn visited_styles_enabled(&self) -> bool {
|
pub fn visited_styles_enabled(&self) -> bool {
|
||||||
let doc = self.stylist.device().pres_context().mDocument.mRawPtr;
|
unsafe { bindings::Gecko_VisitedStylesEnabled(self.stylist.device().document()) }
|
||||||
unsafe { bindings::Gecko_VisitedStylesEnabled(doc) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Measure heap usage.
|
/// Measure heap usage.
|
||||||
|
|
|
@ -83,14 +83,14 @@ impl Device {
|
||||||
/// Trivially constructs a new `Device`.
|
/// Trivially constructs a new `Device`.
|
||||||
pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self {
|
pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self {
|
||||||
assert!(!pres_context.is_null());
|
assert!(!pres_context.is_null());
|
||||||
|
let doc = unsafe { &*(*pres_context).mDocument.mRawPtr };
|
||||||
|
let prefs = unsafe { &*bindings::Gecko_GetPrefSheetPrefs(doc) };
|
||||||
Device {
|
Device {
|
||||||
pres_context,
|
pres_context,
|
||||||
default_values: ComputedValues::default_values(unsafe {
|
default_values: ComputedValues::default_values(doc),
|
||||||
&*(*pres_context).mDocument.mRawPtr
|
|
||||||
}),
|
|
||||||
// FIXME(bz): Seems dubious?
|
// FIXME(bz): Seems dubious?
|
||||||
root_font_size: AtomicIsize::new(FontSize::medium().size().0 as isize),
|
root_font_size: AtomicIsize::new(FontSize::medium().size().0 as isize),
|
||||||
body_text_color: AtomicUsize::new(unsafe { &*pres_context }.mDefaultColor as usize),
|
body_text_color: AtomicUsize::new(prefs.mDefaultColor as usize),
|
||||||
used_root_font_size: AtomicBool::new(false),
|
used_root_font_size: AtomicBool::new(false),
|
||||||
used_viewport_size: AtomicBool::new(false),
|
used_viewport_size: AtomicBool::new(false),
|
||||||
environment: CssEnvironment,
|
environment: CssEnvironment,
|
||||||
|
@ -168,6 +168,12 @@ impl Device {
|
||||||
unsafe { &*self.pres_context().mDocument.mRawPtr }
|
unsafe { &*self.pres_context().mDocument.mRawPtr }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the preference stylesheet prefs for our document.
|
||||||
|
#[inline]
|
||||||
|
pub fn pref_sheet_prefs(&self) -> &structs::PreferenceSheet_Prefs {
|
||||||
|
unsafe { &*bindings::Gecko_GetPrefSheetPrefs(self.document()) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Recreates the default computed values.
|
/// Recreates the default computed values.
|
||||||
pub fn reset_computed_values(&mut self) {
|
pub fn reset_computed_values(&mut self) {
|
||||||
self.default_values = ComputedValues::default_values(self.document());
|
self.default_values = ComputedValues::default_values(self.document());
|
||||||
|
@ -243,7 +249,7 @@ impl Device {
|
||||||
|
|
||||||
/// Returns the default background color.
|
/// Returns the default background color.
|
||||||
pub fn default_background_color(&self) -> RGBA {
|
pub fn default_background_color(&self) -> RGBA {
|
||||||
convert_nscolor_to_rgba(self.pres_context().mBackgroundColor)
|
convert_nscolor_to_rgba(self.pref_sheet_prefs().mDefaultBackgroundColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies text zoom to a font-size or line-height value (see nsStyleFont::ZoomText).
|
/// Applies text zoom to a font-size or line-height value (see nsStyleFont::ZoomText).
|
||||||
|
|
|
@ -1243,7 +1243,7 @@ impl<'le> TElement for GeckoElement<'le> {
|
||||||
|
|
||||||
fn owner_doc_matches_for_testing(&self, device: &Device) -> bool {
|
fn owner_doc_matches_for_testing(&self, device: &Device) -> bool {
|
||||||
self.as_node().owner_doc().0 as *const structs::Document ==
|
self.as_node().owner_doc().0 as *const structs::Document ==
|
||||||
device.pres_context().mDocument.mRawPtr
|
device.document() as *const _
|
||||||
}
|
}
|
||||||
|
|
||||||
fn style_attribute(&self) -> Option<ArcBorrow<Locked<PropertyDeclarationBlock>>> {
|
fn style_attribute(&self) -> Option<ArcBorrow<Locked<PropertyDeclarationBlock>>> {
|
||||||
|
|
|
@ -351,13 +351,13 @@ impl Color {
|
||||||
Color::Special(special) => {
|
Color::Special(special) => {
|
||||||
use self::gecko::SpecialColorKeyword as Keyword;
|
use self::gecko::SpecialColorKeyword as Keyword;
|
||||||
_context.map(|context| {
|
_context.map(|context| {
|
||||||
let pres_context = context.device().pres_context();
|
let prefs = context.device().pref_sheet_prefs();
|
||||||
convert_nscolor_to_computedcolor(match special {
|
convert_nscolor_to_computedcolor(match special {
|
||||||
Keyword::MozDefaultColor => pres_context.mDefaultColor,
|
Keyword::MozDefaultColor => prefs.mDefaultColor,
|
||||||
Keyword::MozDefaultBackgroundColor => pres_context.mBackgroundColor,
|
Keyword::MozDefaultBackgroundColor => prefs.mDefaultBackgroundColor,
|
||||||
Keyword::MozHyperlinktext => pres_context.mLinkColor,
|
Keyword::MozHyperlinktext => prefs.mLinkColor,
|
||||||
Keyword::MozActivehyperlinktext => pres_context.mActiveLinkColor,
|
Keyword::MozActivehyperlinktext => prefs.mActiveLinkColor,
|
||||||
Keyword::MozVisitedhyperlinktext => pres_context.mVisitedLinkColor,
|
Keyword::MozVisitedhyperlinktext => prefs.mVisitedLinkColor,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue