Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Zoom In / Out Functionality with Key Combination

Post Reply
MTKor
Posts: 7
Joined: Thu Nov 12, 2020 7:25 am

Zoom In / Out Functionality with Key Combination

Post by MTKor »

Hello,

First of all, thank you very much for the time and effort you have invested in CEF4Delphi.

I am working on a project in which a tailormade browser application is created using the SimpleBrowser demo as the basis. Now there is a need to add Zoom In / Zoom Out functionality using key combinations that are familiar to users. The current idea is to use Ctrl_+ for Zoom In and Ctrl_- for Zoom Out. The application uses Pop Up browser windows and the Zoom functionality should apply to the browser window that has the focus.

Do you have any sample code of how to implement this functionality ?

Thank you in advance!
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Zoom In / Out Functionality with Key Combination

Post by salvadordf »

Hi,

If your application needs any feature that it's not included in the SimpleBrowser demo I would suggest that you use the SimpleBrowser2 demo instead. It's easier to add features, events, etc. to that demo.

The MiniBrowser demo has zoom controls in the button with the 3 horizontal lines at the top-right corner. You only have to call TChromium.IncZoomStep, TChromium.DecZoomStep and TChromium.ResetZoomStep.

If you want to modify the zoom level with key combinations then you have to use the TChromium.OnPreKeyEvent and TChromium.OnKeyEvent events.
The MiniBrowser demo uses the F12 key to show and hide the DevTools using those events and also the TApplicationEvents.OnMessage event.

Read this for more information about the TChromium events :
https://magpcss.org/ceforum/apidocs3/pr ... ndler.html
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Zoom In / Out Functionality with Key Combination

Post by salvadordf »

I forgot to add one thing : The zoom in Chromium is set by domain.

That means that if you set a different zoom level in one browser that is showing certain domain and then you open a new browser to navigate to the same domain, Chromium will use the same zoom level in both browsers.

This is a Chromium feature and there's no workaround.
MTKor
Posts: 7
Joined: Thu Nov 12, 2020 7:25 am

Re: Zoom In / Out Functionality with Key Combination

Post by MTKor »

Hi,

Thank you for the information, now I got the zoom working partially i.e. on the main browser form.

However, the use case is such that this tailormade browser application automatically loads a specific URL that in turn automatically leads to opening of another, new popup browser instance for user login. I have created procedures TMainForm1.Chromium1PreKeyEvent and TMainForm1.Chromium1KeyEvent and used TChromium.OnPreKeyEvent and TChromium.OnKeyEvent events as advised. Unfortunately these do not have any effect on the login popup browser instance even when that window has focus/is active without any doubt i.e. the zoom functionality does not work on it.

Any ideas how this could be resolved?
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Zoom In / Out Functionality with Key Combination

Post by salvadordf »

It depends on the popup window type.

If the popup window is a custom Delphi/Lazarus form then you need to implement the same TChromium events in the child form to handle the Zoom. Take a look at the PopupBrowser2 demo to know how to use custom forms for popup windows.

If you let CEF create the popup windows then you will handle all the events using the same TChromium component from the main window. The MiniBrowser demo do this and it sets Chromium1.MultiBrowserMode to TRUE. In this case you would have to use the "browser" parameter in the TChromium events to call "browser.Host.ZoomLevel" manually. See the uCEFChromiumCore.pas unit for more details about the ZoomLevel.
MTKor
Posts: 7
Joined: Thu Nov 12, 2020 7:25 am

Re: Zoom In / Out Functionality with Key Combination

Post by MTKor »

Thank you for the additional information, I am currently studying it.

I already tested this specific URL with the MiniBrowser demo. However, the zoom functionality of the Main Form has no effect on the popup login browser window.
Post Reply