Commit 945f4bf5 authored by johnme's avatar johnme Committed by Commit Bot

[ElementVisibilityObserver] Fix regression with default threshold

https://codereview.chromium.org/2830713003 (r468137,
913ee5fe) changed the default threshold
of ElementVisibilityObserver from std::numeric_limits<float>::min() to
zero, assuming that they would behave the same.

It turns out that there's some confusion here - see
https://github.com/WICG/IntersectionObserver/issues/164 - and for now
we should continue to use std::numeric_limits<float>::min() to
distinguish between completely hidden and partially visible.

BUG=726839

Review-Url: https://codereview.chromium.org/2919543002
Cr-Commit-Position: refs/heads/master@{#476265}
parent 84ca4474
...@@ -52,7 +52,7 @@ DEFINE_TRACE(ElementVisibilityObserver) { ...@@ -52,7 +52,7 @@ DEFINE_TRACE(ElementVisibilityObserver) {
void ElementVisibilityObserver::OnVisibilityChanged( void ElementVisibilityObserver::OnVisibilityChanged(
const HeapVector<Member<IntersectionObserverEntry>>& entries) { const HeapVector<Member<IntersectionObserverEntry>>& entries) {
bool is_visible = entries.back()->intersectionRatio() > bool is_visible = entries.back()->intersectionRatio() >=
intersection_observer_->thresholds()[0]; intersection_observer_->thresholds()[0];
(*callback_.get())(is_visible); (*callback_.get())(is_visible);
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef ElementVisibilityObserver_h #ifndef ElementVisibilityObserver_h
#define ElementVisibilityObserver_h #define ElementVisibilityObserver_h
#include <limits>
#include "core/CoreExport.h" #include "core/CoreExport.h"
#include "core/dom/IntersectionObserver.h" #include "core/dom/IntersectionObserver.h"
#include "platform/heap/Heap.h" #include "platform/heap/Heap.h"
...@@ -34,7 +36,9 @@ class CORE_EXPORT ElementVisibilityObserver final ...@@ -34,7 +36,9 @@ class CORE_EXPORT ElementVisibilityObserver final
virtual ~ElementVisibilityObserver(); virtual ~ElementVisibilityObserver();
// The |threshold| is the minimum fraction that needs to be visible. // The |threshold| is the minimum fraction that needs to be visible.
void Start(float threshold = 0.0); // See https://github.com/WICG/IntersectionObserver/issues/164 for why this
// defaults to std::numeric_limits<float>::min() rather than zero.
void Start(float threshold = std::numeric_limits<float>::min());
void Stop(); void Stop();
void DeliverObservationsForTesting(); void DeliverObservationsForTesting();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment