зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1556556
- Move GetCallbackTransform() into a new ViewportUtils class. r=kats
This function (and helper functions that wrap it) will be used extensively throughout layout code, so keeping it in APZCCallbackHelper seems awkward. nsLayoutUtils would also be a reasonable place but has the downside that adding a new function to it triggers recompiling the world. Differential Revision: https://phabricator.services.mozilla.com/D68296
This commit is contained in:
Родитель
6a461317ca
Коммит
f02fcb17b4
|
@ -20,6 +20,7 @@
|
|||
#include "mozilla/layers/WebRenderBridgeChild.h"
|
||||
#include "mozilla/PresShell.h"
|
||||
#include "mozilla/TouchEvents.h"
|
||||
#include "mozilla/ViewportUtils.h"
|
||||
#include "nsContainerFrame.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIContent.h"
|
||||
|
@ -451,38 +452,6 @@ PresShell* APZCCallbackHelper::GetRootContentDocumentPresShellForContent(
|
|||
return context->PresShell();
|
||||
}
|
||||
|
||||
mozilla::CSSToCSSMatrix4x4 APZCCallbackHelper::GetCallbackTransform(
|
||||
ScrollableLayerGuid::ViewID aScrollId) {
|
||||
if (aScrollId == ScrollableLayerGuid::NULL_SCROLL_ID) {
|
||||
return {};
|
||||
}
|
||||
nsCOMPtr<nsIContent> content = nsLayoutUtils::FindContentFor(aScrollId);
|
||||
if (!content) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// First, scale inversely by the root content document's pres shell
|
||||
// resolution to cancel the scale-to-resolution transform that the
|
||||
// compositor adds to the layer with the pres shell resolution. The points
|
||||
// sent to Gecko by APZ don't have this transform unapplied (unlike other
|
||||
// compositor-side transforms) because Gecko needs it applied when hit
|
||||
// testing against content that's conceptually outside the resolution,
|
||||
// such as scrollbars.
|
||||
float resolution = 1.0f;
|
||||
if (PresShell* presShell =
|
||||
GetRootContentDocumentPresShellForContent(content)) {
|
||||
resolution = presShell->GetResolution();
|
||||
}
|
||||
|
||||
// Now apply the callback-transform. This is only approximately correct,
|
||||
// see the comment on GetCumulativeApzCallbackTransform for details.
|
||||
CSSPoint transform = nsLayoutUtils::GetCumulativeApzCallbackTransform(
|
||||
content->GetPrimaryFrame());
|
||||
|
||||
return mozilla::CSSToCSSMatrix4x4::Scaling(1 / resolution, 1 / resolution, 1)
|
||||
.PostTranslate(transform.x, transform.y, 0);
|
||||
}
|
||||
|
||||
nsEventStatus APZCCallbackHelper::DispatchWidgetEvent(WidgetGUIEvent& aEvent) {
|
||||
nsEventStatus status = nsEventStatus_eConsumeNoDefault;
|
||||
if (aEvent.mWidget) {
|
||||
|
|
|
@ -98,23 +98,6 @@ class APZCCallbackHelper {
|
|||
static PresShell* GetRootContentDocumentPresShellForContent(
|
||||
nsIContent* aContent);
|
||||
|
||||
/* Return a "callback transform" to be applied to the coordinates of input
|
||||
events targeting content inside the scroll frame identified by |aScrollId|.
|
||||
The callback transform has two components:
|
||||
1. The pres shell resolution, representing the pinch-zoom scale
|
||||
(if the scroll frame |aScrollId| is inside the resolution, which
|
||||
is most of the time).
|
||||
2. A translation representing async scrolling. This can contain:
|
||||
- For any scroll frame, a scroll component resulting from the main
|
||||
thread incompletely applying an APZ-requested scroll position.
|
||||
- For the RCD-RSF only, a persistent component representing the
|
||||
offset of the visual viewport relative to the layout viewport.
|
||||
The translation is accumulated for all scroll frames form |aScrollId|
|
||||
up to the root, using values populated in UpdateCallbackTransform. See
|
||||
that method's documentation for additional details. */
|
||||
static CSSToCSSMatrix4x4 GetCallbackTransform(
|
||||
ScrollableLayerGuid::ViewID aScrollId);
|
||||
|
||||
/* Dispatch a widget event via the widget stored in the event, if any.
|
||||
* In a child process, allows the BrowserParent event-capture mechanism to
|
||||
* intercept the event. */
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/* 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/. */
|
||||
|
||||
#include "mozilla/PresShell.h"
|
||||
#include "mozilla/ViewportUtils.h"
|
||||
#include "mozilla/layers/APZCCallbackHelper.h"
|
||||
#include "mozilla/layers/ScrollableLayerGuid.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsLayoutUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
using layers::APZCCallbackHelper;
|
||||
using layers::ScrollableLayerGuid;
|
||||
|
||||
CSSToCSSMatrix4x4 ViewportUtils::GetCallbackTransform(
|
||||
ScrollableLayerGuid::ViewID aScrollId) {
|
||||
if (aScrollId == ScrollableLayerGuid::NULL_SCROLL_ID) {
|
||||
return {};
|
||||
}
|
||||
nsCOMPtr<nsIContent> content = nsLayoutUtils::FindContentFor(aScrollId);
|
||||
if (!content) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// First, scale inversely by the root content document's pres shell
|
||||
// resolution to cancel the scale-to-resolution transform that the
|
||||
// compositor adds to the layer with the pres shell resolution. The points
|
||||
// sent to Gecko by APZ don't have this transform unapplied (unlike other
|
||||
// compositor-side transforms) because Gecko needs it applied when hit
|
||||
// testing against content that's conceptually outside the resolution,
|
||||
// such as scrollbars.
|
||||
float resolution = 1.0f;
|
||||
if (PresShell* presShell =
|
||||
APZCCallbackHelper::GetRootContentDocumentPresShellForContent(
|
||||
content)) {
|
||||
resolution = presShell->GetResolution();
|
||||
}
|
||||
|
||||
// Now apply the callback-transform. This is only approximately correct,
|
||||
// see the comment on GetCumulativeApzCallbackTransform for details.
|
||||
CSSPoint transform = nsLayoutUtils::GetCumulativeApzCallbackTransform(
|
||||
content->GetPrimaryFrame());
|
||||
|
||||
return mozilla::CSSToCSSMatrix4x4::Scaling(1 / resolution, 1 / resolution, 1)
|
||||
.PostTranslate(transform.x, transform.y, 0);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,36 @@
|
|||
/* 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 mozilla_ViewportUtils_h
|
||||
#define mozilla_ViewportUtils_h
|
||||
|
||||
#include "Units.h"
|
||||
#include "mozilla/layers/ScrollableLayerGuid.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class ViewportUtils {
|
||||
public:
|
||||
/* Return a "callback transform" to be applied to the coordinates of input
|
||||
events targeting content inside the scroll frame identified by |aScrollId|.
|
||||
The callback transform has two components:
|
||||
1. The pres shell resolution, representing the pinch-zoom scale
|
||||
(if the scroll frame |aScrollId| is inside the resolution, which
|
||||
is most of the time).
|
||||
2. A translation representing async scrolling. This can contain:
|
||||
- For any scroll frame, a scroll component resulting from the main
|
||||
thread incompletely applying an APZ-requested scroll position.
|
||||
- For the RCD-RSF only, a persistent component representing the
|
||||
offset of the visual viewport relative to the layout viewport.
|
||||
The translation is accumulated for all scroll frames form |aScrollId|
|
||||
up to the root, using values populated in
|
||||
APZCCallbackHelper::UpdateCallbackTransform. See that method's
|
||||
documentation for additional details. */
|
||||
static CSSToCSSMatrix4x4 GetCallbackTransform(
|
||||
layers::ScrollableLayerGuid::ViewID aScrollId);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_ViewportUtils_h */
|
|
@ -87,6 +87,7 @@ EXPORTS.mozilla += [
|
|||
'ScrollTypes.h',
|
||||
'ShapeUtils.h',
|
||||
'StaticPresData.h',
|
||||
'ViewportUtils.h',
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.layout += [
|
||||
|
@ -129,6 +130,7 @@ UNIFIED_SOURCES += [
|
|||
'StackArena.cpp',
|
||||
'StaticPresData.cpp',
|
||||
'TouchManager.cpp',
|
||||
'ViewportUtils.cpp',
|
||||
'ZoomConstraintsClient.cpp',
|
||||
]
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "nsIContent.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIDocumentViewerPrint.h"
|
||||
#include "nsIScreen.h"
|
||||
#include "mozilla/dom/BrowsingContext.h"
|
||||
#include "mozilla/dom/BeforeUnloadEvent.h"
|
||||
#include "mozilla/dom/PopupBlocker.h"
|
||||
|
|
Загрузка…
Ссылка в новой задаче