Files
palemoon27/layout/base/ZoomConstraintsClient.cpp
T
roytam1 6e2582b2b6 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1117087 Don't reset IM context when nsGtkIMContext receives selection change during dispatching compositionstart r=m_kato (0bbca7a4c)
- Bug 1155494 - Add a 'compressall' message flag. f=handyman r=billm (parts of this patch were written by handyman with r=billm) (5bb9ccd32)
- Bug 1167882 - Move a couple of static helpers functions higher up in TabChild.cpp. r=kats (75a880959)
- Bug 1167882 - Add utility functions MaxScaleRatio() and MinScaleRatio() to Units.h. r=kats (3604aa9e2)
- Bug 1167882 - Use the display size (includes scrollbar areas) rather than the root composition bounds (excludes scrollbar areas) to calculate the intrinsic scale. r=kats (8b6f2917c)
- Fix a potential null-deref in TabChild::HandlePossibleViewportChange. (bug 1156156, r=kats) (55e5e79f4)
- Bug 1164406 - Exclude the scrollbars from the composition bounds in TabChild::HandleCalculateViewportChange() when appropriate. r=kats (28a7efaad)
- Bug 1089090, e10s, support custom cursors, r=jmathies (6f005a600)
- Bug 1125325 - Make TabParent/TabChild UpdateDimensions messages aware of the display scale. r=kats (07ac774b2)
- Bug 1157248 - TabChild should initialize ServiceWorkerManager before starting the first loading, r=nsm (0eb50c148)
- Bug 1060643 - Give content the opportunity to block chrome keyhandlers. r=smaug (93cdd9608)
- Bug 1137555 - Add implementation of PuppetWidget::GetMaxTouchPoints(). r=smaug, r=jimm (d859fd19a)
- Bug 1164763 - Avoid one extra IPC round-trip when compositor-lru-size == 0. r=mattwoodrow,billm (19cfdf029)
- bug 1167295 - manage PDocAccessible with PBrowser instead of PContent r=smaug (5787cd60c)
- Bug 1161592 - If we don't get a target frame from the touch point try using the root scrollable frame. r=botond (c0d49d85f)
- Bug 1162648. When updating layout with the latest async values from the APZC do the scrolling last because it can flush layout. r=botond,kats (f8a354aab)
- Bug 1163572 - Modify UpdateRootFrame to automatically compute the nsIContent* and nsIPresShell* from the metrics. r=botond (9d7fda5c8)
- Bug 1163572 - Have ChromeProcessController also handle root-frame repaint requests. r=botond (67786ad9f)
- Bug 1163572 - Modify UpdateSubFrame to automatically figure out the nsIContent from the scrollId. r=botond (136aff8a1)
- Bug 1175383 TabChild should store PuppetWidget as is rather than as nsIWidget r=smaug (3e2bfd3ad)
- Bug 1158424 - Expose IsRootContent() in AsyncPanZoomController. r=kats (632ba6051)
- Bug 1158424 - Clean up uses of HasNoParentWithSameLayersId() related to zoom constraints. r=kats (c94b5f517)
- Bug 1166942 - Add logging code for gfx::Matrix. r=nical (5dc405fa6)
- Bug 1055557 - Move storage of ZoomConstraints from RemoteContentController to APZCTreeManager. r=botond (8e1056b71)
- Bug 1055557 - Add a ZoomConstraintsClient class to manage pushing zoom constraints updates to the APZ code. r=botond (69f1ae857)
- Bug 1055557 - Constify some methods. r=botond (b81ec32f9)
- Bug 1055557 - Ensure the right presShell resolution is used in ApplyCallbackTransform for fennec-apz scenarios. r=botond (6df0c30e7)
- Bug 1175217 - Fix non-unified (and some unified) builds for nsDisplayListInvalidation.cpp. r=mstange (cd0662dfa)
- Bug 1160421 - Replace nsThreadPool with a custom thread pool implementation in DecodePool. r=tn (66ae4fac2)
- Bug 1130935 part.1 Add a method to check if current IME supports vertical writing mode r=emk (056232715)
- Bug 1130935 part.2 Set proper composition font when writing mode is changed r=emk (e5cc07c43)
- Bug 1130935 part.3 Add hack for Japanist because its candidate window is broken with @System font r=emk (4e7587585)
- Bug 1130935 part.4 nsIMM32Handler::GetCharacterRectOfSelectedTextAt() should return wrting mode if it's necessary r=emk+smaug (92e76951a)
- Bug 1130935 part.5 nsIMM32Handler should compute candidate window position with writing mode r=emk (676e1c274)
- Bug 1130935 part.6 Selection change notification should have selection range and writing mode information r=smaug (a0e37af25)
2021-02-06 08:28:03 +08:00

202 lines
5.9 KiB
C++

/* -*- 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/. */
#include "ZoomConstraintsClient.h"
#include <inttypes.h>
#include "FrameMetrics.h"
#include "LayersLogging.h"
#include "mozilla/layers/APZCCallbackHelper.h"
#include "nsDocument.h"
#include "nsIFrame.h"
#include "nsLayoutUtils.h"
#include "nsPoint.h"
#include "nsPresShell.h"
#include "nsView.h"
#include "nsViewportInfo.h"
#include "Units.h"
#include "UnitTransforms.h"
#define ZCC_LOG(...)
// #define ZCC_LOG(...) printf_stderr("ZCC: " __VA_ARGS__)
NS_IMPL_ISUPPORTS(ZoomConstraintsClient, nsIDOMEventListener, nsIObserver)
static const nsLiteralString DOM_META_ADDED = NS_LITERAL_STRING("DOMMetaAdded");
static const nsLiteralCString BEFORE_FIRST_PAINT = NS_LITERAL_CSTRING("before-first-paint");
using namespace mozilla;
using namespace mozilla::layers;
ZoomConstraintsClient::ZoomConstraintsClient() :
mDocument(nullptr),
mPresShell(nullptr)
{
}
ZoomConstraintsClient::~ZoomConstraintsClient()
{
}
static nsIWidget*
GetWidget(nsIPresShell* aShell)
{
if (nsIFrame* rootFrame = aShell->GetRootFrame()) {
#ifdef MOZ_WIDGET_ANDROID
return rootFrame->GetNearestWidget();
#else
if (nsView* view = rootFrame->GetView()) {
return view->GetWidget();
}
#endif
}
return nullptr;
}
void
ZoomConstraintsClient::Destroy()
{
if (!(mPresShell && mDocument)) {
return;
}
ZCC_LOG("Destroying %p\n", this);
if (mEventTarget) {
mEventTarget->RemoveEventListener(DOM_META_ADDED, this, false);
mEventTarget = nullptr;
}
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
if (observerService) {
observerService->RemoveObserver(this, BEFORE_FIRST_PAINT.Data());
}
if (mGuid) {
if (nsIWidget* widget = GetWidget(mPresShell)) {
ZCC_LOG("Sending null constraints in %p for { %u, %" PRIu64 " }\n",
this, mGuid->mPresShellId, mGuid->mScrollId);
widget->UpdateZoomConstraints(mGuid->mPresShellId, mGuid->mScrollId, Nothing());
mGuid = Nothing();
}
}
mDocument = nullptr;
mPresShell = nullptr;
}
void
ZoomConstraintsClient::Init(nsIPresShell* aPresShell, nsIDocument* aDocument)
{
if (!(aPresShell && aDocument)) {
return;
}
mPresShell = aPresShell;
mDocument = aDocument;
if (nsCOMPtr<nsPIDOMWindow> window = mDocument->GetWindow()) {
mEventTarget = window->GetChromeEventHandler();
}
if (mEventTarget) {
mEventTarget->AddEventListener(DOM_META_ADDED, this, false);
}
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
if (observerService) {
observerService->AddObserver(this, BEFORE_FIRST_PAINT.Data(), false);
}
}
NS_IMETHODIMP
ZoomConstraintsClient::HandleEvent(nsIDOMEvent* event)
{
nsAutoString type;
event->GetType(type);
if (type.Equals(DOM_META_ADDED)) {
ZCC_LOG("Got a dom-meta-added event in %p\n", this);
RefreshZoomConstraints();
}
return NS_OK;
}
NS_IMETHODIMP
ZoomConstraintsClient::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
{
if (SameCOMIdentity(aSubject, mDocument) && BEFORE_FIRST_PAINT.EqualsASCII(aTopic)) {
ZCC_LOG("Got a before-first-paint event in %p\n", this);
RefreshZoomConstraints();
}
return NS_OK;
}
mozilla::layers::ZoomConstraints
ComputeZoomConstraintsFromViewportInfo(const nsViewportInfo& aViewportInfo)
{
mozilla::layers::ZoomConstraints constraints;
constraints.mAllowZoom = aViewportInfo.IsZoomAllowed();
constraints.mAllowDoubleTapZoom = aViewportInfo.IsDoubleTapZoomAllowed();
constraints.mMinZoom.scale = aViewportInfo.GetMinZoom().scale;
constraints.mMaxZoom.scale = aViewportInfo.GetMaxZoom().scale;
return constraints;
}
void
ZoomConstraintsClient::RefreshZoomConstraints()
{
nsIWidget* widget = GetWidget(mPresShell);
if (!widget) {
return;
}
uint32_t presShellId = 0;
FrameMetrics::ViewID viewId = FrameMetrics::NULL_SCROLL_ID;
bool scrollIdentifiersValid = APZCCallbackHelper::GetOrCreateScrollIdentifiers(
mDocument->GetDocumentElement(),
&presShellId, &viewId);
if (!scrollIdentifiersValid) {
return;
}
nsIFrame* rootFrame = mPresShell->GetRootScrollFrame();
if (!rootFrame) {
rootFrame = mPresShell->GetRootFrame();
}
nsSize size = nsLayoutUtils::CalculateCompositionSizeForFrame(rootFrame, false);
int32_t auPerDevPixel = mPresShell->GetPresContext()->AppUnitsPerDevPixel();
LayoutDeviceIntSize screenSize = LayoutDeviceIntSize::FromAppUnitsRounded(
size, auPerDevPixel);
nsViewportInfo viewportInfo = nsContentUtils::GetViewportInfo(
mDocument,
ViewAs<ScreenPixel>(screenSize, PixelCastJustification::LayoutDeviceIsScreenForBounds));
mozilla::layers::ZoomConstraints zoomConstraints =
ComputeZoomConstraintsFromViewportInfo(viewportInfo);
if (zoomConstraints.mAllowDoubleTapZoom) {
// If the CSS viewport is narrower than the screen (i.e. width <= device-width)
// then we disable double-tap-to-zoom behaviour.
CSSToLayoutDeviceScale scale(
(float)nsPresContext::AppUnitsPerCSSPixel() / auPerDevPixel);
if ((viewportInfo.GetSize() * scale).width <= screenSize.width) {
zoomConstraints.mAllowDoubleTapZoom = false;
}
}
ScrollableLayerGuid newGuid(0, presShellId, viewId);
if (mGuid && mGuid.value() != newGuid) {
ZCC_LOG("Clearing old constraints in %p for { %u, %" PRIu64 " }\n",
this, mGuid->mPresShellId, mGuid->mScrollId);
// If the guid changes, send a message to clear the old one
widget->UpdateZoomConstraints(mGuid->mPresShellId, mGuid->mScrollId, Nothing());
}
mGuid = Some(newGuid);
ZCC_LOG("Sending constraints %s in %p for { %u, %" PRIu64 " }\n",
Stringify(zoomConstraints).c_str(), this, presShellId, viewId);
widget->UpdateZoomConstraints(presShellId, viewId, Some(zoomConstraints));
}