nsSVGStopFrame.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // Keep in (case-insensitive) order:
  6. #include "nsContainerFrame.h"
  7. #include "nsFrame.h"
  8. #include "nsGkAtoms.h"
  9. #include "nsStyleContext.h"
  10. #include "nsSVGEffects.h"
  11. // This is a very simple frame whose only purpose is to capture style change
  12. // events and propagate them to the parent. Most of the heavy lifting is done
  13. // within the nsSVGGradientFrame, which is the parent for this frame
  14. class nsSVGStopFrame : public nsFrame
  15. {
  16. friend nsIFrame*
  17. NS_NewSVGStopFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
  18. protected:
  19. explicit nsSVGStopFrame(nsStyleContext* aContext)
  20. : nsFrame(aContext)
  21. {
  22. AddStateBits(NS_FRAME_IS_NONDISPLAY);
  23. }
  24. public:
  25. NS_DECL_FRAMEARENA_HELPERS
  26. // nsIFrame interface:
  27. #ifdef DEBUG
  28. virtual void Init(nsIContent* aContent,
  29. nsContainerFrame* aParent,
  30. nsIFrame* aPrevInFlow) override;
  31. #endif
  32. void BuildDisplayList(nsDisplayListBuilder* aBuilder,
  33. const nsDisplayListSet& aLists) override {}
  34. virtual nsresult AttributeChanged(int32_t aNameSpaceID,
  35. nsIAtom* aAttribute,
  36. int32_t aModType) override;
  37. /**
  38. * Get the "type" of the frame
  39. *
  40. * @see nsGkAtoms::svgStopFrame
  41. */
  42. virtual nsIAtom* GetType() const override;
  43. virtual bool IsFrameOfType(uint32_t aFlags) const override
  44. {
  45. return nsFrame::IsFrameOfType(aFlags & ~(nsIFrame::eSVG));
  46. }
  47. #ifdef DEBUG_FRAME_DUMP
  48. virtual nsresult GetFrameName(nsAString& aResult) const override
  49. {
  50. return MakeFrameName(NS_LITERAL_STRING("SVGStop"), aResult);
  51. }
  52. #endif
  53. };
  54. //----------------------------------------------------------------------
  55. // Implementation
  56. NS_IMPL_FRAMEARENA_HELPERS(nsSVGStopFrame)
  57. //----------------------------------------------------------------------
  58. // nsIFrame methods:
  59. #ifdef DEBUG
  60. void
  61. nsSVGStopFrame::Init(nsIContent* aContent,
  62. nsContainerFrame* aParent,
  63. nsIFrame* aPrevInFlow)
  64. {
  65. NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::stop), "Content is not a stop element");
  66. nsFrame::Init(aContent, aParent, aPrevInFlow);
  67. }
  68. #endif /* DEBUG */
  69. nsIAtom *
  70. nsSVGStopFrame::GetType() const
  71. {
  72. return nsGkAtoms::svgStopFrame;
  73. }
  74. nsresult
  75. nsSVGStopFrame::AttributeChanged(int32_t aNameSpaceID,
  76. nsIAtom* aAttribute,
  77. int32_t aModType)
  78. {
  79. if (aNameSpaceID == kNameSpaceID_None &&
  80. aAttribute == nsGkAtoms::offset) {
  81. MOZ_ASSERT(GetParent()->GetType() == nsGkAtoms::svgLinearGradientFrame ||
  82. GetParent()->GetType() == nsGkAtoms::svgRadialGradientFrame,
  83. "Observers observe the gradient, so that's what we must invalidate");
  84. nsSVGEffects::InvalidateDirectRenderingObservers(GetParent());
  85. }
  86. return nsFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
  87. }
  88. // -------------------------------------------------------------------------
  89. // Public functions
  90. // -------------------------------------------------------------------------
  91. nsIFrame* NS_NewSVGStopFrame(nsIPresShell* aPresShell,
  92. nsStyleContext* aContext)
  93. {
  94. return new (aPresShell) nsSVGStopFrame(aContext);
  95. }