tor-browser

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

nsViewportInfo.cpp (1786B)


      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 "nsViewportInfo.h"
      8 
      9 #include <algorithm>
     10 
     11 #include "mozilla/Assertions.h"
     12 
     13 using namespace mozilla;
     14 
     15 void nsViewportInfo::ConstrainViewportValues() {
     16  // Non-positive zoom factors can produce NaN or negative viewport sizes,
     17  // so we better be sure our constraints will produce positive zoom factors.
     18  MOZ_ASSERT(mMinZoom > CSSToScreenScale(0.0f), "zoom factor must be positive");
     19  MOZ_ASSERT(mMaxZoom > CSSToScreenScale(0.0f), "zoom factor must be positive");
     20 
     21  if (mDefaultZoom > mMaxZoom) {
     22    mDefaultZoomValid = false;
     23    mDefaultZoom = mMaxZoom;
     24  }
     25  if (mDefaultZoom < mMinZoom) {
     26    mDefaultZoomValid = false;
     27    mDefaultZoom = mMinZoom;
     28  }
     29 }
     30 
     31 static const float& MinOrMax(const float& aA, const float& aB,
     32                             const float& (*aMinOrMax)(const float&,
     33                                                       const float&)) {
     34  MOZ_ASSERT(aA != nsViewportInfo::kExtendToZoom &&
     35             aA != nsViewportInfo::kDeviceSize &&
     36             aB != nsViewportInfo::kExtendToZoom &&
     37             aB != nsViewportInfo::kDeviceSize);
     38  if (aA == nsViewportInfo::kAuto) {
     39    return aB;
     40  }
     41  if (aB == nsViewportInfo::kAuto) {
     42    return aA;
     43  }
     44  return aMinOrMax(aA, aB);
     45 }
     46 
     47 // static
     48 const float& nsViewportInfo::Min(const float& aA, const float& aB) {
     49  return MinOrMax(aA, aB, std::min);
     50 }
     51 
     52 // static
     53 const float& nsViewportInfo::Max(const float& aA, const float& aB) {
     54  return MinOrMax(aA, aB, std::max);
     55 }