Bug 1352863 - Move the GetAxis*() functions from AsyncPanZoomController.cpp into a new DirectionUtils.h header. r=kats

Also take advantage of the new CoordOf metafunction to combine some of their overloads.

MozReview-Commit-ID: ETybNn7b5ic

--HG--
extra : rebase_source : 5798103462e454dc61abb7c8a26b997f02c8be36
This commit is contained in:
Botond Ballo 2017-05-24 15:47:01 -04:00
Родитель ae4b8838b4
Коммит ec17a356c2
3 изменённых файлов: 58 добавлений и 54 удалений

Просмотреть файл

@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* 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 {
namespace gfx {
using layers::ScrollDirection;
template <typename PointOrRect>
CoordOf<PointOrRect> GetAxisStart(ScrollDirection aDir, const PointOrRect& aValue) {
if (aDir == ScrollDirection::HORIZONTAL) {
return aValue.x;
} else {
return aValue.y;
}
}
template <typename Rect>
CoordOf<Rect> GetAxisEnd(ScrollDirection aDir, const Rect& aValue) {
if (aDir == ScrollDirection::HORIZONTAL) {
return aValue.x + aValue.width;
} else {
return aValue.y + aValue.height;
}
}
template <typename Rect>
CoordOf<Rect> GetAxisLength(ScrollDirection aDir, const Rect& aValue) {
if (aDir == ScrollDirection::HORIZONTAL) {
return aValue.width;
} else {
return aValue.height;
}
}
template <typename FromUnits, typename ToUnits>
float GetAxisScale(ScrollDirection aDir, const ScaleFactors2D<FromUnits, ToUnits>& aValue) {
if (aDir == ScrollDirection::HORIZONTAL) {
return aValue.xScale;
} else {
return aValue.yScale;
}
}
} // namespace layers
} // namespace mozilla
#endif /* GFX_DIRECTIONUTILS_H */

Просмотреть файл

@ -54,6 +54,7 @@
#include "mozilla/layers/AxisPhysicsModel.h" // for AxisPhysicsModel
#include "mozilla/layers/AxisPhysicsMSDModel.h" // for AxisPhysicsMSDModel
#include "mozilla/layers/CompositorController.h" // for CompositorController
#include "mozilla/layers/DirectionUtils.h" // for GetAxis{Start,End,Length,Scale}
#include "mozilla/layers/LayerTransactionParent.h" // for LayerTransactionParent
#include "mozilla/layers/MetricsSharingController.h" // for MetricsSharingController
#include "mozilla/layers/ScrollInputMethods.h" // for ScrollInputMethod
@ -832,60 +833,6 @@ AsyncPanZoomController::ArePointerEventsConsumable(TouchBlockState* aBlock, uint
return true;
}
template <typename Units>
static CoordTyped<Units> GetAxisStart(ScrollDirection aDir, const PointTyped<Units>& aValue) {
if (aDir == ScrollDirection::HORIZONTAL) {
return aValue.x;
} else {
return aValue.y;
}
}
template <typename Units>
static CoordTyped<Units> GetAxisStart(ScrollDirection aDir, const RectTyped<Units>& aValue) {
if (aDir == ScrollDirection::HORIZONTAL) {
return aValue.x;
} else {
return aValue.y;
}
}
template <typename Units>
static IntCoordTyped<Units> GetAxisStart(ScrollDirection aDir, const IntRectTyped<Units>& aValue) {
if (aDir == ScrollDirection::HORIZONTAL) {
return aValue.x;
} else {
return aValue.y;
}
}
template <typename Units>
static CoordTyped<Units> GetAxisEnd(ScrollDirection aDir, const RectTyped<Units>& aValue) {
if (aDir == ScrollDirection::HORIZONTAL) {
return aValue.x + aValue.width;
} else {
return aValue.y + aValue.height;
}
}
template <typename Units>
static CoordTyped<Units> GetAxisLength(ScrollDirection aDir, const RectTyped<Units>& aValue) {
if (aDir == ScrollDirection::HORIZONTAL) {
return aValue.width;
} else {
return aValue.height;
}
}
template <typename FromUnits, typename ToUnits>
static float GetAxisScale(ScrollDirection aDir, const ScaleFactors2D<FromUnits, ToUnits>& aValue) {
if (aDir == ScrollDirection::HORIZONTAL) {
return aValue.xScale;
} else {
return aValue.yScale;
}
}
nsEventStatus AsyncPanZoomController::HandleDragEvent(const MouseInput& aEvent,
const AsyncDragMetrics& aDragMetrics)
{

Просмотреть файл

@ -153,6 +153,7 @@ EXPORTS.mozilla.layers += [
'CompositorTypes.h',
'D3D11ShareHandleImage.h',
'D3D9SurfaceImage.h',
'DirectionUtils.h',
'Effects.h',
'ImageDataSerializer.h',
'ipc/APZChild.h',