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 #ifndef GFX_DIRECTIONUTILS_H
8 #define GFX_DIRECTIONUTILS_H
10 #include "LayersTypes.h" // for ScrollDirection
11 #include "Units.h" // for Coord, Point, and Rect types
16 template <typename PointOrRect
>
17 CoordOf
<PointOrRect
> GetAxisStart(ScrollDirection aDir
,
18 const PointOrRect
& aValue
) {
19 if (aDir
== ScrollDirection::eHorizontal
) {
26 template <typename Rect
>
27 CoordOf
<Rect
> GetAxisEnd(ScrollDirection aDir
, const Rect
& aValue
) {
28 if (aDir
== ScrollDirection::eHorizontal
) {
29 return aValue
.XMost();
31 return aValue
.YMost();
35 template <typename Rect
>
36 CoordOf
<Rect
> GetAxisLength(ScrollDirection aDir
, const Rect
& aValue
) {
37 if (aDir
== ScrollDirection::eHorizontal
) {
38 return aValue
.Width();
40 return aValue
.Height();
44 template <typename FromUnits
, typename ToUnits
>
45 float GetAxisScale(ScrollDirection aDir
,
46 const gfx::ScaleFactors2D
<FromUnits
, ToUnits
>& aValue
) {
47 if (aDir
== ScrollDirection::eHorizontal
) {
54 inline ScrollDirection
GetPerpendicularDirection(ScrollDirection aDir
) {
55 return aDir
== ScrollDirection::eHorizontal
? ScrollDirection::eVertical
56 : ScrollDirection::eHorizontal
;
60 } // namespace mozilla
62 #endif /* GFX_DIRECTIONUTILS_H */