Add new CanZoom/Zoom API (fixes #3284)

Add a simpler CanZoom/Zoom API as an alternative to the more error-prone
SetZoomLevel/GetZoomLevel API. Both APIs are now implemented for both runtimes.
With the Chrome runtime a zoom notification bubble will be displayed unless
CefBrowserSettings.chrome_zoom_bubble is set to STATE_DISABLED.

To test:
- Run cefclient and select zoom entries from the Tests menu.
- chrome: Run cefclient with `--hide-chrome-bubbles` command-line flag to hide
  the zoom notification bubble.
This commit is contained in:
Marshall Greenblatt
2023-10-04 19:46:45 -04:00
parent 238aa32bc2
commit 721b365c10
20 changed files with 338 additions and 80 deletions

View File

@ -34,10 +34,10 @@
#include "base/functional/callback_helpers.h"
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
#include "components/zoom/page_zoom.h"
#include "content/browser/gpu/compositor_util.h"
#include "content/public/browser/desktop_media_id.h"
#include "content/public/browser/file_select_listener.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/keyboard_event_processing_result.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_handle.h"
@ -330,31 +330,6 @@ CefWindowHandle AlloyBrowserHostImpl::GetOpenerWindowHandle() {
return opener_;
}
double AlloyBrowserHostImpl::GetZoomLevel() {
// Verify that this method is being called on the UI thread.
if (!CEF_CURRENTLY_ON_UIT()) {
DCHECK(false) << "called on invalid thread";
return 0;
}
if (web_contents()) {
return content::HostZoomMap::GetZoomLevel(web_contents());
}
return 0;
}
void AlloyBrowserHostImpl::SetZoomLevel(double zoomLevel) {
if (CEF_CURRENTLY_ON_UIT()) {
if (web_contents()) {
content::HostZoomMap::SetZoomLevel(web_contents(), zoomLevel);
}
} else {
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::SetZoomLevel,
this, zoomLevel));
}
}
void AlloyBrowserHostImpl::Find(const CefString& searchText,
bool forward,
bool matchCase,
@ -1118,6 +1093,11 @@ bool AlloyBrowserHostImpl::DidAddMessageToConsole(
line_no, source_id);
}
void AlloyBrowserHostImpl::ContentsZoomChange(bool zoom_in) {
zoom::PageZoom::Zoom(
web_contents(), zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT);
}
void AlloyBrowserHostImpl::BeforeUnloadFired(content::WebContents* source,
bool proceed,
bool* proceed_to_fire_unload) {