tor-browser

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

SVGRect.cpp (3800B)


      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/SVGRect.h"
      8 
      9 #include "SVGAnimatedViewBox.h"
     10 #include "mozilla/dom/SVGRectBinding.h"
     11 #include "mozilla/dom/SVGSVGElement.h"
     12 #include "nsWrapperCache.h"
     13 
     14 using namespace mozilla::gfx;
     15 
     16 namespace mozilla::dom {
     17 
     18 //----------------------------------------------------------------------
     19 // nsISupports methods:
     20 
     21 NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(SVGRect, mParent)
     22 
     23 //----------------------------------------------------------------------
     24 // implementation:
     25 
     26 SVGRect::SVGRect(SVGSVGElement* aSVGElement)
     27    : mVal(nullptr), mParent(aSVGElement), mType(RectType::CreatedValue) {
     28  MOZ_ASSERT(mParent);
     29  mRect = gfx::Rect(0, 0, 0, 0);
     30 }
     31 
     32 JSObject* SVGRect::WrapObject(JSContext* aCx,
     33                              JS::Handle<JSObject*> aGivenProto) {
     34  MOZ_ASSERT(mParent);
     35  return SVGRect_Binding::Wrap(aCx, this, aGivenProto);
     36 }
     37 
     38 float SVGRect::X() {
     39  switch (mType) {
     40    case RectType::AnimValue:
     41      static_cast<SVGElement*>(mParent.get())->FlushAnimations();
     42      return mVal->GetAnimValue().x;
     43    case RectType::BaseValue:
     44      return mVal->GetBaseValue().x;
     45    default:
     46      return mRect.x;
     47  }
     48 }
     49 
     50 float SVGRect::Y() {
     51  switch (mType) {
     52    case RectType::AnimValue:
     53      static_cast<SVGElement*>(mParent.get())->FlushAnimations();
     54      return mVal->GetAnimValue().y;
     55    case RectType::BaseValue:
     56      return mVal->GetBaseValue().y;
     57    default:
     58      return mRect.y;
     59  }
     60 }
     61 
     62 float SVGRect::Width() {
     63  switch (mType) {
     64    case RectType::AnimValue:
     65      static_cast<SVGElement*>(mParent.get())->FlushAnimations();
     66      return mVal->GetAnimValue().width;
     67    case RectType::BaseValue:
     68      return mVal->GetBaseValue().width;
     69    default:
     70      return mRect.width;
     71  }
     72 }
     73 
     74 float SVGRect::Height() {
     75  switch (mType) {
     76    case RectType::AnimValue:
     77      static_cast<SVGElement*>(mParent.get())->FlushAnimations();
     78      return mVal->GetAnimValue().height;
     79    case RectType::BaseValue:
     80      return mVal->GetBaseValue().height;
     81    default:
     82      return mRect.height;
     83  }
     84 }
     85 
     86 void SVGRect::SetX(float aX, ErrorResult& aRv) {
     87  switch (mType) {
     88    case RectType::AnimValue:
     89      aRv.ThrowNoModificationAllowedError("Animated values cannot be set");
     90      return;
     91    case RectType::BaseValue:
     92      mVal->SetBaseX(aX, static_cast<SVGElement*>(mParent.get()));
     93      return;
     94    default:
     95      mRect.x = aX;
     96  }
     97 }
     98 
     99 void SVGRect::SetY(float aY, ErrorResult& aRv) {
    100  switch (mType) {
    101    case RectType::AnimValue:
    102      aRv.ThrowNoModificationAllowedError("Animated values cannot be set");
    103      return;
    104    case RectType::BaseValue:
    105      mVal->SetBaseY(aY, static_cast<SVGElement*>(mParent.get()));
    106      return;
    107    default:
    108      mRect.y = aY;
    109  }
    110 }
    111 
    112 void SVGRect::SetWidth(float aWidth, ErrorResult& aRv) {
    113  switch (mType) {
    114    case RectType::AnimValue:
    115      aRv.ThrowNoModificationAllowedError("Animated values cannot be set");
    116      return;
    117    case RectType::BaseValue: {
    118      mVal->SetBaseWidth(aWidth, static_cast<SVGElement*>(mParent.get()));
    119      return;
    120    }
    121    default:
    122      mRect.width = aWidth;
    123  }
    124 }
    125 
    126 void SVGRect::SetHeight(float aHeight, ErrorResult& aRv) {
    127  switch (mType) {
    128    case RectType::AnimValue:
    129      aRv.ThrowNoModificationAllowedError("Animated values cannot be set");
    130      return;
    131    case RectType::BaseValue:
    132      mVal->SetBaseHeight(aHeight, static_cast<SVGElement*>(mParent.get()));
    133      return;
    134    default:
    135      mRect.height = aHeight;
    136  }
    137 }
    138 
    139 }  // namespace mozilla::dom