1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 // Keep in (case-insensitive) order:
7 #include "nsContainerFrame.h"
8 #include "nsFrame.h"
9 #include "nsGkAtoms.h"
10 #include "nsSVGEffects.h"
11 #include "nsSVGFilters.h"
12 
13 class SVGFEUnstyledLeafFrame : public nsFrame
14 {
15   friend nsIFrame*
16   NS_NewSVGFEUnstyledLeafFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
17 protected:
SVGFEUnstyledLeafFrame(nsStyleContext * aContext)18   explicit SVGFEUnstyledLeafFrame(nsStyleContext* aContext)
19     : nsFrame(aContext)
20   {
21     AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_NONDISPLAY);
22   }
23 
24 public:
25   NS_DECL_FRAMEARENA_HELPERS
26 
BuildDisplayList(nsDisplayListBuilder * aBuilder,const nsRect & aDirtyRect,const nsDisplayListSet & aLists)27   virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
28                                 const nsRect&           aDirtyRect,
29                                 const nsDisplayListSet& aLists) override {}
30 
IsFrameOfType(uint32_t aFlags) const31   virtual bool IsFrameOfType(uint32_t aFlags) const override
32   {
33     return nsFrame::IsFrameOfType(aFlags & ~(nsIFrame::eSVG));
34   }
35 
36 #ifdef DEBUG_FRAME_DUMP
GetFrameName(nsAString & aResult) const37   virtual nsresult GetFrameName(nsAString& aResult) const override
38   {
39     return MakeFrameName(NS_LITERAL_STRING("SVGFEUnstyledLeaf"), aResult);
40   }
41 #endif
42 
43   /**
44    * Get the "type" of the frame
45    *
46    * @see nsGkAtoms::svgFEUnstyledLeafFrame
47    */
48   virtual nsIAtom* GetType() const override;
49 
50   virtual nsresult AttributeChanged(int32_t  aNameSpaceID,
51                                     nsIAtom* aAttribute,
52                                     int32_t  aModType) override;
53 
ComputeCustomOverflow(nsOverflowAreas & aOverflowAreas)54   virtual bool ComputeCustomOverflow(nsOverflowAreas& aOverflowAreas) override {
55     // We don't maintain a visual overflow rect
56     return false;
57   }
58 };
59 
60 nsIFrame*
NS_NewSVGFEUnstyledLeafFrame(nsIPresShell * aPresShell,nsStyleContext * aContext)61 NS_NewSVGFEUnstyledLeafFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
62 {
63   return new (aPresShell) SVGFEUnstyledLeafFrame(aContext);
64 }
65 
NS_IMPL_FRAMEARENA_HELPERS(SVGFEUnstyledLeafFrame)66 NS_IMPL_FRAMEARENA_HELPERS(SVGFEUnstyledLeafFrame)
67 
68 nsIAtom *
69 SVGFEUnstyledLeafFrame::GetType() const
70 {
71   return nsGkAtoms::svgFEUnstyledLeafFrame;
72 }
73 
74 nsresult
AttributeChanged(int32_t aNameSpaceID,nsIAtom * aAttribute,int32_t aModType)75 SVGFEUnstyledLeafFrame::AttributeChanged(int32_t  aNameSpaceID,
76                                          nsIAtom* aAttribute,
77                                          int32_t  aModType)
78 {
79   SVGFEUnstyledElement *element = static_cast<SVGFEUnstyledElement*>(mContent);
80   if (element->AttributeAffectsRendering(aNameSpaceID, aAttribute)) {
81     MOZ_ASSERT(GetParent()->GetParent()->GetType() == nsGkAtoms::svgFilterFrame,
82                "Observers observe the filter, so that's what we must invalidate");
83     nsSVGEffects::InvalidateDirectRenderingObservers(GetParent()->GetParent());
84   }
85 
86   return nsFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
87 }
88