gecko-dev/servo/components/style/timer.rs
Bobby Holley b515de0c66 servo: Merge #20603 - Run rustfmt on selectors, servo_arc, and style (from bholley:rustfmt_style); r=Manishearth
Now that rustfmt is getting close to stable, and work on the style system has died down a bit, it seemed like an opportune time to auto-format the style crates.

The first commit disables import reordering, since tidy and rustfmt don't currently agree on the correct ordering. The second commit does a bunch of manual fixups such that the output of rustfmt passes tidy. The third commit runs rustfmt on the three aforementioned crate.

There are a few dozen warnings in the style crate about lines longer than 100 characters. It would be good to fix these, but I don't have time for that now.

Source-Repo: https://github.com/servo/servo
Source-Revision: 9a900ef019cd643bff961d7b20db6da69f3edb29

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 2b228d52a084bc832444ac686290840c4369f98d
2018-04-10 21:00:11 -04:00

64 lines
1.8 KiB
Rust

/* 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/. */
#![deny(missing_docs)]
//! A timer module, used to define a `Timer` type, that is controlled by script.
use time;
/// The `TimerMode` is used to determine what time should the `Timer` return.
#[derive(Clone, Debug)]
enum TimerMode {
/// The timer should return a fixed value.
Test(f64),
/// The timer should return the actual time.
Current,
}
/// A `Timer` struct that takes care of giving the current time for animations.
///
/// This is needed to be allowed to hook the time in the animations' test-mode.
#[derive(Clone, Debug)]
pub struct Timer {
mode: TimerMode,
}
impl Timer {
/// Creates a new "normal" timer, i.e., a "Current" mode timer.
#[inline]
pub fn new() -> Self {
Timer {
mode: TimerMode::Current,
}
}
/// Creates a new "test mode" timer, with initial time 0.
#[inline]
pub fn test_mode() -> Self {
Timer {
mode: TimerMode::Test(0.),
}
}
/// Returns the current time, at least from the caller's perspective. In
/// test mode returns whatever the value is.
pub fn seconds(&self) -> f64 {
match self.mode {
TimerMode::Test(test_value) => test_value,
TimerMode::Current => time::precise_time_s(),
}
}
/// Increments the current clock. Panics if the clock is not on test mode.
pub fn increment(&mut self, by: f64) {
match self.mode {
TimerMode::Test(ref mut val) => *val += by,
TimerMode::Current => {
panic!("Timer::increment called for a non-test mode timer. This is a bug.")
},
}
}
}