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"
|
2012-03-26 11:58:59 +00:00
|
|
|
#include "nsSVGPathGeometryFrame.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"
|
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"
|
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;
|
2004-12-17 23:45:30 +00:00
|
|
|
|
|
|
|
class nsSVGImageFrame;
|
|
|
|
|
2012-10-12 16:11:22 +00:00
|
|
|
class nsSVGImageListener MOZ_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;
|
|
|
|
};
|
|
|
|
|
2011-10-19 15:37:49 +00:00
|
|
|
typedef nsSVGPathGeometryFrame nsSVGImageFrameBase;
|
2004-12-17 23:45:30 +00:00
|
|
|
|
2013-09-15 00:05:05 +00:00
|
|
|
class nsSVGImageFrame : public nsSVGImageFrameBase,
|
|
|
|
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:
|
2014-09-01 03:36:37 +00:00
|
|
|
explicit nsSVGImageFrame(nsStyleContext* aContext) : nsSVGImageFrameBase(aContext),
|
|
|
|
mReflowCallbackPosted(false) {}
|
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:
|
2014-10-31 20:08:54 +00:00
|
|
|
virtual nsresult PaintSVG(gfxContext& aContext,
|
2014-08-29 19:42:07 +00:00
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
const nsIntRect* aDirtyRect = nullptr) MOZ_OVERRIDE;
|
2014-08-07 07:09:31 +00:00
|
|
|
virtual nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) MOZ_OVERRIDE;
|
2014-02-24 14:41:56 +00:00
|
|
|
virtual void ReflowSVG() MOZ_OVERRIDE;
|
2004-12-17 23:45:30 +00:00
|
|
|
|
2006-06-20 17:01:09 +00:00
|
|
|
// nsSVGPathGeometryFrame methods:
|
2014-01-04 08:29:02 +00:00
|
|
|
virtual uint16_t GetHitTestFlags() MOZ_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,
|
2014-02-24 14:41:56 +00:00
|
|
|
int32_t aModType) MOZ_OVERRIDE;
|
2014-05-24 22:20:40 +00:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2014-02-24 14:41:56 +00:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_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
|
|
|
*/
|
2014-02-24 14:41:56 +00:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE;
|
2005-04-01 19:56:08 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-24 14:41:56 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_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
|
|
|
|
virtual bool ReflowFinished() MOZ_OVERRIDE;
|
|
|
|
virtual void ReflowCallbackCanceled() MOZ_OVERRIDE;
|
|
|
|
|
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
|
|
|
{
|
2013-01-08 03:22:41 +00:00
|
|
|
NS_ASSERTION(aContent->IsSVG(nsGkAtoms::image),
|
|
|
|
"Content is not an SVG image!");
|
2009-01-19 18:31:34 +00:00
|
|
|
|
2013-03-20 01:47:48 +00:00
|
|
|
nsSVGImageFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2013-01-08 03:22:41 +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) {
|
|
|
|
NS_RUNTIMEABORT("Why is this not an image loading content?");
|
|
|
|
}
|
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)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
if (aNameSpaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
2011-10-29 08:18:25 +00:00
|
|
|
|
|
|
|
// Prevent setting image.src by exiting early
|
|
|
|
if (nsContentUtils::IsImageSrcSetDisabled()) {
|
2011-10-19 15:37:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-01-06 09:32:01 +00:00
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
2011-10-19 15:37:49 +00:00
|
|
|
|
2013-01-06 09:32:01 +00:00
|
|
|
if (element->mStringAttributes[SVGImageElement::HREF].IsExplicitlySet()) {
|
2011-10-19 15:37:49 +00:00
|
|
|
element->LoadSVGImage(true, true);
|
|
|
|
} else {
|
|
|
|
element->CancelImageRequests(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsSVGImageFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
2004-12-17 23:45:30 +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:
|
2014-02-19 22:34:31 +00:00
|
|
|
nsresult
|
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
|
|
|
{
|
2006-10-27 10:34:23 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
if (!StyleVisibility()->IsVisible())
|
2005-01-25 03:55:03 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
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
|
|
|
|
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)) {
|
2010-12-20 00:45:29 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
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)) {
|
2013-02-16 21:51:02 +00:00
|
|
|
opacity = StyleDisplay()->mOpacity;
|
2007-01-04 15:05:39 +00:00
|
|
|
}
|
|
|
|
|
2013-09-15 03:40:11 +00:00
|
|
|
if (opacity != 1.0f || StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2014-10-31 20:08:54 +00:00
|
|
|
aContext.PushGroup(gfxContentType::COLOR_ALPHA);
|
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");
|
2010-10-22 22:55:04 +00:00
|
|
|
dirtyRect = aDirtyRect->ToAppUnits(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
|
|
|
|
// attributes of mImageContainer's internal SVG document.
|
2014-08-22 20:12:38 +00:00
|
|
|
SVGImageContext context(nsIntSize(width, height),
|
|
|
|
Some(imgElem->mPreserveAspectRatio.GetAnimValue()));
|
2013-02-28 20:22:43 +00:00
|
|
|
|
2010-12-20 00:45:29 +00:00
|
|
|
nsRect destRect(0, 0,
|
|
|
|
appUnitsPerDevPx * width,
|
|
|
|
appUnitsPerDevPx * height);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
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,
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this),
|
|
|
|
destRect,
|
|
|
|
aDirtyRect ? dirtyRect : destRect,
|
2013-02-28 20:22:43 +00:00
|
|
|
&context,
|
2010-12-20 00:45:29 +00:00
|
|
|
drawFlags);
|
|
|
|
} else { // mImageContainer->GetType() == TYPE_RASTER
|
|
|
|
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,
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this),
|
|
|
|
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
|
|
|
|
2013-09-15 03:40:11 +00:00
|
|
|
if (opacity != 1.0f || StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2014-10-31 20:08:54 +00:00
|
|
|
aContext.PopGroupToSource();
|
|
|
|
aContext.SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
aContext.Paint(opacity);
|
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
|
|
|
}
|
|
|
|
|
2006-10-27 10:34:23 +00:00
|
|
|
return rv;
|
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
|
|
|
{
|
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
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGPathGeometryFrame methods:
|
|
|
|
|
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
|
|
|
|
2013-07-12 07:13:07 +00:00
|
|
|
NS_ABORT_IF_FALSE(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
2012-07-22 00:01:44 +00:00
|
|
|
"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;
|
|
|
|
|
|
|
|
nsLayoutUtils::UpdateImageVisibilityForFrame(this);
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
switch(StyleVisibility()->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;
|
|
|
|
}
|
|
|
|
|