tor-browser

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

SVGFEContainerFrame.cpp (3426B)


      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/PresShell.h"
      9 #include "mozilla/SVGObserverUtils.h"
     10 #include "mozilla/dom/SVGFilters.h"
     11 #include "nsContainerFrame.h"
     12 #include "nsGkAtoms.h"
     13 #include "nsIFrame.h"
     14 #include "nsLiteralString.h"
     15 
     16 using namespace mozilla::dom;
     17 
     18 nsIFrame* NS_NewSVGFEContainerFrame(mozilla::PresShell* aPresShell,
     19                                    mozilla::ComputedStyle* aStyle);
     20 
     21 namespace mozilla {
     22 
     23 /*
     24 * This frame is used by filter primitive elements that
     25 * have special child elements that provide parameters.
     26 */
     27 class SVGFEContainerFrame final : public nsContainerFrame {
     28  friend nsIFrame* ::NS_NewSVGFEContainerFrame(mozilla::PresShell* aPresShell,
     29                                               ComputedStyle* aStyle);
     30 
     31 protected:
     32  explicit SVGFEContainerFrame(ComputedStyle* aStyle,
     33                               nsPresContext* aPresContext)
     34      : nsContainerFrame(aStyle, aPresContext, kClassID) {
     35    AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_NONDISPLAY);
     36  }
     37 
     38 public:
     39  NS_DECL_FRAMEARENA_HELPERS(SVGFEContainerFrame)
     40 
     41 #ifdef DEBUG_FRAME_DUMP
     42  nsresult GetFrameName(nsAString& aResult) const override {
     43    return MakeFrameName(u"SVGFEContainer"_ns, aResult);
     44  }
     45 #endif
     46 
     47 #ifdef DEBUG
     48  void Init(nsIContent* aContent, nsContainerFrame* aParent,
     49            nsIFrame* aPrevInFlow) override;
     50 #endif
     51 
     52  nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
     53                            AttrModType aModType) override;
     54 
     55  bool ComputeCustomOverflow(OverflowAreas& aOverflowAreas) override {
     56    // We don't maintain a ink overflow rect
     57    return false;
     58  }
     59 };
     60 
     61 }  // namespace mozilla
     62 
     63 nsIFrame* NS_NewSVGFEContainerFrame(mozilla::PresShell* aPresShell,
     64                                    mozilla::ComputedStyle* aStyle) {
     65  return new (aPresShell)
     66      mozilla::SVGFEContainerFrame(aStyle, aPresShell->GetPresContext());
     67 }
     68 
     69 namespace mozilla {
     70 
     71 NS_IMPL_FRAMEARENA_HELPERS(SVGFEContainerFrame)
     72 
     73 #ifdef DEBUG
     74 void SVGFEContainerFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
     75                               nsIFrame* aPrevInFlow) {
     76  NS_ASSERTION(aContent->IsSVGFilterPrimitiveElement(),
     77               "Trying to construct an SVGFEContainerFrame for a "
     78               "content element that doesn't support the right interfaces");
     79 
     80  nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
     81 }
     82 #endif /* DEBUG */
     83 
     84 nsresult SVGFEContainerFrame::AttributeChanged(int32_t aNameSpaceID,
     85                                               nsAtom* aAttribute,
     86                                               AttrModType aModType) {
     87  dom::SVGFilterPrimitiveElement* element =
     88      static_cast<dom::SVGFilterPrimitiveElement*>(GetContent());
     89  if (element->AttributeAffectsRendering(aNameSpaceID, aAttribute)) {
     90    MOZ_ASSERT(
     91        GetParent()->IsSVGFilterFrame(),
     92        "Observers observe the filter, so that's what we must invalidate");
     93    SVGObserverUtils::InvalidateRenderingObservers(GetParent());
     94  }
     95 
     96  return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
     97 }
     98 
     99 }  // namespace mozilla