2004-12-17 23:45:30 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2004-12-17 23:45:30 +00:00
|
|
|
|
2012-03-26 11:58:59 +00:00
|
|
|
// Keep in (case-insensitive) order:
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxPlatform.h"
|
2014-03-31 11:53:54 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2004-12-17 23:45:30 +00:00
|
|
|
#include "imgIContainer.h"
|
2014-05-24 22:20:39 +00:00
|
|
|
#include "nsContainerFrame.h"
|
2013-01-06 09:32:01 +00:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2009-04-05 09:52:14 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-10-12 16:11:22 +00:00
|
|
|
#include "imgINotificationObserver.h"
|
2012-03-20 12:15:53 +00:00
|
|
|
#include "nsSVGEffects.h"
|
2013-01-09 23:02:45 +00:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2012-03-26 11:58:59 +00:00
|
|
|
#include "nsSVGUtils.h"
|
2012-09-22 19:26:05 +00:00
|
|
|
#include "SVGContentUtils.h"
|
2016-12-18 11:11:47 +00:00
|
|
|
#include "SVGGeometryFrame.h"
|
2013-02-28 20:22:43 +00:00
|
|
|
#include "SVGImageContext.h"
|
2013-01-06 09:32:01 +00:00
|
|
|
#include "mozilla/dom/SVGImageElement.h"
|
2013-01-31 23:11:49 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-09-15 00:05:05 +00:00
|
|
|
#include "nsIReflowCallback.h"
|
2016-08-23 04:09:32 +00:00
|
|
|
#include "mozilla/Unused.h"
|
2011-10-19 15:37:49 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-01-06 09:32:01 +00:00
|
|
|
using namespace mozilla::dom;
|
2014-03-31 11:53:54 +00:00
|
|
|
using namespace mozilla::gfx;
|
2016-07-14 04:47:06 +00:00
|
|
|
using namespace mozilla::image;
|
2004-12-17 23:45:30 +00:00
|
|
|
|
|
|
|
class nsSVGImageFrame;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsSVGImageListener final : public imgINotificationObserver
|
2004-12-17 23:45:30 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 03:36:37 +00:00
|
|
|
explicit nsSVGImageListener(nsSVGImageFrame *aFrame);
|
2004-12-17 23:45:30 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2012-10-12 16:11:22 +00:00
|
|
|
NS_DECL_IMGINOTIFICATIONOBSERVER
|
2004-12-17 23:45:30 +00:00
|
|
|
|
|
|
|
void SetFrame(nsSVGImageFrame *frame) { mFrame = frame; }
|
|
|
|
|
|
|
|
private:
|
2014-06-23 22:40:01 +00:00
|
|
|
~nsSVGImageListener() {}
|
|
|
|
|
2004-12-17 23:45:30 +00:00
|
|
|
nsSVGImageFrame *mFrame;
|
|
|
|
};
|
|
|
|
|
2016-12-18 11:11:47 +00:00
|
|
|
class nsSVGImageFrame : public SVGGeometryFrame
|
2016-04-18 07:21:40 +00:00
|
|
|
, public nsIReflowCallback
|
2004-12-17 23:45:30 +00:00
|
|
|
{
|
2005-11-11 02:36:29 +00:00
|
|
|
friend nsIFrame*
|
2009-01-19 18:31:34 +00:00
|
|
|
NS_NewSVGImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2004-12-17 23:45:30 +00:00
|
|
|
|
2007-07-13 09:32:37 +00:00
|
|
|
protected:
|
2016-03-25 21:49:43 +00:00
|
|
|
explicit nsSVGImageFrame(nsStyleContext* aContext)
|
2016-12-18 11:11:47 +00:00
|
|
|
: SVGGeometryFrame(aContext)
|
2016-03-25 21:49:43 +00:00
|
|
|
, mReflowCallbackPosted(false)
|
|
|
|
{
|
|
|
|
EnableVisibilityTracking();
|
|
|
|
}
|
|
|
|
|
2004-12-17 23:45:30 +00:00
|
|
|
virtual ~nsSVGImageFrame();
|
|
|
|
|
|
|
|
public:
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2004-12-17 23:45:30 +00:00
|
|
|
// nsISVGChildFrame interface:
|
2016-07-14 04:47:06 +00:00
|
|
|
virtual DrawResult PaintSVG(gfxContext& aContext,
|
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
const nsIntRect* aDirtyRect = nullptr) override;
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) override;
|
|
|
|
virtual void ReflowSVG() override;
|
2004-12-17 23:45:30 +00:00
|
|
|
|
2016-12-18 11:11:47 +00:00
|
|
|
// SVGGeometryFrame methods:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual uint16_t GetHitTestFlags() override;
|
2006-06-20 17:01:09 +00:00
|
|
|
|
|
|
|
// nsIFrame interface:
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2014-02-18 08:36:33 +00:00
|
|
|
nsIAtom* aAttribute,
|
2015-03-21 16:28:04 +00:00
|
|
|
int32_t aModType) override;
|
2016-03-25 21:49:43 +00:00
|
|
|
|
2016-09-12 05:19:07 +00:00
|
|
|
void OnVisibilityChange(Visibility aNewVisibility,
|
2017-02-13 17:07:40 +00:00
|
|
|
const Maybe<OnNonvisible>& aNonvisibleAction = Nothing()) override;
|
2016-03-25 21:49:43 +00:00
|
|
|
|
2014-05-24 22:20:40 +00:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
|
2006-06-20 17:01:09 +00:00
|
|
|
|
2005-04-01 19:56:08 +00:00
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
2006-12-26 17:47:52 +00:00
|
|
|
* @see nsGkAtoms::svgImageFrame
|
2005-04-01 19:56:08 +00:00
|
|
|
*/
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsIAtom* GetType() const override;
|
2005-04-01 19:56:08 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override
|
2005-04-01 19:56:08 +00:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGImage"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-15 00:05:05 +00:00
|
|
|
// nsIReflowCallback
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool ReflowFinished() override;
|
|
|
|
virtual void ReflowCallbackCanceled() override;
|
2013-09-15 00:05:05 +00:00
|
|
|
|
2004-12-17 23:45:30 +00:00
|
|
|
private:
|
2013-12-30 21:42:26 +00:00
|
|
|
gfx::Matrix GetRasterImageTransform(int32_t aNativeWidth,
|
2014-08-29 19:42:07 +00:00
|
|
|
int32_t aNativeHeight);
|
|
|
|
gfx::Matrix GetVectorImageTransform();
|
2013-09-11 07:27:45 +00:00
|
|
|
bool TransformContextForPainting(gfxContext* aGfxContext,
|
2014-08-29 19:42:07 +00:00
|
|
|
const gfxMatrix& aTransform);
|
2006-09-19 16:35:29 +00:00
|
|
|
|
2012-10-12 16:11:22 +00:00
|
|
|
nsCOMPtr<imgINotificationObserver> mListener;
|
2004-12-17 23:45:30 +00:00
|
|
|
|
2006-12-06 22:23:10 +00:00
|
|
|
nsCOMPtr<imgIContainer> mImageContainer;
|
2004-12-17 23:45:30 +00:00
|
|
|
|
2013-09-15 00:05:05 +00:00
|
|
|
bool mReflowCallbackPosted;
|
|
|
|
|
2004-12-17 23:45:30 +00:00
|
|
|
friend class nsSVGImageListener;
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2005-11-11 02:36:29 +00:00
|
|
|
nsIFrame*
|
2009-01-19 18:31:34 +00:00
|
|
|
NS_NewSVGImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2004-12-17 23:45:30 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsSVGImageFrame(aContext);
|
2004-12-17 23:45:30 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGImageFrame)
|
|
|
|
|
2004-12-17 23:45:30 +00:00
|
|
|
nsSVGImageFrame::~nsSVGImageFrame()
|
|
|
|
{
|
|
|
|
// set the frame to null so we don't send messages to a dead object.
|
|
|
|
if (mListener) {
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (imageLoader) {
|
|
|
|
imageLoader->RemoveObserver(mListener);
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
reinterpret_cast<nsSVGImageListener*>(mListener.get())->SetFrame(nullptr);
|
2004-12-17 23:45:30 +00:00
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
mListener = nullptr;
|
2004-12-17 23:45:30 +00:00
|
|
|
}
|
|
|
|
|
2013-03-20 01:47:48 +00:00
|
|
|
void
|
2014-05-24 22:20:40 +00:00
|
|
|
nsSVGImageFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2004-12-17 23:45:30 +00:00
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::image),
|
2013-01-08 03:22:41 +00:00
|
|
|
"Content is not an SVG image!");
|
2009-01-19 18:31:34 +00:00
|
|
|
|
2016-12-18 11:11:47 +00:00
|
|
|
SVGGeometryFrame::Init(aContent, aParent, aPrevInFlow);
|
2013-01-08 03:22:41 +00:00
|
|
|
|
2016-03-26 16:07:03 +00:00
|
|
|
if (GetStateBits() & NS_FRAME_IS_NONDISPLAY) {
|
|
|
|
// Non-display frames are likely to be patterns, masks or the like.
|
|
|
|
// Treat them as always visible.
|
2016-09-12 05:19:08 +00:00
|
|
|
IncApproximateVisibleCount();
|
2016-03-26 16:07:03 +00:00
|
|
|
}
|
|
|
|
|
2004-12-17 23:45:30 +00:00
|
|
|
mListener = new nsSVGImageListener(this);
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
2013-03-20 01:47:48 +00:00
|
|
|
if (!imageLoader) {
|
2016-12-02 21:46:53 +00:00
|
|
|
MOZ_CRASH("Why is this not an image loading content?");
|
2013-03-20 01:47:48 +00:00
|
|
|
}
|
2011-02-01 04:50:01 +00:00
|
|
|
|
2011-11-09 21:39:16 +00:00
|
|
|
// We should have a PresContext now, so let's notify our image loader that
|
|
|
|
// we need to register any image animations with the refresh driver.
|
|
|
|
imageLoader->FrameCreated(this);
|
|
|
|
|
2004-12-17 23:45:30 +00:00
|
|
|
imageLoader->AddObserver(mListener);
|
|
|
|
}
|
|
|
|
|
2011-11-09 21:39:16 +00:00
|
|
|
/* virtual */ void
|
|
|
|
nsSVGImageFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|
|
|
{
|
2016-03-26 16:07:03 +00:00
|
|
|
if (GetStateBits() & NS_FRAME_IS_NONDISPLAY) {
|
2016-09-12 05:19:08 +00:00
|
|
|
DecApproximateVisibleCount();
|
2016-03-26 16:07:03 +00:00
|
|
|
}
|
|
|
|
|
2013-09-15 00:05:05 +00:00
|
|
|
if (mReflowCallbackPosted) {
|
|
|
|
PresContext()->PresShell()->CancelReflowCallback(this);
|
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
}
|
|
|
|
|
2011-11-09 21:39:16 +00:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader =
|
|
|
|
do_QueryInterface(nsFrame::mContent);
|
|
|
|
|
|
|
|
if (imageLoader) {
|
|
|
|
imageLoader->FrameDestroyed(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFrame::DestroyFrom(aDestructRoot);
|
|
|
|
}
|
|
|
|
|
2004-12-17 23:45:30 +00:00
|
|
|
//----------------------------------------------------------------------
|
2006-03-02 20:22:19 +00:00
|
|
|
// nsIFrame methods:
|
2004-12-17 23:45:30 +00:00
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSVGImageFrame::AttributeChanged(int32_t aNameSpaceID,
|
2006-03-02 20:22:19 +00:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType)
|
2004-12-17 23:45:30 +00:00
|
|
|
{
|
2012-03-20 12:15:53 +00:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::x ||
|
|
|
|
aAttribute == nsGkAtoms::y ||
|
|
|
|
aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::height) {
|
2014-11-06 09:30:11 +00:00
|
|
|
nsLayoutUtils::PostRestyleEvent(
|
|
|
|
mContent->AsElement(), nsRestyleHint(0),
|
|
|
|
nsChangeHint_InvalidateRenderingObservers);
|
2012-11-28 09:42:13 +00:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-03-20 12:15:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (aAttribute == nsGkAtoms::preserveAspectRatio) {
|
2013-11-24 19:50:45 +00:00
|
|
|
// We don't paint the content of the image using display lists, therefore
|
|
|
|
// we have to invalidate for this children-only transform changes since
|
|
|
|
// there is no layer tree to notice that the transform changed and
|
|
|
|
// recomposite.
|
|
|
|
InvalidateFrame();
|
2012-03-20 12:15:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-19 15:37:49 +00:00
|
|
|
}
|
2016-07-05 09:35:24 +00:00
|
|
|
if ((aNameSpaceID == kNameSpaceID_XLink ||
|
|
|
|
aNameSpaceID == kNameSpaceID_None) &&
|
2011-10-19 15:37:49 +00:00
|
|
|
aAttribute == nsGkAtoms::href) {
|
2013-01-06 09:32:01 +00:00
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
2011-10-19 15:37:49 +00:00
|
|
|
|
2016-07-05 09:35:24 +00:00
|
|
|
bool hrefIsSet =
|
|
|
|
element->mStringAttributes[SVGImageElement::HREF].IsExplicitlySet() ||
|
|
|
|
element->mStringAttributes[SVGImageElement::XLINK_HREF].IsExplicitlySet();
|
|
|
|
if (hrefIsSet) {
|
2011-10-19 15:37:49 +00:00
|
|
|
element->LoadSVGImage(true, true);
|
|
|
|
} else {
|
|
|
|
element->CancelImageRequests(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-18 11:11:47 +00:00
|
|
|
return SVGGeometryFrame::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
2004-12-17 23:45:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-25 21:49:43 +00:00
|
|
|
void
|
2016-09-12 05:19:07 +00:00
|
|
|
nsSVGImageFrame::OnVisibilityChange(Visibility aNewVisibility,
|
2017-02-13 17:07:40 +00:00
|
|
|
const Maybe<OnNonvisible>& aNonvisibleAction)
|
2016-03-25 21:49:43 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (!imageLoader) {
|
2016-12-18 11:11:47 +00:00
|
|
|
SVGGeometryFrame::OnVisibilityChange(aNewVisibility, aNonvisibleAction);
|
2016-03-25 21:49:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-12 05:19:07 +00:00
|
|
|
imageLoader->OnVisibilityChange(aNewVisibility, aNonvisibleAction);
|
2016-03-25 21:49:43 +00:00
|
|
|
|
2016-12-18 11:11:47 +00:00
|
|
|
SVGGeometryFrame::OnVisibilityChange(aNewVisibility, aNonvisibleAction);
|
2016-03-25 21:49:43 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 21:42:26 +00:00
|
|
|
gfx::Matrix
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSVGImageFrame::GetRasterImageTransform(int32_t aNativeWidth,
|
2014-08-29 19:42:07 +00:00
|
|
|
int32_t aNativeHeight)
|
2006-09-19 16:35:29 +00:00
|
|
|
{
|
|
|
|
float x, y, width, height;
|
2013-01-06 09:32:01 +00:00
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
2012-07-30 14:20:58 +00:00
|
|
|
element->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2006-09-19 16:35:29 +00:00
|
|
|
|
2013-12-30 06:50:17 +00:00
|
|
|
Matrix viewBoxTM =
|
2013-03-03 08:11:03 +00:00
|
|
|
SVGContentUtils::GetViewBoxTransform(width, height,
|
2012-09-22 19:26:05 +00:00
|
|
|
0, 0, aNativeWidth, aNativeHeight,
|
|
|
|
element->mPreserveAspectRatio);
|
2009-07-23 08:35:59 +00:00
|
|
|
|
2014-08-29 19:42:07 +00:00
|
|
|
return viewBoxTM * gfx::Matrix::Translation(x, y);
|
2006-09-19 16:35:29 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 21:42:26 +00:00
|
|
|
gfx::Matrix
|
2014-08-29 19:42:07 +00:00
|
|
|
nsSVGImageFrame::GetVectorImageTransform()
|
2010-12-20 00:45:29 +00:00
|
|
|
{
|
|
|
|
float x, y, width, height;
|
2013-01-06 09:32:01 +00:00
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
2012-07-30 14:20:58 +00:00
|
|
|
element->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2010-12-20 00:45:29 +00:00
|
|
|
|
|
|
|
// No viewBoxTM needed here -- our height/width overrides any concept of
|
|
|
|
// "native size" that the SVG image has, and it will handle viewBox and
|
|
|
|
// preserveAspectRatio on its own once we give it a region to draw into.
|
|
|
|
|
2014-08-29 19:42:07 +00:00
|
|
|
return gfx::Matrix::Translation(x, y);
|
2010-12-20 00:45:29 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2013-09-11 07:27:45 +00:00
|
|
|
nsSVGImageFrame::TransformContextForPainting(gfxContext* aGfxContext,
|
2014-08-29 19:42:07 +00:00
|
|
|
const gfxMatrix& aTransform)
|
2010-12-20 00:45:29 +00:00
|
|
|
{
|
2013-12-30 21:42:26 +00:00
|
|
|
gfx::Matrix imageTransform;
|
2010-12-20 00:45:29 +00:00
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
|
2014-08-29 19:42:07 +00:00
|
|
|
imageTransform = GetVectorImageTransform() * ToMatrix(aTransform);
|
2010-12-20 00:45:29 +00:00
|
|
|
} else {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t nativeWidth, nativeHeight;
|
2010-12-20 00:45:29 +00:00
|
|
|
if (NS_FAILED(mImageContainer->GetWidth(&nativeWidth)) ||
|
|
|
|
NS_FAILED(mImageContainer->GetHeight(&nativeHeight)) ||
|
|
|
|
nativeWidth == 0 || nativeHeight == 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-12-20 00:45:29 +00:00
|
|
|
}
|
2012-06-30 11:20:46 +00:00
|
|
|
imageTransform =
|
2014-08-29 19:42:07 +00:00
|
|
|
GetRasterImageTransform(nativeWidth, nativeHeight) * ToMatrix(aTransform);
|
2013-11-08 23:14:53 +00:00
|
|
|
|
|
|
|
// NOTE: We need to cancel out the effects of Full-Page-Zoom, or else
|
|
|
|
// it'll get applied an extra time by DrawSingleUnscaledImage.
|
|
|
|
nscoord appUnitsPerDevPx = PresContext()->AppUnitsPerDevPixel();
|
|
|
|
gfxFloat pageZoomFactor =
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(appUnitsPerDevPx);
|
2014-09-10 17:29:35 +00:00
|
|
|
imageTransform.PreScale(pageZoomFactor, pageZoomFactor);
|
2010-12-20 00:45:29 +00:00
|
|
|
}
|
|
|
|
|
2011-01-11 05:57:19 +00:00
|
|
|
if (imageTransform.IsSingular()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-01-11 05:57:19 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 21:42:26 +00:00
|
|
|
aGfxContext->Multiply(ThebesMatrix(imageTransform));
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-12-20 00:45:29 +00:00
|
|
|
}
|
|
|
|
|
2004-12-17 23:45:30 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods:
|
2016-07-14 04:47:06 +00:00
|
|
|
DrawResult
|
2014-10-31 20:08:54 +00:00
|
|
|
nsSVGImageFrame::PaintSVG(gfxContext& aContext,
|
2014-08-29 19:42:07 +00:00
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
const nsIntRect *aDirtyRect)
|
2004-12-17 23:45:30 +00:00
|
|
|
{
|
2013-02-16 21:51:02 +00:00
|
|
|
if (!StyleVisibility()->IsVisible())
|
2016-07-14 04:47:06 +00:00
|
|
|
return DrawResult::SUCCESS;
|
2005-01-25 03:55:03 +00:00
|
|
|
|
2007-07-12 15:40:46 +00:00
|
|
|
float x, y, width, height;
|
2013-01-06 09:32:01 +00:00
|
|
|
SVGImageElement *imgElem = static_cast<SVGImageElement*>(mContent);
|
2012-07-30 14:20:58 +00:00
|
|
|
imgElem->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2012-03-03 09:21:09 +00:00
|
|
|
NS_ASSERTION(width > 0 && height > 0,
|
|
|
|
"Should only be painting things with valid width/height");
|
2007-07-12 15:40:46 +00:00
|
|
|
|
2006-12-06 22:23:10 +00:00
|
|
|
if (!mImageContainer) {
|
2004-12-17 23:45:30 +00:00
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (imageLoader)
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
|
|
|
|
|
|
|
if (currentRequest)
|
2006-12-06 22:23:10 +00:00
|
|
|
currentRequest->GetImage(getter_AddRefs(mImageContainer));
|
|
|
|
}
|
2004-12-17 23:45:30 +00:00
|
|
|
|
2016-07-14 04:47:06 +00:00
|
|
|
DrawResult result = DrawResult::SUCCESS;
|
2010-10-11 20:08:19 +00:00
|
|
|
if (mImageContainer) {
|
2014-10-31 20:08:54 +00:00
|
|
|
gfxContextAutoSaveRestore autoRestorer(&aContext);
|
2006-11-27 17:30:57 +00:00
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow()) {
|
2010-10-11 20:08:19 +00:00
|
|
|
gfxRect clipRect = nsSVGUtils::GetClipRectForFrame(this, x, y,
|
|
|
|
width, height);
|
2014-10-31 20:08:54 +00:00
|
|
|
nsSVGUtils::SetClipRect(&aContext, aTransform, clipRect);
|
2006-03-22 23:17:26 +00:00
|
|
|
}
|
|
|
|
|
2014-10-31 20:08:54 +00:00
|
|
|
if (!TransformContextForPainting(&aContext, aTransform)) {
|
2016-07-14 04:47:06 +00:00
|
|
|
return DrawResult::SUCCESS;
|
2010-12-20 00:45:29 +00:00
|
|
|
}
|
2010-10-11 20:08:19 +00:00
|
|
|
|
2007-01-04 15:05:39 +00:00
|
|
|
// fill-opacity doesn't affect <image>, so if we're allowed to
|
|
|
|
// optimize group opacity, the opacity used for compositing the
|
|
|
|
// image into the current canvas is just the group opacity.
|
|
|
|
float opacity = 1.0f;
|
|
|
|
if (nsSVGUtils::CanOptimizeOpacity(this)) {
|
2016-04-12 05:52:43 +00:00
|
|
|
opacity = StyleEffects()->mOpacity;
|
2007-01-04 15:05:39 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 05:52:42 +00:00
|
|
|
if (opacity != 1.0f || StyleEffects()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2015-11-11 15:15:39 +00:00
|
|
|
aContext.PushGroupForBlendBack(gfxContentType::COLOR_ALPHA, opacity);
|
2010-10-11 20:08:19 +00:00
|
|
|
}
|
2008-03-12 17:19:51 +00:00
|
|
|
|
2010-12-20 00:45:29 +00:00
|
|
|
nscoord appUnitsPerDevPx = PresContext()->AppUnitsPerDevPixel();
|
2010-10-11 20:08:19 +00:00
|
|
|
nsRect dirtyRect; // only used if aDirtyRect is non-null
|
|
|
|
if (aDirtyRect) {
|
2012-07-20 18:12:29 +00:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
2013-07-12 07:13:07 +00:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 18:12:29 +00:00
|
|
|
"Display lists handle dirty rect intersection test");
|
2015-04-21 15:04:57 +00:00
|
|
|
dirtyRect = ToAppUnits(*aDirtyRect, appUnitsPerDevPx);
|
2010-10-22 16:52:41 +00:00
|
|
|
// Adjust dirtyRect to match our local coordinate system.
|
2012-02-10 12:33:46 +00:00
|
|
|
nsRect rootRect =
|
2014-08-29 19:42:07 +00:00
|
|
|
nsSVGUtils::TransformFrameRectToOuterSVG(mRect, aTransform,
|
|
|
|
PresContext());
|
2012-02-10 12:33:46 +00:00
|
|
|
dirtyRect.MoveBy(-rootRect.TopLeft());
|
2010-10-11 20:08:19 +00:00
|
|
|
}
|
2006-03-22 23:17:26 +00:00
|
|
|
|
2010-10-11 20:08:19 +00:00
|
|
|
// XXXbholley - I don't think huge images in SVGs are common enough to
|
|
|
|
// warrant worrying about the responsiveness impact of doing synchronous
|
|
|
|
// decodes. The extra code complexity of determinining when we want to
|
|
|
|
// force sync probably just isn't worth it, so always pass FLAG_SYNC_DECODE
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t drawFlags = imgIContainer::FLAG_SYNC_DECODE;
|
2010-12-20 00:45:29 +00:00
|
|
|
|
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
|
2013-02-28 20:22:43 +00:00
|
|
|
// Package up the attributes of this image element which can override the
|
2015-04-03 19:48:12 +00:00
|
|
|
// attributes of mImageContainer's internal SVG document. The 'width' &
|
|
|
|
// 'height' values we're passing in here are in CSS units (though they
|
|
|
|
// come from width/height *attributes* in SVG). They influence the region
|
|
|
|
// of the SVG image's internal document that is visible, in combination
|
|
|
|
// with preserveAspectRatio and viewBox.
|
2017-01-11 01:48:29 +00:00
|
|
|
const Maybe<const SVGImageContext> context(
|
|
|
|
Some(SVGImageContext(CSSIntSize::Truncate(width, height),
|
|
|
|
Some(imgElem->mPreserveAspectRatio.GetAnimValue()),
|
|
|
|
1.0, /* aIsPaintingSVGImageElement */ true)));
|
2013-02-28 20:22:43 +00:00
|
|
|
|
2015-04-03 19:48:12 +00:00
|
|
|
// For the actual draw operation to draw crisply (and at the right size),
|
|
|
|
// our destination rect needs to be |width|x|height|, *in dev pixels*.
|
|
|
|
LayoutDeviceSize devPxSize(width, height);
|
|
|
|
nsRect destRect(nsPoint(),
|
|
|
|
LayoutDevicePixel::ToAppUnits(devPxSize,
|
|
|
|
appUnitsPerDevPx));
|
2010-12-20 00:45:29 +00:00
|
|
|
|
|
|
|
// Note: Can't use DrawSingleUnscaledImage for the TYPE_VECTOR case.
|
|
|
|
// That method needs our image to have a fixed native width & height,
|
|
|
|
// and that's not always true for TYPE_VECTOR images.
|
2016-07-14 04:47:06 +00:00
|
|
|
result = nsLayoutUtils::DrawSingleImage(
|
2014-11-01 10:45:09 +00:00
|
|
|
aContext,
|
2014-06-20 06:42:30 +00:00
|
|
|
PresContext(),
|
2010-12-20 00:45:29 +00:00
|
|
|
mImageContainer,
|
2016-05-25 16:01:18 +00:00
|
|
|
nsLayoutUtils::GetSamplingFilterForFrame(this),
|
2010-12-20 00:45:29 +00:00
|
|
|
destRect,
|
|
|
|
aDirtyRect ? dirtyRect : destRect,
|
2017-01-11 01:48:29 +00:00
|
|
|
context,
|
2010-12-20 00:45:29 +00:00
|
|
|
drawFlags);
|
|
|
|
} else { // mImageContainer->GetType() == TYPE_RASTER
|
2016-07-14 04:47:06 +00:00
|
|
|
result = nsLayoutUtils::DrawSingleUnscaledImage(
|
2014-11-01 10:45:09 +00:00
|
|
|
aContext,
|
2014-06-20 06:42:30 +00:00
|
|
|
PresContext(),
|
2010-12-20 00:45:29 +00:00
|
|
|
mImageContainer,
|
2016-05-25 16:01:18 +00:00
|
|
|
nsLayoutUtils::GetSamplingFilterForFrame(this),
|
2010-12-20 00:45:29 +00:00
|
|
|
nsPoint(0, 0),
|
2012-07-30 14:20:58 +00:00
|
|
|
aDirtyRect ? &dirtyRect : nullptr,
|
2010-12-20 00:45:29 +00:00
|
|
|
drawFlags);
|
|
|
|
}
|
2010-10-11 20:08:19 +00:00
|
|
|
|
2016-04-12 05:52:42 +00:00
|
|
|
if (opacity != 1.0f || StyleEffects()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2015-11-11 15:15:39 +00:00
|
|
|
aContext.PopGroupAndBlend();
|
2010-10-11 20:08:19 +00:00
|
|
|
}
|
|
|
|
// gfxContextAutoSaveRestore goes out of scope & cleans up our gfxContext
|
2004-12-17 23:45:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 04:47:06 +00:00
|
|
|
return result;
|
2004-12-17 23:45:30 +00:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:34:31 +00:00
|
|
|
nsIFrame*
|
2014-08-07 07:09:31 +00:00
|
|
|
nsSVGImageFrame::GetFrameForPoint(const gfxPoint& aPoint)
|
2006-09-19 16:35:29 +00:00
|
|
|
{
|
2015-01-19 15:06:01 +00:00
|
|
|
if (!(GetStateBits() & NS_STATE_SVG_CLIPPATH_CHILD) && !GetHitTestFlags()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-07 07:09:31 +00:00
|
|
|
Rect rect;
|
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
|
|
|
element->GetAnimatedLengthValues(&rect.x, &rect.y,
|
|
|
|
&rect.width, &rect.height, nullptr);
|
|
|
|
|
|
|
|
if (!rect.Contains(ToPoint(aPoint))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2010-12-20 00:45:29 +00:00
|
|
|
// Special case for raster images -- we only want to accept points that fall
|
2014-08-07 07:09:31 +00:00
|
|
|
// in the underlying image's (scaled to fit) native bounds. That region
|
|
|
|
// doesn't necessarily map to our <image> element's [x,y,width,height] if the
|
|
|
|
// raster image's aspect ratio is being preserved. We have to look up the
|
|
|
|
// native image size & our viewBox transform in order to filter out points
|
|
|
|
// that fall outside that area. (This special case doesn't apply to vector
|
|
|
|
// images because they don't limit their drawing to explicit "native
|
|
|
|
// bounds" -- they have an infinite canvas on which to place content.)
|
2013-02-16 21:51:02 +00:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow() && mImageContainer) {
|
2010-12-20 00:45:29 +00:00
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_RASTER) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t nativeWidth, nativeHeight;
|
2010-12-20 00:45:29 +00:00
|
|
|
if (NS_FAILED(mImageContainer->GetWidth(&nativeWidth)) ||
|
|
|
|
NS_FAILED(mImageContainer->GetHeight(&nativeHeight)) ||
|
|
|
|
nativeWidth == 0 || nativeHeight == 0) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-12-20 00:45:29 +00:00
|
|
|
}
|
2014-08-07 07:09:31 +00:00
|
|
|
Matrix viewBoxTM =
|
|
|
|
SVGContentUtils::GetViewBoxTransform(rect.width, rect.height,
|
|
|
|
0, 0, nativeWidth, nativeHeight,
|
|
|
|
element->mPreserveAspectRatio);
|
|
|
|
if (!nsSVGUtils::HitTestRect(viewBoxTM,
|
|
|
|
0, 0, nativeWidth, nativeHeight,
|
|
|
|
aPoint.x - rect.x, aPoint.y - rect.y)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-12-20 00:45:29 +00:00
|
|
|
}
|
2006-09-19 16:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 07:09:31 +00:00
|
|
|
return this;
|
2006-09-19 16:35:29 +00:00
|
|
|
}
|
|
|
|
|
2005-04-01 19:56:08 +00:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGImageFrame::GetType() const
|
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
return nsGkAtoms::svgImageFrame;
|
2005-04-01 19:56:08 +00:00
|
|
|
}
|
|
|
|
|
2006-06-21 15:42:28 +00:00
|
|
|
//----------------------------------------------------------------------
|
2016-12-18 11:11:47 +00:00
|
|
|
// SVGGeometryFrame methods:
|
2006-06-21 15:42:28 +00:00
|
|
|
|
2009-08-31 11:26:23 +00:00
|
|
|
// Lie about our fill/stroke so that covered region and hit detection work properly
|
|
|
|
|
2012-03-20 12:15:53 +00:00
|
|
|
void
|
2012-07-22 00:01:44 +00:00
|
|
|
nsSVGImageFrame::ReflowSVG()
|
2009-08-31 11:26:23 +00:00
|
|
|
{
|
2012-07-22 00:01:44 +00:00
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this),
|
|
|
|
"This call is probably a wasteful mistake");
|
2012-03-20 12:15:53 +00:00
|
|
|
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"ReflowSVG mechanism not designed for this");
|
2012-03-20 12:15:53 +00:00
|
|
|
|
2012-07-22 00:01:44 +00:00
|
|
|
if (!nsSVGUtils::NeedsReflowSVG(this)) {
|
2012-03-20 12:15:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-08-31 11:26:23 +00:00
|
|
|
|
2014-03-31 11:53:54 +00:00
|
|
|
float x, y, width, height;
|
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
|
|
|
element->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
|
|
|
|
|
|
|
Rect extent(x, y, width, height);
|
2009-08-31 11:26:23 +00:00
|
|
|
|
|
|
|
if (!extent.IsEmpty()) {
|
2012-02-10 12:33:18 +00:00
|
|
|
mRect = nsLayoutUtils::RoundGfxRectToAppRect(extent,
|
2012-02-17 06:07:51 +00:00
|
|
|
PresContext()->AppUnitsPerCSSPixel());
|
2012-03-20 12:15:53 +00:00
|
|
|
} else {
|
|
|
|
mRect.SetEmpty();
|
2009-08-31 11:26:23 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 04:05:09 +00:00
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
|
|
|
// Make sure we have our filter property (if any) before calling
|
|
|
|
// FinishAndStoreOverflow (subsequent filter changes are handled off
|
|
|
|
// nsChangeHint_UpdateEffects):
|
|
|
|
nsSVGEffects::UpdateEffects(this);
|
2013-09-15 00:05:05 +00:00
|
|
|
|
|
|
|
if (!mReflowCallbackPosted) {
|
|
|
|
nsIPresShell* shell = PresContext()->PresShell();
|
2013-09-15 00:05:06 +00:00
|
|
|
mReflowCallbackPosted = true;
|
|
|
|
shell->PostReflowCallback(this);
|
2013-09-15 00:05:05 +00:00
|
|
|
}
|
2012-05-17 04:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect overflow = nsRect(nsPoint(0,0), mRect.Size());
|
|
|
|
nsOverflowAreas overflowAreas(overflow, overflow);
|
|
|
|
FinishAndStoreOverflow(overflowAreas, mRect.Size());
|
|
|
|
|
2012-03-20 12:15:53 +00:00
|
|
|
mState &= ~(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
|
2012-11-28 10:34:58 +00:00
|
|
|
// Invalidate, but only if this is not our first reflow (since if it is our
|
|
|
|
// first reflow then we haven't had our first paint yet).
|
|
|
|
if (!(GetParent()->GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
InvalidateFrame();
|
2012-03-20 12:15:53 +00:00
|
|
|
}
|
2009-08-31 11:26:23 +00:00
|
|
|
}
|
2005-04-01 20:49:42 +00:00
|
|
|
|
2013-09-15 00:05:05 +00:00
|
|
|
bool
|
|
|
|
nsSVGImageFrame::ReflowFinished()
|
|
|
|
{
|
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
|
2016-03-25 21:49:43 +00:00
|
|
|
// XXX(seth): We don't need this. The purpose of updating visibility
|
|
|
|
// synchronously is to ensure that animated images start animating
|
|
|
|
// immediately. In the short term, however,
|
|
|
|
// nsImageLoadingContent::OnUnlockedDraw() is enough to ensure that
|
|
|
|
// animations start as soon as the image is painted for the first time, and in
|
|
|
|
// the long term we want to update visibility information from the display
|
|
|
|
// list whenever we paint, so we don't actually need to do this. However, to
|
|
|
|
// avoid behavior changes during the transition from the old image visibility
|
|
|
|
// code, we'll leave it in for now.
|
|
|
|
UpdateVisibilitySynchronously();
|
2013-09-15 00:05:05 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGImageFrame::ReflowCallbackCanceled()
|
|
|
|
{
|
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t
|
2011-07-08 13:20:14 +00:00
|
|
|
nsSVGImageFrame::GetHitTestFlags()
|
2005-04-01 20:49:42 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t flags = 0;
|
2005-04-01 20:49:42 +00:00
|
|
|
|
2016-04-12 05:52:41 +00:00
|
|
|
switch (StyleUserInterface()->mPointerEvents) {
|
2005-04-01 20:49:42 +00:00
|
|
|
case NS_STYLE_POINTER_EVENTS_NONE:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEPAINTED:
|
2009-08-27 03:53:35 +00:00
|
|
|
case NS_STYLE_POINTER_EVENTS_AUTO:
|
2013-02-16 21:51:02 +00:00
|
|
|
if (StyleVisibility()->IsVisible()) {
|
2005-04-01 20:49:42 +00:00
|
|
|
/* XXX: should check pixel transparency */
|
2011-07-08 13:20:14 +00:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2005-04-01 20:49:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEFILL:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLESTROKE:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLE:
|
2013-02-16 21:51:02 +00:00
|
|
|
if (StyleVisibility()->IsVisible()) {
|
2011-07-08 13:20:14 +00:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2005-04-01 20:49:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_PAINTED:
|
|
|
|
/* XXX: should check pixel transparency */
|
2011-07-08 13:20:14 +00:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2005-04-01 20:49:42 +00:00
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_FILL:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_STROKE:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_ALL:
|
2011-07-08 13:20:14 +00:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2005-04-01 20:49:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("not reached");
|
|
|
|
break;
|
|
|
|
}
|
2006-06-20 17:01:09 +00:00
|
|
|
|
2011-07-08 13:20:14 +00:00
|
|
|
return flags;
|
2005-04-01 20:49:42 +00:00
|
|
|
}
|
|
|
|
|
2004-12-17 23:45:30 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGImageListener implementation
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsSVGImageListener, imgINotificationObserver)
|
2004-12-17 23:45:30 +00:00
|
|
|
|
|
|
|
nsSVGImageListener::nsSVGImageListener(nsSVGImageFrame *aFrame) : mFrame(aFrame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-12 16:11:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGImageListener::Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData)
|
2012-10-12 01:58:24 +00:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-01-18 17:46:36 +00:00
|
|
|
|
2012-10-12 16:11:23 +00:00
|
|
|
if (aType == imgINotificationObserver::LOAD_COMPLETE) {
|
2013-06-10 00:14:01 +00:00
|
|
|
mFrame->InvalidateFrame();
|
2014-11-06 09:30:11 +00:00
|
|
|
nsLayoutUtils::PostRestyleEvent(
|
|
|
|
mFrame->GetContent()->AsElement(), nsRestyleHint(0),
|
|
|
|
nsChangeHint_InvalidateRenderingObservers);
|
2012-11-28 09:42:13 +00:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(mFrame);
|
2012-10-12 16:11:22 +00:00
|
|
|
}
|
2012-10-12 01:58:24 +00:00
|
|
|
|
2012-10-12 16:11:23 +00:00
|
|
|
if (aType == imgINotificationObserver::FRAME_UPDATE) {
|
2012-10-12 16:11:22 +00:00
|
|
|
// No new dimensions, so we don't need to call
|
|
|
|
// nsSVGUtils::InvalidateAndScheduleBoundsUpdate.
|
2014-11-06 09:30:11 +00:00
|
|
|
nsLayoutUtils::PostRestyleEvent(
|
|
|
|
mFrame->GetContent()->AsElement(), nsRestyleHint(0),
|
|
|
|
nsChangeHint_InvalidateRenderingObservers);
|
2013-06-10 00:14:01 +00:00
|
|
|
mFrame->InvalidateFrame();
|
2012-10-12 16:11:22 +00:00
|
|
|
}
|
2012-10-12 01:58:24 +00:00
|
|
|
|
2012-10-12 16:11:23 +00:00
|
|
|
if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
|
2012-10-12 16:11:22 +00:00
|
|
|
// Called once the resource's dimensions have been obtained.
|
|
|
|
aRequest->GetImage(getter_AddRefs(mFrame->mImageContainer));
|
2013-06-10 00:14:01 +00:00
|
|
|
mFrame->InvalidateFrame();
|
2014-11-06 09:30:11 +00:00
|
|
|
nsLayoutUtils::PostRestyleEvent(
|
|
|
|
mFrame->GetContent()->AsElement(), nsRestyleHint(0),
|
|
|
|
nsChangeHint_InvalidateRenderingObservers);
|
2012-11-28 09:42:13 +00:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(mFrame);
|
2012-10-12 16:11:22 +00:00
|
|
|
}
|
2007-01-18 17:46:36 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|