Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2696893002: [Blink>Media] Add heuristic for dominant video detection for Android (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 namespace blink { 118 namespace blink {
119 119
120 using namespace HTMLNames; 120 using namespace HTMLNames;
121 121
122 using WeakMediaElementSet = HeapHashSet<WeakMember<HTMLMediaElement>>; 122 using WeakMediaElementSet = HeapHashSet<WeakMember<HTMLMediaElement>>;
123 using DocumentElementSetMap = 123 using DocumentElementSetMap =
124 HeapHashMap<WeakMember<Document>, Member<WeakMediaElementSet>>; 124 HeapHashMap<WeakMember<Document>, Member<WeakMediaElementSet>>;
125 125
126 namespace { 126 namespace {
127 127
128 constexpr float kMostlyFillViewportThreshold = 0.85f; 128 constexpr float kMostlyFillViewportThresholdInDominantDimension = 0.85f;
129 constexpr float kMostlyFillViewportThresholdForTargetVisibleRatio = 0.75f;
129 constexpr double kMostlyFillViewportBecomeStableSeconds = 5; 130 constexpr double kMostlyFillViewportBecomeStableSeconds = 5;
130 constexpr double kCheckViewportIntersectionIntervalSeconds = 1; 131 constexpr double kCheckViewportIntersectionIntervalSeconds = 1;
131 132
132 enum MediaControlsShow { 133 enum MediaControlsShow {
133 MediaControlsShowAttribute = 0, 134 MediaControlsShowAttribute = 0,
134 MediaControlsShowFullscreen, 135 MediaControlsShowFullscreen,
135 MediaControlsShowNoScript, 136 MediaControlsShowNoScript,
136 MediaControlsShowNotShown, 137 MediaControlsShowNotShown,
137 MediaControlsShowMax 138 MediaControlsShowMax
138 }; 139 };
(...skipping 3963 matching lines...) Expand 10 before | Expand all | Expand 10 after
4102 shouldReportRootBounds); 4103 shouldReportRootBounds);
4103 geometry.computeGeometry(); 4104 geometry.computeGeometry();
4104 IntRect intersectRect = geometry.intersectionIntRect(); 4105 IntRect intersectRect = geometry.intersectionIntRect();
4105 if (m_currentIntersectRect == intersectRect) 4106 if (m_currentIntersectRect == intersectRect)
4106 return; 4107 return;
4107 4108
4108 m_currentIntersectRect = intersectRect; 4109 m_currentIntersectRect = intersectRect;
4109 // Reset on any intersection change, since this indicates the user is 4110 // Reset on any intersection change, since this indicates the user is
4110 // scrolling around in the document, the document is changing layout, etc. 4111 // scrolling around in the document, the document is changing layout, etc.
4111 m_viewportFillDebouncerTimer.stop(); 4112 m_viewportFillDebouncerTimer.stop();
4112 bool isMostlyFillingViewport = 4113
4113 (m_currentIntersectRect.size().area() > 4114 bool isMostlyFillingViewport = computeIsMostlyFillingViewport(
4114 kMostlyFillViewportThreshold * geometry.rootIntRect().size().area()); 4115 geometry.targetIntRect(), geometry.rootIntRect(),
4116 geometry.intersectionIntRect());
4115 if (m_mostlyFillingViewport == isMostlyFillingViewport) 4117 if (m_mostlyFillingViewport == isMostlyFillingViewport)
4116 return; 4118 return;
4117 4119
4118 if (!isMostlyFillingViewport) { 4120 if (!isMostlyFillingViewport) {
4119 m_mostlyFillingViewport = isMostlyFillingViewport; 4121 m_mostlyFillingViewport = isMostlyFillingViewport;
4120 if (m_webMediaPlayer) 4122 if (m_webMediaPlayer)
4121 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport); 4123 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport);
4122 return; 4124 return;
4123 } 4125 }
4124 4126
4125 m_viewportFillDebouncerTimer.startOneShot( 4127 m_viewportFillDebouncerTimer.startOneShot(
4126 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE); 4128 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE);
4127 } 4129 }
4128 4130
4129 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) { 4131 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) {
4130 m_mostlyFillingViewport = true; 4132 m_mostlyFillingViewport = true;
4131 if (m_webMediaPlayer) 4133 if (m_webMediaPlayer)
4132 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport); 4134 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport);
4133 } 4135 }
4134 4136
4137 bool HTMLMediaElement::computeIsMostlyFillingViewport(
4138 const IntRect& targetRect,
4139 const IntRect& rootRect,
4140 const IntRect& intersectionRect) {
4141 if (targetRect.size().area() == 0 ||
4142 intersectionRect.size().area() <=
4143 kMostlyFillViewportThresholdForTargetVisibleRatio *
4144 targetRect.size().area()) {
4145 return false;
4146 }
4147
4148 float xOccupationRatio = 1.0f * intersectionRect.width() / rootRect.width();
4149 float yOccupationRatio = 1.0f * intersectionRect.height() / rootRect.height();
mlamouri (slow - plz ping) 2017/02/15 11:08:04 nit: I guess those can be `const float`
Zhiqiang Zhang (Slow) 2017/02/15 11:52:09 Done.
4150
4151 return std::max(xOccupationRatio, yOccupationRatio) >=
4152 kMostlyFillViewportThresholdInDominantDimension;
4153 }
4154
4135 } // namespace blink 4155 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698