aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/geom.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2020-01-21 13:03:27 -0500
committerGitHub <noreply@github.com>2020-01-21 13:03:27 -0500
commit35eb6dd0748dd9cd47e4b754166107aac72e62db (patch)
treed06978906668e6398f7f76fc82bdcd85aaf473f0 /components/layout_2020/geom.rs
parent0c4205ebfe3ab2c78b0318371858225021d4cb06 (diff)
parente4a55d77555ec60ce37f8272cfe6ec7292b6af5f (diff)
downloadservo-35eb6dd0748dd9cd47e4b754166107aac72e62db.tar.gz
servo-35eb6dd0748dd9cd47e4b754166107aac72e62db.zip
Auto merge of #25560 - mrobinson:scrollable-overflow-v1, r=SimonSapin
Add initial scrolling support to layout_2020 This adds very early scrolling support to layout_2020. Only the root element scrolls for now, but the idea is to continue to polish this. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/layout_2020/geom.rs')
-rw-r--r--components/layout_2020/geom.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs
index 166ba7a0494..918cbf47fd2 100644
--- a/components/layout_2020/geom.rs
+++ b/components/layout_2020/geom.rs
@@ -60,6 +60,15 @@ pub(crate) mod flow_relative {
}
}
+impl<T: Zero> physical::Vec2<T> {
+ pub fn zero() -> Self {
+ Self {
+ x: T::zero(),
+ y: T::zero(),
+ }
+ }
+}
+
impl<T: fmt::Debug> fmt::Debug for physical::Vec2<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Not using f.debug_struct on purpose here, to keep {:?} output somewhat compact
@@ -387,6 +396,33 @@ impl<T> physical::Rect<T> {
}
}
+impl physical::Rect<Length> {
+ pub fn axis_aligned_bounding_box(&self, other: &Self) -> Self {
+ let top_left = physical::Vec2 {
+ x: self.top_left.x.min(other.top_left.x),
+ y: self.top_left.y.min(other.top_left.y),
+ };
+
+ let bottom_corner_x = (self.top_left.x + self.size.x).max(other.top_left.x + other.size.x);
+ let bottom_corner_y = (self.top_left.y + self.size.y).max(other.top_left.y + other.size.y);
+ let size = physical::Vec2 {
+ x: bottom_corner_x - top_left.x,
+ y: bottom_corner_y - top_left.y,
+ };
+
+ Self { top_left, size }
+ }
+}
+
+impl<T: Zero> physical::Rect<T> {
+ pub fn zero() -> Self {
+ Self {
+ top_left: physical::Vec2::zero(),
+ size: physical::Vec2::zero(),
+ }
+ }
+}
+
impl From<physical::Rect<Length>> for Rect<CSSPixel> {
fn from(r: physical::Rect<Length>) -> Self {
Rect {