Bug 1556556 - Support both CSS and LayoutDevice units in GetVisualToLayoutTransform(). r=kats

Differential Revision: https://phabricator.services.mozilla.com/D68725
This commit is contained in:
Botond Ballo 2020-05-05 19:22:42 +00:00
Родитель 1011b024c4
Коммит 5175a2bf21
2 изменённых файлов: 40 добавлений и 4 удалений

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

@ -16,8 +16,14 @@ using layers::APZCCallbackHelper;
using layers::InputAPZContext;
using layers::ScrollableLayerGuid;
CSSToCSSMatrix4x4 ViewportUtils::GetVisualToLayoutTransform(
template <typename Units>
gfx::Matrix4x4Typed<Units, Units> ViewportUtils::GetVisualToLayoutTransform(
ScrollableLayerGuid::ViewID aScrollId) {
static_assert(
std::is_same_v<Units, CSSPixel> ||
std::is_same_v<Units, LayoutDevicePixel>,
"GetCallbackTransform() may only be used with CSS or LayoutDevice units");
if (aScrollId == ScrollableLayerGuid::NULL_SCROLL_ID) {
return {};
}
@ -42,10 +48,18 @@ CSSToCSSMatrix4x4 ViewportUtils::GetVisualToLayoutTransform(
// Now apply the callback-transform. This is only approximately correct,
// see the comment on GetCumulativeApzCallbackTransform for details.
CSSPoint transform = nsLayoutUtils::GetCumulativeApzCallbackTransform(
gfx::PointTyped<Units> transform;
CSSPoint transformCSS = nsLayoutUtils::GetCumulativeApzCallbackTransform(
content->GetPrimaryFrame());
if constexpr (std::is_same_v<Units, CSSPixel>) {
transform = transformCSS;
} else { // Units == LayoutDevicePixel
transform = transformCSS *
content->GetPrimaryFrame()->PresContext()->CSSToDevPixelScale();
}
return mozilla::CSSToCSSMatrix4x4::Scaling(1 / resolution, 1 / resolution, 1)
return gfx::Matrix4x4Typed<Units, Units>::Scaling(1 / resolution,
1 / resolution, 1)
.PostTranslate(transform.x, transform.y, 0);
}
@ -94,4 +108,13 @@ nsPoint ViewportUtils::LayoutToVisual(const nsPoint& aPt, PresShell* aContext) {
return CSSPoint::ToAppUnits(transformed);
}
// Definitions of the two explicit instantiations forward declared in the header
// file. This causes code for these instantiations to be emitted into the object
// file for ViewportUtils.cpp.
template CSSToCSSMatrix4x4 ViewportUtils::GetVisualToLayoutTransform<CSSPixel>(
ScrollableLayerGuid::ViewID);
template LayoutDeviceToLayoutDeviceMatrix4x4
ViewportUtils::GetVisualToLayoutTransform<LayoutDevicePixel>(
ScrollableLayerGuid::ViewID);
} // namespace mozilla

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

@ -34,7 +34,8 @@ class ViewportUtils {
up to the root, using values populated in
APZCCallbackHelper::UpdateCallbackTransform. See that method's
documentation for additional details. */
static CSSToCSSMatrix4x4 GetVisualToLayoutTransform(
template <typename Units = CSSPixel>
static gfx::Matrix4x4Typed<Units, Units> GetVisualToLayoutTransform(
layers::ScrollableLayerGuid::ViewID aScrollId);
/* The functions below apply GetVisualToLayoutTransform() or its inverse
@ -51,6 +52,18 @@ class ViewportUtils {
static nsPoint LayoutToVisual(const nsPoint& aPt, PresShell* aContext);
};
// Forward declare explicit instantiations of GetVisualToLayoutTransform() for
// CSSPixel and LayoutDevicePixel, the only two types it gets used with.
// These declarations promise to callers in any translation unit that _some_
// translation unit (in this case, ViewportUtils.cpp) will contain the
// definitions of these instantiations. This allows us to keep the definition
// out-of-line in the source.
extern template CSSToCSSMatrix4x4 ViewportUtils::GetVisualToLayoutTransform<
CSSPixel>(layers::ScrollableLayerGuid::ViewID);
extern template LayoutDeviceToLayoutDeviceMatrix4x4
ViewportUtils::GetVisualToLayoutTransform<LayoutDevicePixel>(
layers::ScrollableLayerGuid::ViewID);
} // namespace mozilla
#endif /* mozilla_ViewportUtils_h */