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
Layout viewer for layout 2020 #25803
Merged
+622
−43
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5cbe053
Add layout debugger support to layout_2020
ferjm cce74e8
Ignore layout debugger trace files
ferjm 84dd334
Display fragment tree on layout viewer
ferjm 67706f9
Add fragment debug id
ferjm aaa3cd9
Display fragment tree info on layout viewer
ferjm a042f85
Dump box tree state into json files and display it on layout 2020 viewer
ferjm c4276aa
Fix rebase issues and run Prettier on layout viewer code
ferjm f81a2f0
Show box tree node info and clean up unused code
ferjm c33a517
Keep layout viewer versions for both 2013 and 2020 engines
ferjm 5e76c93
Minor improvements to layout_debug and associated code
ferjm File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Some generated files are not rendered by default. Learn more.
Oops, something went wrong.
| @@ -4,8 +4,12 @@ | ||
|
|
||
| use crate::geom::flow_relative::{Rect, Sides, Vec2}; | ||
| use crate::geom::{PhysicalPoint, PhysicalRect}; | ||
| #[cfg(debug_assertions)] | ||
| use crate::layout_debug; | ||
| use gfx::text::glyph::GlyphStore; | ||
| use gfx_traits::print_tree::PrintTree; | ||
| #[cfg(not(debug_assertions))] | ||
| use serde::ser::{Serialize, Serializer}; | ||
| use servo_arc::Arc as ServoArc; | ||
| use std::sync::Arc; | ||
| use style::computed_values::overflow_x::T as ComputedOverflow; | ||
| @@ -16,15 +20,19 @@ use style::values::computed::Length; | ||
| use style::Zero; | ||
| use webrender_api::{FontInstanceKey, ImageKey}; | ||
|
|
||
| #[derive(Serialize)] | ||
| pub(crate) enum Fragment { | ||
| Box(BoxFragment), | ||
| Anonymous(AnonymousFragment), | ||
| Text(TextFragment), | ||
| Image(ImageFragment), | ||
| } | ||
|
|
||
| #[derive(Serialize)] | ||
| pub(crate) struct BoxFragment { | ||
| pub tag: OpaqueNode, | ||
| pub debug_id: DebugId, | ||
| #[serde(skip_serializing)] | ||
| pub style: ServoArc<ComputedValues>, | ||
| pub children: Vec<Fragment>, | ||
|
|
||
| @@ -43,20 +51,23 @@ pub(crate) struct BoxFragment { | ||
| pub scrollable_overflow_from_children: PhysicalRect<Length>, | ||
| } | ||
|
|
||
| #[derive(Serialize)] | ||
| pub(crate) struct CollapsedBlockMargins { | ||
| pub collapsed_through: bool, | ||
| pub start: CollapsedMargin, | ||
| pub end: CollapsedMargin, | ||
| } | ||
|
|
||
| #[derive(Clone, Copy)] | ||
| #[derive(Clone, Copy, Serialize)] | ||
| pub(crate) struct CollapsedMargin { | ||
| max_positive: Length, | ||
| min_negative: Length, | ||
| } | ||
|
|
||
| /// Can contain child fragments with relative coordinates, but does not contribute to painting itself. | ||
| #[derive(Serialize)] | ||
| pub(crate) struct AnonymousFragment { | ||
| pub debug_id: DebugId, | ||
| pub rect: Rect<Length>, | ||
| pub children: Vec<Fragment>, | ||
| pub mode: WritingMode, | ||
| @@ -65,18 +76,26 @@ pub(crate) struct AnonymousFragment { | ||
| pub scrollable_overflow: PhysicalRect<Length>, | ||
| } | ||
|
|
||
| #[derive(Serialize)] | ||
| pub(crate) struct TextFragment { | ||
| pub debug_id: DebugId, | ||
| pub tag: OpaqueNode, | ||
| #[serde(skip_serializing)] | ||
| pub parent_style: ServoArc<ComputedValues>, | ||
| pub rect: Rect<Length>, | ||
| pub ascent: Length, | ||
| #[serde(skip_serializing)] | ||
| pub font_key: FontInstanceKey, | ||
| pub glyphs: Vec<Arc<GlyphStore>>, | ||
| } | ||
|
|
||
| #[derive(Serialize)] | ||
| pub(crate) struct ImageFragment { | ||
| pub debug_id: DebugId, | ||
| #[serde(skip_serializing)] | ||
| pub style: ServoArc<ComputedValues>, | ||
| pub rect: Rect<Length>, | ||
| #[serde(skip_serializing)] | ||
| pub image_key: ImageKey, | ||
| } | ||
|
|
||
| @@ -119,6 +138,7 @@ impl Fragment { | ||
| impl AnonymousFragment { | ||
| pub fn no_op(mode: WritingMode) -> Self { | ||
| Self { | ||
| debug_id: DebugId::new(), | ||
| children: vec![], | ||
| rect: Rect::zero(), | ||
| mode, | ||
| @@ -136,6 +156,7 @@ impl AnonymousFragment { | ||
| ) | ||
| }); | ||
| AnonymousFragment { | ||
| debug_id: DebugId::new(), | ||
| rect, | ||
| children, | ||
| mode, | ||
| @@ -175,6 +196,7 @@ impl BoxFragment { | ||
| }); | ||
| BoxFragment { | ||
| tag, | ||
| debug_id: DebugId::new(), | ||
| style, | ||
| children, | ||
| content_rect, | ||
| @@ -342,3 +364,33 @@ impl CollapsedMargin { | ||
| self.max_positive + self.min_negative | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(debug_assertions))] | ||
| #[derive(Clone)] | ||
| pub struct DebugId; | ||
|
|
||
| #[cfg(debug_assertions)] | ||
| #[derive(Clone, Serialize)] | ||
| #[serde(transparent)] | ||
| pub struct DebugId(u16); | ||
|
|
||
| #[cfg(not(debug_assertions))] | ||
| impl DebugId { | ||
| pub fn new() -> DebugId { | ||
| DebugId | ||
| } | ||
| } | ||
|
|
||
| #[cfg(debug_assertions)] | ||
| impl DebugId { | ||
| pub fn new() -> DebugId { | ||
| DebugId(layout_debug::generate_unique_debug_id()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(debug_assertions))] | ||
| impl Serialize for DebugId { | ||
| fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { | ||
| serializer.serialize_str(&format!("{:p}", &self)) | ||
| } | ||
| } | ||
|
This conversation was marked as resolved
by SimonSapin
ferjm
Author
Member
|
||
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
For these three impls: why are they not derived? Could they be derived with some attributes from https://serde.rs/field-attrs.html ?