Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / nsViewportInfo.cpp
blob67ac728330d2548323460030824e479a5a87de96
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/. */
7 #include "nsViewportInfo.h"
8 #include "mozilla/Assertions.h"
9 #include <algorithm>
11 using namespace mozilla;
13 void nsViewportInfo::ConstrainViewportValues() {
14 // Non-positive zoom factors can produce NaN or negative viewport sizes,
15 // so we better be sure our constraints will produce positive zoom factors.
16 MOZ_ASSERT(mMinZoom > CSSToScreenScale(0.0f), "zoom factor must be positive");
17 MOZ_ASSERT(mMaxZoom > CSSToScreenScale(0.0f), "zoom factor must be positive");
19 if (mDefaultZoom > mMaxZoom) {
20 mDefaultZoomValid = false;
21 mDefaultZoom = mMaxZoom;
23 if (mDefaultZoom < mMinZoom) {
24 mDefaultZoomValid = false;
25 mDefaultZoom = mMinZoom;
29 static const float& MinOrMax(const float& aA, const float& aB,
30 const float& (*aMinOrMax)(const float&,
31 const float&)) {
32 MOZ_ASSERT(aA != nsViewportInfo::kExtendToZoom &&
33 aA != nsViewportInfo::kDeviceSize &&
34 aB != nsViewportInfo::kExtendToZoom &&
35 aB != nsViewportInfo::kDeviceSize);
36 if (aA == nsViewportInfo::kAuto) {
37 return aB;
39 if (aB == nsViewportInfo::kAuto) {
40 return aA;
42 return aMinOrMax(aA, aB);
45 // static
46 const float& nsViewportInfo::Min(const float& aA, const float& aB) {
47 return MinOrMax(aA, aB, std::min);
50 // static
51 const float& nsViewportInfo::Max(const float& aA, const float& aB) {
52 return MinOrMax(aA, aB, std::max);