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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
alwu 2019-07-06 00:53:20 +00:00
Родитель 0a425ceb11
Коммит 07e34c8bba
2 изменённых файлов: 25 добавлений и 14 удалений

Просмотреть файл

@ -311,6 +311,8 @@ void TextTrackManager::PopulatePendingList() {
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,
@ -416,14 +418,20 @@ TextTrackManager::HandleEvent(Event* aEvent) {
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();
}

Просмотреть файл

@ -238,18 +238,19 @@ already_AddRefed<Layer> nsVideoFrame::BuildLayer(
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,
@ -354,10 +355,12 @@ void nsVideoFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics,
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 {