Skip to content
Permalink
Browse files

style: Refactor preference stylesheet prefs to not require a pres con…

…text.

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
  • Loading branch information...
emilio committed Mar 6, 2019
1 parent 33814a9 commit 4e3e4c106a6ce694c028166956ab03cb3b3e7881
@@ -150,7 +150,7 @@ impl PerDocumentStyleData {
// right now not always honored, see bug 1405543...
//
// 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 {
stylist: Stylist::new(device, quirks_mode.into()),
@@ -191,8 +191,7 @@ impl PerDocumentStyleDataImpl {
/// Returns whether visited styles are enabled.
#[inline]
pub fn visited_styles_enabled(&self) -> bool {
let doc = self.stylist.device().pres_context().mDocument.mRawPtr;
unsafe { bindings::Gecko_VisitedStylesEnabled(doc) }
unsafe { bindings::Gecko_VisitedStylesEnabled(self.stylist.device().document()) }
}

/// Measure heap usage.
@@ -83,14 +83,14 @@ impl Device {
/// Trivially constructs a new `Device`.
pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self {
assert!(!pres_context.is_null());
let doc = unsafe { &*(*pres_context).mDocument.mRawPtr };
let prefs = unsafe { &*bindings::Gecko_GetPrefSheetPrefs(doc) };
Device {
pres_context,
default_values: ComputedValues::default_values(unsafe {
&*(*pres_context).mDocument.mRawPtr
}),
default_values: ComputedValues::default_values(doc),
// FIXME(bz): Seems dubious?
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_viewport_size: AtomicBool::new(false),
environment: CssEnvironment,
@@ -168,6 +168,12 @@ impl Device {
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.
pub fn reset_computed_values(&mut self) {
self.default_values = ComputedValues::default_values(self.document());
@@ -243,7 +249,7 @@ impl Device {

/// Returns the default background color.
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).
@@ -1243,7 +1243,7 @@ impl<'le> TElement for GeckoElement<'le> {

fn owner_doc_matches_for_testing(&self, device: &Device) -> bool {
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>>> {
@@ -351,13 +351,13 @@ impl Color {
Color::Special(special) => {
use self::gecko::SpecialColorKeyword as Keyword;
_context.map(|context| {
let pres_context = context.device().pres_context();
let prefs = context.device().pref_sheet_prefs();
convert_nscolor_to_computedcolor(match special {
Keyword::MozDefaultColor => pres_context.mDefaultColor,
Keyword::MozDefaultBackgroundColor => pres_context.mBackgroundColor,
Keyword::MozHyperlinktext => pres_context.mLinkColor,
Keyword::MozActivehyperlinktext => pres_context.mActiveLinkColor,
Keyword::MozVisitedhyperlinktext => pres_context.mVisitedLinkColor,
Keyword::MozDefaultColor => prefs.mDefaultColor,
Keyword::MozDefaultBackgroundColor => prefs.mDefaultBackgroundColor,
Keyword::MozHyperlinktext => prefs.mLinkColor,
Keyword::MozActivehyperlinktext => prefs.mActiveLinkColor,
Keyword::MozVisitedhyperlinktext => prefs.mVisitedLinkColor,
})
})
},

0 comments on commit 4e3e4c1

Please sign in to comment.
You can’t perform that action at this time.