tor-browser

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

SVGFELeafFrame.cpp (3259B)


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