PRBool nsVideoFrame::ShouldDisplayPoster() { if (!HasVideoElement()) return PR_FALSE; nsHTMLVideoElement* element = static_cast<nsHTMLVideoElement*>(GetContent()); if (element->GetPlayedOrSeeked() && HasVideoData()) return PR_FALSE; nsCOMPtr<nsIImageLoadingContent> imgContent = do_QueryInterface(mPosterImage); NS_ENSURE_TRUE(imgContent, PR_FALSE); nsCOMPtr<imgIRequest> request; nsresult res = imgContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST, getter_AddRefs(request)); if (NS_FAILED(res) || !request) { return PR_FALSE; } PRUint32 status = 0; res = request->GetImageStatus(&status); if (NS_FAILED(res) || (status & imgIRequest::STATUS_ERROR)) return PR_FALSE; return PR_TRUE; }
NS_IMETHODIMP nsVideoFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsRect& aDirtyRect, const nsDisplayListSet& aLists) { if (!IsVisibleForPainting(aBuilder)) return NS_OK; DO_GLOBAL_REFLOW_COUNT_DSP("nsVideoFrame"); nsresult rv = DisplayBorderBackgroundOutline(aBuilder, aLists); NS_ENSURE_SUCCESS(rv, rv); if (!ShouldDisplayPoster() && HasVideoData()) { rv = aLists.Content()->AppendNewToTop( new (aBuilder) nsDisplayGeneric(this, ::PaintVideo, "Video")); NS_ENSURE_SUCCESS(rv, rv); } // Add child frames to display list. We expect up to two children, an image // frame for the poster, and the box frame for the video controls. for (nsIFrame *child = mFrames.FirstChild(); child; child = child->GetNextSibling()) { if (child->GetType() == nsGkAtoms::imageFrame && ShouldDisplayPoster()) { rv = child->BuildDisplayListForStackingContext(aBuilder, aDirtyRect - child->GetOffsetTo(this), aLists.Content()); NS_ENSURE_SUCCESS(rv,rv); } else if (child->GetType() == nsGkAtoms::boxFrame) { rv = child->BuildDisplayListForStackingContext(aBuilder, aDirtyRect - child->GetOffsetTo(this), aLists.Content()); NS_ENSURE_SUCCESS(rv,rv); } } return NS_OK; }
nsSize nsVideoFrame::GetVideoIntrinsicSize(nsIRenderingContext *aRenderingContext) { // Defaulting size to 300x150 if no size given. nsIntSize size(300,150); if (ShouldDisplayPoster()) { // Use the poster image frame's size. nsIFrame *child = mFrames.FirstChild(); if (child && child->GetType() == nsGkAtoms::imageFrame) { nsImageFrame* imageFrame = static_cast<nsImageFrame*>(child); nsSize imgsize; imageFrame->GetIntrinsicImageSize(imgsize); return imgsize; } } if (!HasVideoData()) { if (!aRenderingContext || !mFrames.FirstChild()) { // We just want our intrinsic ratio, but audio elements need no // intrinsic ratio, so just return "no ratio". Also, if there's // no controls frame, we prefer to be zero-sized. return nsSize(0, 0); } // Ask the controls frame what its preferred height is nsBoxLayoutState boxState(PresContext(), aRenderingContext, 0); nscoord prefHeight = mFrames.LastChild()->GetPrefSize(boxState).height; return nsSize(nsPresContext::CSSPixelsToAppUnits(size.width), prefHeight); } nsHTMLVideoElement* element = static_cast<nsHTMLVideoElement*>(GetContent()); size = element->GetVideoSize(size); return nsSize(nsPresContext::CSSPixelsToAppUnits(size.width), nsPresContext::CSSPixelsToAppUnits(size.height)); }