tor-browser

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

SVGFEOffsetElement.cpp (3680B)


      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/SVGFEOffsetElement.h"
      8 
      9 #include "mozilla/SVGFilterInstance.h"
     10 #include "mozilla/dom/BindContext.h"
     11 #include "mozilla/dom/Document.h"
     12 #include "mozilla/dom/SVGFEOffsetElementBinding.h"
     13 
     14 NS_IMPL_NS_NEW_SVG_ELEMENT(FEOffset)
     15 
     16 using namespace mozilla::gfx;
     17 
     18 namespace mozilla::dom {
     19 
     20 JSObject* SVGFEOffsetElement::WrapNode(JSContext* aCx,
     21                                       JS::Handle<JSObject*> aGivenProto) {
     22  return SVGFEOffsetElement_Binding::Wrap(aCx, this, aGivenProto);
     23 }
     24 
     25 SVGElement::NumberInfo SVGFEOffsetElement::sNumberInfo[2] = {
     26    {nsGkAtoms::dx, 0}, {nsGkAtoms::dy, 0}};
     27 
     28 SVGElement::StringInfo SVGFEOffsetElement::sStringInfo[2] = {
     29    {nsGkAtoms::result, kNameSpaceID_None, true},
     30    {nsGkAtoms::in, kNameSpaceID_None, true}};
     31 
     32 //----------------------------------------------------------------------
     33 // nsINode methods
     34 
     35 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEOffsetElement)
     36 
     37 //----------------------------------------------------------------------
     38 
     39 already_AddRefed<DOMSVGAnimatedString> SVGFEOffsetElement::In1() {
     40  return mStringAttributes[IN1].ToDOMAnimatedString(this);
     41 }
     42 
     43 already_AddRefed<DOMSVGAnimatedNumber> SVGFEOffsetElement::Dx() {
     44  return mNumberAttributes[DX].ToDOMAnimatedNumber(this);
     45 }
     46 
     47 already_AddRefed<DOMSVGAnimatedNumber> SVGFEOffsetElement::Dy() {
     48  return mNumberAttributes[DY].ToDOMAnimatedNumber(this);
     49 }
     50 
     51 FilterPrimitiveDescription SVGFEOffsetElement::GetPrimitiveDescription(
     52    SVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
     53    const nsTArray<bool>& aInputsAreTainted,
     54    nsTArray<RefPtr<SourceSurface>>& aInputImages) {
     55  OffsetAttributes atts;
     56  IntPoint offset(int32_t(aInstance->GetPrimitiveNumber(
     57                      SVGContentUtils::X, &mNumberAttributes[DX])),
     58                  int32_t(aInstance->GetPrimitiveNumber(
     59                      SVGContentUtils::Y, &mNumberAttributes[DY])));
     60  atts.mValue = offset;
     61  return FilterPrimitiveDescription(AsVariant(std::move(atts)));
     62 }
     63 
     64 bool SVGFEOffsetElement::AttributeAffectsRendering(int32_t aNameSpaceID,
     65                                                   nsAtom* aAttribute) const {
     66  return SVGFEOffsetElementBase::AttributeAffectsRendering(aNameSpaceID,
     67                                                           aAttribute) ||
     68         (aNameSpaceID == kNameSpaceID_None &&
     69          (aAttribute == nsGkAtoms::in || aAttribute == nsGkAtoms::dx ||
     70           aAttribute == nsGkAtoms::dy));
     71 }
     72 
     73 void SVGFEOffsetElement::GetSourceImageNames(
     74    nsTArray<SVGStringInfo>& aSources) {
     75  aSources.AppendElement(SVGStringInfo(&mStringAttributes[IN1], this));
     76 }
     77 
     78 nsresult SVGFEOffsetElement::BindToTree(BindContext& aCtx, nsINode& aParent) {
     79  if (aCtx.InComposedDoc()) {
     80    aCtx.OwnerDoc().SetUseCounter(eUseCounter_custom_feOffset);
     81  }
     82 
     83  return SVGFEOffsetElementBase::BindToTree(aCtx, aParent);
     84 }
     85 
     86 //----------------------------------------------------------------------
     87 // SVGElement methods
     88 
     89 SVGElement::NumberAttributesInfo SVGFEOffsetElement::GetNumberInfo() {
     90  return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
     91                              std::size(sNumberInfo));
     92 }
     93 
     94 SVGElement::StringAttributesInfo SVGFEOffsetElement::GetStringInfo() {
     95  return StringAttributesInfo(mStringAttributes, sStringInfo,
     96                              std::size(sStringInfo));
     97 }
     98 
     99 }  // namespace mozilla::dom