Add per-Mount scrolling with shared paint and input clipping
Verify Tessera GUI / verify (push) Failing after 7m33s
Verify Tessera GUI / verify (push) Failing after 7m33s
This commit is contained in:
+64
-14
@@ -18,6 +18,7 @@ pub struct Mount {
|
||||
pub first_child: Option<WeakObjectRef>,
|
||||
pub next_sibling: Option<WeakObjectRef>,
|
||||
pub geometry: MountGeometry,
|
||||
pub scroll_offset: [f32; 2],
|
||||
pub version: u64,
|
||||
pub mounted: bool,
|
||||
// Private derived scratch, installed before the read-only layout call and
|
||||
@@ -46,6 +47,10 @@ impl ObjectPayload for Mount {
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum Query {
|
||||
Bounds,
|
||||
ScrollTo,
|
||||
ScrollBy,
|
||||
ScrollPosition,
|
||||
ScrollIntoView,
|
||||
Parent,
|
||||
FirstChild,
|
||||
NextSibling,
|
||||
@@ -64,10 +69,24 @@ struct Method {
|
||||
impl NativeCallable for Method {
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let mount = cx.store().payload::<Mount>(self.owner, "Mount")?.clone();
|
||||
if !mount.mounted && matches!(self.query, Query::Bounds | Query::Focus | Query::HitTest) {
|
||||
if !mount.mounted
|
||||
&& matches!(
|
||||
self.query,
|
||||
Query::Bounds
|
||||
| Query::Focus
|
||||
| Query::HitTest
|
||||
| Query::ScrollTo
|
||||
| Query::ScrollBy
|
||||
| Query::ScrollIntoView
|
||||
| Query::ScrollPosition
|
||||
)
|
||||
{
|
||||
return Err(VmError::InvalidArgument("Mount is no longer attached"));
|
||||
}
|
||||
let arity = if matches!(self.query, Query::HitTest) {
|
||||
let arity = if matches!(
|
||||
self.query,
|
||||
Query::HitTest | Query::ScrollTo | Query::ScrollBy
|
||||
) {
|
||||
2
|
||||
} else {
|
||||
0
|
||||
@@ -76,6 +95,34 @@ impl NativeCallable for Method {
|
||||
return Err(VmError::InvalidArgument("incorrect Mount method arity"));
|
||||
}
|
||||
let value = match self.query {
|
||||
Query::ScrollTo | Query::ScrollBy => {
|
||||
crate::scroll::set(
|
||||
cx,
|
||||
self.owner,
|
||||
self.desktop,
|
||||
[
|
||||
crate::scroll::coordinate(&args[0])?,
|
||||
crate::scroll::coordinate(&args[1])?,
|
||||
],
|
||||
matches!(self.query, Query::ScrollBy),
|
||||
)?;
|
||||
Value::Nil
|
||||
}
|
||||
Query::ScrollIntoView => {
|
||||
crate::scroll::into_view(cx, self.owner, self.desktop)?;
|
||||
Value::Nil
|
||||
}
|
||||
Query::ScrollPosition => {
|
||||
let p = mount
|
||||
.geometry
|
||||
.scroll
|
||||
.ok_or(VmError::InvalidArgument("Mount is not scrollable"))?;
|
||||
let result = cx.new_object()?;
|
||||
for (name, value) in [("x", p[0]), ("y", p[1]), ("maxX", p[2]), ("maxY", p[3])] {
|
||||
cx.set_attr(result, name, Value::Number((value as f64).into()))?;
|
||||
}
|
||||
Value::Object(result)
|
||||
}
|
||||
Query::Bounds => {
|
||||
let geometry = if let Some(layout) = &mount.layout {
|
||||
layout
|
||||
@@ -110,6 +157,7 @@ impl NativeCallable for Method {
|
||||
Value::Object(bounds)
|
||||
}
|
||||
Query::Focus => {
|
||||
crate::scroll::into_view(cx, self.owner, self.desktop)?;
|
||||
if !mount.geometry.interactive {
|
||||
return Err(VmError::InvalidArgument("Mount is not focusable"));
|
||||
}
|
||||
@@ -145,18 +193,10 @@ impl NativeCallable for Method {
|
||||
}
|
||||
Ok(number)
|
||||
};
|
||||
Value::Bool(
|
||||
crate::geometry::Rect::new(
|
||||
mount.geometry.x,
|
||||
mount.geometry.y,
|
||||
mount.geometry.width,
|
||||
mount.geometry.height,
|
||||
)
|
||||
.contains(crate::geometry::Point::new(
|
||||
number(&args[0])?,
|
||||
number(&args[1])?,
|
||||
)),
|
||||
)
|
||||
Value::Bool(mount.geometry.contains(crate::geometry::Point::new(
|
||||
number(&args[0])?,
|
||||
number(&args[1])?,
|
||||
)))
|
||||
}
|
||||
query => {
|
||||
let weak = match query {
|
||||
@@ -277,6 +317,7 @@ impl NativeCallable for Sync {
|
||||
first_child: None,
|
||||
next_sibling: None,
|
||||
geometry: geometry.clone(),
|
||||
scroll_offset: [0.0, 0.0],
|
||||
version: self.frame.layout_version,
|
||||
mounted: true,
|
||||
layout: None,
|
||||
@@ -284,6 +325,10 @@ impl NativeCallable for Sync {
|
||||
crate::ui_bridge::attach_desktop_type(cx, object, "Mount", self.desktop)?;
|
||||
for (name, query) in [
|
||||
("bounds", Query::Bounds),
|
||||
("scrollTo", Query::ScrollTo),
|
||||
("scrollBy", Query::ScrollBy),
|
||||
("scrollPosition", Query::ScrollPosition),
|
||||
("scrollIntoView", Query::ScrollIntoView),
|
||||
("parent", Query::Parent),
|
||||
("firstChild", Query::FirstChild),
|
||||
("nextSibling", Query::NextSibling),
|
||||
@@ -322,6 +367,11 @@ impl NativeCallable for Sync {
|
||||
first_child: link(geometry.first_child)?,
|
||||
next_sibling: link(geometry.next_sibling)?,
|
||||
geometry: geometry.clone(),
|
||||
scroll_offset: if self.preparing {
|
||||
cx.store().payload::<Mount>(object, "Mount")?.scroll_offset
|
||||
} else {
|
||||
geometry.scroll.map(|s| [s[0], s[1]]).unwrap_or([0.0, 0.0])
|
||||
},
|
||||
version: self.frame.layout_version,
|
||||
mounted: true,
|
||||
layout: if self.preparing {
|
||||
|
||||
Reference in New Issue
Block a user