mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #17447 - emilio:root-disconnected-subtree, r=heycam,Manishearth
style: Be more strict when setting the root font size. Before this commit, we assumed that if the element had no parent element, it was the root of the document, which is plain false, since we can arrive there from, let's say, getComputedStyle on a detached node. Bug: 1374062 Reviewed-By: heycam MozReview-Commit-ID: 65DxdzXgd0J <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17447) <!-- Reviewable:end -->
This commit is contained in:
commit
7d785e75cd
16 changed files with 78 additions and 59 deletions
|
@ -46,7 +46,7 @@ impl PerDocumentStyleData {
|
|||
pub fn new(pres_context: RawGeckoPresContextOwned) -> Self {
|
||||
let device = Device::new(pres_context);
|
||||
let quirks_mode = unsafe {
|
||||
(*(*device.pres_context).mDocument.raw::<nsIDocument>()).mCompatMode
|
||||
(*device.pres_context().mDocument.raw::<nsIDocument>()).mCompatMode
|
||||
};
|
||||
|
||||
PerDocumentStyleData(AtomicRefCell::new(PerDocumentStyleDataImpl {
|
||||
|
|
|
@ -14,7 +14,7 @@ use gecko_bindings::bindings;
|
|||
use gecko_bindings::structs::{nsCSSKeyword, nsCSSProps_KTableEntry, nsCSSValue, nsCSSUnit, nsStringBuffer};
|
||||
use gecko_bindings::structs::{nsMediaExpression_Range, nsMediaFeature};
|
||||
use gecko_bindings::structs::{nsMediaFeature_ValueType, nsMediaFeature_RangeType, nsMediaFeature_RequirementFlags};
|
||||
use gecko_bindings::structs::RawGeckoPresContextOwned;
|
||||
use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextOwned};
|
||||
use media_queries::MediaType;
|
||||
use parser::ParserContext;
|
||||
use properties::{ComputedValues, StyleBuilder};
|
||||
|
@ -36,7 +36,7 @@ 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.
|
||||
pub pres_context: RawGeckoPresContextOwned,
|
||||
pres_context: RawGeckoPresContextOwned,
|
||||
default_values: Arc<ComputedValues>,
|
||||
viewport_override: Option<ViewportConstraints>,
|
||||
/// The font size of the root element
|
||||
|
@ -105,11 +105,16 @@ impl Device {
|
|||
self.root_font_size.store(size.0 as isize, Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Gets the pres context associated with this document.
|
||||
pub fn pres_context(&self) -> &nsPresContext {
|
||||
unsafe { &*self.pres_context }
|
||||
}
|
||||
|
||||
/// Recreates the default computed values.
|
||||
pub fn reset_computed_values(&mut self) {
|
||||
// NB: A following stylesheet flush will populate this if appropriate.
|
||||
self.viewport_override = None;
|
||||
self.default_values = ComputedValues::default_values(unsafe { &*self.pres_context });
|
||||
self.default_values = ComputedValues::default_values(self.pres_context());
|
||||
self.used_root_font_size.store(false, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
|
@ -134,10 +139,10 @@ impl Device {
|
|||
// FIXME(emilio): Gecko allows emulating random media with
|
||||
// mIsEmulatingMedia / mMediaEmulated . Refactor both sides so that
|
||||
// is supported (probably just making MediaType an Atom).
|
||||
if (*self.pres_context).mMedium == atom!("screen").as_ptr() {
|
||||
if self.pres_context().mMedium == atom!("screen").as_ptr() {
|
||||
MediaType::Screen
|
||||
} else {
|
||||
debug_assert!((*self.pres_context).mMedium == atom!("print").as_ptr());
|
||||
debug_assert!(self.pres_context().mMedium == atom!("print").as_ptr());
|
||||
MediaType::Print
|
||||
}
|
||||
}
|
||||
|
@ -150,19 +155,19 @@ impl Device {
|
|||
Au::from_f32_px(v.size.height))
|
||||
}).unwrap_or_else(|| unsafe {
|
||||
// TODO(emilio): Need to take into account scrollbars.
|
||||
Size2D::new(Au((*self.pres_context).mVisibleArea.width),
|
||||
Au((*self.pres_context).mVisibleArea.height))
|
||||
let area = &self.pres_context().mVisibleArea;
|
||||
Size2D::new(Au(area.width), Au(area.height))
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns whether document colors are enabled.
|
||||
pub fn use_document_colors(&self) -> bool {
|
||||
unsafe { (*self.pres_context).mUseDocumentColors() != 0 }
|
||||
self.pres_context().mUseDocumentColors() != 0
|
||||
}
|
||||
|
||||
/// Returns the default background color.
|
||||
pub fn default_background_color(&self) -> RGBA {
|
||||
convert_nscolor_to_rgba(unsafe { (*self.pres_context).mBackgroundColor })
|
||||
convert_nscolor_to_rgba(self.pres_context().mBackgroundColor)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -401,7 +401,7 @@ impl CounterStyleOrNone {
|
|||
pub fn to_gecko_value(self, gecko_value: &mut CounterStylePtr, device: &Device) {
|
||||
use gecko_bindings::bindings::Gecko_SetCounterStyleToName as set_name;
|
||||
use gecko_bindings::bindings::Gecko_SetCounterStyleToSymbols as set_symbols;
|
||||
let pres_context = unsafe { &*device.pres_context };
|
||||
let pres_context = device.pres_context();
|
||||
match self {
|
||||
CounterStyleOrNone::None => unsafe {
|
||||
set_name(gecko_value, atom!("none").into_addrefed(), pres_context);
|
||||
|
|
|
@ -672,7 +672,7 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
|
|||
in_media_query: bool, device: &Device) -> FontMetricsQueryResult {
|
||||
use gecko_bindings::bindings::Gecko_GetFontMetrics;
|
||||
let gecko_metrics = unsafe {
|
||||
Gecko_GetFontMetrics(&*device.pres_context,
|
||||
Gecko_GetFontMetrics(device.pres_context(),
|
||||
wm.is_vertical() && !wm.is_sideways(),
|
||||
font.gecko(),
|
||||
font_size.0,
|
||||
|
@ -771,6 +771,11 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
unsafe { GeckoNode(&*(self.0 as *const _ as *const RawGeckoNode)) }
|
||||
}
|
||||
|
||||
fn owner_doc_matches_for_testing(&self, device: &Device) -> bool {
|
||||
self.as_node().owner_doc() as *const structs::nsIDocument ==
|
||||
device.pres_context().mDocument.raw::<structs::nsIDocument>()
|
||||
}
|
||||
|
||||
fn style_attribute(&self) -> Option<&Arc<Locked<PropertyDeclarationBlock>>> {
|
||||
if !self.may_have_style_attribute() {
|
||||
return None;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue