2012-08-14 02:04:19 +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/. */
|
|
|
|
|
|
|
|
/* A class that handles style system image loads (other image loads are handled
|
|
|
|
* by the nodes in the content tree).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mozilla/css/ImageLoader.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2012-08-14 02:04:19 +04:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2012-08-15 17:52:06 +04:00
|
|
|
#include "nsError.h"
|
2012-11-07 02:04:53 +04:00
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "FrameLayerBuilder.h"
|
2013-09-04 15:13:11 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2013-10-02 01:00:38 +04:00
|
|
|
#include "imgIContainer.h"
|
2015-03-17 22:25:35 +03:00
|
|
|
#include "Image.h"
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageLoader::DropDocumentReference()
|
|
|
|
{
|
2014-09-05 08:27:16 +04:00
|
|
|
// It's okay if GetPresContext returns null here (due to the presshell pointer
|
|
|
|
// on the document being null) as that means the presshell has already
|
|
|
|
// been destroyed, and it also calls ClearFrames when it is destroyed.
|
|
|
|
ClearFrames(GetPresContext());
|
2015-07-14 03:13:32 +03:00
|
|
|
|
|
|
|
for (auto it = mImages.Iter(); !it.Done(); it.Next()) {
|
|
|
|
ImageLoader::Image* image = it.Get()->GetKey();
|
|
|
|
imgIRequest* request = image->mRequests.GetWeak(mDocument);
|
|
|
|
if (request) {
|
|
|
|
request->CancelAndForgetObserver(NS_BINDING_ABORTED);
|
|
|
|
}
|
|
|
|
image->mRequests.Remove(mDocument);
|
|
|
|
}
|
|
|
|
mImages.Clear();
|
|
|
|
|
2012-08-15 00:34:20 +04:00
|
|
|
mDocument = nullptr;
|
2012-08-14 02:04:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageLoader::AssociateRequestToFrame(imgIRequest* aRequest,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
2012-10-12 20:11:22 +04:00
|
|
|
nsCOMPtr<imgINotificationObserver> observer;
|
|
|
|
aRequest->GetNotificationObserver(getter_AddRefs(observer));
|
2012-08-14 02:04:19 +04:00
|
|
|
if (!observer) {
|
|
|
|
// The request has already been canceled, so ignore it. This is ok because
|
|
|
|
// we're not going to get any more notifications from a canceled request.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(observer == this);
|
|
|
|
|
2012-08-15 00:34:20 +04:00
|
|
|
FrameSet* frameSet = nullptr;
|
2012-08-14 02:04:19 +04:00
|
|
|
if (mRequestToFrameMap.Get(aRequest, &frameSet)) {
|
|
|
|
NS_ASSERTION(frameSet, "This should never be null!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!frameSet) {
|
|
|
|
nsAutoPtr<FrameSet> newFrameSet(new FrameSet());
|
|
|
|
|
|
|
|
mRequestToFrameMap.Put(aRequest, newFrameSet);
|
|
|
|
frameSet = newFrameSet.forget();
|
2012-08-22 03:14:06 +04:00
|
|
|
|
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
if (presContext) {
|
|
|
|
nsLayoutUtils::RegisterImageRequestIfAnimated(presContext,
|
|
|
|
aRequest,
|
|
|
|
nullptr);
|
|
|
|
}
|
2012-08-14 02:04:19 +04:00
|
|
|
}
|
|
|
|
|
2012-08-15 00:34:20 +04:00
|
|
|
RequestSet* requestSet = nullptr;
|
2012-08-14 02:04:19 +04:00
|
|
|
if (mFrameToRequestMap.Get(aFrame, &requestSet)) {
|
|
|
|
NS_ASSERTION(requestSet, "This should never be null");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!requestSet) {
|
|
|
|
nsAutoPtr<RequestSet> newRequestSet(new RequestSet());
|
|
|
|
|
|
|
|
mFrameToRequestMap.Put(aFrame, newRequestSet);
|
|
|
|
requestSet = newRequestSet.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add these to the sets, but only if they're not already there.
|
2013-02-13 19:11:53 +04:00
|
|
|
uint32_t i = frameSet->IndexOfFirstElementGt(aFrame);
|
|
|
|
if (i == 0 || aFrame != frameSet->ElementAt(i-1)) {
|
2012-08-14 02:04:19 +04:00
|
|
|
frameSet->InsertElementAt(i, aFrame);
|
|
|
|
}
|
2013-02-13 19:11:53 +04:00
|
|
|
i = requestSet->IndexOfFirstElementGt(aRequest);
|
|
|
|
if (i == 0 || aRequest != requestSet->ElementAt(i-1)) {
|
2012-08-14 02:04:19 +04:00
|
|
|
requestSet->InsertElementAt(i, aRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-24 21:50:49 +04:00
|
|
|
ImageLoader::MaybeRegisterCSSImage(ImageLoader::Image* aImage)
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aImage, "This should never be null!");
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
aImage->mRequests.GetWeak(mDocument, &found);
|
|
|
|
if (found) {
|
|
|
|
// This document already has a request.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-12 16:43:01 +04:00
|
|
|
imgRequestProxy* canonicalRequest = aImage->mRequests.GetWeak(nullptr);
|
2012-08-14 02:04:19 +04:00
|
|
|
if (!canonicalRequest) {
|
|
|
|
// The image was blocked or something.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy> request;
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
// Ignore errors here. If cloning fails for some reason we'll put a null
|
|
|
|
// entry in the hash and we won't keep trying to clone.
|
|
|
|
mInClone = true;
|
|
|
|
canonicalRequest->Clone(this, getter_AddRefs(request));
|
|
|
|
mInClone = false;
|
|
|
|
|
|
|
|
aImage->mRequests.Put(mDocument, request);
|
|
|
|
|
|
|
|
AddImage(aImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-24 21:50:49 +04:00
|
|
|
ImageLoader::DeregisterCSSImage(ImageLoader::Image* aImage)
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
|
|
|
RemoveImage(aImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageLoader::DisassociateRequestFromFrame(imgIRequest* aRequest,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
2012-08-15 00:34:20 +04:00
|
|
|
FrameSet* frameSet = nullptr;
|
|
|
|
RequestSet* requestSet = nullptr;
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2012-10-12 20:11:22 +04:00
|
|
|
nsCOMPtr<imgINotificationObserver> observer;
|
|
|
|
aRequest->GetNotificationObserver(getter_AddRefs(observer));
|
2012-08-14 02:04:19 +04:00
|
|
|
MOZ_ASSERT(!observer || observer == this);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mRequestToFrameMap.Get(aRequest, &frameSet);
|
|
|
|
mFrameToRequestMap.Get(aFrame, &requestSet);
|
|
|
|
|
|
|
|
if (frameSet) {
|
|
|
|
frameSet->RemoveElementSorted(aFrame);
|
|
|
|
}
|
|
|
|
if (requestSet) {
|
|
|
|
requestSet->RemoveElementSorted(aRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frameSet && !frameSet->Length()) {
|
|
|
|
mRequestToFrameMap.Remove(aRequest);
|
|
|
|
|
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
if (presContext) {
|
|
|
|
nsLayoutUtils::DeregisterImageRequest(presContext,
|
|
|
|
aRequest,
|
2012-08-15 00:34:20 +04:00
|
|
|
nullptr);
|
2012-08-14 02:04:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requestSet && !requestSet->Length()) {
|
|
|
|
mFrameToRequestMap.Remove(aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageLoader::DropRequestsForFrame(nsIFrame* aFrame)
|
|
|
|
{
|
2012-08-15 00:34:20 +04:00
|
|
|
RequestSet* requestSet = nullptr;
|
2012-08-14 02:04:19 +04:00
|
|
|
if (!mFrameToRequestMap.Get(aFrame, &requestSet)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(requestSet, "This should never be null");
|
|
|
|
|
|
|
|
RequestSet frozenRequestSet(*requestSet);
|
|
|
|
for (RequestSet::size_type i = frozenRequestSet.Length(); i != 0; --i) {
|
|
|
|
imgIRequest* request = frozenRequestSet.ElementAt(i - 1);
|
|
|
|
|
|
|
|
DisassociateRequestFromFrame(request, aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
ImageLoader::SetAnimationMode(uint16_t aMode)
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aMode == imgIContainer::kNormalAnimMode ||
|
|
|
|
aMode == imgIContainer::kDontAnimMode ||
|
|
|
|
aMode == imgIContainer::kLoopOnceAnimMode,
|
|
|
|
"Wrong Animation Mode is being set!");
|
|
|
|
|
2015-07-30 23:48:10 +03:00
|
|
|
for (auto iter = mRequestToFrameMap.ConstIter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto request = static_cast<imgIRequest*>(iter.Key());
|
2014-09-05 08:27:16 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2015-07-30 23:48:10 +03:00
|
|
|
{
|
2015-07-31 00:01:49 +03:00
|
|
|
nsCOMPtr<imgIRequest> debugRequest = do_QueryInterface(request);
|
2015-07-30 23:48:10 +03:00
|
|
|
NS_ASSERTION(debugRequest == request, "This is bad");
|
|
|
|
}
|
2014-09-05 08:27:16 +04:00
|
|
|
#endif
|
|
|
|
|
2015-07-30 23:48:10 +03:00
|
|
|
nsCOMPtr<imgIContainer> container;
|
|
|
|
request->GetImage(getter_AddRefs(container));
|
|
|
|
if (!container) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-05 08:27:16 +04:00
|
|
|
|
2015-07-30 23:48:10 +03:00
|
|
|
// This can fail if the image is in error, and we don't care.
|
|
|
|
container->SetAnimationMode(aMode);
|
|
|
|
}
|
2014-09-05 08:27:16 +04:00
|
|
|
}
|
|
|
|
|
2012-08-14 02:04:19 +04:00
|
|
|
void
|
2014-09-05 08:27:16 +04:00
|
|
|
ImageLoader::ClearFrames(nsPresContext* aPresContext)
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
2015-07-30 23:48:10 +03:00
|
|
|
for (auto iter = mRequestToFrameMap.ConstIter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto request = static_cast<imgIRequest*>(iter.Key());
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2015-07-31 00:01:49 +03:00
|
|
|
nsCOMPtr<imgIRequest> debugRequest = do_QueryInterface(request);
|
2015-07-30 23:48:10 +03:00
|
|
|
NS_ASSERTION(debugRequest == request, "This is bad");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (aPresContext) {
|
|
|
|
nsLayoutUtils::DeregisterImageRequest(aPresContext,
|
|
|
|
request,
|
|
|
|
nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-14 02:04:19 +04:00
|
|
|
mRequestToFrameMap.Clear();
|
|
|
|
mFrameToRequestMap.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageLoader::LoadImage(nsIURI* aURI, nsIPrincipal* aOriginPrincipal,
|
2012-08-24 21:50:49 +04:00
|
|
|
nsIURI* aReferrer, ImageLoader::Image* aImage)
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aImage->mRequests.Count() == 0, "Huh?");
|
|
|
|
|
2012-08-15 00:34:20 +04:00
|
|
|
aImage->mRequests.Put(nullptr, nullptr);
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
if (!aURI) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy> request;
|
2016-04-27 20:41:13 +03:00
|
|
|
nsresult rv = nsContentUtils::LoadImage(aURI, mDocument, mDocument,
|
|
|
|
aOriginPrincipal, aReferrer,
|
|
|
|
mDocument->GetReferrerPolicy(),
|
|
|
|
nullptr, nsIRequest::LOAD_NORMAL,
|
|
|
|
NS_LITERAL_STRING("css"),
|
|
|
|
getter_AddRefs(request));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || !request) {
|
2012-08-14 02:04:19 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy> clonedRequest;
|
2012-08-14 02:04:19 +04:00
|
|
|
mInClone = true;
|
2016-04-27 20:41:13 +03:00
|
|
|
rv = request->Clone(this, getter_AddRefs(clonedRequest));
|
2012-08-14 02:04:19 +04:00
|
|
|
mInClone = false;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-15 00:34:20 +04:00
|
|
|
aImage->mRequests.Put(nullptr, request);
|
2012-08-14 02:04:19 +04:00
|
|
|
aImage->mRequests.Put(mDocument, clonedRequest);
|
|
|
|
|
|
|
|
AddImage(aImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-24 21:50:49 +04:00
|
|
|
ImageLoader::AddImage(ImageLoader::Image* aImage)
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mImages.Contains(aImage), "Huh?");
|
2015-05-27 00:04:24 +03:00
|
|
|
mImages.PutEntry(aImage);
|
2012-08-14 02:04:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-24 21:50:49 +04:00
|
|
|
ImageLoader::RemoveImage(ImageLoader::Image* aImage)
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mImages.Contains(aImage), "Huh?");
|
|
|
|
mImages.RemoveEntry(aImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext*
|
|
|
|
ImageLoader::GetPresContext()
|
|
|
|
{
|
|
|
|
if (!mDocument) {
|
2012-08-15 00:34:20 +04:00
|
|
|
return nullptr;
|
2012-08-14 02:04:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* shell = mDocument->GetShell();
|
|
|
|
if (!shell) {
|
2012-08-15 00:34:20 +04:00
|
|
|
return nullptr;
|
2012-08-14 02:04:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return shell->GetPresContext();
|
|
|
|
}
|
|
|
|
|
2012-11-07 02:04:53 +04:00
|
|
|
void InvalidateImagesCallback(nsIFrame* aFrame,
|
|
|
|
FrameLayerBuilder::DisplayItemData* aItem)
|
|
|
|
{
|
|
|
|
nsDisplayItem::Type type = nsDisplayItem::GetDisplayItemTypeFromKey(aItem->GetDisplayItemKey());
|
|
|
|
uint8_t flags = nsDisplayItem::GetDisplayItemFlagsForType(type);
|
|
|
|
|
|
|
|
if (flags & nsDisplayItem::TYPE_RENDERS_NO_IMAGES) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-23 06:32:00 +03:00
|
|
|
if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) {
|
|
|
|
printf_stderr("Invalidating display item(type=%d) based on frame %p \
|
|
|
|
because it might contain an invalidated image\n", type, aFrame);
|
|
|
|
}
|
2012-11-07 02:04:53 +04:00
|
|
|
aItem->Invalidate();
|
2014-11-08 02:40:12 +03:00
|
|
|
aFrame->SchedulePaint();
|
2012-11-07 02:04:53 +04:00
|
|
|
}
|
|
|
|
|
2012-08-14 02:04:19 +04:00
|
|
|
void
|
2014-11-08 02:40:12 +03:00
|
|
|
ImageLoader::DoRedraw(FrameSet* aFrameSet, bool aForcePaint)
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrameSet, "Must have a frame set");
|
|
|
|
NS_ASSERTION(mDocument, "Should have returned earlier!");
|
|
|
|
|
|
|
|
FrameSet::size_type length = aFrameSet->Length();
|
|
|
|
for (FrameSet::size_type i = 0; i < length; i++) {
|
|
|
|
nsIFrame* frame = aFrameSet->ElementAt(i);
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
if (frame->StyleVisibility()->IsVisible()) {
|
2013-03-08 06:18:45 +04:00
|
|
|
if (frame->IsFrameOfType(nsIFrame::eTablePart)) {
|
|
|
|
// Tables don't necessarily build border/background display items
|
|
|
|
// for the individual table part frames, so IterateRetainedDataFor
|
|
|
|
// might not find the right display item.
|
|
|
|
frame->InvalidateFrame();
|
|
|
|
} else {
|
|
|
|
FrameLayerBuilder::IterateRetainedDataFor(frame, InvalidateImagesCallback);
|
2015-06-25 20:46:00 +03:00
|
|
|
|
|
|
|
// Update ancestor rendering observers (-moz-element etc)
|
|
|
|
nsIFrame *f = frame;
|
|
|
|
while (f && !f->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) {
|
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(f);
|
|
|
|
f = nsLayoutUtils::GetCrossDocParentFrame(f);
|
|
|
|
}
|
|
|
|
|
2014-11-08 02:40:12 +03:00
|
|
|
if (aForcePaint) {
|
|
|
|
frame->SchedulePaint();
|
|
|
|
}
|
2013-03-08 06:18:45 +04:00
|
|
|
}
|
2012-08-14 02:04:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(ImageLoader)
|
|
|
|
NS_IMPL_RELEASE(ImageLoader)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(ImageLoader)
|
2012-10-12 20:11:22 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(imgINotificationObserver)
|
2012-08-14 03:04:17 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(imgIOnloadBlocker)
|
2012-08-14 02:04:19 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-18 01:29:56 +03:00
|
|
|
ImageLoader::Notify(imgIRequest* aRequest, int32_t aType, const nsIntRect* aData)
|
2012-10-12 20:11:22 +04:00
|
|
|
{
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
|
2012-10-12 20:11:22 +04:00
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
aRequest->GetImage(getter_AddRefs(image));
|
2014-11-18 01:29:56 +03:00
|
|
|
return OnSizeAvailable(aRequest, image);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aType == imgINotificationObserver::IS_ANIMATED) {
|
|
|
|
return OnImageIsAnimated(aRequest);
|
|
|
|
}
|
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
if (aType == imgINotificationObserver::FRAME_COMPLETE) {
|
2014-11-18 01:29:56 +03:00
|
|
|
return OnFrameComplete(aRequest);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::FRAME_UPDATE) {
|
2014-11-18 01:29:56 +03:00
|
|
|
return OnFrameUpdate(aRequest);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
|
|
|
|
2015-06-03 20:42:07 +03:00
|
|
|
if (aType == imgINotificationObserver::DECODE_COMPLETE) {
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
aRequest->GetImage(getter_AddRefs(image));
|
|
|
|
if (image && mDocument) {
|
|
|
|
image->PropagateUseCounters(mDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-11-18 01:29:56 +03:00
|
|
|
ImageLoader::OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage)
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
if (!presContext) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
aImage->SetAnimationMode(presContext->ImageAnimationMode());
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
nsresult
|
2012-08-14 02:04:19 +04:00
|
|
|
ImageLoader::OnImageIsAnimated(imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
if (!mDocument) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 03:14:06 +04:00
|
|
|
FrameSet* frameSet = nullptr;
|
|
|
|
if (!mRequestToFrameMap.Get(aRequest, &frameSet)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-14 02:04:19 +04:00
|
|
|
// Register with the refresh driver now that we are aware that
|
|
|
|
// we are animated.
|
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
if (presContext) {
|
|
|
|
nsLayoutUtils::RegisterImageRequest(presContext,
|
|
|
|
aRequest,
|
2012-08-15 00:34:20 +04:00
|
|
|
nullptr);
|
2012-08-14 02:04:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
nsresult
|
2014-11-18 01:29:56 +03:00
|
|
|
ImageLoader::OnFrameComplete(imgIRequest* aRequest)
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
2012-08-21 04:14:04 +04:00
|
|
|
if (!mDocument || mInClone) {
|
2012-08-14 02:04:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-15 00:34:20 +04:00
|
|
|
FrameSet* frameSet = nullptr;
|
2012-08-14 02:04:19 +04:00
|
|
|
if (!mRequestToFrameMap.Get(aRequest, &frameSet)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(frameSet, "This should never be null!");
|
|
|
|
|
2014-11-08 02:40:12 +03:00
|
|
|
// Since we just finished decoding a frame, we always want to paint, in case
|
|
|
|
// we're now able to paint an image that we couldn't paint before (and hence
|
|
|
|
// that we don't have retained data for).
|
|
|
|
DoRedraw(frameSet, /* aForcePaint = */ true);
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
nsresult
|
2014-11-18 01:29:56 +03:00
|
|
|
ImageLoader::OnFrameUpdate(imgIRequest* aRequest)
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
2012-08-21 04:14:04 +04:00
|
|
|
if (!mDocument || mInClone) {
|
2012-08-14 02:04:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-15 00:34:20 +04:00
|
|
|
FrameSet* frameSet = nullptr;
|
2012-08-14 02:04:19 +04:00
|
|
|
if (!mRequestToFrameMap.Get(aRequest, &frameSet)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(frameSet, "This should never be null!");
|
|
|
|
|
2014-11-08 02:40:12 +03:00
|
|
|
DoRedraw(frameSet, /* aForcePaint = */ false);
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-14 03:04:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ImageLoader::BlockOnload(imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
if (!mDocument) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocument->BlockOnload();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ImageLoader::UnblockOnload(imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
if (!mDocument) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocument->UnblockOnload(false);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:25:35 +03:00
|
|
|
void
|
|
|
|
ImageLoader::FlushUseCounters()
|
|
|
|
{
|
|
|
|
for (auto iter = mImages.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsPtrHashKey<Image>* key = iter.Get();
|
|
|
|
ImageLoader::Image* image = key->GetKey();
|
|
|
|
|
|
|
|
imgIRequest* request = image->mRequests.GetWeak(mDocument);
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> container;
|
|
|
|
request->GetImage(getter_AddRefs(container));
|
|
|
|
if (container) {
|
|
|
|
static_cast<image::Image*>(container.get())->ReportUseCounters();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-14 02:04:19 +04:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|