tor-browser

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

SVGFEDropShadowElement.cpp (5751B)


      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/SVGFEDropShadowElement.h"
      8 
      9 #include "mozilla/SVGFilterInstance.h"
     10 #include "mozilla/dom/SVGFEDropShadowElementBinding.h"
     11 #include "nsIFrame.h"
     12 
     13 NS_IMPL_NS_NEW_SVG_ELEMENT(FEDropShadow)
     14 
     15 using namespace mozilla::gfx;
     16 
     17 namespace mozilla::dom {
     18 
     19 JSObject* SVGFEDropShadowElement::WrapNode(JSContext* aCx,
     20                                           JS::Handle<JSObject*> aGivenProto) {
     21  return SVGFEDropShadowElement_Binding::Wrap(aCx, this, aGivenProto);
     22 }
     23 
     24 SVGElement::NumberInfo SVGFEDropShadowElement::sNumberInfo[2] = {
     25    {nsGkAtoms::dx, 2}, {nsGkAtoms::dy, 2}};
     26 
     27 SVGElement::NumberPairInfo SVGFEDropShadowElement::sNumberPairInfo[1] = {
     28    {nsGkAtoms::stdDeviation, 2, 2}};
     29 
     30 SVGElement::StringInfo SVGFEDropShadowElement::sStringInfo[2] = {
     31    {nsGkAtoms::result, kNameSpaceID_None, true},
     32    {nsGkAtoms::in, kNameSpaceID_None, true}};
     33 
     34 //----------------------------------------------------------------------
     35 // nsINode methods
     36 
     37 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEDropShadowElement)
     38 
     39 //----------------------------------------------------------------------
     40 
     41 already_AddRefed<DOMSVGAnimatedString> SVGFEDropShadowElement::In1() {
     42  return mStringAttributes[IN1].ToDOMAnimatedString(this);
     43 }
     44 
     45 already_AddRefed<DOMSVGAnimatedNumber> SVGFEDropShadowElement::Dx() {
     46  return mNumberAttributes[DX].ToDOMAnimatedNumber(this);
     47 }
     48 
     49 already_AddRefed<DOMSVGAnimatedNumber> SVGFEDropShadowElement::Dy() {
     50  return mNumberAttributes[DY].ToDOMAnimatedNumber(this);
     51 }
     52 
     53 already_AddRefed<DOMSVGAnimatedNumber> SVGFEDropShadowElement::StdDeviationX() {
     54  return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(
     55      SVGAnimatedNumberPair::eFirst, this);
     56 }
     57 
     58 already_AddRefed<DOMSVGAnimatedNumber> SVGFEDropShadowElement::StdDeviationY() {
     59  return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(
     60      SVGAnimatedNumberPair::eSecond, this);
     61 }
     62 
     63 void SVGFEDropShadowElement::SetStdDeviation(float stdDeviationX,
     64                                             float stdDeviationY) {
     65  mNumberPairAttributes[STD_DEV].SetBaseValues(stdDeviationX, stdDeviationY,
     66                                               this);
     67 }
     68 
     69 FilterPrimitiveDescription SVGFEDropShadowElement::GetPrimitiveDescription(
     70    SVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
     71    const nsTArray<bool>& aInputsAreTainted,
     72    nsTArray<RefPtr<SourceSurface>>& aInputImages) {
     73  float stdX = aInstance->GetPrimitiveNumber(SVGContentUtils::X,
     74                                             &mNumberPairAttributes[STD_DEV],
     75                                             SVGAnimatedNumberPair::eFirst);
     76  float stdY = aInstance->GetPrimitiveNumber(SVGContentUtils::Y,
     77                                             &mNumberPairAttributes[STD_DEV],
     78                                             SVGAnimatedNumberPair::eSecond);
     79  if (stdX < 0 || stdY < 0) {
     80    return FilterPrimitiveDescription();
     81  }
     82 
     83  Point offset(
     84      aInstance->GetPrimitiveNumber(SVGContentUtils::X, &mNumberAttributes[DX]),
     85      aInstance->GetPrimitiveNumber(SVGContentUtils::Y,
     86                                    &mNumberAttributes[DY]));
     87 
     88  DropShadowAttributes atts;
     89  atts.mStdDeviation = Size(stdX, stdY);
     90  atts.mOffset = offset;
     91 
     92  if (const auto* frame = GetPrimaryFrame()) {
     93    const nsStyleSVGReset* styleSVGReset = frame->Style()->StyleSVGReset();
     94    sRGBColor color(
     95        sRGBColor::FromABGR(styleSVGReset->mFloodColor.CalcColor(frame)));
     96    color.a *= styleSVGReset->mFloodOpacity;
     97    atts.mColor = color;
     98  } else {
     99    atts.mColor = sRGBColor();
    100  }
    101  return FilterPrimitiveDescription(AsVariant(std::move(atts)));
    102 }
    103 
    104 bool SVGFEDropShadowElement::OutputIsTainted(
    105    const nsTArray<bool>& aInputsAreTainted,
    106    nsIPrincipal* aReferencePrincipal) {
    107  if (const auto* frame = GetPrimaryFrame()) {
    108    if (frame->Style()->StyleSVGReset()->mFloodColor.IsCurrentColor()) {
    109      return true;
    110    }
    111  }
    112 
    113  return SVGFEDropShadowElementBase::OutputIsTainted(aInputsAreTainted,
    114                                                     aReferencePrincipal);
    115 }
    116 
    117 bool SVGFEDropShadowElement::AttributeAffectsRendering(
    118    int32_t aNameSpaceID, nsAtom* aAttribute) const {
    119  return SVGFEDropShadowElementBase::AttributeAffectsRendering(aNameSpaceID,
    120                                                               aAttribute) ||
    121         (aNameSpaceID == kNameSpaceID_None &&
    122          (aAttribute == nsGkAtoms::in ||
    123           aAttribute == nsGkAtoms::stdDeviation ||
    124           aAttribute == nsGkAtoms::dx || aAttribute == nsGkAtoms::dy));
    125 }
    126 
    127 void SVGFEDropShadowElement::GetSourceImageNames(
    128    nsTArray<SVGStringInfo>& aSources) {
    129  aSources.AppendElement(SVGStringInfo(&mStringAttributes[IN1], this));
    130 }
    131 
    132 //----------------------------------------------------------------------
    133 // SVGElement methods
    134 
    135 SVGElement::NumberAttributesInfo SVGFEDropShadowElement::GetNumberInfo() {
    136  return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
    137                              std::size(sNumberInfo));
    138 }
    139 
    140 SVGElement::NumberPairAttributesInfo
    141 SVGFEDropShadowElement::GetNumberPairInfo() {
    142  return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
    143                                  std::size(sNumberPairInfo));
    144 }
    145 
    146 SVGElement::StringAttributesInfo SVGFEDropShadowElement::GetStringInfo() {
    147  return StringAttributesInfo(mStringAttributes, sStringInfo,
    148                              std::size(sStringInfo));
    149 }
    150 
    151 }  // namespace mozilla::dom