зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1530751 - Make the pres context optional in the style system. r=jwatt
Differential Revision: https://phabricator.services.mozilla.com/D21239 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8c9a745531
Коммит
2028cb1479
|
@ -170,7 +170,6 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType)
|
|||
mHasPendingInterrupt(false),
|
||||
mPendingInterruptFromTest(false),
|
||||
mInterruptsEnabled(false),
|
||||
mUseDocumentColors(true),
|
||||
mSendAfterPaintToContent(false),
|
||||
mUseFocusColors(false),
|
||||
mDrawImageBackground(true), // always draw the background
|
||||
|
@ -344,28 +343,6 @@ void nsPresContext::GetDocumentColorPreferences() {
|
|||
// but in some reference tests, that is not the case.
|
||||
gfxPrefs::GetSingleton();
|
||||
PreferenceSheet::EnsureInitialized();
|
||||
|
||||
static int32_t sDocumentColorsSetting;
|
||||
static bool sDocumentColorsSettingPrefCached = false;
|
||||
if (!sDocumentColorsSettingPrefCached) {
|
||||
sDocumentColorsSettingPrefCached = true;
|
||||
Preferences::AddIntVarCache(&sDocumentColorsSetting,
|
||||
"browser.display.document_color_use", 0);
|
||||
}
|
||||
|
||||
// Now deal with the pref:
|
||||
// 0 = default: always, except in high contrast mode
|
||||
// 1 = always
|
||||
// 2 = never
|
||||
if (sDocumentColorsSetting == 1 || mDocument->IsBeingUsedAsImage()) {
|
||||
mUseDocumentColors = true;
|
||||
} else if (sDocumentColorsSetting == 2) {
|
||||
mUseDocumentColors = IsChrome() || IsChromeOriginImage();
|
||||
} else {
|
||||
bool useAccessibilityTheme =
|
||||
PreferenceSheet::UseAccessibilityTheme(IsChrome());
|
||||
mUseDocumentColors = !useAccessibilityTheme;
|
||||
}
|
||||
}
|
||||
|
||||
void nsPresContext::GetUserPreferences() {
|
||||
|
@ -1662,9 +1639,9 @@ bool nsPresContext::HasAuthorSpecifiedRules(const nsIFrame* aFrame,
|
|||
if (aFrame->Style()->IsAnonBox()) {
|
||||
return false;
|
||||
}
|
||||
return Servo_HasAuthorSpecifiedRules(aFrame->Style(), elem,
|
||||
aFrame->Style()->GetPseudoType(),
|
||||
aRuleTypeMask, UseDocumentColors());
|
||||
|
||||
auto* set = PresShell()->StyleSet()->RawSet();
|
||||
return Servo_HasAuthorSpecifiedRules(set, aFrame->Style(), elem, aRuleTypeMask);
|
||||
}
|
||||
|
||||
gfxUserFontSet* nsPresContext::GetUserFontSet() {
|
||||
|
|
|
@ -841,14 +841,6 @@ class nsPresContext : public nsISupports,
|
|||
bool HasAuthorSpecifiedRules(const nsIFrame* aFrame,
|
||||
uint32_t ruleTypeMask) const;
|
||||
|
||||
// Is it OK to let the page specify colors and backgrounds?
|
||||
bool UseDocumentColors() const {
|
||||
MOZ_ASSERT(mUseDocumentColors || !(IsChrome() || IsChromeOriginImage()),
|
||||
"We should never have a chrome doc or image that can't use its "
|
||||
"colors.");
|
||||
return mUseDocumentColors;
|
||||
}
|
||||
|
||||
// Explicitly enable and disable paint flashing.
|
||||
void SetPaintFlashing(bool aPaintFlashing) {
|
||||
mPaintFlashing = aPaintFlashing;
|
||||
|
@ -1227,7 +1219,6 @@ class nsPresContext : public nsISupports,
|
|||
unsigned mHasPendingInterrupt : 1;
|
||||
unsigned mPendingInterruptFromTest : 1;
|
||||
unsigned mInterruptsEnabled : 1;
|
||||
unsigned mUseDocumentColors : 1;
|
||||
unsigned mSendAfterPaintToContent : 1;
|
||||
unsigned mUseFocusColors : 1;
|
||||
unsigned mFocusRingOnAnything : 1;
|
||||
|
|
|
@ -39,7 +39,7 @@ bool PreferenceSheet::ShouldUseChromePrefs(const Document& aDoc) {
|
|||
(aDoc.IsBeingUsedAsImage() && aDoc.IsDocumentURISchemeChrome());
|
||||
}
|
||||
|
||||
bool PreferenceSheet::UseAccessibilityTheme(bool aIsChrome) {
|
||||
static bool UseAccessibilityTheme(bool aIsChrome) {
|
||||
return !aIsChrome &&
|
||||
!!LookAndFeel::GetInt(LookAndFeel::eIntID_UseAccessibilityTheme, 0);
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ bool PreferenceSheet::UseAccessibilityTheme(bool aIsChrome) {
|
|||
void PreferenceSheet::Prefs::Load(bool aIsChrome) {
|
||||
*this = {};
|
||||
|
||||
mIsChrome = aIsChrome;
|
||||
mUseAccessibilityTheme = UseAccessibilityTheme(aIsChrome);
|
||||
mUnderlineLinks = StaticPrefs::browser_underline_anchors();
|
||||
|
||||
mUseFocusColors = StaticPrefs::browser_display_use_focus_colors();
|
||||
|
@ -54,7 +56,7 @@ void PreferenceSheet::Prefs::Load(bool aIsChrome) {
|
|||
mFocusRingStyle = StaticPrefs::browser_display_focus_ring_style();
|
||||
mFocusRingOnAnything = StaticPrefs::browser_display_focus_ring_on_anything();
|
||||
|
||||
const bool usePrefColors = !aIsChrome && !UseAccessibilityTheme(aIsChrome) &&
|
||||
const bool usePrefColors = !aIsChrome && !mUseAccessibilityTheme &&
|
||||
!StaticPrefs::browser_display_use_system_colors();
|
||||
|
||||
if (nsContentUtils::UseStandinsForNativeColors()) {
|
||||
|
|
|
@ -31,6 +31,9 @@ struct PreferenceSheet {
|
|||
nscolor mFocusTextColor = mDefaultColor;
|
||||
nscolor mFocusBackgroundColor = mDefaultBackgroundColor;
|
||||
|
||||
bool mIsChrome = false;
|
||||
bool mUseAccessibilityTheme = false;
|
||||
|
||||
bool mUnderlineLinks = true;
|
||||
bool mUseFocusColors = false;
|
||||
uint8_t mFocusRingWidth = 1;
|
||||
|
@ -63,7 +66,6 @@ struct PreferenceSheet {
|
|||
}
|
||||
|
||||
static bool ShouldUseChromePrefs(const dom::Document&);
|
||||
static bool UseAccessibilityTheme(bool aIsChrome);
|
||||
static const Prefs& PrefsFor(const dom::Document& aDocument) {
|
||||
return ShouldUseChromePrefs(aDocument) ? ChromePrefs() : ContentPrefs();
|
||||
}
|
||||
|
|
|
@ -836,11 +836,10 @@ ComputedStyleStrong Servo_ComputedValues_ResolveXULTreePseudoStyle(
|
|||
void Servo_SetExplicitStyle(RawGeckoElementBorrowed element,
|
||||
ComputedStyleBorrowed primary_style);
|
||||
|
||||
bool Servo_HasAuthorSpecifiedRules(ComputedStyleBorrowed style,
|
||||
bool Servo_HasAuthorSpecifiedRules(RawServoStyleSetBorrowed set,
|
||||
ComputedStyleBorrowed style,
|
||||
RawGeckoElementBorrowed element,
|
||||
mozilla::PseudoStyleType pseudo_type,
|
||||
uint32_t rule_type_mask,
|
||||
bool author_colors_allowed);
|
||||
uint32_t rule_type_mask);
|
||||
|
||||
// Resolves style for an element or pseudo-element without processing pending
|
||||
// restyles first. The Element and its ancestors may be unstyled, have pending
|
||||
|
|
|
@ -581,6 +581,14 @@ VARCACHE_PREF(
|
|||
bool, true
|
||||
)
|
||||
|
||||
// 0 = default: always, except in high contrast mode
|
||||
// 1 = always
|
||||
// 2 = never
|
||||
VARCACHE_PREF(
|
||||
"browser.display.document_color_use",
|
||||
browser_display_document_color_use,
|
||||
uint32_t, 0
|
||||
)
|
||||
VARCACHE_PREF(
|
||||
"browser.display.use_focus_colors",
|
||||
browser_display_use_focus_colors,
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
use crate::context::QuirksMode;
|
||||
use crate::dom::TElement;
|
||||
use crate::gecko_bindings::bindings::{self, RawServoStyleSet};
|
||||
use crate::gecko_bindings::structs::{RawGeckoPresContextBorrowed, ServoStyleSetSizes};
|
||||
use crate::gecko_bindings::structs::{self, ServoStyleSetSizes};
|
||||
use crate::gecko_bindings::structs::{StyleSheet as DomStyleSheet, StyleSheetInfo};
|
||||
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasBoxFFI, HasFFI, HasSimpleFFI};
|
||||
use crate::invalidation::media_queries::{MediaListKey, ToMediaListKey};
|
||||
|
@ -142,9 +142,9 @@ pub struct PerDocumentStyleDataImpl {
|
|||
pub struct PerDocumentStyleData(AtomicRefCell<PerDocumentStyleDataImpl>);
|
||||
|
||||
impl PerDocumentStyleData {
|
||||
/// Create a dummy `PerDocumentStyleData`.
|
||||
pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self {
|
||||
let device = Device::new(pres_context);
|
||||
/// Create a `PerDocumentStyleData`.
|
||||
pub fn new(document: *const structs::Document) -> Self {
|
||||
let device = Device::new(document);
|
||||
|
||||
// FIXME(emilio, tlin): How is this supposed to work with XBL? This is
|
||||
// right now not always honored, see bug 1405543...
|
||||
|
|
|
@ -17,13 +17,14 @@ use app_units::Au;
|
|||
use euclid::Size2D;
|
||||
|
||||
fn viewport_size(device: &Device) -> Size2D<Au> {
|
||||
let pc = device.pres_context();
|
||||
if let Some(pc) = device.pres_context() {
|
||||
if pc.mIsRootPaginatedDocument() != 0 {
|
||||
// We want the page size, including unprintable areas and margins.
|
||||
// FIXME(emilio, bug 1414600): Not quite!
|
||||
let area = &pc.mPageSize;
|
||||
return Size2D::new(Au(area.width), Au(area.height));
|
||||
}
|
||||
}
|
||||
device.au_viewport_size()
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ use crate::custom_properties::CssEnvironment;
|
|||
use crate::gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
|
||||
use crate::gecko_bindings::bindings;
|
||||
use crate::gecko_bindings::structs;
|
||||
use crate::gecko_bindings::structs::{nsPresContext, RawGeckoPresContextBorrowed};
|
||||
use crate::media_queries::MediaType;
|
||||
use crate::properties::ComputedValues;
|
||||
use crate::string_cache::Atom;
|
||||
|
@ -28,10 +27,9 @@ use style_traits::{CSSPixel, DevicePixel};
|
|||
/// The `Device` in Gecko wraps a pres context, has a default values computed,
|
||||
/// and contains all the viewport rule state.
|
||||
pub struct Device {
|
||||
/// NB: The pres context lifetime is tied to the styleset, who owns the
|
||||
/// stylist, and thus the `Device`, so having a raw pres context pointer
|
||||
/// here is fine.
|
||||
pres_context: RawGeckoPresContextBorrowed,
|
||||
/// NB: The document owns the styleset, who owns the stylist, and thus the
|
||||
/// `Device`, so having a raw document pointer here is fine.
|
||||
document: *const structs::Document,
|
||||
default_values: Arc<ComputedValues>,
|
||||
/// The font size of the root element
|
||||
/// This is set when computing the style of the root
|
||||
|
@ -81,12 +79,12 @@ unsafe impl Send for Device {}
|
|||
|
||||
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 };
|
||||
pub fn new(document: *const structs::Document) -> Self {
|
||||
assert!(!document.is_null());
|
||||
let doc = unsafe { &*document };
|
||||
let prefs = unsafe { &*bindings::Gecko_GetPrefSheetPrefs(doc) };
|
||||
Device {
|
||||
pres_context,
|
||||
document,
|
||||
default_values: ComputedValues::default_values(doc),
|
||||
// FIXME(bz): Seems dubious?
|
||||
root_font_size: AtomicIsize::new(FontSize::medium().size().0 as isize),
|
||||
|
@ -112,9 +110,14 @@ impl Device {
|
|||
/// Whether any animation name may be referenced from the style of any
|
||||
/// element.
|
||||
pub fn animation_name_may_be_referenced(&self, name: &KeyframesName) -> bool {
|
||||
let pc = match self.pres_context() {
|
||||
Some(pc) => pc,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
unsafe {
|
||||
bindings::Gecko_AnimationNameMayBeReferencedFromStyle(
|
||||
self.pres_context(),
|
||||
pc,
|
||||
name.as_atom().as_ptr(),
|
||||
)
|
||||
}
|
||||
|
@ -156,16 +159,18 @@ impl Device {
|
|||
convert_nscolor_to_rgba(self.body_text_color.load(Ordering::Relaxed) as u32)
|
||||
}
|
||||
|
||||
/// Gets the pres context associated with this document.
|
||||
#[inline]
|
||||
pub fn pres_context(&self) -> &nsPresContext {
|
||||
unsafe { &*self.pres_context }
|
||||
}
|
||||
|
||||
/// Gets the document pointer.
|
||||
#[inline]
|
||||
pub fn document(&self) -> &structs::Document {
|
||||
unsafe { &*self.pres_context().mDocument.mRawPtr }
|
||||
unsafe { &*self.document }
|
||||
}
|
||||
|
||||
/// Gets the pres context associated with this document.
|
||||
#[inline]
|
||||
pub fn pres_context(&self) -> Option<&structs::nsPresContext> {
|
||||
unsafe {
|
||||
self.document().mPresShell.as_ref()?.mPresContext.mRawPtr.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the preference stylesheet prefs for our document.
|
||||
|
@ -201,13 +206,17 @@ impl Device {
|
|||
|
||||
/// Returns the current media type of the device.
|
||||
pub fn media_type(&self) -> MediaType {
|
||||
let pc = match self.pres_context() {
|
||||
Some(pc) => pc,
|
||||
None => return MediaType::screen(),
|
||||
};
|
||||
|
||||
// Gecko allows emulating random media with mIsEmulatingMedia and
|
||||
// mMediaEmulated.
|
||||
let context = self.pres_context();
|
||||
let medium_to_use = if context.mIsEmulatingMedia() != 0 {
|
||||
context.mMediaEmulated.mRawPtr
|
||||
let medium_to_use = if pc.mIsEmulatingMedia() != 0 {
|
||||
pc.mMediaEmulated.mRawPtr
|
||||
} else {
|
||||
context.mMedium
|
||||
pc.mMedium
|
||||
};
|
||||
|
||||
MediaType(CustomIdent(unsafe { Atom::from_raw(medium_to_use) }))
|
||||
|
@ -215,7 +224,11 @@ impl Device {
|
|||
|
||||
/// Returns the current viewport size in app units.
|
||||
pub fn au_viewport_size(&self) -> Size2D<Au> {
|
||||
let area = &self.pres_context().mVisibleArea;
|
||||
let pc = match self.pres_context() {
|
||||
Some(pc) => pc,
|
||||
None => return Size2D::new(Au(0), Au(0)),
|
||||
};
|
||||
let area = &pc.mVisibleArea;
|
||||
Size2D::new(Au(area.width), Au(area.height))
|
||||
}
|
||||
|
||||
|
@ -233,18 +246,37 @@ impl Device {
|
|||
|
||||
/// Returns the device pixel ratio.
|
||||
pub fn device_pixel_ratio(&self) -> TypedScale<f32, CSSPixel, DevicePixel> {
|
||||
let override_dppx = self.pres_context().mOverrideDPPX;
|
||||
let pc = match self.pres_context() {
|
||||
Some(pc) => pc,
|
||||
None => return TypedScale::new(1.),
|
||||
};
|
||||
|
||||
let override_dppx = pc.mOverrideDPPX;
|
||||
if override_dppx > 0.0 {
|
||||
return TypedScale::new(override_dppx);
|
||||
}
|
||||
let au_per_dpx = self.pres_context().mCurAppUnitsPerDevPixel as f32;
|
||||
|
||||
let au_per_dpx = pc.mCurAppUnitsPerDevPixel as f32;
|
||||
let au_per_px = AU_PER_PX as f32;
|
||||
TypedScale::new(au_per_px / au_per_dpx)
|
||||
}
|
||||
|
||||
/// Returns whether document colors are enabled.
|
||||
#[inline]
|
||||
pub fn use_document_colors(&self) -> bool {
|
||||
self.pres_context().mUseDocumentColors() != 0
|
||||
let doc = self.document();
|
||||
if doc.mIsBeingUsedAsImage() {
|
||||
return true;
|
||||
}
|
||||
let document_color_use = unsafe {
|
||||
structs::StaticPrefs_sVarCache_browser_display_document_color_use
|
||||
};
|
||||
let prefs = self.pref_sheet_prefs();
|
||||
match document_color_use {
|
||||
1 => true,
|
||||
2 => prefs.mIsChrome,
|
||||
_ => !prefs.mUseAccessibilityTheme,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the default background color.
|
||||
|
@ -252,15 +284,25 @@ impl Device {
|
|||
convert_nscolor_to_rgba(self.pref_sheet_prefs().mDefaultBackgroundColor)
|
||||
}
|
||||
|
||||
/// Returns the current effective text zoom.
|
||||
#[inline]
|
||||
fn effective_text_zoom(&self) -> f32 {
|
||||
let pc = match self.pres_context() {
|
||||
Some(pc) => pc,
|
||||
None => return 1.,
|
||||
};
|
||||
pc.mEffectiveTextZoom
|
||||
}
|
||||
|
||||
/// Applies text zoom to a font-size or line-height value (see nsStyleFont::ZoomText).
|
||||
#[inline]
|
||||
pub fn zoom_text(&self, size: Au) -> Au {
|
||||
size.scale_by(self.pres_context().mEffectiveTextZoom)
|
||||
size.scale_by(self.effective_text_zoom())
|
||||
}
|
||||
|
||||
/// Un-apply text zoom.
|
||||
#[inline]
|
||||
pub fn unzoom_text(&self, size: Au) -> Au {
|
||||
size.scale_by(1. / self.pres_context().mEffectiveTextZoom)
|
||||
size.scale_by(1. / self.effective_text_zoom())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1044,9 +1044,13 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
|
|||
device: &Device,
|
||||
) -> FontMetricsQueryResult {
|
||||
use crate::gecko_bindings::bindings::Gecko_GetFontMetrics;
|
||||
let pc = match device.pres_context() {
|
||||
Some(pc) => pc,
|
||||
None => return FontMetricsQueryResult::NotAvailable,
|
||||
};
|
||||
let gecko_metrics = unsafe {
|
||||
Gecko_GetFontMetrics(
|
||||
device.pres_context(),
|
||||
pc,
|
||||
wm.is_vertical() && !wm.is_sideways(),
|
||||
font.gecko(),
|
||||
font_size.0,
|
||||
|
|
|
@ -3349,18 +3349,20 @@ pub extern "C" fn Servo_SetExplicitStyle(
|
|||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_HasAuthorSpecifiedRules(
|
||||
raw_data: RawServoStyleSetBorrowed,
|
||||
style: ComputedStyleBorrowed,
|
||||
element: RawGeckoElementBorrowed,
|
||||
pseudo_type: PseudoStyleType,
|
||||
rule_type_mask: u32,
|
||||
author_colors_allowed: bool,
|
||||
) -> bool {
|
||||
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let element = GeckoElement(element);
|
||||
let pseudo = PseudoElement::from_pseudo_type(pseudo_type);
|
||||
|
||||
let guard = (*GLOBAL_STYLE_DATA).shared_lock.read();
|
||||
let guards = StylesheetGuards::same(&guard);
|
||||
|
||||
let pseudo = style.pseudo();
|
||||
let author_colors_allowed = data.stylist.device().use_document_colors();
|
||||
|
||||
style.rules().has_author_specified_rules(
|
||||
element,
|
||||
pseudo,
|
||||
|
@ -3576,7 +3578,8 @@ pub extern "C" fn Servo_ComputedValues_GetStyleRuleList(
|
|||
pub extern "C" fn Servo_StyleSet_Init(
|
||||
pres_context: RawGeckoPresContextBorrowed,
|
||||
) -> *mut RawServoStyleSet {
|
||||
let data = Box::new(PerDocumentStyleData::new(pres_context));
|
||||
let doc = pres_context.mDocument.mRawPtr;
|
||||
let data = Box::new(PerDocumentStyleData::new(doc));
|
||||
Box::into_raw(data) as *mut RawServoStyleSet
|
||||
}
|
||||
|
||||
|
@ -3594,9 +3597,8 @@ pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) {
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Servo_StyleSet_CompatModeChanged(raw_data: RawServoStyleSetBorrowed) {
|
||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||
let doc = &*data.stylist.device().pres_context().mDocument.mRawPtr;
|
||||
data.stylist
|
||||
.set_quirks_mode(QuirksMode::from(doc.mCompatMode));
|
||||
let quirks_mode = data.stylist.device().document().mCompatMode;
|
||||
data.stylist.set_quirks_mode(quirks_mode.into());
|
||||
}
|
||||
|
||||
fn parse_property_into(
|
||||
|
|
Загрузка…
Ссылка в новой задаче