mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Run rustfmt on selectors, servo_arc, and style.
This was generated with: ./mach cargo fmt --package selectors && ./mach cargo fmt --package servo_arc && ./mach cargo fmt --package style Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
This commit is contained in:
parent
f7ae1a37e3
commit
c99bcdd4b8
181 changed files with 9981 additions and 7933 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
//! Geometry in flow-relative space.
|
||||
|
||||
use euclid::{Point2D, Rect, Size2D, SideOffsets2D};
|
||||
use euclid::{Point2D, Rect, SideOffsets2D, Size2D};
|
||||
use euclid::num::Zero;
|
||||
use properties::style_structs;
|
||||
use std::cmp::{max, min};
|
||||
|
@ -15,12 +15,12 @@ use unicode_bidi as bidi;
|
|||
pub enum BlockFlowDirection {
|
||||
TopToBottom,
|
||||
RightToLeft,
|
||||
LeftToRight
|
||||
LeftToRight,
|
||||
}
|
||||
|
||||
pub enum InlineBaseDirection {
|
||||
LeftToRight,
|
||||
RightToLeft
|
||||
RightToLeft,
|
||||
}
|
||||
|
||||
// TODO: improve the readability of the WritingMode serialization, refer to the Debug:fmt()
|
||||
|
@ -228,7 +228,6 @@ impl fmt::Display for WritingMode {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Wherever logical geometry is used, the writing mode is known based on context:
|
||||
/// every method takes a `mode` parameter.
|
||||
/// However, this context is easy to get wrong.
|
||||
|
@ -244,7 +243,7 @@ struct DebugWritingMode;
|
|||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(Serialize))]
|
||||
struct DebugWritingMode {
|
||||
mode: WritingMode
|
||||
mode: WritingMode,
|
||||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
|
@ -291,28 +290,30 @@ impl Debug for DebugWritingMode {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Used to specify the logical direction.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(Serialize))]
|
||||
pub enum Direction {
|
||||
Inline,
|
||||
Block
|
||||
Block,
|
||||
}
|
||||
|
||||
/// A 2D size in flow-relative dimensions
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(Serialize))]
|
||||
pub struct LogicalSize<T> {
|
||||
pub inline: T, // inline-size, a.k.a. logical width, a.k.a. measure
|
||||
pub inline: T, // inline-size, a.k.a. logical width, a.k.a. measure
|
||||
pub block: T, // block-size, a.k.a. logical height, a.k.a. extent
|
||||
debug_writing_mode: DebugWritingMode,
|
||||
}
|
||||
|
||||
impl<T: Debug> Debug for LogicalSize<T> {
|
||||
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
|
||||
write!(formatter, "LogicalSize({:?}, i{:?}×b{:?})",
|
||||
self.debug_writing_mode, self.inline, self.block)
|
||||
write!(
|
||||
formatter,
|
||||
"LogicalSize({:?}, i{:?}×b{:?})",
|
||||
self.debug_writing_mode, self.inline, self.block
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,12 +409,13 @@ impl<T: Copy> LogicalSize<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Add<T, Output=T>> Add for LogicalSize<T> {
|
||||
impl<T: Add<T, Output = T>> Add for LogicalSize<T> {
|
||||
type Output = LogicalSize<T>;
|
||||
|
||||
#[inline]
|
||||
fn add(self, other: LogicalSize<T>) -> LogicalSize<T> {
|
||||
self.debug_writing_mode.check_debug(other.debug_writing_mode);
|
||||
self.debug_writing_mode
|
||||
.check_debug(other.debug_writing_mode);
|
||||
LogicalSize {
|
||||
debug_writing_mode: self.debug_writing_mode,
|
||||
inline: self.inline + other.inline,
|
||||
|
@ -422,12 +424,13 @@ impl<T: Add<T, Output=T>> Add for LogicalSize<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Sub<T, Output=T>> Sub for LogicalSize<T> {
|
||||
impl<T: Sub<T, Output = T>> Sub for LogicalSize<T> {
|
||||
type Output = LogicalSize<T>;
|
||||
|
||||
#[inline]
|
||||
fn sub(self, other: LogicalSize<T>) -> LogicalSize<T> {
|
||||
self.debug_writing_mode.check_debug(other.debug_writing_mode);
|
||||
self.debug_writing_mode
|
||||
.check_debug(other.debug_writing_mode);
|
||||
LogicalSize {
|
||||
debug_writing_mode: self.debug_writing_mode,
|
||||
inline: self.inline - other.inline,
|
||||
|
@ -436,7 +439,6 @@ impl<T: Sub<T, Output=T>> Sub for LogicalSize<T> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// A 2D point in flow-relative dimensions
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(Serialize))]
|
||||
|
@ -450,8 +452,11 @@ pub struct LogicalPoint<T> {
|
|||
|
||||
impl<T: Debug> Debug for LogicalPoint<T> {
|
||||
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
|
||||
write!(formatter, "LogicalPoint({:?} (i{:?}, b{:?}))",
|
||||
self.debug_writing_mode, self.i, self.b)
|
||||
write!(
|
||||
formatter,
|
||||
"LogicalPoint({:?} (i{:?}, b{:?}))",
|
||||
self.debug_writing_mode, self.i, self.b
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -478,19 +483,34 @@ impl<T: Copy> LogicalPoint<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Sub<T, Output=T>> LogicalPoint<T> {
|
||||
impl<T: Copy + Sub<T, Output = T>> LogicalPoint<T> {
|
||||
#[inline]
|
||||
pub fn from_physical(mode: WritingMode, point: Point2D<T>, container_size: Size2D<T>)
|
||||
-> LogicalPoint<T> {
|
||||
pub fn from_physical(
|
||||
mode: WritingMode,
|
||||
point: Point2D<T>,
|
||||
container_size: Size2D<T>,
|
||||
) -> LogicalPoint<T> {
|
||||
if mode.is_vertical() {
|
||||
LogicalPoint {
|
||||
i: if mode.is_inline_tb() { point.y } else { container_size.height - point.y },
|
||||
b: if mode.is_vertical_lr() { point.x } else { container_size.width - point.x },
|
||||
i: if mode.is_inline_tb() {
|
||||
point.y
|
||||
} else {
|
||||
container_size.height - point.y
|
||||
},
|
||||
b: if mode.is_vertical_lr() {
|
||||
point.x
|
||||
} else {
|
||||
container_size.width - point.x
|
||||
},
|
||||
debug_writing_mode: DebugWritingMode::new(mode),
|
||||
}
|
||||
} else {
|
||||
LogicalPoint {
|
||||
i: if mode.is_bidi_ltr() { point.x } else { container_size.width - point.x },
|
||||
i: if mode.is_bidi_ltr() {
|
||||
point.x
|
||||
} else {
|
||||
container_size.width - point.x
|
||||
},
|
||||
b: point.y,
|
||||
debug_writing_mode: DebugWritingMode::new(mode),
|
||||
}
|
||||
|
@ -501,9 +521,17 @@ impl<T: Copy + Sub<T, Output=T>> LogicalPoint<T> {
|
|||
pub fn x(&self, mode: WritingMode, container_size: Size2D<T>) -> T {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
if mode.is_vertical_lr() { self.b } else { container_size.width - self.b }
|
||||
if mode.is_vertical_lr() {
|
||||
self.b
|
||||
} else {
|
||||
container_size.width - self.b
|
||||
}
|
||||
} else {
|
||||
if mode.is_bidi_ltr() { self.i } else { container_size.width - self.i }
|
||||
if mode.is_bidi_ltr() {
|
||||
self.i
|
||||
} else {
|
||||
container_size.width - self.i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -511,9 +539,17 @@ impl<T: Copy + Sub<T, Output=T>> LogicalPoint<T> {
|
|||
pub fn set_x(&mut self, mode: WritingMode, x: T, container_size: Size2D<T>) {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
self.b = if mode.is_vertical_lr() { x } else { container_size.width - x }
|
||||
self.b = if mode.is_vertical_lr() {
|
||||
x
|
||||
} else {
|
||||
container_size.width - x
|
||||
}
|
||||
} else {
|
||||
self.i = if mode.is_bidi_ltr() { x } else { container_size.width - x }
|
||||
self.i = if mode.is_bidi_ltr() {
|
||||
x
|
||||
} else {
|
||||
container_size.width - x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -521,7 +557,11 @@ impl<T: Copy + Sub<T, Output=T>> LogicalPoint<T> {
|
|||
pub fn y(&self, mode: WritingMode, container_size: Size2D<T>) -> T {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
if mode.is_inline_tb() { self.i } else { container_size.height - self.i }
|
||||
if mode.is_inline_tb() {
|
||||
self.i
|
||||
} else {
|
||||
container_size.height - self.i
|
||||
}
|
||||
} else {
|
||||
self.b
|
||||
}
|
||||
|
@ -531,7 +571,11 @@ impl<T: Copy + Sub<T, Output=T>> LogicalPoint<T> {
|
|||
pub fn set_y(&mut self, mode: WritingMode, y: T, container_size: Size2D<T>) {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
self.i = if mode.is_inline_tb() { y } else { container_size.height - y }
|
||||
self.i = if mode.is_inline_tb() {
|
||||
y
|
||||
} else {
|
||||
container_size.height - y
|
||||
}
|
||||
} else {
|
||||
self.b = y
|
||||
}
|
||||
|
@ -542,34 +586,56 @@ impl<T: Copy + Sub<T, Output=T>> LogicalPoint<T> {
|
|||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
Point2D::new(
|
||||
if mode.is_vertical_lr() { self.b } else { container_size.width - self.b },
|
||||
if mode.is_inline_tb() { self.i } else { container_size.height - self.i })
|
||||
if mode.is_vertical_lr() {
|
||||
self.b
|
||||
} else {
|
||||
container_size.width - self.b
|
||||
},
|
||||
if mode.is_inline_tb() {
|
||||
self.i
|
||||
} else {
|
||||
container_size.height - self.i
|
||||
},
|
||||
)
|
||||
} else {
|
||||
Point2D::new(
|
||||
if mode.is_bidi_ltr() { self.i } else { container_size.width - self.i },
|
||||
self.b)
|
||||
if mode.is_bidi_ltr() {
|
||||
self.i
|
||||
} else {
|
||||
container_size.width - self.i
|
||||
},
|
||||
self.b,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn convert(&self, mode_from: WritingMode, mode_to: WritingMode, container_size: Size2D<T>)
|
||||
-> LogicalPoint<T> {
|
||||
pub fn convert(
|
||||
&self,
|
||||
mode_from: WritingMode,
|
||||
mode_to: WritingMode,
|
||||
container_size: Size2D<T>,
|
||||
) -> LogicalPoint<T> {
|
||||
if mode_from == mode_to {
|
||||
self.debug_writing_mode.check(mode_from);
|
||||
*self
|
||||
} else {
|
||||
LogicalPoint::from_physical(
|
||||
mode_to, self.to_physical(mode_from, container_size), container_size)
|
||||
mode_to,
|
||||
self.to_physical(mode_from, container_size),
|
||||
container_size,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Add<T, Output=T>> LogicalPoint<T> {
|
||||
impl<T: Copy + Add<T, Output = T>> LogicalPoint<T> {
|
||||
/// This doesn’t really makes sense,
|
||||
/// but happens when dealing with multiple origins.
|
||||
#[inline]
|
||||
pub fn add_point(&self, other: &LogicalPoint<T>) -> LogicalPoint<T> {
|
||||
self.debug_writing_mode.check_debug(other.debug_writing_mode);
|
||||
self.debug_writing_mode
|
||||
.check_debug(other.debug_writing_mode);
|
||||
LogicalPoint {
|
||||
debug_writing_mode: self.debug_writing_mode,
|
||||
i: self.i + other.i,
|
||||
|
@ -578,12 +644,13 @@ impl<T: Copy + Add<T, Output=T>> LogicalPoint<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Add<T, Output=T>> Add<LogicalSize<T>> for LogicalPoint<T> {
|
||||
impl<T: Copy + Add<T, Output = T>> Add<LogicalSize<T>> for LogicalPoint<T> {
|
||||
type Output = LogicalPoint<T>;
|
||||
|
||||
#[inline]
|
||||
fn add(self, other: LogicalSize<T>) -> LogicalPoint<T> {
|
||||
self.debug_writing_mode.check_debug(other.debug_writing_mode);
|
||||
self.debug_writing_mode
|
||||
.check_debug(other.debug_writing_mode);
|
||||
LogicalPoint {
|
||||
debug_writing_mode: self.debug_writing_mode,
|
||||
i: self.i + other.inline,
|
||||
|
@ -592,12 +659,13 @@ impl<T: Copy + Add<T, Output=T>> Add<LogicalSize<T>> for LogicalPoint<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Sub<T, Output=T>> Sub<LogicalSize<T>> for LogicalPoint<T> {
|
||||
impl<T: Copy + Sub<T, Output = T>> Sub<LogicalSize<T>> for LogicalPoint<T> {
|
||||
type Output = LogicalPoint<T>;
|
||||
|
||||
#[inline]
|
||||
fn sub(self, other: LogicalSize<T>) -> LogicalPoint<T> {
|
||||
self.debug_writing_mode.check_debug(other.debug_writing_mode);
|
||||
self.debug_writing_mode
|
||||
.check_debug(other.debug_writing_mode);
|
||||
LogicalPoint {
|
||||
debug_writing_mode: self.debug_writing_mode,
|
||||
i: self.i - other.inline,
|
||||
|
@ -606,7 +674,6 @@ impl<T: Copy + Sub<T, Output=T>> Sub<LogicalSize<T>> for LogicalPoint<T> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// A "margin" in flow-relative dimensions
|
||||
/// Represents the four sides of the margins, borders, or padding of a CSS box,
|
||||
/// or a combination of those.
|
||||
|
@ -629,12 +696,15 @@ impl<T: Debug> Debug for LogicalMargin<T> {
|
|||
"".to_owned()
|
||||
};
|
||||
|
||||
write!(formatter, "LogicalMargin({}i:{:?}..{:?} b:{:?}..{:?})",
|
||||
write!(
|
||||
formatter,
|
||||
"LogicalMargin({}i:{:?}..{:?} b:{:?}..{:?})",
|
||||
writing_mode_string,
|
||||
self.inline_start,
|
||||
self.inline_end,
|
||||
self.block_start,
|
||||
self.block_end)
|
||||
self.block_end
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -653,8 +723,13 @@ impl<T: Zero> LogicalMargin<T> {
|
|||
|
||||
impl<T: Copy> LogicalMargin<T> {
|
||||
#[inline]
|
||||
pub fn new(mode: WritingMode, block_start: T, inline_end: T, block_end: T, inline_start: T)
|
||||
-> LogicalMargin<T> {
|
||||
pub fn new(
|
||||
mode: WritingMode,
|
||||
block_start: T,
|
||||
inline_end: T,
|
||||
block_end: T,
|
||||
inline_start: T,
|
||||
) -> LogicalMargin<T> {
|
||||
LogicalMargin {
|
||||
block_start: block_start,
|
||||
inline_end: inline_end,
|
||||
|
@ -708,7 +783,11 @@ impl<T: Copy> LogicalMargin<T> {
|
|||
pub fn top(&self, mode: WritingMode) -> T {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
if mode.is_inline_tb() { self.inline_start } else { self.inline_end }
|
||||
if mode.is_inline_tb() {
|
||||
self.inline_start
|
||||
} else {
|
||||
self.inline_end
|
||||
}
|
||||
} else {
|
||||
self.block_start
|
||||
}
|
||||
|
@ -718,7 +797,11 @@ impl<T: Copy> LogicalMargin<T> {
|
|||
pub fn set_top(&mut self, mode: WritingMode, top: T) {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
if mode.is_inline_tb() { self.inline_start = top } else { self.inline_end = top }
|
||||
if mode.is_inline_tb() {
|
||||
self.inline_start = top
|
||||
} else {
|
||||
self.inline_end = top
|
||||
}
|
||||
} else {
|
||||
self.block_start = top
|
||||
}
|
||||
|
@ -728,9 +811,17 @@ impl<T: Copy> LogicalMargin<T> {
|
|||
pub fn right(&self, mode: WritingMode) -> T {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
if mode.is_vertical_lr() { self.block_end } else { self.block_start }
|
||||
if mode.is_vertical_lr() {
|
||||
self.block_end
|
||||
} else {
|
||||
self.block_start
|
||||
}
|
||||
} else {
|
||||
if mode.is_bidi_ltr() { self.inline_end } else { self.inline_start }
|
||||
if mode.is_bidi_ltr() {
|
||||
self.inline_end
|
||||
} else {
|
||||
self.inline_start
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -738,9 +829,17 @@ impl<T: Copy> LogicalMargin<T> {
|
|||
pub fn set_right(&mut self, mode: WritingMode, right: T) {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
if mode.is_vertical_lr() { self.block_end = right } else { self.block_start = right }
|
||||
if mode.is_vertical_lr() {
|
||||
self.block_end = right
|
||||
} else {
|
||||
self.block_start = right
|
||||
}
|
||||
} else {
|
||||
if mode.is_bidi_ltr() { self.inline_end = right } else { self.inline_start = right }
|
||||
if mode.is_bidi_ltr() {
|
||||
self.inline_end = right
|
||||
} else {
|
||||
self.inline_start = right
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -748,7 +847,11 @@ impl<T: Copy> LogicalMargin<T> {
|
|||
pub fn bottom(&self, mode: WritingMode) -> T {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
if mode.is_inline_tb() { self.inline_end } else { self.inline_start }
|
||||
if mode.is_inline_tb() {
|
||||
self.inline_end
|
||||
} else {
|
||||
self.inline_start
|
||||
}
|
||||
} else {
|
||||
self.block_end
|
||||
}
|
||||
|
@ -758,7 +861,11 @@ impl<T: Copy> LogicalMargin<T> {
|
|||
pub fn set_bottom(&mut self, mode: WritingMode, bottom: T) {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
if mode.is_inline_tb() { self.inline_end = bottom } else { self.inline_start = bottom }
|
||||
if mode.is_inline_tb() {
|
||||
self.inline_end = bottom
|
||||
} else {
|
||||
self.inline_start = bottom
|
||||
}
|
||||
} else {
|
||||
self.block_end = bottom
|
||||
}
|
||||
|
@ -768,9 +875,17 @@ impl<T: Copy> LogicalMargin<T> {
|
|||
pub fn left(&self, mode: WritingMode) -> T {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
if mode.is_vertical_lr() { self.block_start } else { self.block_end }
|
||||
if mode.is_vertical_lr() {
|
||||
self.block_start
|
||||
} else {
|
||||
self.block_end
|
||||
}
|
||||
} else {
|
||||
if mode.is_bidi_ltr() { self.inline_start } else { self.inline_end }
|
||||
if mode.is_bidi_ltr() {
|
||||
self.inline_start
|
||||
} else {
|
||||
self.inline_end
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -778,9 +893,17 @@ impl<T: Copy> LogicalMargin<T> {
|
|||
pub fn set_left(&mut self, mode: WritingMode, left: T) {
|
||||
self.debug_writing_mode.check(mode);
|
||||
if mode.is_vertical() {
|
||||
if mode.is_vertical_lr() { self.block_start = left } else { self.block_end = left }
|
||||
if mode.is_vertical_lr() {
|
||||
self.block_start = left
|
||||
} else {
|
||||
self.block_end = left
|
||||
}
|
||||
} else {
|
||||
if mode.is_bidi_ltr() { self.inline_start = left } else { self.inline_end = left }
|
||||
if mode.is_bidi_ltr() {
|
||||
self.inline_start = left
|
||||
} else {
|
||||
self.inline_end = left
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -835,11 +958,11 @@ impl<T: PartialEq + Zero> LogicalMargin<T> {
|
|||
#[inline]
|
||||
pub fn is_zero(&self) -> bool {
|
||||
self.block_start == Zero::zero() && self.inline_end == Zero::zero() &&
|
||||
self.block_end == Zero::zero() && self.inline_start == Zero::zero()
|
||||
self.block_end == Zero::zero() && self.inline_start == Zero::zero()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Add<T, Output=T>> LogicalMargin<T> {
|
||||
impl<T: Copy + Add<T, Output = T>> LogicalMargin<T> {
|
||||
#[inline]
|
||||
pub fn inline_start_end(&self) -> T {
|
||||
self.inline_start + self.inline_end
|
||||
|
@ -853,10 +976,8 @@ impl<T: Copy + Add<T, Output=T>> LogicalMargin<T> {
|
|||
#[inline]
|
||||
pub fn start_end(&self, direction: Direction) -> T {
|
||||
match direction {
|
||||
Direction::Inline =>
|
||||
self.inline_start + self.inline_end,
|
||||
Direction::Block =>
|
||||
self.block_start + self.block_end
|
||||
Direction::Inline => self.inline_start + self.inline_end,
|
||||
Direction::Block => self.block_start + self.block_end,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -881,12 +1002,13 @@ impl<T: Copy + Add<T, Output=T>> LogicalMargin<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Add<T, Output=T>> Add for LogicalMargin<T> {
|
||||
impl<T: Add<T, Output = T>> Add for LogicalMargin<T> {
|
||||
type Output = LogicalMargin<T>;
|
||||
|
||||
#[inline]
|
||||
fn add(self, other: LogicalMargin<T>) -> LogicalMargin<T> {
|
||||
self.debug_writing_mode.check_debug(other.debug_writing_mode);
|
||||
self.debug_writing_mode
|
||||
.check_debug(other.debug_writing_mode);
|
||||
LogicalMargin {
|
||||
debug_writing_mode: self.debug_writing_mode,
|
||||
block_start: self.block_start + other.block_start,
|
||||
|
@ -897,12 +1019,13 @@ impl<T: Add<T, Output=T>> Add for LogicalMargin<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Sub<T, Output=T>> Sub for LogicalMargin<T> {
|
||||
impl<T: Sub<T, Output = T>> Sub for LogicalMargin<T> {
|
||||
type Output = LogicalMargin<T>;
|
||||
|
||||
#[inline]
|
||||
fn sub(self, other: LogicalMargin<T>) -> LogicalMargin<T> {
|
||||
self.debug_writing_mode.check_debug(other.debug_writing_mode);
|
||||
self.debug_writing_mode
|
||||
.check_debug(other.debug_writing_mode);
|
||||
LogicalMargin {
|
||||
debug_writing_mode: self.debug_writing_mode,
|
||||
block_start: self.block_start - other.block_start,
|
||||
|
@ -913,7 +1036,6 @@ impl<T: Sub<T, Output=T>> Sub for LogicalMargin<T> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// A rectangle in flow-relative dimensions
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(Serialize))]
|
||||
|
@ -931,12 +1053,11 @@ impl<T: Debug> Debug for LogicalRect<T> {
|
|||
"".to_owned()
|
||||
};
|
||||
|
||||
write!(formatter, "LogicalRect({}i{:?}×b{:?}, @ (i{:?},b{:?}))",
|
||||
writing_mode_string,
|
||||
self.size.inline,
|
||||
self.size.block,
|
||||
self.start.i,
|
||||
self.start.b)
|
||||
write!(
|
||||
formatter,
|
||||
"LogicalRect({}i{:?}×b{:?}, @ (i{:?},b{:?}))",
|
||||
writing_mode_string, self.size.inline, self.size.block, self.start.i, self.start.b
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -953,8 +1074,13 @@ impl<T: Zero> LogicalRect<T> {
|
|||
|
||||
impl<T: Copy> LogicalRect<T> {
|
||||
#[inline]
|
||||
pub fn new(mode: WritingMode, inline_start: T, block_start: T, inline: T, block: T)
|
||||
-> LogicalRect<T> {
|
||||
pub fn new(
|
||||
mode: WritingMode,
|
||||
inline_start: T,
|
||||
block_start: T,
|
||||
inline: T,
|
||||
block: T,
|
||||
) -> LogicalRect<T> {
|
||||
LogicalRect {
|
||||
start: LogicalPoint::new(mode, inline_start, block_start),
|
||||
size: LogicalSize::new(mode, inline, block),
|
||||
|
@ -963,8 +1089,11 @@ impl<T: Copy> LogicalRect<T> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_point_size(mode: WritingMode, start: LogicalPoint<T>, size: LogicalSize<T>)
|
||||
-> LogicalRect<T> {
|
||||
pub fn from_point_size(
|
||||
mode: WritingMode,
|
||||
start: LogicalPoint<T>,
|
||||
size: LogicalSize<T>,
|
||||
) -> LogicalRect<T> {
|
||||
start.debug_writing_mode.check(mode);
|
||||
size.debug_writing_mode.check(mode);
|
||||
LogicalRect {
|
||||
|
@ -975,10 +1104,13 @@ impl<T: Copy> LogicalRect<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Add<T, Output=T> + Sub<T, Output=T>> LogicalRect<T> {
|
||||
impl<T: Copy + Add<T, Output = T> + Sub<T, Output = T>> LogicalRect<T> {
|
||||
#[inline]
|
||||
pub fn from_physical(mode: WritingMode, rect: Rect<T>, container_size: Size2D<T>)
|
||||
-> LogicalRect<T> {
|
||||
pub fn from_physical(
|
||||
mode: WritingMode,
|
||||
rect: Rect<T>,
|
||||
container_size: Size2D<T>,
|
||||
) -> LogicalRect<T> {
|
||||
let inline_start;
|
||||
let block_start;
|
||||
let inline;
|
||||
|
@ -1060,14 +1192,21 @@ impl<T: Copy + Add<T, Output=T> + Sub<T, Output=T>> LogicalRect<T> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn convert(&self, mode_from: WritingMode, mode_to: WritingMode, container_size: Size2D<T>)
|
||||
-> LogicalRect<T> {
|
||||
pub fn convert(
|
||||
&self,
|
||||
mode_from: WritingMode,
|
||||
mode_to: WritingMode,
|
||||
container_size: Size2D<T>,
|
||||
) -> LogicalRect<T> {
|
||||
if mode_from == mode_to {
|
||||
self.debug_writing_mode.check(mode_from);
|
||||
*self
|
||||
} else {
|
||||
LogicalRect::from_physical(
|
||||
mode_to, self.to_physical(mode_from, container_size), container_size)
|
||||
mode_to,
|
||||
self.to_physical(mode_from, container_size),
|
||||
container_size,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1091,10 +1230,11 @@ impl<T: Copy + Add<T, Output=T> + Sub<T, Output=T>> LogicalRect<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Ord + Add<T, Output=T> + Sub<T, Output=T>> LogicalRect<T> {
|
||||
impl<T: Copy + Ord + Add<T, Output = T> + Sub<T, Output = T>> LogicalRect<T> {
|
||||
#[inline]
|
||||
pub fn union(&self, other: &LogicalRect<T>) -> LogicalRect<T> {
|
||||
self.debug_writing_mode.check_debug(other.debug_writing_mode);
|
||||
self.debug_writing_mode
|
||||
.check_debug(other.debug_writing_mode);
|
||||
|
||||
let inline_start = min(self.start.i, other.start.i);
|
||||
let block_start = min(self.start.b, other.start.b);
|
||||
|
@ -1114,12 +1254,13 @@ impl<T: Copy + Ord + Add<T, Output=T> + Sub<T, Output=T>> LogicalRect<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Add<T, Output=T> + Sub<T, Output=T>> Add<LogicalMargin<T>> for LogicalRect<T> {
|
||||
impl<T: Copy + Add<T, Output = T> + Sub<T, Output = T>> Add<LogicalMargin<T>> for LogicalRect<T> {
|
||||
type Output = LogicalRect<T>;
|
||||
|
||||
#[inline]
|
||||
fn add(self, other: LogicalMargin<T>) -> LogicalRect<T> {
|
||||
self.debug_writing_mode.check_debug(other.debug_writing_mode);
|
||||
self.debug_writing_mode
|
||||
.check_debug(other.debug_writing_mode);
|
||||
LogicalRect {
|
||||
start: LogicalPoint {
|
||||
// Growing a rectangle on the start side means pushing its
|
||||
|
@ -1138,13 +1279,13 @@ impl<T: Copy + Add<T, Output=T> + Sub<T, Output=T>> Add<LogicalMargin<T>> for Lo
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl<T: Copy + Add<T, Output=T> + Sub<T, Output=T>> Sub<LogicalMargin<T>> for LogicalRect<T> {
|
||||
impl<T: Copy + Add<T, Output = T> + Sub<T, Output = T>> Sub<LogicalMargin<T>> for LogicalRect<T> {
|
||||
type Output = LogicalRect<T>;
|
||||
|
||||
#[inline]
|
||||
fn sub(self, other: LogicalMargin<T>) -> LogicalRect<T> {
|
||||
self.debug_writing_mode.check_debug(other.debug_writing_mode);
|
||||
self.debug_writing_mode
|
||||
.check_debug(other.debug_writing_mode);
|
||||
LogicalRect {
|
||||
start: LogicalPoint {
|
||||
// Shrinking a rectangle on the start side means pushing its
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue