Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add paint metrics to Performance Timeline API
- Loading branch information
Showing
15 changed files
with
152 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* 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/. */ | ||
|
||
use dom::bindings::codegen::Bindings::PerformancePaintTimingBinding; | ||
use dom::bindings::js::Root; | ||
use dom::bindings::reflector::reflect_dom_object; | ||
use dom::bindings::str::DOMString; | ||
use dom::globalscope::GlobalScope; | ||
use dom::performanceentry::PerformanceEntry; | ||
use dom_struct::dom_struct; | ||
use script_traits::PaintMetricType; | ||
|
||
#[dom_struct] | ||
pub struct PerformancePaintTiming { | ||
entry: PerformanceEntry, | ||
} | ||
|
||
impl PerformancePaintTiming { | ||
fn new_inherited(metric_type: PaintMetricType, start_time: f64) | ||
-> PerformancePaintTiming { | ||
let name = match metric_type { | ||
PaintMetricType::FirstPaint => DOMString::from("first-paint"), | ||
PaintMetricType::FirstContentfulPaint => DOMString::from("first-contentful-paint"), | ||
}; | ||
PerformancePaintTiming { | ||
entry: PerformanceEntry::new_inherited(name, | ||
DOMString::from("paint"), | ||
start_time, | ||
0.) | ||
} | ||
} | ||
|
||
#[allow(unrooted_must_root)] | ||
pub fn new(global: &GlobalScope, | ||
metric_type: PaintMetricType, | ||
start_time: f64) -> Root<PerformancePaintTiming> { | ||
let entry = PerformancePaintTiming::new_inherited(metric_type, start_time); | ||
reflect_dom_object(box entry, global, PerformancePaintTimingBinding::Wrap) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
components/script/dom/webidls/PerformancePaintTiming.webidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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/. | ||
* | ||
* The origin of this IDL file is | ||
* https://wicg.github.io/paint-timing/#sec-PerformancePaintTiming | ||
*/ | ||
|
||
[Exposed=(Window,Worker)] | ||
interface PerformancePaintTiming : PerformanceEntry { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
<title>Paint Timing API</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
var t = async_test("Performance entries observer"); | ||
var observer = new PerformanceObserver(t.step_func_done(list => { | ||
list.getEntries().forEach((entry, i) => { | ||
var name = i == 0 ? "first-paint" : "first-contentful-paint"; | ||
assert_equals(entry.name, name, "Name is " + name); | ||
assert_equals(entry.entryType, "paint", "Entry type is paint"); | ||
assert_true(entry.startTime > 0, "Start time is > 0"); | ||
assert_equals(entry.duration, 0, "Duration is 0"); | ||
}); | ||
})); | ||
observer.observe({entryTypes: ['paint']}); | ||
</script> |