tor-browser

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

SVGFESpecularLightingElement.cpp (3728B)


      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/SVGFESpecularLightingElement.h"
      8 
      9 #include "mozilla/SVGFilterInstance.h"
     10 #include "mozilla/dom/BindContext.h"
     11 #include "mozilla/dom/Document.h"
     12 #include "mozilla/dom/SVGFESpecularLightingElementBinding.h"
     13 
     14 NS_IMPL_NS_NEW_SVG_ELEMENT(FESpecularLighting)
     15 
     16 using namespace mozilla::gfx;
     17 
     18 namespace mozilla::dom {
     19 
     20 JSObject* SVGFESpecularLightingElement::WrapNode(
     21    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     22  return SVGFESpecularLightingElement_Binding::Wrap(aCx, this, aGivenProto);
     23 }
     24 
     25 //----------------------------------------------------------------------
     26 // nsINode methods
     27 
     28 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFESpecularLightingElement)
     29 
     30 already_AddRefed<DOMSVGAnimatedString> SVGFESpecularLightingElement::In1() {
     31  return mStringAttributes[IN1].ToDOMAnimatedString(this);
     32 }
     33 
     34 already_AddRefed<DOMSVGAnimatedNumber>
     35 SVGFESpecularLightingElement::SurfaceScale() {
     36  return mNumberAttributes[SURFACE_SCALE].ToDOMAnimatedNumber(this);
     37 }
     38 
     39 already_AddRefed<DOMSVGAnimatedNumber>
     40 SVGFESpecularLightingElement::SpecularConstant() {
     41  return mNumberAttributes[SPECULAR_CONSTANT].ToDOMAnimatedNumber(this);
     42 }
     43 
     44 already_AddRefed<DOMSVGAnimatedNumber>
     45 SVGFESpecularLightingElement::SpecularExponent() {
     46  return mNumberAttributes[SPECULAR_EXPONENT].ToDOMAnimatedNumber(this);
     47 }
     48 
     49 already_AddRefed<DOMSVGAnimatedNumber>
     50 SVGFESpecularLightingElement::KernelUnitLengthX() {
     51  return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
     52      SVGAnimatedNumberPair::eFirst, this);
     53 }
     54 
     55 already_AddRefed<DOMSVGAnimatedNumber>
     56 SVGFESpecularLightingElement::KernelUnitLengthY() {
     57  return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
     58      SVGAnimatedNumberPair::eSecond, this);
     59 }
     60 
     61 //----------------------------------------------------------------------
     62 // SVGElement methods
     63 
     64 FilterPrimitiveDescription
     65 SVGFESpecularLightingElement::GetPrimitiveDescription(
     66    SVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
     67    const nsTArray<bool>& aInputsAreTainted,
     68    nsTArray<RefPtr<SourceSurface>>& aInputImages) {
     69  float specularExponent = mNumberAttributes[SPECULAR_EXPONENT].GetAnimValue();
     70  float specularConstant = mNumberAttributes[SPECULAR_CONSTANT].GetAnimValue();
     71 
     72  // specification defined range (15.22)
     73  if (specularExponent < 1 || specularExponent > 128) {
     74    return FilterPrimitiveDescription();
     75  }
     76 
     77  SpecularLightingAttributes atts;
     78  atts.mLightingConstant = specularConstant;
     79  atts.mSpecularExponent = specularExponent;
     80  if (!AddLightingAttributes(&atts, aInstance)) {
     81    return FilterPrimitiveDescription();
     82  }
     83 
     84  return FilterPrimitiveDescription(AsVariant(std::move(atts)));
     85 }
     86 
     87 bool SVGFESpecularLightingElement::AttributeAffectsRendering(
     88    int32_t aNameSpaceID, nsAtom* aAttribute) const {
     89  return SVGFESpecularLightingElementBase::AttributeAffectsRendering(
     90             aNameSpaceID, aAttribute) ||
     91         (aNameSpaceID == kNameSpaceID_None &&
     92          (aAttribute == nsGkAtoms::specularConstant ||
     93           aAttribute == nsGkAtoms::specularExponent));
     94 }
     95 
     96 nsresult SVGFESpecularLightingElement::BindToTree(BindContext& aCtx,
     97                                                  nsINode& aParent) {
     98  if (aCtx.InComposedDoc()) {
     99    aCtx.OwnerDoc().SetUseCounter(eUseCounter_custom_feSpecularLighting);
    100  }
    101 
    102  return SVGFESpecularLightingElementBase::BindToTree(aCtx, aParent);
    103 }
    104 
    105 }  // namespace mozilla::dom