mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Improve how intrinsic sizes work for videos (#31746)
* feat: patch for video layout sizes added rebase from main 2024/10/05 Co-authored-by: Josh Matthews <josh@joshmatthews.net> Signed-off-by: eri <epazos@igalia.com> * feat: take width and height parameters if provided Signed-off-by: eri <epazos@igalia.com> * chore: tidy the code and update test expectations Signed-off-by: eri <epazos@igalia.com> * feat: handle removing poster Signed-off-by: eri <epazos@igalia.com> * chore: update test expectations and remove debug code Signed-off-by: eri <epazos@igalia.com> * fix: issues after rebasing to main Signed-off-by: eri <epazos@igalia.com> * feat: pass src remove test and tidy Signed-off-by: eri <epazos@igalia.com> * chore: clippy fixes Signed-off-by: eri <epazos@igalia.com> * chore: update passing test expectations Signed-off-by: eri <epazos@igalia.com> * fix object-position-svg test Signed-off-by: eri <epazos@igalia.com> * fix unintentional override of video size and resize events Signed-off-by: eri <epazos@igalia.com> * change how resize events are sent to better match the spec Signed-off-by: eri <epazos@igalia.com> * simplify poster mutation handling Co-authored-by: Oriol Brufau <obrufau@igalia.com> Signed-off-by: eri <eri@inventati.org> * improved handling of intrinsic sizes - differentiate between natural size and css size - presentational attributes - fallback ratio for video element - handle more cases where the src/poster are added/removed - aspect ratio hints Signed-off-by: eri <epazos@igalia.com> * update test expectations Signed-off-by: eri <epazos@igalia.com> * fix cleaning current frame Signed-off-by: eri <epazos@igalia.com> * update test expectations Signed-off-by: eri <epazos@igalia.com> * Apply suggestions from code review Co-authored-by: Oriol Brufau <obrufau@igalia.com> Signed-off-by: eri <eri@inventati.org> * More code review suggestions Signed-off-by: eri <epazos@igalia.com> * Prevent aspect-ratio:auto from pulling the ratio from the default object size As resolved in https://github.com/w3c/csswg-drafts/issues/7524#issuecomment-1204462924 Signed-off-by: Oriol Brufau <obrufau@igalia.com> --------- Signed-off-by: eri <epazos@igalia.com> Signed-off-by: eri <eri@inventati.org> Signed-off-by: Oriol Brufau <obrufau@igalia.com> Co-authored-by: Josh Matthews <josh@joshmatthews.net> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
43d1601016
commit
01820e2a8a
25 changed files with 290 additions and 360 deletions
|
@ -55,6 +55,8 @@ use style::selector_parser::{
|
|||
use style::shared_lock::{Locked, SharedRwLock};
|
||||
use style::stylesheets::layer_rule::LayerOrder;
|
||||
use style::stylesheets::{CssRuleType, UrlExtraData};
|
||||
use style::values::generics::position::PreferredRatio;
|
||||
use style::values::generics::ratio::Ratio;
|
||||
use style::values::generics::NonNegative;
|
||||
use style::values::{computed, specified, AtomIdent, AtomString, CSSFloat};
|
||||
use style::{dom_apis, thread_state, ArcSlice, CaseSensitivityExt};
|
||||
|
@ -132,6 +134,7 @@ use crate::dom::htmltablesectionelement::{
|
|||
};
|
||||
use crate::dom::htmltemplateelement::HTMLTemplateElement;
|
||||
use crate::dom::htmltextareaelement::{HTMLTextAreaElement, LayoutHTMLTextAreaElementHelpers};
|
||||
use crate::dom::htmlvideoelement::{HTMLVideoElement, LayoutHTMLVideoElementHelpers};
|
||||
use crate::dom::mutationobserver::{Mutation, MutationObserver};
|
||||
use crate::dom::namednodemap::NamedNodeMap;
|
||||
use crate::dom::node::{
|
||||
|
@ -849,6 +852,8 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
|||
this.get_width()
|
||||
} else if let Some(this) = self.downcast::<HTMLImageElement>() {
|
||||
this.get_width()
|
||||
} else if let Some(this) = self.downcast::<HTMLVideoElement>() {
|
||||
this.get_width()
|
||||
} else if let Some(this) = self.downcast::<HTMLTableElement>() {
|
||||
this.get_width()
|
||||
} else if let Some(this) = self.downcast::<HTMLTableCellElement>() {
|
||||
|
@ -891,6 +896,8 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
|||
this.get_height()
|
||||
} else if let Some(this) = self.downcast::<HTMLImageElement>() {
|
||||
this.get_height()
|
||||
} else if let Some(this) = self.downcast::<HTMLVideoElement>() {
|
||||
this.get_height()
|
||||
} else if let Some(this) = self.downcast::<HTMLTableElement>() {
|
||||
this.get_height()
|
||||
} else if let Some(this) = self.downcast::<HTMLTableCellElement>() {
|
||||
|
@ -927,6 +934,27 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
|||
},
|
||||
}
|
||||
|
||||
// Aspect ratio when providing both width and height.
|
||||
// https://html.spec.whatwg.org/multipage/#attributes-for-embedded-content-and-images
|
||||
if self.downcast::<HTMLImageElement>().is_some() ||
|
||||
self.downcast::<HTMLVideoElement>().is_some()
|
||||
{
|
||||
if let LengthOrPercentageOrAuto::Length(width) = width {
|
||||
if let LengthOrPercentageOrAuto::Length(height) = height {
|
||||
let width_value = NonNegative(specified::Number::new(width.to_f32_px()));
|
||||
let height_value = NonNegative(specified::Number::new(height.to_f32_px()));
|
||||
let aspect_ratio = specified::position::AspectRatio {
|
||||
auto: true,
|
||||
ratio: PreferredRatio::Ratio(Ratio(width_value, height_value)),
|
||||
};
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::AspectRatio(aspect_ratio),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let cols = if let Some(this) = self.downcast::<HTMLTextAreaElement>() {
|
||||
match this.get_cols() {
|
||||
0 => None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue