Skip to content
Permalink
Browse files

Make layout_2020 be layout_2013

  • Loading branch information...
nox committed Jul 23, 2019
1 parent 87e7e3d commit 4846d76e82e2d60875472fb8ea375e22d40a0800
Showing with 34,595 additions and 22 deletions.
  1. +66 −0 Cargo.lock
  2. +44 −0 components/layout_2020/Cargo.toml
  3. +211 −0 components/layout_2020/animation.rs
  4. +3,697 −0 components/layout_2020/block.rs
  5. +2,443 −0 components/layout_2020/construct.rs
  6. +201 −0 components/layout_2020/context.rs
  7. +68 −0 components/layout_2020/data.rs
  8. +336 −0 components/layout_2020/display_list/background.rs
  9. +199 −0 components/layout_2020/display_list/border.rs
  10. +3,024 −0 components/layout_2020/display_list/builder.rs
  11. +167 −0 components/layout_2020/display_list/conversions.rs
  12. +323 −0 components/layout_2020/display_list/gradient.rs
  13. +795 −0 components/layout_2020/display_list/items.rs
  14. +19 −0 components/layout_2020/display_list/mod.rs
  15. +321 −0 components/layout_2020/display_list/webrender_helpers.rs
  16. +1,128 −0 components/layout_2020/flex.rs
  17. +605 −0 components/layout_2020/floats.rs
  18. +1,458 −0 components/layout_2020/flow.rs
  19. +197 −0 components/layout_2020/flow_list.rs
  20. +64 −0 components/layout_2020/flow_ref.rs
  21. +3,455 −0 components/layout_2020/fragment.rs
  22. +651 −0 components/layout_2020/generated_content.rs
  23. +101 −0 components/layout_2020/incremental.rs
  24. +2,220 −0 components/layout_2020/inline.rs
  25. +124 −0 components/layout_2020/layout_debug.rs
  26. +60 −0 components/layout_2020/lib.rs
  27. +21 −0 components/layout_2020/linked_list.rs
  28. +323 −0 components/layout_2020/list_item.rs
  29. +609 −0 components/layout_2020/model.rs
  30. +384 −0 components/layout_2020/multicol.rs
  31. +19 −0 components/layout_2020/opaque_node.rs
  32. +232 −0 components/layout_2020/parallel.rs
  33. +101 −0 components/layout_2020/persistent_list.rs
  34. +1,111 −0 components/layout_2020/query.rs
  35. +193 −0 components/layout_2020/sequential.rs
  36. +1,378 −0 components/layout_2020/table.rs
  37. +139 −0 components/layout_2020/table_caption.rs
  38. +506 −0 components/layout_2020/table_cell.rs
  39. +131 −0 components/layout_2020/table_colgroup.rs
  40. +1,158 −0 components/layout_2020/table_row.rs
  41. +274 −0 components/layout_2020/table_rowgroup.rs
  42. +996 −0 components/layout_2020/table_wrapper.rs
  43. +18 −0 components/layout_2020/tests/size_of.rs
  44. +798 −0 components/layout_2020/text.rs
  45. +350 −0 components/layout_2020/traversal.rs
  46. +174 −0 components/layout_2020/wrapper.rs
  47. +26 −1 components/layout_thread_2020/Cargo.toml
  48. +1,550 −0 components/layout_thread_2020/dom_wrapper.rs
  49. +2,127 −21 components/layout_thread_2020/lib.rs

Some generated files are not rendered by default. Learn more.

@@ -7,9 +7,53 @@ edition = "2018"
publish = false

[lib]
name = "layout"
path = "lib.rs"
test = false
doctest = false

[dependencies]
app_units = "0.7"
atomic_refcell = "0.1"
bitflags = "1.0"
canvas_traits = {path = "../canvas_traits"}
crossbeam-channel = "0.3"
embedder_traits = {path = "../embedder_traits"}
euclid = "0.19"
fnv = "1.0"
fxhash = "0.2"
gfx = {path = "../gfx"}
gfx_traits = {path = "../gfx_traits"}
html5ever = "0.23"
ipc-channel = "0.11"
libc = "0.2"
log = "0.4"
malloc_size_of = { path = "../malloc_size_of" }
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
num-traits = "0.2"
ordered-float = "1.0"
parking_lot = "0.8"
profile_traits = {path = "../profile_traits"}
range = {path = "../range"}
rayon = "1"
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
selectors = { path = "../selectors" }
serde = "1.0"
servo_arc = {path = "../servo_arc"}
servo_atoms = {path = "../atoms"}
servo_geometry = {path = "../geometry"}
serde_json = "1.0"
servo_config = {path = "../config"}
servo_url = {path = "../url"}
smallvec = { version = "0.6", features = ["std", "union"] }
style = {path = "../style", features = ["servo", "servo-layout-2020"]}
style_traits = {path = "../style_traits"}
unicode-bidi = {version = "0.3", features = ["with_serde"]}
unicode-script = {version = "0.3", features = ["harfbuzz"]}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
xi-unicode = "0.1.0"

[dev-dependencies]
size_of_test = {path = "../size_of_test"}
@@ -0,0 +1,211 @@
/* 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/. */

//! CSS transitions and animations.

use crate::context::LayoutContext;
use crate::display_list::items::OpaqueNode;
use crate::flow::{Flow, GetBaseFlow};
use crate::opaque_node::OpaqueNodeMethods;
use crossbeam_channel::Receiver;
use fxhash::{FxHashMap, FxHashSet};
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::PipelineId;
use script_traits::UntrustedNodeAddress;
use script_traits::{AnimationState, ConstellationControlMsg, LayoutMsg as ConstellationMsg};
use style::animation::{update_style_for_animation, Animation};
use style::dom::TElement;
use style::font_metrics::ServoMetricsProvider;
use style::selector_parser::RestyleDamage;
use style::timer::Timer;

/// Processes any new animations that were discovered after style recalculation.
/// Also expire any old animations that have completed, inserting them into
/// `expired_animations`.
pub fn update_animation_state<E>(
constellation_chan: &IpcSender<ConstellationMsg>,
script_chan: &IpcSender<ConstellationControlMsg>,
running_animations: &mut FxHashMap<OpaqueNode, Vec<Animation>>,
expired_animations: &mut FxHashMap<OpaqueNode, Vec<Animation>>,
mut keys_to_remove: FxHashSet<OpaqueNode>,
mut newly_transitioning_nodes: Option<&mut Vec<UntrustedNodeAddress>>,
new_animations_receiver: &Receiver<Animation>,
pipeline_id: PipelineId,
timer: &Timer,
) where
E: TElement,
{
let mut new_running_animations = vec![];
while let Ok(animation) = new_animations_receiver.try_recv() {
let mut should_push = true;
if let Animation::Keyframes(ref node, _, ref name, ref state) = animation {
// If the animation was already present in the list for the
// node, just update its state, else push the new animation to
// run.
if let Some(ref mut animations) = running_animations.get_mut(node) {
// TODO: This being linear is probably not optimal.
for anim in animations.iter_mut() {
if let Animation::Keyframes(_, _, ref anim_name, ref mut anim_state) = *anim {
if *name == *anim_name {
debug!("update_animation_state: Found other animation {}", name);
anim_state.update_from_other(&state, timer);
should_push = false;
break;
}
}
}
}
}

if should_push {
new_running_animations.push(animation);
}
}

if running_animations.is_empty() && new_running_animations.is_empty() {
// Nothing to do. Return early so we don't flood the compositor with
// `ChangeRunningAnimationsState` messages.
return;
}

let now = timer.seconds();
// Expire old running animations.
//
// TODO: Do not expunge Keyframes animations, since we need that state if
// the animation gets re-triggered. Probably worth splitting in two
// different maps, or at least using a linked list?
for (key, running_animations) in running_animations.iter_mut() {
let mut animations_still_running = vec![];
for mut running_animation in running_animations.drain(..) {
let still_running = !running_animation.is_expired() &&
match running_animation {
Animation::Transition(_, started_at, ref frame) => {
now < started_at + frame.duration
},
Animation::Keyframes(_, _, _, ref mut state) => {
// This animation is still running, or we need to keep
// iterating.
now < state.started_at + state.duration || state.tick()
},
};

debug!(
"update_animation_state({:?}): {:?}",
still_running, running_animation
);

if still_running {
animations_still_running.push(running_animation);
continue;
}

if let Animation::Transition(node, _, ref frame) = running_animation {
script_chan
.send(ConstellationControlMsg::TransitionEnd(
node.to_untrusted_node_address(),
frame.property_animation.property_name().into(),
frame.duration,
))
.unwrap();
}

expired_animations
.entry(*key)
.or_insert_with(Vec::new)
.push(running_animation);
}

if animations_still_running.is_empty() {
keys_to_remove.insert(*key);
} else {
*running_animations = animations_still_running
}
}

for key in keys_to_remove {
running_animations.remove(&key).unwrap();
}

// Add new running animations.
for new_running_animation in new_running_animations {
if new_running_animation.is_transition() {
match newly_transitioning_nodes {
Some(ref mut nodes) => {
nodes.push(new_running_animation.node().to_untrusted_node_address());
},
None => {
warn!("New transition encountered from compositor-initiated layout.");
},
}
}

running_animations
.entry(*new_running_animation.node())
.or_insert_with(Vec::new)
.push(new_running_animation)
}

let animation_state = if running_animations.is_empty() {
AnimationState::NoAnimationsPresent
} else {
AnimationState::AnimationsPresent
};

constellation_chan
.send(ConstellationMsg::ChangeRunningAnimationsState(
pipeline_id,
animation_state,
))
.unwrap();
}

/// Recalculates style for a set of animations. This does *not* run with the DOM
/// lock held. Returns a set of nodes associated with animations that are no longer
/// valid.
pub fn recalc_style_for_animations<E>(
context: &LayoutContext,
flow: &mut dyn Flow,
animations: &FxHashMap<OpaqueNode, Vec<Animation>>,
) -> FxHashSet<OpaqueNode>
where
E: TElement,
{
let mut invalid_nodes = animations.keys().cloned().collect();
do_recalc_style_for_animations::<E>(context, flow, animations, &mut invalid_nodes);
invalid_nodes
}

fn do_recalc_style_for_animations<E>(
context: &LayoutContext,
flow: &mut dyn Flow,
animations: &FxHashMap<OpaqueNode, Vec<Animation>>,
invalid_nodes: &mut FxHashSet<OpaqueNode>,
) where
E: TElement,
{
let mut damage = RestyleDamage::empty();
flow.mutate_fragments(&mut |fragment| {
if let Some(ref animations) = animations.get(&fragment.node) {
invalid_nodes.remove(&fragment.node);
for animation in animations.iter() {
let old_style = fragment.style.clone();
update_style_for_animation::<E>(
&context.style_context,
animation,
&mut fragment.style,
&ServoMetricsProvider,
);
let difference =
RestyleDamage::compute_style_difference(&old_style, &fragment.style);
damage |= difference.damage;
}
}
});

let base = flow.mut_base();
base.restyle_damage.insert(damage);
for kid in base.children.iter_mut() {
do_recalc_style_for_animations::<E>(context, kid, animations, invalid_nodes)
}
}

0 comments on commit 4846d76

Please sign in to comment.
You can’t perform that action at this time.