From 9426438383cc227385cb237bba1e01120188717b Mon Sep 17 00:00:00 2001 From: Brad Werth Date: Wed, 22 Jan 2020 23:13:50 +0000 Subject: [PATCH] Bug 1516413 Part 1: Make EventStateManager zoom delta functions send chrome events instead of acting directly. r=mstange This patch changes the zoom behavior to always be routed through the frontend Zoom Actor. In the existing code, the ZoomChangeUsingMouseWheel event is sent as an after-the-fact notification of the zoom being modified directly. This part of the patch supplements the existing event with 2 new events that trigger the frontend to do the +/- 10% math in ChangeFullZoom and ChangeTextZoom. The next part of the patch supplies that logic in the frontend Zoom Actor. This also changes the handling of events from the zoom in/out keys. Before, those keys would only change full zoom levels. Now, they will respect the full zoom vs text zoom toggle. Differential Revision: https://phabricator.services.mozilla.com/D59259 --HG-- extra : moz-landing-system : lando --- dom/events/EventStateManager.cpp | 60 ++++++++------------------------ dom/events/EventStateManager.h | 3 +- 2 files changed, 15 insertions(+), 48 deletions(-) diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 6c89b57879cf..a6eab83a350b 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -26,7 +26,6 @@ #include "mozilla/dom/FrameLoaderBinding.h" #include "mozilla/dom/MouseEventBinding.h" #include "mozilla/dom/BrowserChild.h" -#include "mozilla/dom/BrowserParent.h" #include "mozilla/dom/UIEvent.h" #include "mozilla/dom/UIEventBinding.h" #include "mozilla/dom/UserActivation.h" @@ -2223,44 +2222,18 @@ nsresult EventStateManager::GetContentViewer(nsIContentViewer** aCv) { return NS_OK; } -nsresult EventStateManager::ChangeTextSize(int32_t change) { - nsCOMPtr cv; - nsresult rv = GetContentViewer(getter_AddRefs(cv)); - NS_ENSURE_SUCCESS(rv, rv); +nsresult EventStateManager::ChangeZoom(int32_t change) { + MOZ_ASSERT(change == 1 || change == -1, "Can only change by +/- 10%."); - if (cv) { - float textzoom; - float zoomMin = ((float)StaticPrefs::zoom_minPercent()) / 100; - float zoomMax = ((float)StaticPrefs::zoom_maxPercent()) / 100; - cv->GetTextZoom(&textzoom); - textzoom += ((float)change) / 10; - if (textzoom < zoomMin) - textzoom = zoomMin; - else if (textzoom > zoomMax) - textzoom = zoomMax; - cv->SetTextZoom(textzoom); - } - - return NS_OK; -} - -nsresult EventStateManager::ChangeFullZoom(int32_t change) { - nsCOMPtr cv; - nsresult rv = GetContentViewer(getter_AddRefs(cv)); - NS_ENSURE_SUCCESS(rv, rv); - - if (cv) { - float fullzoom; - float zoomMin = ((float)StaticPrefs::zoom_minPercent()) / 100; - float zoomMax = ((float)StaticPrefs::zoom_maxPercent()) / 100; - cv->GetFullZoom(&fullzoom); - fullzoom += ((float)change) / 10; - if (fullzoom < zoomMin) - fullzoom = zoomMin; - else if (fullzoom > zoomMax) - fullzoom = zoomMax; - cv->SetFullZoom(fullzoom); - } + // Send the zoom change as a chrome event so it will be handled + // by the front end actors in the same way as other zoom actions. + // This excludes documents hosted in non-browser containers, like + // in a WebExtension. + nsContentUtils::DispatchChromeEvent( + mDocument, ToSupports(mDocument), + (change == 1 ? NS_LITERAL_STRING("DoZoomEnlargeBy10") + : NS_LITERAL_STRING("DoZoomReduceBy10")), + CanBubble::eYes, Cancelable::eYes); return NS_OK; } @@ -2288,12 +2261,7 @@ void EventStateManager::DoScrollZoom(nsIFrame* aTargetFrame, int32_t change = (adjustment > 0) ? -1 : 1; EnsureDocument(mPresContext); - if (Preferences::GetBool("browser.zoom.full") || - content->OwnerDoc()->IsSyntheticDocument()) { - ChangeFullZoom(change); - } else { - ChangeTextSize(change); - } + ChangeZoom(change); nsContentUtils::DispatchChromeEvent( mDocument, ToSupports(mDocument), NS_LITERAL_STRING("ZoomChangeUsingMouseWheel"), CanBubble::eYes, @@ -3136,8 +3104,8 @@ void EventStateManager::PostHandleKeyboardEvent( switch (aKeyboardEvent->mKeyNameIndex) { case KEY_NAME_INDEX_ZoomIn: case KEY_NAME_INDEX_ZoomOut: - ChangeFullZoom( - aKeyboardEvent->mKeyNameIndex == KEY_NAME_INDEX_ZoomIn ? 1 : -1); + ChangeZoom(aKeyboardEvent->mKeyNameIndex == KEY_NAME_INDEX_ZoomIn ? 1 + : -1); aStatus = nsEventStatus_eConsumeNoDefault; break; default: diff --git a/dom/events/EventStateManager.h b/dom/events/EventStateManager.h index 6d3ed35a51a8..47849b1bbff8 100644 --- a/dom/events/EventStateManager.h +++ b/dom/events/EventStateManager.h @@ -926,8 +926,7 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver { void DoScrollHistory(int32_t direction); void DoScrollZoom(nsIFrame* aTargetFrame, int32_t adjustment); nsresult GetContentViewer(nsIContentViewer** aCv); - nsresult ChangeTextSize(int32_t change); - nsresult ChangeFullZoom(int32_t change); + nsresult ChangeZoom(int32_t change); /** * DeltaAccumulator class manages delta values for dispatching DOMMouseScroll