Bug 1387325 - Part1. Refactor nsImageBoxFrame::PaintImage to make it easier to add WR support. r=mattwoodrow
MozReview-Commit-ID: AmHPifpVAHZ
--- a/layout/xul/nsImageBoxFrame.cpp
+++ b/layout/xul/nsImageBoxFrame.cpp
@@ -336,42 +336,63 @@ nsImageBoxFrame::BuildDisplayList(nsDisp
list.AppendNewToTop(
new (aBuilder) nsDisplayXULImage(aBuilder, this));
CreateOwnLayerIfNeeded(aBuilder, &list);
aLists.Content()->AppendToTop(&list);
}
-DrawResult
-nsImageBoxFrame::PaintImage(gfxContext& aRenderingContext,
- const nsRect& aDirtyRect, nsPoint aPt,
- uint32_t aFlags)
+already_AddRefed<imgIContainer>
+nsImageBoxFrame::GetImageContainerForPainting(const nsPoint& aPt,
+ DrawResult& aDrawResult,
+ Maybe<nsPoint>& aAnchorPoint,
+ nsRect& aDest)
{
if (!mImageRequest) {
// This probably means we're drawn by a native theme.
- return DrawResult::SUCCESS;
+ aDrawResult = DrawResult::SUCCESS;
+ return nullptr;
}
// Don't draw if the image's size isn't available.
uint32_t imgStatus;
if (!NS_SUCCEEDED(mImageRequest->GetImageStatus(&imgStatus)) ||
!(imgStatus & imgIRequest::STATUS_SIZE_AVAILABLE)) {
- return DrawResult::NOT_READY;
+ aDrawResult = DrawResult::NOT_READY;
+ return nullptr;
}
nsCOMPtr<imgIContainer> imgCon;
mImageRequest->GetImage(getter_AddRefs(imgCon));
if (!imgCon) {
- return DrawResult::NOT_READY;
+ aDrawResult = DrawResult::NOT_READY;
+ return nullptr;
}
+ aDest = GetDestRect(aPt, aAnchorPoint);
+ aDrawResult = DrawResult::SUCCESS;
+ return imgCon.forget();
+}
+
+DrawResult
+nsImageBoxFrame::PaintImage(gfxContext& aRenderingContext,
+ const nsRect& aDirtyRect, nsPoint aPt,
+ uint32_t aFlags)
+{
+ DrawResult result;
Maybe<nsPoint> anchorPoint;
- nsRect dest = GetDestRect(aPt, anchorPoint);
+ nsRect dest;
+ nsCOMPtr<imgIContainer> imgCon = GetImageContainerForPainting(aPt, result,
+ anchorPoint,
+ dest);
+ if (!imgCon) {
+ return result;
+ }
// don't draw if the image is not dirty
// XXX(seth): Can this actually happen anymore?
nsRect dirty;
if (!dirty.IntersectRect(aDirtyRect, dest)) {
return DrawResult::TEMPORARY_ERROR;
}
--- a/layout/xul/nsImageBoxFrame.h
+++ b/layout/xul/nsImageBoxFrame.h
@@ -85,16 +85,21 @@ public:
*/
void UpdateLoadFlags();
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists) override;
virtual ~nsImageBoxFrame();
+ already_AddRefed<imgIContainer> GetImageContainerForPainting(const nsPoint& aPt,
+ DrawResult& aDrawResult,
+ Maybe<nsPoint>& aAnchorPoint,
+ nsRect& aDest);
+
DrawResult PaintImage(gfxContext& aRenderingContext,
const nsRect& aDirtyRect,
nsPoint aPt, uint32_t aFlags);
bool CanOptimizeToImageLayer();
nsRect GetDestRect(const nsPoint& aOffset, Maybe<nsPoint>& aAnchorPoint);