зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
da8c270950
Коммит
23f9ccf4aa
|
@ -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<nsIContentViewer> 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<nsIContentViewer> 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;
|
||||
}
|
||||
|
@ -2281,19 +2254,14 @@ void EventStateManager::DoScrollHistory(int32_t direction) {
|
|||
|
||||
void EventStateManager::DoScrollZoom(nsIFrame* aTargetFrame,
|
||||
int32_t adjustment) {
|
||||
// Exclude form controls and content in chrome docshells.
|
||||
// Exclude content in chrome docshells.
|
||||
nsIContent* content = aTargetFrame->GetContent();
|
||||
if (content && !nsContentUtils::IsInChromeDocshell(content->OwnerDoc())) {
|
||||
// positive adjustment to decrease zoom, negative to increase
|
||||
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:
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче