2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-07-09 12:22:20 +04:00
|
|
|
|
|
|
|
/* rendering object for the HTML <video> element */
|
|
|
|
|
2013-09-25 05:43:43 +04:00
|
|
|
#include "nsVideoFrame.h"
|
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
|
2013-03-19 16:27:35 +04:00
|
|
|
#include "mozilla/dom/HTMLVideoElement.h"
|
2018-09-12 00:35:50 +03:00
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2017-06-29 01:12:25 +03:00
|
|
|
#include "mozilla/layers/WebRenderLayerManager.h"
|
2008-07-09 12:22:20 +04:00
|
|
|
#include "nsDisplayList.h"
|
2013-05-29 00:55:00 +04:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2008-07-09 12:22:20 +04:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsBoxFrame.h"
|
2018-09-12 00:35:50 +03:00
|
|
|
#include "nsIContentInlines.h"
|
2009-06-26 11:25:17 +04:00
|
|
|
#include "nsImageFrame.h"
|
|
|
|
#include "nsIImageLoadingContent.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-08-19 23:33:25 +04:00
|
|
|
#include "ImageContainer.h"
|
|
|
|
#include "ImageLayers.h"
|
2014-11-15 03:45:23 +03:00
|
|
|
#include "nsStyleUtil.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2010-08-02 07:06:58 +04:00
|
|
|
using namespace mozilla;
|
2010-03-02 02:41:49 +03:00
|
|
|
using namespace mozilla::layers;
|
2011-06-01 05:46:57 +04:00
|
|
|
using namespace mozilla::dom;
|
2013-12-31 13:06:12 +04:00
|
|
|
using namespace mozilla::gfx;
|
2010-03-02 02:41:49 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
nsIFrame* NS_NewHTMLVideoFrame(nsIPresShell* aPresShell,
|
|
|
|
ComputedStyle* aStyle) {
|
|
|
|
return new (aPresShell) nsVideoFrame(aStyle);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsVideoFrame)
|
|
|
|
|
2016-05-11 20:54:52 +03:00
|
|
|
// A matrix to obtain a correct-rotated video frame.
|
|
|
|
static Matrix ComputeRotationMatrix(gfxFloat aRotatedWidth,
|
|
|
|
gfxFloat aRotatedHeight,
|
|
|
|
VideoInfo::Rotation aDegrees) {
|
|
|
|
Matrix shiftVideoCenterToOrigin;
|
|
|
|
if (aDegrees == VideoInfo::Rotation::kDegree_90 ||
|
|
|
|
aDegrees == VideoInfo::Rotation::kDegree_270) {
|
|
|
|
shiftVideoCenterToOrigin =
|
|
|
|
Matrix::Translation(-aRotatedHeight / 2.0, -aRotatedWidth / 2.0);
|
|
|
|
} else {
|
|
|
|
shiftVideoCenterToOrigin =
|
|
|
|
Matrix::Translation(-aRotatedWidth / 2.0, -aRotatedHeight / 2.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Matrix rotation = Matrix::Rotation(gfx::Float(aDegrees / 180.0 * M_PI));
|
|
|
|
Matrix shiftLeftTopToOrigin =
|
|
|
|
Matrix::Translation(aRotatedWidth / 2.0, aRotatedHeight / 2.0);
|
|
|
|
return shiftVideoCenterToOrigin * rotation * shiftLeftTopToOrigin;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SwapScaleWidthHeightForRotation(IntSize& aSize,
|
|
|
|
VideoInfo::Rotation aDegrees) {
|
|
|
|
if (aDegrees == VideoInfo::Rotation::kDegree_90 ||
|
|
|
|
aDegrees == VideoInfo::Rotation::kDegree_270) {
|
|
|
|
int32_t tmpWidth = aSize.width;
|
|
|
|
aSize.width = aSize.height;
|
|
|
|
aSize.height = tmpWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
nsVideoFrame::nsVideoFrame(ComputedStyle* aStyle)
|
|
|
|
: nsContainerFrame(aStyle, kClassID) {
|
2016-03-26 00:49:43 +03:00
|
|
|
EnableVisibilityTracking();
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsVideoFrame::~nsVideoFrame() {}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsVideoFrame)
|
2013-05-28 00:34:00 +04:00
|
|
|
NS_QUERYFRAME_ENTRY(nsVideoFrame)
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
2016-04-18 09:26:44 +03:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2011-05-07 00:04:44 +04:00
|
|
|
nsresult nsVideoFrame::CreateAnonymousContent(
|
|
|
|
nsTArray<ContentInfo>& aElements) {
|
2014-09-25 02:52:12 +04:00
|
|
|
nsNodeInfoManager* nodeInfoManager =
|
|
|
|
GetContent()->GetComposedDoc()->NodeInfoManager();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NodeInfo> nodeInfo;
|
2013-02-27 01:06:51 +04:00
|
|
|
|
2009-06-26 11:25:17 +04:00
|
|
|
if (HasVideoElement()) {
|
|
|
|
// Create an anonymous image element as a child to hold the poster
|
|
|
|
// image. We may not have a poster image now, but one could be added
|
|
|
|
// before we load, or on a subsequent load.
|
|
|
|
nodeInfo = nodeInfoManager->GetNodeInfo(
|
2018-01-30 07:10:53 +03:00
|
|
|
nsGkAtoms::img, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE);
|
2009-06-26 11:25:17 +04:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
2017-12-05 20:05:51 +03:00
|
|
|
mPosterImage = NS_NewHTMLImageElement(nodeInfo.forget());
|
2009-06-26 11:25:17 +04:00
|
|
|
NS_ENSURE_TRUE(mPosterImage, NS_ERROR_OUT_OF_MEMORY);
|
2009-11-05 16:56:52 +03:00
|
|
|
|
2009-06-26 11:25:17 +04:00
|
|
|
// Set the nsImageLoadingContent::ImageState() to 0. This means that the
|
|
|
|
// image will always report its state as 0, so it will never be reframed
|
|
|
|
// to show frames for loading or the broken image icon. This is important,
|
|
|
|
// as the image is native anonymous, and so can't be reframed (currently).
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imgContent =
|
|
|
|
do_QueryInterface(mPosterImage);
|
|
|
|
NS_ENSURE_TRUE(imgContent, NS_ERROR_FAILURE);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
imgContent->ForceImageState(true, 0);
|
2011-06-01 05:46:57 +04:00
|
|
|
// And now have it update its internal state
|
2017-12-05 20:05:51 +03:00
|
|
|
mPosterImage->UpdateState(false);
|
2009-06-26 11:25:17 +04:00
|
|
|
|
2013-12-04 05:06:16 +04:00
|
|
|
UpdatePosterSource(false);
|
2009-11-05 16:56:52 +03:00
|
|
|
|
2009-06-26 11:25:17 +04:00
|
|
|
if (!aElements.AppendElement(mPosterImage)) return NS_ERROR_OUT_OF_MEMORY;
|
2013-02-27 01:06:51 +04:00
|
|
|
|
|
|
|
// Set up the caption overlay div for showing any TextTrack data
|
|
|
|
nodeInfo = nodeInfoManager->GetNodeInfo(
|
2018-01-30 07:10:53 +03:00
|
|
|
nsGkAtoms::div, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE);
|
2013-02-27 01:06:51 +04:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
mCaptionDiv = NS_NewHTMLDivElement(nodeInfo.forget());
|
|
|
|
NS_ENSURE_TRUE(mCaptionDiv, NS_ERROR_OUT_OF_MEMORY);
|
2013-05-29 00:55:00 +04:00
|
|
|
nsGenericHTMLElement* div =
|
|
|
|
static_cast<nsGenericHTMLElement*>(mCaptionDiv.get());
|
|
|
|
div->SetClassName(NS_LITERAL_STRING("caption-box"));
|
2013-02-27 01:06:51 +04:00
|
|
|
|
|
|
|
if (!aElements.AppendElement(mCaptionDiv)) return NS_ERROR_OUT_OF_MEMORY;
|
2017-03-28 11:48:40 +03:00
|
|
|
UpdateTextTrack();
|
2009-11-05 16:56:52 +03:00
|
|
|
}
|
2009-06-26 11:25:17 +04:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
// Set up "videocontrols" XUL element which will be XBL-bound to the
|
|
|
|
// actual controls.
|
2009-06-26 11:25:17 +04:00
|
|
|
nodeInfo =
|
|
|
|
nodeInfoManager->GetNodeInfo(nsGkAtoms::videocontrols, nullptr,
|
2018-01-30 07:10:53 +03:00
|
|
|
kNameSpaceID_XUL, nsINode::ELEMENT_NODE);
|
2008-09-26 02:46:52 +04:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2018-06-27 21:12:38 +03:00
|
|
|
if (!nsContentUtils::IsUAWidgetEnabled()) {
|
|
|
|
NS_TrustedNewXULElement(getter_AddRefs(mVideoControls), nodeInfo.forget());
|
|
|
|
if (!aElements.AppendElement(mVideoControls)) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2009-06-26 11:25:17 +04:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-16 22:41:57 +04:00
|
|
|
void nsVideoFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFliter) {
|
2014-07-16 22:41:57 +04:00
|
|
|
if (mPosterImage) {
|
|
|
|
aElements.AppendElement(mPosterImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mVideoControls) {
|
|
|
|
aElements.AppendElement(mVideoControls);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCaptionDiv) {
|
|
|
|
aElements.AppendElement(mCaptionDiv);
|
|
|
|
}
|
2010-02-11 20:34:01 +03:00
|
|
|
}
|
|
|
|
|
2018-06-27 21:12:38 +03:00
|
|
|
nsIContent* nsVideoFrame::GetVideoControls() {
|
|
|
|
if (mVideoControls) {
|
|
|
|
return mVideoControls;
|
|
|
|
}
|
|
|
|
if (mContent->GetShadowRoot()) {
|
2018-08-17 23:43:46 +03:00
|
|
|
// The video controls <div> is the only child of the UA Widget Shadow Root
|
|
|
|
// if it is present. It is only lazily inserted into the DOM when
|
|
|
|
// the controls attribute is set.
|
2018-06-29 23:39:46 +03:00
|
|
|
MOZ_ASSERT(mContent->GetShadowRoot()->IsUAWidget());
|
2018-08-17 23:43:46 +03:00
|
|
|
MOZ_ASSERT(1 >= mContent->GetShadowRoot()->GetChildCount());
|
2018-06-27 21:12:38 +03:00
|
|
|
return mContent->GetShadowRoot()->GetFirstChild();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
void nsVideoFrame::DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) {
|
|
|
|
aPostDestroyData.AddAnonymousContent(mCaptionDiv.forget());
|
|
|
|
aPostDestroyData.AddAnonymousContent(mVideoControls.forget());
|
|
|
|
aPostDestroyData.AddAnonymousContent(mPosterImage.forget());
|
|
|
|
nsContainerFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2010-03-02 02:41:49 +03:00
|
|
|
already_AddRefed<Layer> nsVideoFrame::BuildLayer(
|
|
|
|
nsDisplayListBuilder* aBuilder, LayerManager* aManager,
|
2012-09-17 02:25:33 +04:00
|
|
|
nsDisplayItem* aItem,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters) {
|
2014-11-26 02:40:02 +03:00
|
|
|
nsRect area = GetContentRectRelativeToSelf() + aItem->ToReferenceFrame();
|
2013-03-19 16:27:35 +04:00
|
|
|
HTMLVideoElement* element = static_cast<HTMLVideoElement*>(GetContent());
|
2014-11-15 03:45:24 +03:00
|
|
|
|
|
|
|
nsIntSize videoSizeInPx;
|
|
|
|
if (NS_FAILED(element->GetVideoSize(&videoSizeInPx)) || area.IsEmpty()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-05-11 12:32:15 +04:00
|
|
|
}
|
2010-03-02 02:41:49 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageContainer> container = element->GetImageContainer();
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!container) return nullptr;
|
2016-05-11 20:54:52 +03:00
|
|
|
|
2010-04-27 12:53:44 +04:00
|
|
|
// Retrieve the size of the decoded video frame, before being scaled
|
|
|
|
// by pixel aspect ratio.
|
2013-12-13 21:32:02 +04:00
|
|
|
mozilla::gfx::IntSize frameSize = container->GetCurrentSize();
|
2010-04-27 12:53:44 +04:00
|
|
|
if (frameSize.width == 0 || frameSize.height == 0) {
|
|
|
|
// No image, or zero-sized image. No point creating a layer.
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-04-27 12:53:44 +04:00
|
|
|
}
|
|
|
|
|
2014-11-15 03:45:24 +03:00
|
|
|
// Convert video size from pixel units into app units, to get an aspect-ratio
|
|
|
|
// (which has to be represented as a nsSize) and an IntrinsicSize that we
|
|
|
|
// can pass to ComputeObjectRenderRect.
|
|
|
|
nsSize aspectRatio(nsPresContext::CSSPixelsToAppUnits(videoSizeInPx.width),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(videoSizeInPx.height));
|
|
|
|
IntrinsicSize intrinsicSize;
|
|
|
|
intrinsicSize.width.SetCoordValue(aspectRatio.width);
|
|
|
|
intrinsicSize.height.SetCoordValue(aspectRatio.height);
|
|
|
|
|
2014-11-26 02:40:02 +03:00
|
|
|
nsRect dest = nsLayoutUtils::ComputeObjectDestRect(
|
2014-11-15 03:45:24 +03:00
|
|
|
area, intrinsicSize, aspectRatio, StylePosition());
|
|
|
|
|
|
|
|
gfxRect destGFXRect = PresContext()->AppUnitsToGfxUnits(dest);
|
|
|
|
destGFXRect.Round();
|
|
|
|
if (destGFXRect.IsEmpty()) {
|
2012-11-30 02:11:04 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2016-05-11 20:54:52 +03:00
|
|
|
|
|
|
|
VideoInfo::Rotation rotationDeg = element->RotationDegrees();
|
2014-11-15 03:45:24 +03:00
|
|
|
IntSize scaleHint(static_cast<int32_t>(destGFXRect.Width()),
|
|
|
|
static_cast<int32_t>(destGFXRect.Height()));
|
2016-05-11 20:54:52 +03:00
|
|
|
// scaleHint is set regardless of rotation, so swap w/h if needed.
|
|
|
|
SwapScaleWidthHeightForRotation(scaleHint, rotationDeg);
|
2010-10-26 07:11:13 +04:00
|
|
|
container->SetScaleHint(scaleHint);
|
2010-03-02 02:41:49 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageLayer> layer = static_cast<ImageLayer*>(
|
2012-08-29 09:47:15 +04:00
|
|
|
aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, aItem));
|
2010-07-16 01:07:46 +04:00
|
|
|
if (!layer) {
|
|
|
|
layer = aManager->CreateImageLayer();
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!layer) return nullptr;
|
2010-07-16 01:07:46 +04:00
|
|
|
}
|
2010-03-02 02:41:49 +03:00
|
|
|
|
|
|
|
layer->SetContainer(container);
|
2016-05-25 19:01:18 +03:00
|
|
|
layer->SetSamplingFilter(nsLayoutUtils::GetSamplingFilterForFrame(this));
|
2010-03-02 02:41:49 +03:00
|
|
|
// Set a transform on the layer to draw the video in the right place
|
2014-11-15 03:45:24 +03:00
|
|
|
gfxPoint p = destGFXRect.TopLeft() + aContainerParameters.mOffset;
|
2016-05-11 20:54:52 +03:00
|
|
|
|
|
|
|
Matrix preTransform = ComputeRotationMatrix(
|
|
|
|
destGFXRect.Width(), destGFXRect.Height(), rotationDeg);
|
|
|
|
|
|
|
|
Matrix transform = preTransform * Matrix::Translation(p.x, p.y);
|
|
|
|
|
2014-01-27 19:28:33 +04:00
|
|
|
layer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));
|
2014-11-15 03:45:24 +03:00
|
|
|
layer->SetScaleToSize(scaleHint, ScaleMode::STRETCH);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Layer> result = layer.forget();
|
2010-03-02 02:41:49 +03:00
|
|
|
return result.forget();
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class DispatchResizeToControls : public Runnable {
|
2013-05-28 09:00:59 +04:00
|
|
|
public:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit DispatchResizeToControls(nsIContent* aContent)
|
2017-06-12 22:34:10 +03:00
|
|
|
: mozilla::Runnable("DispatchResizeToControls"), mContent(aContent) {}
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2013-05-28 09:00:59 +04:00
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
|
|
|
mContent->OwnerDoc(), mContent,
|
|
|
|
NS_LITERAL_STRING("resizevideocontrols"), CanBubble::eNo,
|
2018-06-25 19:23:50 +03:00
|
|
|
Cancelable::eNo);
|
2013-05-28 09:00:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContent> mContent;
|
|
|
|
};
|
|
|
|
|
2016-09-08 20:21:52 +03:00
|
|
|
void nsVideoFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2016-09-08 20:21:52 +03:00
|
|
|
nsReflowStatus& aStatus) {
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
2008-07-09 12:22:20 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsVideoFrame");
|
2016-07-21 13:36:39 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aMetrics, aStatus);
|
2017-09-13 13:00:25 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
|
2008-07-09 12:22:20 +04:00
|
|
|
NS_FRAME_TRACE(
|
|
|
|
NS_FRAME_TRACE_CALLS,
|
2016-09-08 20:21:52 +03:00
|
|
|
("enter nsVideoFrame::Reflow: availSize=%d,%d",
|
|
|
|
aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight()));
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2016-10-12 08:41:50 +03:00
|
|
|
const WritingMode myWM = aReflowInput.GetWritingMode();
|
|
|
|
nscoord contentBoxBSize = aReflowInput.ComputedBSize();
|
|
|
|
const nscoord borderBoxISize =
|
|
|
|
aReflowInput.ComputedISize() +
|
|
|
|
aReflowInput.ComputedLogicalBorderPadding().IStartEnd(myWM);
|
|
|
|
const bool isBSizeShrinkWrapping = (contentBoxBSize == NS_INTRINSICSIZE);
|
|
|
|
|
|
|
|
nscoord borderBoxBSize;
|
|
|
|
if (!isBSizeShrinkWrapping) {
|
|
|
|
borderBoxBSize =
|
|
|
|
contentBoxBSize +
|
|
|
|
aReflowInput.ComputedLogicalBorderPadding().BStartEnd(myWM);
|
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2016-11-25 09:03:15 +03:00
|
|
|
nsMargin borderPadding = aReflowInput.ComputedPhysicalBorderPadding();
|
2016-10-12 08:41:50 +03:00
|
|
|
|
2018-06-27 21:12:38 +03:00
|
|
|
nsIContent* videoControlsDiv = GetVideoControls();
|
|
|
|
|
2016-10-12 08:41:50 +03:00
|
|
|
// Reflow the child frames. We may have up to three: an image
|
|
|
|
// frame (for the poster image), a container frame for the controls,
|
|
|
|
// and a container frame for the caption.
|
2016-11-15 21:50:59 +03:00
|
|
|
for (nsIFrame* child : mFrames) {
|
2016-10-12 08:41:50 +03:00
|
|
|
nsSize oldChildSize = child->GetSize();
|
2017-09-27 18:27:25 +03:00
|
|
|
nsReflowStatus childStatus;
|
2016-10-12 08:41:50 +03:00
|
|
|
|
2013-02-27 01:06:51 +04:00
|
|
|
if (child->GetContent() == mPosterImage) {
|
2009-06-26 11:25:17 +04:00
|
|
|
// Reflow the poster frame.
|
|
|
|
nsImageFrame* imageFrame = static_cast<nsImageFrame*>(child);
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowOutput kidDesiredSize(aReflowInput);
|
2014-07-24 12:28:46 +04:00
|
|
|
WritingMode wm = imageFrame->GetWritingMode();
|
2016-07-21 13:36:39 +03:00
|
|
|
LogicalSize availableSize = aReflowInput.AvailableSize(wm);
|
2017-09-27 18:04:42 +03:00
|
|
|
availableSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
|
|
|
|
2015-06-04 13:43:02 +03:00
|
|
|
LogicalSize cbSize = aMetrics.Size(aMetrics.GetWritingMode())
|
|
|
|
.ConvertTo(wm, aMetrics.GetWritingMode());
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowInput kidReflowInput(aPresContext, aReflowInput, imageFrame,
|
2009-10-06 11:37:46 +04:00
|
|
|
availableSize, &cbSize);
|
2012-05-11 12:32:29 +04:00
|
|
|
|
2014-11-15 03:45:24 +03:00
|
|
|
nsRect posterRenderRect;
|
|
|
|
if (ShouldDisplayPoster()) {
|
|
|
|
posterRenderRect =
|
2016-11-25 09:03:15 +03:00
|
|
|
nsRect(nsPoint(borderPadding.left, borderPadding.top),
|
2016-07-21 13:36:39 +03:00
|
|
|
nsSize(aReflowInput.ComputedWidth(),
|
|
|
|
aReflowInput.ComputedHeight()));
|
2009-10-06 11:37:46 +04:00
|
|
|
}
|
2016-07-21 13:36:39 +03:00
|
|
|
kidReflowInput.SetComputedWidth(posterRenderRect.width);
|
|
|
|
kidReflowInput.SetComputedHeight(posterRenderRect.height);
|
|
|
|
ReflowChild(imageFrame, aPresContext, kidDesiredSize, kidReflowInput,
|
2017-09-27 18:27:25 +03:00
|
|
|
posterRenderRect.x, posterRenderRect.y, 0, childStatus);
|
|
|
|
MOZ_ASSERT(childStatus.IsFullyComplete(),
|
2017-09-27 18:04:42 +03:00
|
|
|
"We gave our child unconstrained available block-size, "
|
|
|
|
"so it should be complete!");
|
|
|
|
|
2014-11-15 03:45:24 +03:00
|
|
|
FinishReflowChild(imageFrame, aPresContext, kidDesiredSize,
|
|
|
|
&kidReflowInput, posterRenderRect.x, posterRenderRect.y,
|
|
|
|
0);
|
2016-10-12 08:41:50 +03:00
|
|
|
|
|
|
|
} else if (child->GetContent() == mCaptionDiv ||
|
2018-06-27 21:12:38 +03:00
|
|
|
child->GetContent() == videoControlsDiv) {
|
2016-10-12 08:41:50 +03:00
|
|
|
// Reflow the caption and control bar frames.
|
2014-07-24 12:28:46 +04:00
|
|
|
WritingMode wm = child->GetWritingMode();
|
2016-10-12 08:41:50 +03:00
|
|
|
LogicalSize availableSize = aReflowInput.ComputedSize(wm);
|
|
|
|
availableSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowInput kidReflowInput(aPresContext, aReflowInput, child,
|
2016-10-12 08:41:50 +03:00
|
|
|
availableSize);
|
|
|
|
ReflowOutput kidDesiredSize(kidReflowInput);
|
2016-11-15 21:50:59 +03:00
|
|
|
ReflowChild(child, aPresContext, kidDesiredSize, kidReflowInput,
|
2017-09-27 18:27:25 +03:00
|
|
|
borderPadding.left, borderPadding.top, 0, childStatus);
|
|
|
|
MOZ_ASSERT(childStatus.IsFullyComplete(),
|
2017-09-27 18:04:42 +03:00
|
|
|
"We gave our child unconstrained available block-size, "
|
|
|
|
"so it should be complete!");
|
2016-10-12 08:41:50 +03:00
|
|
|
|
2018-06-27 21:12:38 +03:00
|
|
|
if (child->GetContent() == videoControlsDiv && isBSizeShrinkWrapping) {
|
2016-12-08 22:20:25 +03:00
|
|
|
// Resolve our own BSize based on the controls' size in the same axis.
|
|
|
|
contentBoxBSize = myWM.IsOrthogonalTo(wm) ? kidDesiredSize.ISize(wm)
|
|
|
|
: kidDesiredSize.BSize(wm);
|
2016-10-12 08:41:50 +03:00
|
|
|
}
|
|
|
|
|
2013-02-27 01:06:51 +04:00
|
|
|
FinishReflowChild(child, aPresContext, kidDesiredSize, &kidReflowInput,
|
2016-11-25 09:03:15 +03:00
|
|
|
borderPadding.left, borderPadding.top, 0);
|
2016-10-12 08:41:50 +03:00
|
|
|
|
2018-06-27 21:12:38 +03:00
|
|
|
if (child->GetContent() == videoControlsDiv &&
|
|
|
|
child->GetSize() != oldChildSize) {
|
|
|
|
RefPtr<Runnable> event =
|
|
|
|
new DispatchResizeToControls(child->GetContent());
|
|
|
|
nsContentUtils::AddScriptRunner(event);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Extra child frame found in nsVideoFrame. "
|
|
|
|
"Possibly from stray whitespace around the videocontrols container "
|
|
|
|
"element.");
|
2016-10-12 08:41:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isBSizeShrinkWrapping) {
|
|
|
|
if (contentBoxBSize == NS_INTRINSICSIZE) {
|
|
|
|
// We didn't get a BSize from our intrinsic size/ratio, nor did we
|
|
|
|
// get one from our controls. Just use BSize of 0.
|
|
|
|
contentBoxBSize = 0;
|
|
|
|
}
|
|
|
|
contentBoxBSize =
|
|
|
|
NS_CSS_MINMAX(contentBoxBSize, aReflowInput.ComputedMinBSize(),
|
|
|
|
aReflowInput.ComputedMaxBSize());
|
|
|
|
borderBoxBSize =
|
|
|
|
contentBoxBSize +
|
|
|
|
aReflowInput.ComputedLogicalBorderPadding().BStartEnd(myWM);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
2016-10-12 08:41:50 +03:00
|
|
|
|
|
|
|
LogicalSize logicalDesiredSize(myWM, borderBoxISize, borderBoxBSize);
|
|
|
|
aMetrics.SetSize(myWM, logicalDesiredSize);
|
|
|
|
|
2010-10-07 08:25:46 +04:00
|
|
|
aMetrics.SetOverflowAreasToDesiredBounds();
|
2008-07-09 12:22:20 +04:00
|
|
|
|
|
|
|
FinishAndStoreOverflow(&aMetrics);
|
|
|
|
|
2016-09-08 20:21:52 +03:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, ("exit nsVideoFrame::Reflow: size=%d,%d",
|
2013-12-27 21:59:52 +04:00
|
|
|
aMetrics.Width(), aMetrics.Height()));
|
2017-09-27 18:27:25 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "This type of frame can't be split.");
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aMetrics);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2018-06-27 21:12:38 +03:00
|
|
|
/**
|
|
|
|
* nsVideoFrame should be a non-leaf frame when UA Widget is enabled,
|
|
|
|
* so the videocontrols container element inserted under the Shadow Root can be
|
|
|
|
* picked up. No frames will be generated from elements from the web content,
|
|
|
|
* given that they have been replaced by the Shadow Root without and <slots>
|
|
|
|
* element in the DOM tree.
|
|
|
|
*
|
|
|
|
* When the UA Widget is disabled, i.e. the videocontrols is bound as anonymous
|
|
|
|
* content with XBL, nsVideoFrame has to be a leaf so no frames from web content
|
|
|
|
* element will be generated.
|
|
|
|
*/
|
|
|
|
bool nsVideoFrame::IsLeafDynamic() const {
|
|
|
|
return !nsContentUtils::IsUAWidgetEnabled();
|
|
|
|
}
|
|
|
|
|
2010-03-02 02:41:49 +03:00
|
|
|
class nsDisplayVideo : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayVideo(nsDisplayListBuilder* aBuilder, nsVideoFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
2010-03-02 02:41:49 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayVideo);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayVideo() { MOZ_COUNT_DTOR(nsDisplayVideo); }
|
2008-07-09 12:22:20 +04:00
|
|
|
#endif
|
2016-05-11 20:54:52 +03:00
|
|
|
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("Video", TYPE_VIDEO)
|
2010-03-02 02:41:49 +03:00
|
|
|
|
2017-06-29 01:12:25 +03:00
|
|
|
virtual bool CreateWebRenderCommands(
|
|
|
|
mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
2017-06-29 01:12:25 +03:00
|
|
|
const mozilla::layers::StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder) override {
|
|
|
|
nsRect area = Frame()->GetContentRectRelativeToSelf() + ToReferenceFrame();
|
|
|
|
HTMLVideoElement* element =
|
|
|
|
static_cast<HTMLVideoElement*>(Frame()->GetContent());
|
|
|
|
|
|
|
|
nsIntSize videoSizeInPx;
|
|
|
|
if (NS_FAILED(element->GetVideoSize(&videoSizeInPx)) || area.IsEmpty()) {
|
2018-02-01 21:59:10 +03:00
|
|
|
return true;
|
2017-06-29 01:12:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ImageContainer> container = element->GetImageContainer();
|
|
|
|
if (!container) {
|
2018-02-01 21:59:10 +03:00
|
|
|
return true;
|
2017-06-29 01:12:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the size of the decoded video frame, before being scaled
|
|
|
|
// by pixel aspect ratio.
|
|
|
|
mozilla::gfx::IntSize frameSize = container->GetCurrentSize();
|
|
|
|
if (frameSize.width == 0 || frameSize.height == 0) {
|
|
|
|
// No image, or zero-sized image. Don't render.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert video size from pixel units into app units, to get an
|
|
|
|
// aspect-ratio (which has to be represented as a nsSize) and an
|
|
|
|
// IntrinsicSize that we can pass to ComputeObjectRenderRect.
|
|
|
|
nsSize aspectRatio(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(videoSizeInPx.width),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(videoSizeInPx.height));
|
|
|
|
IntrinsicSize intrinsicSize;
|
|
|
|
intrinsicSize.width.SetCoordValue(aspectRatio.width);
|
|
|
|
intrinsicSize.height.SetCoordValue(aspectRatio.height);
|
|
|
|
|
|
|
|
nsRect dest = nsLayoutUtils::ComputeObjectDestRect(
|
|
|
|
area, intrinsicSize, aspectRatio, Frame()->StylePosition());
|
|
|
|
|
|
|
|
gfxRect destGFXRect = Frame()->PresContext()->AppUnitsToGfxUnits(dest);
|
|
|
|
destGFXRect.Round();
|
|
|
|
if (destGFXRect.IsEmpty()) {
|
2018-02-01 21:59:10 +03:00
|
|
|
return true;
|
2017-06-29 01:12:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VideoInfo::Rotation rotationDeg = element->RotationDegrees();
|
|
|
|
IntSize scaleHint(static_cast<int32_t>(destGFXRect.Width()),
|
|
|
|
static_cast<int32_t>(destGFXRect.Height()));
|
|
|
|
// scaleHint is set regardless of rotation, so swap w/h if needed.
|
|
|
|
SwapScaleWidthHeightForRotation(scaleHint, rotationDeg);
|
|
|
|
container->SetScaleHint(scaleHint);
|
|
|
|
|
2018-06-13 20:40:23 +03:00
|
|
|
Matrix transformHint;
|
|
|
|
if (rotationDeg != VideoInfo::Rotation::kDegree_0) {
|
|
|
|
transformHint = ComputeRotationMatrix(destGFXRect.Width(),
|
|
|
|
destGFXRect.Height(), rotationDeg);
|
|
|
|
}
|
|
|
|
container->SetTransformHint(transformHint);
|
|
|
|
|
2018-03-13 16:16:04 +03:00
|
|
|
// If the image container is empty, we don't want to fallback. Any other
|
|
|
|
// failure will be due to resource constraints and fallback is unlikely to
|
|
|
|
// help us. Hence we can ignore the return value from PushImage.
|
2017-10-19 05:25:11 +03:00
|
|
|
LayoutDeviceRect rect(destGFXRect.x, destGFXRect.y, destGFXRect.width,
|
|
|
|
destGFXRect.height);
|
2018-03-13 16:16:04 +03:00
|
|
|
aManager->CommandBuilder().PushImage(this, container, aBuilder, aResources,
|
|
|
|
aSc, rect);
|
|
|
|
return true;
|
2017-06-29 01:12:25 +03:00
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
// It would be great if we could override GetOpaqueRegion to return nonempty
|
2010-03-02 02:41:49 +03:00
|
|
|
// here, but it's probably not safe to do so in general. Video frames are
|
|
|
|
// updated asynchronously from decoder threads, and it's possible that
|
2011-01-03 04:48:09 +03:00
|
|
|
// we might have an opaque video frame when GetOpaqueRegion is called, but
|
2010-03-02 02:41:49 +03:00
|
|
|
// when we come to paint, the video frame is transparent or has gone
|
|
|
|
// away completely (e.g. because of a decoder error). The problem would
|
|
|
|
// be especially acute if we have off-main-thread rendering.
|
|
|
|
|
2017-08-24 18:09:44 +03:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) const override {
|
2012-11-13 23:56:47 +04:00
|
|
|
*aSnap = true;
|
2013-04-19 16:02:13 +04:00
|
|
|
nsIFrame* f = Frame();
|
2014-09-12 01:29:59 +04:00
|
|
|
return f->GetContentRectRelativeToSelf() + ToReferenceFrame();
|
2010-03-02 02:41:49 +03:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2010-03-02 02:41:49 +03:00
|
|
|
virtual already_AddRefed<Layer> BuildLayer(
|
|
|
|
nsDisplayListBuilder* aBuilder, LayerManager* aManager,
|
2015-03-21 19:28:04 +03:00
|
|
|
const ContainerLayerParameters& aContainerParameters) override {
|
2012-09-17 02:25:33 +04:00
|
|
|
return static_cast<nsVideoFrame*>(mFrame)->BuildLayer(
|
|
|
|
aBuilder, aManager, this, aContainerParameters);
|
2010-03-02 02:41:49 +03:00
|
|
|
}
|
2010-07-16 01:08:05 +04:00
|
|
|
|
|
|
|
virtual LayerState GetLayerState(
|
|
|
|
nsDisplayListBuilder* aBuilder, LayerManager* aManager,
|
2015-03-21 19:28:04 +03:00
|
|
|
const ContainerLayerParameters& aParameters) override {
|
2012-07-06 17:23:09 +04:00
|
|
|
if (aManager->IsCompositingCheap()) {
|
|
|
|
// Since ImageLayers don't require additional memory of the
|
|
|
|
// video frames we have to have anyway, we can't save much by
|
|
|
|
// making layers inactive. Also, for many accelerated layer
|
|
|
|
// managers calling imageContainer->GetCurrentAsSurface can be
|
|
|
|
// very expensive. So just always be active when compositing is
|
|
|
|
// cheap (i.e. hardware accelerated).
|
2010-08-02 07:06:58 +04:00
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
2013-03-19 16:23:54 +04:00
|
|
|
HTMLMediaElement* elem =
|
|
|
|
static_cast<HTMLMediaElement*>(mFrame->GetContent());
|
2012-11-30 02:11:06 +04:00
|
|
|
return elem->IsPotentiallyPlaying() ? LAYER_ACTIVE_FORCE : LAYER_INACTIVE;
|
2010-07-16 01:08:05 +04:00
|
|
|
}
|
2010-03-02 02:41:49 +03:00
|
|
|
};
|
2008-07-09 12:22:20 +04:00
|
|
|
|
|
|
|
void nsVideoFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists) {
|
2018-12-06 22:40:50 +03:00
|
|
|
if (!IsVisibleForPainting()) return;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsVideoFrame");
|
|
|
|
|
2013-02-14 15:08:08 +04:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2014-11-15 03:45:23 +03:00
|
|
|
const bool shouldDisplayPoster = ShouldDisplayPoster();
|
|
|
|
|
|
|
|
// NOTE: If we're displaying a poster image (instead of video data), we can
|
|
|
|
// trust the nsImageFrame to constrain its drawing to its content rect
|
|
|
|
// (which happens to be the same as our content rect).
|
|
|
|
uint32_t clipFlags;
|
|
|
|
if (shouldDisplayPoster ||
|
|
|
|
!nsStyleUtil::ObjectPropsMightCauseOverflow(StylePosition())) {
|
|
|
|
clipFlags = DisplayListClipState::ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT;
|
|
|
|
} else {
|
|
|
|
clipFlags = 0;
|
|
|
|
}
|
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
DisplayListClipState::AutoClipContainingBlockDescendantsToContentBox clip(
|
2014-11-15 03:45:23 +03:00
|
|
|
aBuilder, this, clipFlags);
|
2010-09-09 19:21:47 +04:00
|
|
|
|
2014-11-15 03:45:23 +03:00
|
|
|
if (HasVideoElement() && !shouldDisplayPoster) {
|
2017-12-13 20:23:04 +03:00
|
|
|
aLists.Content()->AppendToTop(
|
2018-02-13 03:43:28 +03:00
|
|
|
MakeDisplayItem<nsDisplayVideo>(aBuilder, this));
|
2008-12-17 03:27:46 +03:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2013-02-27 01:06:51 +04:00
|
|
|
// Add child frames to display list. We expect various children,
|
|
|
|
// but only want to draw mPosterImage conditionally. Others we
|
|
|
|
// always add to the display list.
|
2015-06-29 23:02:21 +03:00
|
|
|
for (nsIFrame* child : mFrames) {
|
2017-08-07 05:23:35 +03:00
|
|
|
if (child->GetContent() != mPosterImage || shouldDisplayPoster ||
|
|
|
|
child->IsBoxFrame()) {
|
|
|
|
nsDisplayListBuilder::AutoBuildingDisplayList buildingForChild(
|
|
|
|
aBuilder, child,
|
2017-10-04 04:28:38 +03:00
|
|
|
aBuilder->GetVisibleRect() - child->GetOffsetTo(this),
|
2017-08-07 05:23:35 +03:00
|
|
|
aBuilder->GetDirtyRect() - child->GetOffsetTo(this),
|
|
|
|
aBuilder->IsAtRootOfPseudoStackingContext());
|
|
|
|
|
|
|
|
child->BuildDisplayListForStackingContext(aBuilder, aLists.Content());
|
2009-06-26 11:25:17 +04:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-29 01:53:44 +04:00
|
|
|
a11y::AccType nsVideoFrame::AccessibleType() { return a11y::eHTMLMediaType; }
|
2008-07-09 12:22:20 +04:00
|
|
|
#endif
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2008-07-09 12:22:20 +04:00
|
|
|
nsresult nsVideoFrame::GetFrameName(nsAString& aResult) const {
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("HTMLVideo"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
LogicalSize nsVideoFrame::ComputeSize(
|
|
|
|
gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize,
|
2014-08-24 18:34:44 +04:00
|
|
|
nscoord aAvailableISize, const LogicalSize& aMargin,
|
|
|
|
const LogicalSize& aBorder, const LogicalSize& aPadding,
|
2014-11-11 14:02:41 +03:00
|
|
|
ComputeSizeFlags aFlags) {
|
2016-10-12 08:41:50 +03:00
|
|
|
if (!HasVideoElement()) {
|
|
|
|
return nsContainerFrame::ComputeSize(aRenderingContext, aWM, aCBSize,
|
|
|
|
aAvailableISize, aMargin, aBorder,
|
|
|
|
aPadding, aFlags);
|
|
|
|
}
|
|
|
|
|
2010-01-09 03:37:30 +03:00
|
|
|
nsSize size = GetVideoIntrinsicSize(aRenderingContext);
|
2008-07-09 12:22:20 +04:00
|
|
|
|
|
|
|
IntrinsicSize intrinsicSize;
|
|
|
|
intrinsicSize.width.SetCoordValue(size.width);
|
|
|
|
intrinsicSize.height.SetCoordValue(size.height);
|
|
|
|
|
2013-06-26 02:00:04 +04:00
|
|
|
// Only video elements have an intrinsic ratio.
|
|
|
|
nsSize intrinsicRatio = HasVideoElement() ? size : nsSize(0, 0);
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2016-11-05 04:57:06 +03:00
|
|
|
return ComputeSizeWithIntrinsicDimensions(
|
|
|
|
aRenderingContext, aWM, intrinsicSize, intrinsicRatio, aCBSize, aMargin,
|
2016-11-05 04:57:06 +03:00
|
|
|
aBorder, aPadding, aFlags);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
nscoord nsVideoFrame::GetMinISize(gfxContext* aRenderingContext) {
|
2016-10-12 08:41:50 +03:00
|
|
|
nscoord result;
|
2018-09-12 15:35:47 +03:00
|
|
|
DISPLAY_MIN_INLINE_SIZE(this, result);
|
2016-10-12 08:41:50 +03:00
|
|
|
|
|
|
|
if (HasVideoElement()) {
|
|
|
|
nsSize size = GetVideoIntrinsicSize(aRenderingContext);
|
|
|
|
result = GetWritingMode().IsVertical() ? size.height : size.width;
|
|
|
|
} else {
|
|
|
|
// We expect last and only child of audio elements to be control if
|
|
|
|
// "controls" attribute is present.
|
|
|
|
nsIFrame* kid = mFrames.LastChild();
|
|
|
|
if (kid) {
|
|
|
|
result = nsLayoutUtils::IntrinsicForContainer(aRenderingContext, kid,
|
|
|
|
nsLayoutUtils::MIN_ISIZE);
|
|
|
|
} else {
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
nscoord nsVideoFrame::GetPrefISize(gfxContext* aRenderingContext) {
|
2016-10-12 08:41:50 +03:00
|
|
|
nscoord result;
|
2018-09-12 15:35:47 +03:00
|
|
|
DISPLAY_PREF_INLINE_SIZE(this, result);
|
2016-10-12 08:41:50 +03:00
|
|
|
|
|
|
|
if (HasVideoElement()) {
|
|
|
|
nsSize size = GetVideoIntrinsicSize(aRenderingContext);
|
|
|
|
result = GetWritingMode().IsVertical() ? size.height : size.width;
|
|
|
|
} else {
|
|
|
|
// We expect last and only child of audio elements to be control if
|
|
|
|
// "controls" attribute is present.
|
|
|
|
nsIFrame* kid = mFrames.LastChild();
|
|
|
|
if (kid) {
|
|
|
|
result = nsLayoutUtils::IntrinsicForContainer(aRenderingContext, kid,
|
|
|
|
nsLayoutUtils::PREF_ISIZE);
|
|
|
|
} else {
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize nsVideoFrame::GetIntrinsicRatio() {
|
2013-06-26 02:00:04 +04:00
|
|
|
if (!HasVideoElement()) {
|
|
|
|
// Audio elements have no intrinsic ratio.
|
|
|
|
return nsSize(0, 0);
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return GetVideoIntrinsicSize(nullptr);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsVideoFrame::ShouldDisplayPoster() {
|
2009-06-26 11:25:17 +04:00
|
|
|
if (!HasVideoElement()) return false;
|
|
|
|
|
2013-03-19 16:27:35 +04:00
|
|
|
HTMLVideoElement* element = static_cast<HTMLVideoElement*>(GetContent());
|
2009-06-26 11:25:17 +04:00
|
|
|
if (element->GetPlayedOrSeeked() && HasVideoData()) return false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imgContent = do_QueryInterface(mPosterImage);
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(imgContent, false);
|
2009-11-05 16:56:52 +03:00
|
|
|
|
2009-06-26 11:25:17 +04:00
|
|
|
nsCOMPtr<imgIRequest> request;
|
|
|
|
nsresult res = imgContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(request));
|
|
|
|
if (NS_FAILED(res) || !request) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-06-26 11:25:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t status = 0;
|
2009-06-26 11:25:17 +04:00
|
|
|
res = request->GetImageStatus(&status);
|
|
|
|
if (NS_FAILED(res) || (status & imgIRequest::STATUS_ERROR)) return false;
|
2009-11-05 16:56:52 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-06-26 11:25:17 +04:00
|
|
|
}
|
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
nsSize nsVideoFrame::GetVideoIntrinsicSize(gfxContext* aRenderingContext) {
|
2008-07-09 12:22:20 +04:00
|
|
|
// Defaulting size to 300x150 if no size given.
|
2010-06-16 01:53:44 +04:00
|
|
|
nsIntSize size(300, 150);
|
2013-06-26 02:00:04 +04:00
|
|
|
|
2013-03-19 16:27:35 +04:00
|
|
|
HTMLVideoElement* element = static_cast<HTMLVideoElement*>(GetContent());
|
2012-05-11 12:32:15 +04:00
|
|
|
if (NS_FAILED(element->GetVideoSize(&size)) && ShouldDisplayPoster()) {
|
|
|
|
// Use the poster image frame's size.
|
|
|
|
nsIFrame* child = mPosterImage->GetPrimaryFrame();
|
|
|
|
nsImageFrame* imageFrame = do_QueryFrame(child);
|
|
|
|
nsSize imgsize;
|
|
|
|
if (NS_SUCCEEDED(imageFrame->GetIntrinsicImageSize(imgsize))) {
|
|
|
|
return imgsize;
|
|
|
|
}
|
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2009-11-05 16:56:52 +03:00
|
|
|
return nsSize(nsPresContext::CSSPixelsToAppUnits(size.width),
|
2008-07-09 12:22:20 +04:00
|
|
|
nsPresContext::CSSPixelsToAppUnits(size.height));
|
|
|
|
}
|
2008-12-17 03:27:46 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void nsVideoFrame::UpdatePosterSource(bool aNotify) {
|
2009-06-26 11:25:17 +04:00
|
|
|
NS_ASSERTION(HasVideoElement(), "Only call this on <video> elements.");
|
2013-03-19 16:27:35 +04:00
|
|
|
HTMLVideoElement* element = static_cast<HTMLVideoElement*>(GetContent());
|
2009-06-26 11:25:17 +04:00
|
|
|
|
2016-07-10 10:06:00 +03:00
|
|
|
if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::poster) &&
|
|
|
|
!element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::poster,
|
|
|
|
nsGkAtoms::_empty, eIgnoreCase)) {
|
2013-12-04 05:06:16 +04:00
|
|
|
nsAutoString posterStr;
|
|
|
|
element->GetPoster(posterStr);
|
|
|
|
mPosterImage->SetAttr(kNameSpaceID_None, nsGkAtoms::src, posterStr,
|
|
|
|
aNotify);
|
|
|
|
} else {
|
2016-07-10 10:06:00 +03:00
|
|
|
mPosterImage->UnsetAttr(kNameSpaceID_None, nsGkAtoms::src, aNotify);
|
2013-12-04 05:06:16 +04:00
|
|
|
}
|
2009-06-26 11:25:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsVideoFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute, int32_t aModType) {
|
2009-07-07 06:02:06 +04:00
|
|
|
if (aAttribute == nsGkAtoms::poster && HasVideoElement()) {
|
2013-12-04 05:06:16 +04:00
|
|
|
UpdatePosterSource(true);
|
2009-06-26 11:25:17 +04:00
|
|
|
}
|
2016-04-18 09:26:44 +03:00
|
|
|
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
2009-06-26 11:25:17 +04:00
|
|
|
}
|
|
|
|
|
2016-09-12 08:19:07 +03:00
|
|
|
void nsVideoFrame::OnVisibilityChange(
|
2017-02-13 20:07:40 +03:00
|
|
|
Visibility aNewVisibility, const Maybe<OnNonvisible>& aNonvisibleAction) {
|
2016-06-29 12:36:24 +03:00
|
|
|
if (HasVideoElement()) {
|
2018-02-15 08:22:38 +03:00
|
|
|
static_cast<HTMLMediaElement*>(GetContent())
|
|
|
|
->OnVisibilityChange(aNewVisibility);
|
2016-06-29 12:36:24 +03:00
|
|
|
}
|
2016-03-26 00:49:43 +03:00
|
|
|
|
2016-06-29 12:36:24 +03:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader =
|
|
|
|
do_QueryInterface(mPosterImage);
|
|
|
|
if (imageLoader) {
|
|
|
|
imageLoader->OnVisibilityChange(aNewVisibility, aNonvisibleAction);
|
|
|
|
}
|
2016-07-27 01:43:58 +03:00
|
|
|
|
2016-09-12 08:19:07 +03:00
|
|
|
nsContainerFrame::OnVisibilityChange(aNewVisibility, aNonvisibleAction);
|
2016-03-26 00:49:43 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsVideoFrame::HasVideoElement() {
|
2018-02-15 08:22:38 +03:00
|
|
|
return static_cast<HTMLMediaElement*>(GetContent())->IsVideo();
|
2009-06-26 11:25:17 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsVideoFrame::HasVideoData() {
|
2009-06-26 11:25:17 +04:00
|
|
|
if (!HasVideoElement()) return false;
|
2013-03-19 16:27:35 +04:00
|
|
|
HTMLVideoElement* element = static_cast<HTMLVideoElement*>(GetContent());
|
2012-05-11 12:32:15 +04:00
|
|
|
nsIntSize size(0, 0);
|
|
|
|
element->GetVideoSize(&size);
|
2009-06-26 11:25:17 +04:00
|
|
|
return size != nsIntSize(0, 0);
|
2008-12-17 03:27:46 +03:00
|
|
|
}
|
2017-03-28 11:48:40 +03:00
|
|
|
|
|
|
|
void nsVideoFrame::UpdateTextTrack() {
|
2018-02-15 08:22:38 +03:00
|
|
|
static_cast<HTMLMediaElement*>(GetContent())->NotifyCueDisplayStatesChanged();
|
2017-03-28 11:48:40 +03:00
|
|
|
}
|