MCPcopy Create free account
hub / github.com/cztomczak/cefpython / SetBrowserDpiSettings

Function SetBrowserDpiSettings

src/client_handler/dpi_aware.cpp:163–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163void SetBrowserDpiSettings(CefRefPtr<CefBrowser> cefBrowser,
164 CefString autoZooming) {
165 // Setting zoom level immediately after browser was created
166 // won't work. We need to wait a moment before we can set it.
167 REQUIRE_UI_THREAD();
168
169 double oldZoomLevel = cefBrowser->GetHost()->GetZoomLevel();
170 double newZoomLevel = 0.0;
171
172 int dpix = 0;
173 int dpiy = 0;
174 GetSystemDpi(&dpix, &dpiy);
175
176 if (autoZooming.ToString() == "system_dpi") {
177 // Using only "dpix" value to calculate zoom level. All
178 // modern displays have equal horizontal/vertical resolution.
179 // Examples:
180 // dpix=96 zoom=0.0
181 // dpix=120 zoom=1.0
182 // dpix=144 zoom=2.0
183 // dpix=72 zoom=-1.0
184 newZoomLevel = (dpix - DEFAULT_DPIX) / 24;
185 } else {
186 // When atof() fails converting string to double, then
187 // 0.0 is returned.
188 newZoomLevel = atof(autoZooming.ToString().c_str());
189 }
190
191 if (oldZoomLevel != newZoomLevel) {
192 cefBrowser->GetHost()->SetZoomLevel(newZoomLevel);
193 if (cefBrowser->GetHost()->GetZoomLevel() != oldZoomLevel) {
194 // OK succes.
195 LOG(INFO) << "[Browser process] SetBrowserDpiSettings():"
196 " DPI=" << dpix << ""
197 " zoom=" << cefBrowser->GetHost()->GetZoomLevel();
198 }
199 } else {
200 // This code block running can also be a result of executing
201 // SetZoomLevel(), as GetZoomLevel() didn't return the new
202 // value that was set. Documentation says that if SetZoomLevel
203 // is called on the UI thread, then GetZoomLevel should
204 // immediately return the same value that was set. Unfortunately
205 // this seems not to be true.
206 static bool already_logged = false;
207 if (!already_logged) {
208 already_logged = true;
209 // OK success.
210 LOG(INFO) << "[Browser process] SetBrowserDpiSettings():"
211 " DPI=" << dpix << ""
212 " zoom=" << cefBrowser->GetHost()->GetZoomLevel();
213 }
214 }
215 // We need to check zooming constantly, during loading of pages.
216 // If we set zooming to 2.0 for localhost/ and then it navigates
217 // to google.com, then the zomming is back at 0.0 and needs to
218 // be set again.
219 CefPostDelayedTask(
220 TID_UI,

Callers 1

OnAfterCreatedMethod · 0.85

Calls 4

GetSystemDpiFunction · 0.85
BindFunction · 0.85
ToStringMethod · 0.80
c_strMethod · 0.80

Tested by

no test coverage detected