#include "third_party/blink/renderer/core/html/media/media_video_visibility_tracker.h"
#include "base/metrics/histogram_macros.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/visual_viewport.h"
#include "third_party/blink/renderer/core/fullscreen/fullscreen.h"
#include "third_party/blink/renderer/core/html/media/html_video_element.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_video.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/platform/graphics/paint/display_item.h"
#include "third_party/blink/renderer/platform/graphics/paint/display_item_list.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_artifact.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/skia_conversions.h"
namespace blink {
namespace {
HitTestResult HitTestForOcclusionRatio(
const HTMLVideoElement& video_element,
const PhysicalRect& hit_rect,
std::optional<HitTestRequest::HitNodeCb> hit_node_cb) { … }
float ComputeArea(const PhysicalRect& rect) { … }
bool HasEnoughVisibleAreaRemaining(float occluded_area,
const PhysicalRect& video_element_rect,
const int visibility_threshold) { … }
float ComputeOccludingArea(const Vector<SkIRect>& occluding_rects,
float video_element_area) { … }
void RecordTotalCounts(const MediaVideoVisibilityTracker::Metrics& counts) { … }
const Vector<AtomicString>& FullscreenEventTypes() { … }
bool HasEventListenerRegistered(EventTarget& target,
const AtomicString& event_type,
const EventListener* listener) { … }
bool IsContentType(DisplayItem::Type type) { … }
void RecordVideoOcclusionState(
const HTMLVideoElement& video_element,
const MediaVideoVisibilityTracker::OcclusionState& occlusion_state,
bool has_sufficiently_visible_video,
const int visibility_threshold) { … }
}
MediaVideoVisibilityTracker::MediaVideoVisibilityTracker(
HTMLVideoElement& video,
const int visibility_threshold,
ReportVisibilityCb report_visibility_cb,
base::TimeDelta hit_test_interval)
: … { … }
MediaVideoVisibilityTracker::~MediaVideoVisibilityTracker() { … }
void MediaVideoVisibilityTracker::Attach() { … }
void MediaVideoVisibilityTracker::Detach() { … }
void MediaVideoVisibilityTracker::UpdateVisibilityTrackerState() { … }
void MediaVideoVisibilityTracker::ElementDidMoveToNewDocument() { … }
void MediaVideoVisibilityTracker::Invoke(ExecutionContext* context,
Event* event) { … }
void MediaVideoVisibilityTracker::MaybeAddFullscreenEventListeners() { … }
void MediaVideoVisibilityTracker::MaybeRemoveFullscreenEventListeners() { … }
void MediaVideoVisibilityTracker::RequestVisibility(
RequestVisibilityCallback request_visibility_callback) { … }
const MediaVideoVisibilityTracker::ClientIdsSet
MediaVideoVisibilityTracker::GetClientIdsSet(
DisplayItemClientId start_after_display_item_client_id) const { … }
ListBasedHitTestBehavior MediaVideoVisibilityTracker::ComputeOcclusion(
const ClientIdsSet& client_ids_set,
Metrics& counts,
const Node& node) { … }
bool MediaVideoVisibilityTracker::MeetsVisibilityThreshold(
Metrics& counts,
const PhysicalRect& rect) { … }
bool MediaVideoVisibilityTracker::ComputeVisibility() { … }
void MediaVideoVisibilityTracker::ComputeAreaOccludedByViewport(
const LocalFrameView& local_frame_view) { … }
void MediaVideoVisibilityTracker::MaybeComputeVisibility(
ShouldReportVisibility should_report_visibility) { … }
void MediaVideoVisibilityTracker::DidFinishLifecycleUpdate(
const LocalFrameView& local_frame_view) { … }
void MediaVideoVisibilityTracker::Trace(Visitor* visitor) const { … }
}