Bug 1521243 - Show a warning for invalid declarations and filter icon for overridden...
[gecko.git] / gfx / layers / DirectionUtils.h
blob84d9cb696900500a7254e3fefd165221a2295eac
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
13 namespace mozilla {
14 namespace layers {
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();
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();
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();
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;
54 inline ScrollDirection GetPerpendicularDirection(ScrollDirection aDir) {
55 return aDir == ScrollDirection::eHorizontal ? ScrollDirection::eVertical
56 : ScrollDirection::eHorizontal;
59 } // namespace layers
60 } // namespace mozilla
62 #endif /* GFX_DIRECTIONUTILS_H */