Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef GFX_DIRECTIONUTILS_H
7 : #define GFX_DIRECTIONUTILS_H
8 :
9 : #include "LayersTypes.h" // for ScrollDirection
10 : #include "Units.h" // for Coord, Point, and Rect types
11 :
12 : namespace mozilla {
13 : namespace layers {
14 :
15 : template <typename PointOrRect>
16 0 : CoordOf<PointOrRect> GetAxisStart(ScrollDirection aDir, const PointOrRect& aValue) {
17 0 : if (aDir == ScrollDirection::HORIZONTAL) {
18 0 : return aValue.x;
19 : } else {
20 0 : return aValue.y;
21 : }
22 : }
23 :
24 : template <typename Rect>
25 : CoordOf<Rect> GetAxisEnd(ScrollDirection aDir, const Rect& aValue) {
26 : if (aDir == ScrollDirection::HORIZONTAL) {
27 : return aValue.x + aValue.width;
28 : } else {
29 : return aValue.y + aValue.height;
30 : }
31 : }
32 :
33 : template <typename Rect>
34 0 : CoordOf<Rect> GetAxisLength(ScrollDirection aDir, const Rect& aValue) {
35 0 : if (aDir == ScrollDirection::HORIZONTAL) {
36 0 : return aValue.width;
37 : } else {
38 0 : return aValue.height;
39 : }
40 : }
41 :
42 : template <typename FromUnits, typename ToUnits>
43 : float GetAxisScale(ScrollDirection aDir, const gfx::ScaleFactors2D<FromUnits, ToUnits>& aValue) {
44 : if (aDir == ScrollDirection::HORIZONTAL) {
45 : return aValue.xScale;
46 : } else {
47 : return aValue.yScale;
48 : }
49 : }
50 :
51 0 : inline ScrollDirection GetPerpendicularDirection(ScrollDirection aDir) {
52 : return aDir == ScrollDirection::HORIZONTAL
53 0 : ? ScrollDirection::VERTICAL
54 0 : : ScrollDirection::HORIZONTAL;
55 : }
56 :
57 : } // namespace layers
58 : } // namespace mozilla
59 :
60 : #endif /* GFX_DIRECTIONUTILS_H */
|