1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/svg/SVGFEImageFrame.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,144 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +// Keep in (case-insensitive) order: 1.10 +#include "nsContentUtils.h" 1.11 +#include "nsFrame.h" 1.12 +#include "nsGkAtoms.h" 1.13 +#include "nsLiteralString.h" 1.14 +#include "nsSVGEffects.h" 1.15 +#include "nsSVGFilters.h" 1.16 +#include "mozilla/dom/SVGFEImageElement.h" 1.17 + 1.18 +using namespace mozilla; 1.19 +using namespace mozilla::dom; 1.20 + 1.21 +typedef nsFrame SVGFEImageFrameBase; 1.22 + 1.23 +class SVGFEImageFrame : public SVGFEImageFrameBase 1.24 +{ 1.25 + friend nsIFrame* 1.26 + NS_NewSVGFEImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.27 +protected: 1.28 + SVGFEImageFrame(nsStyleContext* aContext) 1.29 + : SVGFEImageFrameBase(aContext) 1.30 + { 1.31 + AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_NONDISPLAY); 1.32 + } 1.33 + 1.34 +public: 1.35 + NS_DECL_FRAMEARENA_HELPERS 1.36 + 1.37 + virtual void Init(nsIContent* aContent, 1.38 + nsIFrame* aParent, 1.39 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.40 + virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; 1.41 + 1.42 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.43 + { 1.44 + return SVGFEImageFrameBase::IsFrameOfType(aFlags & ~(nsIFrame::eSVG)); 1.45 + } 1.46 + 1.47 +#ifdef DEBUG_FRAME_DUMP 1.48 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE 1.49 + { 1.50 + return MakeFrameName(NS_LITERAL_STRING("SVGFEImage"), aResult); 1.51 + } 1.52 +#endif 1.53 + 1.54 + /** 1.55 + * Get the "type" of the frame 1.56 + * 1.57 + * @see nsGkAtoms::svgFEImageFrame 1.58 + */ 1.59 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.60 + 1.61 + virtual nsresult AttributeChanged(int32_t aNameSpaceID, 1.62 + nsIAtom* aAttribute, 1.63 + int32_t aModType) MOZ_OVERRIDE; 1.64 + 1.65 + virtual bool UpdateOverflow() MOZ_OVERRIDE { 1.66 + // We don't maintain a visual overflow rect 1.67 + return false; 1.68 + } 1.69 +}; 1.70 + 1.71 +nsIFrame* 1.72 +NS_NewSVGFEImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) 1.73 +{ 1.74 + return new (aPresShell) SVGFEImageFrame(aContext); 1.75 +} 1.76 + 1.77 +NS_IMPL_FRAMEARENA_HELPERS(SVGFEImageFrame) 1.78 + 1.79 +/* virtual */ void 1.80 +SVGFEImageFrame::DestroyFrom(nsIFrame* aDestructRoot) 1.81 +{ 1.82 + nsCOMPtr<nsIImageLoadingContent> imageLoader = 1.83 + do_QueryInterface(SVGFEImageFrameBase::mContent); 1.84 + 1.85 + if (imageLoader) { 1.86 + imageLoader->FrameDestroyed(this); 1.87 + imageLoader->DecrementVisibleCount(); 1.88 + } 1.89 + 1.90 + SVGFEImageFrameBase::DestroyFrom(aDestructRoot); 1.91 +} 1.92 + 1.93 +void 1.94 +SVGFEImageFrame::Init(nsIContent* aContent, 1.95 + nsIFrame* aParent, 1.96 + nsIFrame* aPrevInFlow) 1.97 +{ 1.98 + NS_ASSERTION(aContent->IsSVG(nsGkAtoms::feImage), 1.99 + "Trying to construct an SVGFEImageFrame for a " 1.100 + "content element that doesn't support the right interfaces"); 1.101 + 1.102 + SVGFEImageFrameBase::Init(aContent, aParent, aPrevInFlow); 1.103 + nsCOMPtr<nsIImageLoadingContent> imageLoader = 1.104 + do_QueryInterface(SVGFEImageFrameBase::mContent); 1.105 + 1.106 + if (imageLoader) { 1.107 + // We assume that feImage's are always visible. 1.108 + // Increment the visible count before calling FrameCreated so that 1.109 + // FrameCreated will actually track the image correctly. 1.110 + imageLoader->IncrementVisibleCount(); 1.111 + imageLoader->FrameCreated(this); 1.112 + } 1.113 +} 1.114 + 1.115 +nsIAtom * 1.116 +SVGFEImageFrame::GetType() const 1.117 +{ 1.118 + return nsGkAtoms::svgFEImageFrame; 1.119 +} 1.120 + 1.121 +nsresult 1.122 +SVGFEImageFrame::AttributeChanged(int32_t aNameSpaceID, 1.123 + nsIAtom* aAttribute, 1.124 + int32_t aModType) 1.125 +{ 1.126 + SVGFEImageElement *element = static_cast<SVGFEImageElement*>(mContent); 1.127 + if (element->AttributeAffectsRendering(aNameSpaceID, aAttribute)) { 1.128 + nsSVGEffects::InvalidateRenderingObservers(this); 1.129 + } 1.130 + if (aNameSpaceID == kNameSpaceID_XLink && 1.131 + aAttribute == nsGkAtoms::href) { 1.132 + 1.133 + // Prevent setting image.src by exiting early 1.134 + if (nsContentUtils::IsImageSrcSetDisabled()) { 1.135 + return NS_OK; 1.136 + } 1.137 + 1.138 + if (element->mStringAttributes[SVGFEImageElement::HREF].IsExplicitlySet()) { 1.139 + element->LoadSVGImage(true, true); 1.140 + } else { 1.141 + element->CancelImageRequests(true); 1.142 + } 1.143 + } 1.144 + 1.145 + return SVGFEImageFrameBase::AttributeChanged(aNameSpaceID, 1.146 + aAttribute, aModType); 1.147 +}