tor-browser

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

DirectionUtils.h (1819B)


      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 #ifndef GFX_DIRECTIONUTILS_H
      8 #define GFX_DIRECTIONUTILS_H
      9 
     10 #include "LayersTypes.h"  // for ScrollDirection
     11 #include "Units.h"        // for Coord, Point, and Rect types
     12 
     13 namespace mozilla {
     14 namespace layers {
     15 
     16 template <typename PointOrRect>
     17 CoordOf<PointOrRect> GetAxisStart(ScrollDirection aDir,
     18                                  const PointOrRect& aValue) {
     19  if (aDir == ScrollDirection::eHorizontal) {
     20    return aValue.X();
     21  } else {
     22    return aValue.Y();
     23  }
     24 }
     25 
     26 template <typename Rect>
     27 CoordOf<Rect> GetAxisEnd(ScrollDirection aDir, const Rect& aValue) {
     28  if (aDir == ScrollDirection::eHorizontal) {
     29    return aValue.XMost();
     30  } else {
     31    return aValue.YMost();
     32  }
     33 }
     34 
     35 template <typename Rect>
     36 CoordOf<Rect> GetAxisLength(ScrollDirection aDir, const Rect& aValue) {
     37  if (aDir == ScrollDirection::eHorizontal) {
     38    return aValue.Width();
     39  } else {
     40    return aValue.Height();
     41  }
     42 }
     43 
     44 template <typename FromUnits, typename ToUnits>
     45 float GetAxisScale(ScrollDirection aDir,
     46                   const gfx::ScaleFactors2D<FromUnits, ToUnits>& aValue) {
     47  if (aDir == ScrollDirection::eHorizontal) {
     48    return aValue.xScale;
     49  } else {
     50    return aValue.yScale;
     51  }
     52 }
     53 
     54 inline ScrollDirection GetPerpendicularDirection(ScrollDirection aDir) {
     55  return aDir == ScrollDirection::eHorizontal ? ScrollDirection::eVertical
     56                                              : ScrollDirection::eHorizontal;
     57 }
     58 
     59 }  // namespace layers
     60 }  // namespace mozilla
     61 
     62 #endif /* GFX_DIRECTIONUTILS_H */