2017-10-27 23:10:06 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2017-05-24 19:47:01 +00:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef GFX_DIRECTIONUTILS_H
|
|
|
|
#define GFX_DIRECTIONUTILS_H
|
|
|
|
|
|
|
|
#include "LayersTypes.h" // for ScrollDirection
|
|
|
|
#include "Units.h" // for Coord, Point, and Rect types
|
|
|
|
|
|
|
|
namespace mozilla {
|
2017-06-08 18:18:09 +00:00
|
|
|
namespace layers {
|
2017-05-24 19:47:01 +00:00
|
|
|
|
|
|
|
template <typename PointOrRect>
|
|
|
|
CoordOf<PointOrRect> GetAxisStart(ScrollDirection aDir,
|
|
|
|
const PointOrRect& aValue) {
|
2017-11-21 00:00:34 +00:00
|
|
|
if (aDir == ScrollDirection::eHorizontal) {
|
2017-12-19 20:48:39 +00:00
|
|
|
return aValue.X();
|
2017-05-24 19:47:01 +00:00
|
|
|
} else {
|
2017-12-19 20:48:39 +00:00
|
|
|
return aValue.Y();
|
2017-05-24 19:47:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Rect>
|
|
|
|
CoordOf<Rect> GetAxisEnd(ScrollDirection aDir, const Rect& aValue) {
|
2017-11-21 00:00:34 +00:00
|
|
|
if (aDir == ScrollDirection::eHorizontal) {
|
2017-12-19 20:48:39 +00:00
|
|
|
return aValue.XMost();
|
2017-05-24 19:47:01 +00:00
|
|
|
} else {
|
2017-12-19 20:48:39 +00:00
|
|
|
return aValue.YMost();
|
2017-05-24 19:47:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Rect>
|
|
|
|
CoordOf<Rect> GetAxisLength(ScrollDirection aDir, const Rect& aValue) {
|
2017-11-21 00:00:34 +00:00
|
|
|
if (aDir == ScrollDirection::eHorizontal) {
|
2017-12-19 20:48:39 +00:00
|
|
|
return aValue.Width();
|
2017-05-24 19:47:01 +00:00
|
|
|
} else {
|
2017-12-19 20:48:39 +00:00
|
|
|
return aValue.Height();
|
2017-05-24 19:47:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FromUnits, typename ToUnits>
|
2017-06-08 18:18:09 +00:00
|
|
|
float GetAxisScale(ScrollDirection aDir,
|
|
|
|
const gfx::ScaleFactors2D<FromUnits, ToUnits>& aValue) {
|
2017-11-21 00:00:34 +00:00
|
|
|
if (aDir == ScrollDirection::eHorizontal) {
|
2017-05-24 19:47:01 +00:00
|
|
|
return aValue.xScale;
|
|
|
|
} else {
|
|
|
|
return aValue.yScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 00:00:23 +00:00
|
|
|
inline ScrollDirection GetPerpendicularDirection(ScrollDirection aDir) {
|
2017-11-21 00:00:34 +00:00
|
|
|
return aDir == ScrollDirection::eHorizontal ? ScrollDirection::eVertical
|
|
|
|
: ScrollDirection::eHorizontal;
|
2017-05-20 00:00:23 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 19:47:01 +00:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* GFX_DIRECTIONUTILS_H */
|