tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SVGStopFrame.cpp (3479B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 // Keep in (case-insensitive) order:
      8 #include "mozilla/ComputedStyle.h"
      9 #include "mozilla/PresShell.h"
     10 #include "mozilla/SVGGradientFrame.h"
     11 #include "mozilla/SVGObserverUtils.h"
     12 #include "nsContainerFrame.h"
     13 #include "nsGkAtoms.h"
     14 #include "nsIFrame.h"
     15 
     16 // This is a very simple frame whose only purpose is to capture style change
     17 // events and propagate them to the parent.  Most of the heavy lifting is done
     18 // within the SVGGradientFrame, which is the parent for this frame
     19 
     20 nsIFrame* NS_NewSVGStopFrame(mozilla::PresShell* aPresShell,
     21                             mozilla::ComputedStyle* aStyle);
     22 
     23 namespace mozilla {
     24 
     25 class SVGStopFrame : public nsIFrame {
     26  friend nsIFrame* ::NS_NewSVGStopFrame(mozilla::PresShell* aPresShell,
     27                                        ComputedStyle* aStyle);
     28 
     29 protected:
     30  explicit SVGStopFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
     31      : nsIFrame(aStyle, aPresContext, kClassID) {
     32    AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_NONDISPLAY);
     33  }
     34 
     35 public:
     36  NS_DECL_FRAMEARENA_HELPERS(SVGStopFrame)
     37 
     38  // nsIFrame interface:
     39 #ifdef DEBUG
     40  void Init(nsIContent* aContent, nsContainerFrame* aParent,
     41            nsIFrame* aPrevInFlow) override;
     42 #endif
     43 
     44  void BuildDisplayList(nsDisplayListBuilder* aBuilder,
     45                        const nsDisplayListSet& aLists) override {}
     46 
     47  nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
     48                            AttrModType aModType) override;
     49 
     50 #ifdef DEBUG_FRAME_DUMP
     51  nsresult GetFrameName(nsAString& aResult) const override {
     52    return MakeFrameName(u"SVGStop"_ns, aResult);
     53  }
     54 #endif
     55 };
     56 
     57 //----------------------------------------------------------------------
     58 // Implementation
     59 
     60 NS_IMPL_FRAMEARENA_HELPERS(SVGStopFrame)
     61 
     62 //----------------------------------------------------------------------
     63 // nsIFrame methods:
     64 
     65 #ifdef DEBUG
     66 void SVGStopFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
     67                        nsIFrame* aPrevInFlow) {
     68  NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::stop),
     69               "Content is not a stop element");
     70 
     71  nsIFrame::Init(aContent, aParent, aPrevInFlow);
     72 }
     73 #endif /* DEBUG */
     74 
     75 nsresult SVGStopFrame::AttributeChanged(int32_t aNameSpaceID,
     76                                        nsAtom* aAttribute,
     77                                        AttrModType aModType) {
     78  if (aNameSpaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::offset) {
     79    MOZ_ASSERT(
     80        static_cast<SVGGradientFrame*>(do_QueryFrame(GetParent())),
     81        "Observers observe the gradient, so that's what we must invalidate");
     82    SVGObserverUtils::InvalidateRenderingObservers(GetParent());
     83  }
     84 
     85  return nsIFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
     86 }
     87 
     88 }  // namespace mozilla
     89 
     90 // -------------------------------------------------------------------------
     91 // Public functions
     92 // -------------------------------------------------------------------------
     93 
     94 nsIFrame* NS_NewSVGStopFrame(mozilla::PresShell* aPresShell,
     95                             mozilla::ComputedStyle* aStyle) {
     96  return new (aPresShell)
     97      mozilla::SVGStopFrame(aStyle, aPresShell->GetPresContext());
     98 }