Files
servo/components/script/dom/visibilitystateentry.rs
Euclid Ye cae0752676 cargo: Rename workspace-local library starting with b to servo_* (#43552)
Follow up of #43526. This addresses Nico's comment:
https://github.com/servo/servo/pull/43526#issuecomment-4104953308

- `bluetooth_traits` -> `servo_bluetooth_traits`
- `base` -> `servo_base`
- `bluetooth` -> `servo_bluetooth`
- `background_hang_monitor` -> `servo_background_hang_monitor`

Testing: This should not change any behaviour.

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2026-03-23 08:26:49 +00:00

81 lines
2.7 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 https://mozilla.org/MPL/2.0/. */
use std::ops::Deref;
use dom_struct::dom_struct;
use servo_base::cross_process_instant::CrossProcessInstant;
use time::Duration;
use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentVisibilityState;
use crate::dom::bindings::codegen::Bindings::PerformanceEntryBinding::PerformanceEntryMethods;
use crate::dom::bindings::codegen::Bindings::VisibilityStateEntryBinding::VisibilityStateEntryMethods;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::performance::performanceentry::{EntryType, PerformanceEntry};
use crate::script_runtime::CanGc;
#[dom_struct]
pub(crate) struct VisibilityStateEntry {
entry: PerformanceEntry,
}
impl VisibilityStateEntry {
fn new_inherited(
state: DocumentVisibilityState,
timestamp: CrossProcessInstant,
) -> VisibilityStateEntry {
let name = match state {
DocumentVisibilityState::Visible => DOMString::from("visible"),
DocumentVisibilityState::Hidden => DOMString::from("hidden"),
};
VisibilityStateEntry {
entry: PerformanceEntry::new_inherited(
name,
EntryType::VisibilityState,
Some(timestamp),
Duration::ZERO,
),
}
}
pub(crate) fn new(
global: &GlobalScope,
state: DocumentVisibilityState,
timestamp: CrossProcessInstant,
can_gc: CanGc,
) -> DomRoot<VisibilityStateEntry> {
reflect_dom_object(
Box::new(VisibilityStateEntry::new_inherited(state, timestamp)),
global,
can_gc,
)
}
}
impl VisibilityStateEntryMethods<crate::DomTypeHolder> for VisibilityStateEntry {
/// <https://html.spec.whatwg.org/multipage/#visibilitystateentry-name>
fn Name(&self) -> DOMString {
self.entry.Name()
}
/// <https://html.spec.whatwg.org/multipage/#visibilitystateentry-entrytype>
fn EntryType(&self) -> DOMString {
self.entry.EntryType()
}
/// <https://html.spec.whatwg.org/multipage/#visibilitystateentry-starttime>
fn StartTime(&self) -> Finite<f64> {
self.entry.StartTime()
}
/// <https://html.spec.whatwg.org/multipage/#visibilitystateentry-duration>
fn Duration(&self) -> u32 {
*self.entry.Duration().deref() as u32
}
}