mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
style: Document cascade_info
.
This commit is contained in:
parent
7bf80e5d50
commit
4108ff8383
1 changed files with 19 additions and 2 deletions
|
@ -1,6 +1,11 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! A structure to collect information about the cascade.
|
||||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use dom::TNode;
|
||||
use properties::{DeclaredValue, PropertyDeclaration};
|
||||
use values::HasViewportPercentage;
|
||||
|
@ -12,12 +17,17 @@ use values::HasViewportPercentage;
|
|||
/// non-inherited property is explicitly inherited, in order to cut-off the
|
||||
/// traversal.
|
||||
pub struct CascadeInfo {
|
||||
/// Whether we've seen viewport units so far.
|
||||
pub saw_viewport_units: bool,
|
||||
/// Whether the cascade has been marked as finished. This is a debug-only
|
||||
/// flag to ensure `finish` is called, given it's optional to not pass a
|
||||
/// `CascadeInfo`.
|
||||
#[cfg(debug_assertions)]
|
||||
finished: bool,
|
||||
}
|
||||
|
||||
impl CascadeInfo {
|
||||
/// Construct a new `CascadeInfo`.
|
||||
#[cfg(debug_assertions)]
|
||||
pub fn new() -> Self {
|
||||
CascadeInfo {
|
||||
|
@ -26,6 +36,7 @@ impl CascadeInfo {
|
|||
}
|
||||
}
|
||||
|
||||
/// Construct a new `CascadeInfo`.
|
||||
#[cfg(not(debug_assertions))]
|
||||
pub fn new() -> Self {
|
||||
CascadeInfo {
|
||||
|
@ -40,7 +51,7 @@ impl CascadeInfo {
|
|||
pub fn on_cascade_property<T>(&mut self,
|
||||
_property_declaration: &PropertyDeclaration,
|
||||
value: &DeclaredValue<T>)
|
||||
where T: HasViewportPercentage
|
||||
where T: HasViewportPercentage,
|
||||
{
|
||||
// TODO: we can be smarter and keep a property bitfield to keep track of
|
||||
// the last applying rule.
|
||||
|
@ -57,6 +68,11 @@ impl CascadeInfo {
|
|||
#[cfg(not(debug_assertions))]
|
||||
fn mark_as_finished_if_appropriate(&mut self) {}
|
||||
|
||||
/// Called when the cascade is finished, in order to use the information
|
||||
/// we've collected.
|
||||
///
|
||||
/// Currently used for styling to mark a node as needing restyling when the
|
||||
/// viewport size changes.
|
||||
#[allow(unsafe_code)]
|
||||
pub fn finish<N: TNode>(mut self, node: &N) {
|
||||
self.mark_as_finished_if_appropriate();
|
||||
|
@ -73,6 +89,7 @@ impl CascadeInfo {
|
|||
impl Drop for CascadeInfo {
|
||||
fn drop(&mut self) {
|
||||
debug_assert!(self.finished,
|
||||
"Didn't use the result of CascadeInfo, if you don't need it, consider passing None");
|
||||
"Didn't use the result of CascadeInfo, if you don't need \
|
||||
it, consider passing None");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue