tor-browser

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

SVGFEFloodElement.cpp (2873B)


      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 #include "mozilla/dom/SVGFEFloodElement.h"
      8 
      9 #include "FilterSupport.h"
     10 #include "mozilla/dom/BindContext.h"
     11 #include "mozilla/dom/Document.h"
     12 #include "mozilla/dom/SVGFEFloodElementBinding.h"
     13 #include "nsColor.h"
     14 #include "nsIFrame.h"
     15 
     16 NS_IMPL_NS_NEW_SVG_ELEMENT(FEFlood)
     17 
     18 using namespace mozilla::gfx;
     19 
     20 namespace mozilla::dom {
     21 
     22 JSObject* SVGFEFloodElement::WrapNode(JSContext* aCx,
     23                                      JS::Handle<JSObject*> aGivenProto) {
     24  return SVGFEFloodElement_Binding::Wrap(aCx, this, aGivenProto);
     25 }
     26 
     27 SVGElement::StringInfo SVGFEFloodElement::sStringInfo[1] = {
     28    {nsGkAtoms::result, kNameSpaceID_None, true}};
     29 
     30 //----------------------------------------------------------------------
     31 // nsINode methods
     32 
     33 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEFloodElement)
     34 
     35 FilterPrimitiveDescription SVGFEFloodElement::GetPrimitiveDescription(
     36    SVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
     37    const nsTArray<bool>& aInputsAreTainted,
     38    nsTArray<RefPtr<SourceSurface>>& aInputImages) {
     39  FloodAttributes atts;
     40  if (const auto* frame = GetPrimaryFrame()) {
     41    const nsStyleSVGReset* styleSVGReset = frame->Style()->StyleSVGReset();
     42    sRGBColor color(
     43        sRGBColor::FromABGR(styleSVGReset->mFloodColor.CalcColor(frame)));
     44    color.a *= styleSVGReset->mFloodOpacity;
     45    atts.mColor = color;
     46  } else {
     47    atts.mColor = sRGBColor();
     48  }
     49  return FilterPrimitiveDescription(AsVariant(std::move(atts)));
     50 }
     51 
     52 bool SVGFEFloodElement::OutputIsTainted(const nsTArray<bool>& aInputsAreTainted,
     53                                        nsIPrincipal* aReferencePrincipal) {
     54  if (const auto* frame = GetPrimaryFrame()) {
     55    if (frame->Style()->StyleSVGReset()->mFloodColor.IsCurrentColor()) {
     56      return true;
     57    }
     58  }
     59 
     60  return SVGFEFloodElementBase::OutputIsTainted(aInputsAreTainted,
     61                                                aReferencePrincipal);
     62 }
     63 
     64 //----------------------------------------------------------------------
     65 // nsIContent methods
     66 
     67 nsresult SVGFEFloodElement::BindToTree(BindContext& aCtx, nsINode& aParent) {
     68  if (aCtx.InComposedDoc()) {
     69    aCtx.OwnerDoc().SetUseCounter(eUseCounter_custom_feFlood);
     70  }
     71 
     72  return SVGFEFloodElementBase::BindToTree(aCtx, aParent);
     73 }
     74 
     75 //----------------------------------------------------------------------
     76 // SVGElement methods
     77 
     78 SVGElement::StringAttributesInfo SVGFEFloodElement::GetStringInfo() {
     79  return StringAttributesInfo(mStringAttributes, sStringInfo,
     80                              std::size(sStringInfo));
     81 }
     82 
     83 }  // namespace mozilla::dom