Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Recascade the document instead of using the dirty_on_viewport_size_change bit #18268

Merged
merged 4 commits into from Aug 29, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -38,7 +38,7 @@ use layout::data::StyleAndLayoutData;
use layout::wrapper::GetRawData;
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use range::Range;
use script::layout_exports::{CAN_BE_FRAGMENTED, DIRTY_ON_VIEWPORT_SIZE_CHANGE, HAS_DIRTY_DESCENDANTS, IS_IN_DOC};
use script::layout_exports::{CAN_BE_FRAGMENTED, HAS_DIRTY_DESCENDANTS, IS_IN_DOC};
use script::layout_exports::{CharacterDataTypeId, ElementTypeId, HTMLElementTypeId, NodeTypeId};
use script::layout_exports::{Document, Element, Node, Text};
use script::layout_exports::{HANDLED_SNAPSHOT, HAS_SNAPSHOT};
@@ -205,14 +205,6 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
as_element(self.node)
}

fn needs_dirty_on_viewport_size_changed(&self) -> bool {
unsafe { self.node.get_flag(DIRTY_ON_VIEWPORT_SIZE_CHANGE) }
}

unsafe fn set_dirty_on_viewport_size_changed(&self) {
self.node.set_flag(DIRTY_ON_VIEWPORT_SIZE_CHANGE, true);
}

fn can_be_fragmented(&self) -> bool {
unsafe { self.node.get_flag(CAN_BE_FRAGMENTED) }
}
@@ -1143,6 +1143,7 @@ impl LayoutThread {
let document_shared_lock = document.style_shared_lock();
self.document_shared_lock = Some(document_shared_lock.clone());
let author_guard = document_shared_lock.read();
let had_used_viewport_units = self.stylist.device().used_viewport_units();
let device = Device::new(MediaType::screen(), initial_viewport, device_pixel_ratio);
let sheet_origins_affected_by_device_change =
self.stylist.set_device(device, &author_guard);
@@ -1165,28 +1166,9 @@ impl LayoutThread {
.send(ConstellationMsg::ViewportConstrained(self.id, constraints.clone()))
.unwrap();
}
if self.stylist.iter_stylesheets().any(|sheet| sheet.0.dirty_on_viewport_size_change()) {
let mut iter = element.as_node().traverse_preorder();

let mut next = iter.next();
while let Some(node) = next {
if node.needs_dirty_on_viewport_size_changed() {
let el = node.as_element().unwrap();
if let Some(mut d) = element.mutate_data() {
if d.has_styles() {
// FIXME(emilio): This only needs to recascade,
// afaict.
d.restyle.hint.insert(RestyleHint::restyle_subtree());
}
}
if let Some(p) = el.parent_element() {
unsafe { p.note_dirty_descendant() };
}

next = iter.next_skipping_children();
} else {
next = iter.next();
}
if had_used_viewport_units {
if let Some(mut data) = element.mutate_data() {
data.restyle.hint.insert(RestyleHint::recascade_subtree());
}
}
}
@@ -109,10 +109,6 @@ impl HTMLMetaElement {
namespaces: Default::default(),
quirks_mode: document.quirks_mode(),
url_data: RwLock::new(window_from_node(self).get_url()),
// Viewport constraints are always recomputed on
// resize; they don't need to force all styles to be
// recomputed.
dirty_on_viewport_size_change: AtomicBool::new(false),
source_map_url: RwLock::new(None),
},
media: Arc::new(shared_lock.wrap(MediaList::empty())),
@@ -169,8 +169,7 @@ bitflags! {
/// Whether any ancestor is a fragmentation container
const CAN_BE_FRAGMENTED = 1 << 4,

#[doc = "Specifies whether this node needs to be dirted when viewport size changed."]
const DIRTY_ON_VIEWPORT_SIZE_CHANGE = 1 << 5,
// There's a free bit here.

#[doc = "Specifies whether the parser has set an associated form owner for \
this element. Only applicable for form-associatable elements."]
@@ -142,7 +142,7 @@ pub mod layout_exports {
pub use dom::characterdata::LayoutCharacterDataHelpers;
pub use dom::document::{Document, LayoutDocumentHelpers, PendingRestyle};
pub use dom::element::{Element, LayoutElementHelpers, RawLayoutElementHelpers};
pub use dom::node::{CAN_BE_FRAGMENTED, DIRTY_ON_VIEWPORT_SIZE_CHANGE, HAS_DIRTY_DESCENDANTS, IS_IN_DOC};
pub use dom::node::{CAN_BE_FRAGMENTED, HAS_DIRTY_DESCENDANTS, IS_IN_DOC};
pub use dom::node::{HANDLED_SNAPSHOT, HAS_SNAPSHOT};
pub use dom::node::{LayoutNodeHelpers, Node};
pub use dom::text::Text;
@@ -289,7 +289,6 @@ impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> {
rules: CssRules::new(Vec::new(), lock),
origin: context.stylesheet_origin,
url_data: RwLock::new(context.url_data.clone()),
dirty_on_viewport_size_change: AtomicBool::new(false),
quirks_mode: context.quirks_mode,
namespaces: RwLock::new(Namespaces::default()),
source_map_url: RwLock::new(None),
@@ -502,7 +502,6 @@ fn compute_style_for_animation_step(context: &SharedStyleContext,
Some(previous_style),
Some(previous_style),
Some(previous_style),
/* cascade_info = */ None,
/* visited_style = */ None,
font_metrics_provider,
CascadeFlags::empty(),

This file was deleted.

@@ -138,12 +138,6 @@ pub trait TNode : Sized + Copy + Clone + Debug + NodeInfo {
/// Get this node as an element, if it's one.
fn as_element(&self) -> Option<Self::ConcreteElement>;

/// Whether this node needs to be laid out on viewport size change.
fn needs_dirty_on_viewport_size_changed(&self) -> bool;

/// Mark this node as needing layout on viewport size change.
unsafe fn set_dirty_on_viewport_size_changed(&self);

/// Whether this node can be fragmented. This is used for multicol, and only
/// for Servo.
fn can_be_fragmented(&self) -> bool;
@@ -156,14 +156,20 @@ impl Device {

/// Returns the current viewport size in app units.
pub fn au_viewport_size(&self) -> Size2D<Au> {
self.used_viewport_size.store(true, Ordering::Relaxed);
unsafe {
// TODO(emilio): Need to take into account scrollbars.
let area = &self.pres_context().mVisibleArea;
Size2D::new(Au(area.width), Au(area.height))
}
}

/// Returns the current viewport size in app units, recording that it's been
/// used for viewport unit resolution.
pub fn au_viewport_size_for_viewport_unit_resolution(&self) -> Size2D<Au> {
self.used_viewport_size.store(true, Ordering::Relaxed);
self.au_viewport_size()
}

/// Returns whether we ever looked up the viewport size of the Device.
pub fn used_viewport_size(&self) -> bool {
self.used_viewport_size.load(Ordering::Relaxed)
@@ -318,17 +318,6 @@ impl<'ln> TNode for GeckoNode<'ln> {
fn is_in_doc(&self) -> bool {
unsafe { bindings::Gecko_IsInDocument(self.0) }
}

fn needs_dirty_on_viewport_size_changed(&self) -> bool {
// Gecko's node doesn't have the DIRTY_ON_VIEWPORT_SIZE_CHANGE flag,
// so we force them to be dirtied on viewport size change, regardless if
// they use viewport percentage size or not.
// TODO(shinglyu): implement this in Gecko: https://github.com/servo/servo/pull/11890
true
}

// TODO(shinglyu): implement this in Gecko: https://github.com/servo/servo/pull/11890
unsafe fn set_dirty_on_viewport_size_changed(&self) {}
}

/// A wrapper on top of two kind of iterators, depending on the parent being
@@ -99,7 +99,6 @@ pub mod applicable_declarations;
pub mod bezier;
pub mod bloom;
pub mod cache;
pub mod cascade_info;
pub mod context;
pub mod counter_style;
pub mod custom_properties;
@@ -275,8 +275,6 @@
#[allow(unused_imports)]
use values::{Auto, Either, None_, Normal};
#[allow(unused_imports)]
use cascade_info::CascadeInfo;
#[allow(unused_imports)]
use error_reporting::ParseErrorReporter;
#[allow(unused_imports)]
use properties::longhands;
@@ -303,7 +301,6 @@
pub fn cascade_property(
declaration: &PropertyDeclaration,
context: &mut computed::Context,
cascade_info: &mut Option<<&mut CascadeInfo>,
) {
let value = match *declaration {
PropertyDeclaration::${property.camel_case}(ref value) => {
@@ -320,9 +317,6 @@
};

% if not property.derived_from:
if let Some(ref mut cascade_info) = *cascade_info {
cascade_info.on_cascade_property(&declaration, &value);
}
match value {
DeclaredValue::Value(ref specified_value) => {
% if property.ident in SYSTEM_FONT_LONGHANDS and product == "gecko":
@@ -43,7 +43,6 @@ use stylesheets::{CssRuleType, MallocSizeOf, MallocSizeOfFn, Origin, UrlExtraDat
use values::generics::text::LineHeight;
use values::computed;
use values::computed::NonNegativeAu;
use cascade_info::CascadeInfo;
use rule_tree::{CascadeLevel, StrongRuleNode};
use self::computed_value_flags::ComputedValueFlags;
use style_adjuster::StyleAdjuster;
@@ -2953,9 +2952,10 @@ mod lazy_static_module {

/// A per-longhand function that performs the CSS cascade for that longhand.
pub type CascadePropertyFn =
extern "Rust" fn(declaration: &PropertyDeclaration,
context: &mut computed::Context,
cascade_info: &mut Option<<&mut CascadeInfo>);
extern "Rust" fn(
declaration: &PropertyDeclaration,
context: &mut computed::Context,
);

/// A per-longhand array of functions to perform the CSS cascade on each of
/// them, effectively doing virtual dispatch.
@@ -3030,7 +3030,6 @@ pub fn cascade(
parent_style_ignoring_first_line: Option<<&ComputedValues>,
layout_parent_style: Option<<&ComputedValues>,
visited_style: Option<Arc<ComputedValues>>,
cascade_info: Option<<&mut CascadeInfo>,
font_metrics_provider: &FontMetricsProvider,
flags: CascadeFlags,
quirks_mode: QuirksMode
@@ -3089,7 +3088,6 @@ pub fn cascade(
parent_style_ignoring_first_line,
layout_parent_style,
visited_style,
cascade_info,
font_metrics_provider,
flags,
quirks_mode,
@@ -3108,7 +3106,6 @@ pub fn apply_declarations<'a, F, I>(
parent_style_ignoring_first_line: Option<<&ComputedValues>,
layout_parent_style: Option<<&ComputedValues>,
visited_style: Option<Arc<ComputedValues>>,
mut cascade_info: Option<<&mut CascadeInfo>,
font_metrics_provider: &FontMetricsProvider,
flags: CascadeFlags,
quirks_mode: QuirksMode,
@@ -3280,9 +3277,7 @@ where
% endif

let discriminant = longhand_id as usize;
(CASCADE_PROPERTY[discriminant])(&*declaration,
&mut context,
&mut cascade_info);
(CASCADE_PROPERTY[discriminant])(&*declaration, &mut context);
}
% if category_to_cascade_now == "early":
let writing_mode = get_writing_mode(context.builder.get_inheritedbox());
@@ -3363,9 +3358,7 @@ where
if let Some(ref declaration) = font_family {

let discriminant = LonghandId::FontFamily as usize;
(CASCADE_PROPERTY[discriminant])(declaration,
&mut context,
&mut cascade_info);
(CASCADE_PROPERTY[discriminant])(declaration, &mut context);
% if product == "gecko":
let device = context.builder.device;
if let PropertyDeclaration::FontFamily(ref val) = **declaration {
@@ -3383,9 +3376,7 @@ where

if let Some(ref declaration) = font_size {
let discriminant = LonghandId::FontSize as usize;
(CASCADE_PROPERTY[discriminant])(declaration,
&mut context,
&mut cascade_info);
(CASCADE_PROPERTY[discriminant])(declaration, &mut context);
% if product == "gecko":
// Font size must be explicitly inherited to handle lang changes and
// scriptlevel changes.
@@ -3397,9 +3388,7 @@ where
let size = PropertyDeclaration::CSSWideKeyword(
LonghandId::FontSize, CSSWideKeyword::Inherit);

(CASCADE_PROPERTY[discriminant])(&size,
&mut context,
&mut cascade_info);
(CASCADE_PROPERTY[discriminant])(&size, &mut context);
% endif
}
% endif
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.