Bug 1541452 - update cue display when window is resized. r=heycam
authoralwu <alwu@mozilla.com>
Sat, 06 Jul 2019 00:53:20 +0000
changeset 481520 16485dcacef6087da868ac4fef2ad829850db195
parent 481519 91d8f385c5e5ec15c5cdb1d6c24b582fe1862acc
child 481521 6d317cd3124aafefc18ffd0ac2056bfe76a119bb
push id36248
push userdvarga@mozilla.com
push dateSat, 06 Jul 2019 09:34:01 +0000
treeherdermozilla-central@1dd4e16a1a96 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1541452
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1541452 - update cue display when window is resized. r=heycam When window is resized, the cue would usually be zoomed in or out automatically with the video and keep its relative position to video. However, if video is being applied the explicit percentage value on its 'width' or 'height', we have to recompute cue's position in this situation, because the width or height of the video would be scaled again after applied the first size scaled which is caused by resizing. Differential Revision: https://phabricator.services.mozilla.com/D36138
dom/html/TextTrackManager.cpp
layout/generic/nsVideoFrame.cpp
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -306,16 +306,18 @@ void TextTrackManager::PopulatePendingLi
       mPendingTextTracks->AddTextTrack(ttrack,
                                        CompareTextTracks(mMediaElement));
     }
   }
 }
 
 void TextTrackManager::AddListeners() {
   if (mMediaElement) {
+    mMediaElement->AddEventListener(NS_LITERAL_STRING("resizecaption"), this,
+                                    false, false);
     mMediaElement->AddEventListener(NS_LITERAL_STRING("resizevideocontrols"),
                                     this, false, false);
     mMediaElement->AddEventListener(NS_LITERAL_STRING("seeked"), this, false,
                                     false);
     mMediaElement->AddEventListener(NS_LITERAL_STRING("controlbarchange"), this,
                                     false, true);
   }
 }
@@ -411,24 +413,30 @@ void TextTrackManager::GetTextTracksOfKi
 NS_IMETHODIMP
 TextTrackManager::HandleEvent(Event* aEvent) {
   if (!mTextTracks) {
     return NS_OK;
   }
 
   nsAutoString type;
   aEvent->GetType(type);
-  if (type.EqualsLiteral("resizevideocontrols") ||
-      type.EqualsLiteral("seeked")) {
+  WEBVTT_LOG("Handle event %s", NS_ConvertUTF16toUTF8(type).get());
+
+  const bool setDirty = type.EqualsLiteral("seeked") ||
+                        type.EqualsLiteral("resizecaption") ||
+                        type.EqualsLiteral("resizevideocontrols");
+  const bool updateDisplay = type.EqualsLiteral("controlbarchange") ||
+                             type.EqualsLiteral("resizecaption");
+
+  if (setDirty) {
     for (uint32_t i = 0; i < mTextTracks->Length(); i++) {
       ((*mTextTracks)[i])->SetCuesDirty();
     }
   }
-
-  if (type.EqualsLiteral("controlbarchange")) {
+  if (updateDisplay) {
     UpdateCueDisplay();
   }
 
   return NS_OK;
 }
 
 class SimpleTextTrackEvent : public Runnable {
  public:
--- a/layout/generic/nsVideoFrame.cpp
+++ b/layout/generic/nsVideoFrame.cpp
@@ -233,28 +233,29 @@ already_AddRefed<Layer> nsVideoFrame::Bu
 
   uint32_t flags = element->HasAlpha() ? 0 : Layer::CONTENT_OPAQUE;
   layer->SetContentFlags(flags);
 
   RefPtr<Layer> result = layer.forget();
   return result.forget();
 }
 
-class DispatchResizeToControls : public Runnable {
+class DispatchResizeEvent : public Runnable {
  public:
-  explicit DispatchResizeToControls(nsIContent* aContent)
-      : mozilla::Runnable("DispatchResizeToControls"), mContent(aContent) {}
+  explicit DispatchResizeEvent(nsIContent* aContent, const nsString& aName)
+      : mozilla::Runnable("DispatchResizeEvent"),
+        mContent(aContent),
+        mName(aName) {}
   NS_IMETHOD Run() override {
-    nsContentUtils::DispatchTrustedEvent(
-        mContent->OwnerDoc(), mContent,
-        NS_LITERAL_STRING("resizevideocontrols"), CanBubble::eNo,
-        Cancelable::eNo);
+    nsContentUtils::DispatchTrustedEvent(mContent->OwnerDoc(), mContent, mName,
+                                         CanBubble::eNo, Cancelable::eNo);
     return NS_OK;
   }
   nsCOMPtr<nsIContent> mContent;
+  nsString mName;
 };
 
 void nsVideoFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics,
                           const ReflowInput& aReflowInput,
                           nsReflowStatus& aStatus) {
   MarkInReflow();
   DO_GLOBAL_REFLOW_COUNT("nsVideoFrame");
   DISPLAY_REFLOW(aPresContext, this, aReflowInput, aMetrics, aStatus);
@@ -349,20 +350,22 @@ void nsVideoFrame::Reflow(nsPresContext*
           contentBoxBSize = myWM.IsOrthogonalTo(wm) ? kidDesiredSize.ISize(wm)
                                                     : kidDesiredSize.BSize(wm);
         }
       }
 
       FinishReflowChild(child, aPresContext, kidDesiredSize, &kidReflowInput,
                         borderPadding.left, borderPadding.top, 0);
 
-      if (child->GetContent() == videoControlsDiv &&
-          child->GetSize() != oldChildSize) {
+      if (child->GetSize() != oldChildSize) {
+        const nsString name = child->GetContent() == videoControlsDiv
+                                  ? NS_LITERAL_STRING("resizevideocontrols")
+                                  : NS_LITERAL_STRING("resizecaption");
         RefPtr<Runnable> event =
-            new DispatchResizeToControls(child->GetContent());
+            new DispatchResizeEvent(child->GetContent(), name);
         nsContentUtils::AddScriptRunner(event);
       }
     } else {
       NS_ERROR("Unexpected extra child frame in nsVideoFrame; skipping");
     }
   }
 
   if (isBSizeShrinkWrapping) {