Increase accuracy of various Web APIs (#2946)
This commit is contained in:
parent
db8de03142
commit
c4d70d75c1
9 changed files with 73 additions and 38 deletions
|
|
@ -400,12 +400,17 @@ impl<T: 'static> Shared<T> {
|
|||
if !runner.0.suspended.get() {
|
||||
for (id, canvas) in &*runner.0.all_canvases.borrow() {
|
||||
if let Some(canvas) = canvas.upgrade() {
|
||||
if backend::is_intersecting(runner.window(), canvas.borrow().raw()) {
|
||||
let is_visible = backend::is_visible(runner.window());
|
||||
// only fire if:
|
||||
// - not visible and intersects
|
||||
// - not visible and we don't know if it intersects yet
|
||||
// - visible and intersects
|
||||
if let (false, Some(true) | None) | (true, Some(true)) =
|
||||
(is_visible, canvas.borrow().is_intersecting)
|
||||
{
|
||||
runner.send_event(Event::WindowEvent {
|
||||
window_id: *id,
|
||||
event: WindowEvent::Occluded(!backend::is_visible(
|
||||
runner.window(),
|
||||
)),
|
||||
event: WindowEvent::Occluded(!is_visible),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -705,9 +705,10 @@ impl<T> EventLoopWindowTarget<T> {
|
|||
},
|
||||
{
|
||||
let runner = self.runner.clone();
|
||||
let canvas = canvas_clone.clone();
|
||||
|
||||
move |new_size| {
|
||||
let canvas = RefCell::borrow(&canvas_clone);
|
||||
let canvas = canvas.borrow();
|
||||
canvas.set_current_size(new_size);
|
||||
if canvas.old_size() != new_size {
|
||||
canvas.set_old_size(new_size);
|
||||
|
|
@ -723,12 +724,17 @@ impl<T> EventLoopWindowTarget<T> {
|
|||
|
||||
let runner = self.runner.clone();
|
||||
canvas.on_intersection(move |is_intersecting| {
|
||||
if backend::is_visible(runner.window()) {
|
||||
// only fire if visible while skipping the first event if it's intersecting
|
||||
if backend::is_visible(runner.window())
|
||||
&& !(is_intersecting && canvas_clone.borrow().is_intersecting.is_none())
|
||||
{
|
||||
runner.send_event(Event::WindowEvent {
|
||||
window_id: RootWindowId(id),
|
||||
event: WindowEvent::Occluded(!is_intersecting),
|
||||
});
|
||||
}
|
||||
|
||||
canvas_clone.borrow_mut().is_intersecting = Some(is_intersecting);
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue