tor-browser

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

SVGViewElement.cpp (2642B)


      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/SVGViewElement.h"
      8 
      9 #include "mozilla/dom/SVGViewElementBinding.h"
     10 
     11 NS_IMPL_NS_NEW_SVG_ELEMENT(View)
     12 
     13 namespace mozilla::dom {
     14 
     15 using namespace SVGViewElement_Binding;
     16 
     17 JSObject* SVGViewElement::WrapNode(JSContext* aCx,
     18                                   JS::Handle<JSObject*> aGivenProto) {
     19  return SVGViewElement_Binding::Wrap(aCx, this, aGivenProto);
     20 }
     21 
     22 SVGEnumMapping SVGViewElement::sZoomAndPanMap[] = {
     23    {nsGkAtoms::disable, SVG_ZOOMANDPAN_DISABLE},
     24    {nsGkAtoms::magnify, SVG_ZOOMANDPAN_MAGNIFY},
     25    {nullptr, 0}};
     26 
     27 SVGElement::EnumInfo SVGViewElement::sEnumInfo[1] = {
     28    {nsGkAtoms::zoomAndPan, sZoomAndPanMap, SVG_ZOOMANDPAN_MAGNIFY}};
     29 
     30 //----------------------------------------------------------------------
     31 // Implementation
     32 
     33 SVGViewElement::SVGViewElement(
     34    already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
     35    : SVGViewElementBase(std::move(aNodeInfo)) {}
     36 
     37 //----------------------------------------------------------------------
     38 // nsINode methods
     39 
     40 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGViewElement)
     41 
     42 void SVGViewElement::SetZoomAndPan(uint16_t aZoomAndPan, ErrorResult& rv) {
     43  if (aZoomAndPan == SVG_ZOOMANDPAN_DISABLE ||
     44      aZoomAndPan == SVG_ZOOMANDPAN_MAGNIFY) {
     45    ErrorResult nestedRv;
     46    mEnumAttributes[ZOOMANDPAN].SetBaseValue(aZoomAndPan, this, nestedRv);
     47    MOZ_ASSERT(!nestedRv.Failed(),
     48               "We already validated our aZoomAndPan value!");
     49    return;
     50  }
     51 
     52  rv.ThrowRangeError<MSG_INVALID_ZOOMANDPAN_VALUE_ERROR>();
     53 }
     54 
     55 //----------------------------------------------------------------------
     56 
     57 already_AddRefed<SVGAnimatedRect> SVGViewElement::ViewBox() {
     58  return mViewBox.ToSVGAnimatedRect(this);
     59 }
     60 
     61 already_AddRefed<DOMSVGAnimatedPreserveAspectRatio>
     62 SVGViewElement::PreserveAspectRatio() {
     63  return mPreserveAspectRatio.ToDOMAnimatedPreserveAspectRatio(this);
     64 }
     65 
     66 //----------------------------------------------------------------------
     67 // SVGElement methods
     68 
     69 SVGElement::EnumAttributesInfo SVGViewElement::GetEnumInfo() {
     70  return EnumAttributesInfo(mEnumAttributes, sEnumInfo, std::size(sEnumInfo));
     71 }
     72 
     73 SVGAnimatedViewBox* SVGViewElement::GetAnimatedViewBox() { return &mViewBox; }
     74 
     75 SVGAnimatedPreserveAspectRatio*
     76 SVGViewElement::GetAnimatedPreserveAspectRatio() {
     77  return &mPreserveAspectRatio;
     78 }
     79 
     80 }  // namespace mozilla::dom