sideview 0.4.0__tar.gz → 0.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sideview-0.4.0 → sideview-0.4.1}/CHANGELOG.md +7 -0
- {sideview-0.4.0 → sideview-0.4.1}/PKG-INFO +1 -1
- {sideview-0.4.0 → sideview-0.4.1}/native/win32/webview_host.cpp +23 -22
- {sideview-0.4.0 → sideview-0.4.1}/pyproject.toml +2 -1
- {sideview-0.4.0 → sideview-0.4.1}/scripts/validate_distribution.py +1 -0
- sideview-0.4.1/scripts/validate_windows_native_bounds.py +116 -0
- {sideview-0.4.0 → sideview-0.4.1}/src/sideview/widget.py +60 -9
- sideview-0.4.1/tests/test_native_bounds.py +83 -0
- {sideview-0.4.0 → sideview-0.4.1}/CONTRIBUTING.md +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/LICENSE +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/README.md +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/SECURITY.md +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/examples/simple_browser.py +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/native/CMakeLists.txt +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/native/linux/webview_host.cpp +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/native/macos/webview_host.mm +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/native/native_webview.h +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/release-please-config.json +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/scripts/benchmark_frame_stream.py +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/scripts/build_linux.sh +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/scripts/build_windows.ps1 +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/scripts/validate_pull_request_title.py +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/src/sideview/__init__.py +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/src/sideview/_backend.py +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/src/sideview/py.typed +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/tests/conftest.py +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/tests/test_imports.py +0 -0
- {sideview-0.4.0 → sideview-0.4.1}/tests/test_release_tooling.py +0 -0
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.1](https://github.com/AlexsanderMe/SideView/compare/v0.4.0...v0.4.1) (2026-07-30)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **windows:** synchronize webview bounds at high DPI ([#6](https://github.com/AlexsanderMe/SideView/issues/6)) ([2951841](https://github.com/AlexsanderMe/SideView/commit/295184105349c3158cb7c61a28ce6600648ff56e))
|
|
9
|
+
|
|
3
10
|
## [0.4.0](https://github.com/AlexsanderMe/SideView/compare/v0.3.0...v0.4.0) (2026-07-26)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -97,31 +97,36 @@ void emit_capture(
|
|
|
97
97
|
);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
100
|
+
void sync_bounds_to_parent(Host *host) {
|
|
101
|
+
if (!host || host->destroyed || !host->parent || !host->hwnd) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
105
104
|
|
|
106
|
-
|
|
107
|
-
if (!host
|
|
105
|
+
RECT parent_rect {};
|
|
106
|
+
if (!GetClientRect(host->parent, &parent_rect)) {
|
|
108
107
|
return;
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
// QWidget geometry is expressed in device-independent pixels. The native
|
|
111
|
+
// parent client rect is the authoritative raw-pixel size for both the
|
|
112
|
+
// child HWND and WebView2, including per-monitor DPI transitions.
|
|
113
|
+
if (!SetWindowPos(
|
|
113
114
|
host->hwnd,
|
|
114
115
|
nullptr,
|
|
115
116
|
0,
|
|
116
117
|
0,
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
parent_rect.right - parent_rect.left,
|
|
119
|
+
parent_rect.bottom - parent_rect.top,
|
|
119
120
|
SWP_NOZORDER | SWP_NOACTIVATE
|
|
120
|
-
)
|
|
121
|
+
)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
121
124
|
|
|
122
125
|
if (host->controller) {
|
|
123
|
-
RECT host_rect
|
|
124
|
-
host->
|
|
126
|
+
RECT host_rect {};
|
|
127
|
+
if (GetClientRect(host->hwnd, &host_rect)) {
|
|
128
|
+
host->controller->put_Bounds(host_rect);
|
|
129
|
+
}
|
|
125
130
|
}
|
|
126
131
|
}
|
|
127
132
|
|
|
@@ -632,7 +637,7 @@ NWV_EXPORT void *nwv_create(void *parent_view, const nwv_options *options) {
|
|
|
632
637
|
host->controller = controller;
|
|
633
638
|
host->controller->get_CoreWebView2(&host->webview);
|
|
634
639
|
host->webview.As(&host->webview2);
|
|
635
|
-
|
|
640
|
+
sync_bounds_to_parent(host.get());
|
|
636
641
|
|
|
637
642
|
if (host->webview) {
|
|
638
643
|
attach_events(host);
|
|
@@ -653,7 +658,7 @@ NWV_EXPORT void *nwv_create(void *parent_view, const nwv_options *options) {
|
|
|
653
658
|
return nullptr;
|
|
654
659
|
}
|
|
655
660
|
|
|
656
|
-
|
|
661
|
+
sync_bounds_to_parent(host.get());
|
|
657
662
|
return new HostHandle { host };
|
|
658
663
|
}
|
|
659
664
|
|
|
@@ -737,7 +742,7 @@ NWV_EXPORT void nwv_set_capture_callback(void *handle, nwv_capture_callback call
|
|
|
737
742
|
host->capture_user_data = user_data;
|
|
738
743
|
}
|
|
739
744
|
|
|
740
|
-
NWV_EXPORT void nwv_resize(void *handle, int
|
|
745
|
+
NWV_EXPORT void nwv_resize(void *handle, int, int) {
|
|
741
746
|
auto *host_handle = static_cast<HostHandle *>(handle);
|
|
742
747
|
if (!host_handle) {
|
|
743
748
|
return;
|
|
@@ -747,11 +752,7 @@ NWV_EXPORT void nwv_resize(void *handle, int width, int height) {
|
|
|
747
752
|
return;
|
|
748
753
|
}
|
|
749
754
|
|
|
750
|
-
|
|
751
|
-
if (host->controller) {
|
|
752
|
-
RECT rect { 0, 0, width, height };
|
|
753
|
-
host->controller->put_Bounds(rect);
|
|
754
|
-
}
|
|
755
|
+
sync_bounds_to_parent(host.get());
|
|
755
756
|
}
|
|
756
757
|
|
|
757
758
|
NWV_EXPORT int nwv_navigate(void *handle, const void *url) {
|
|
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "sideview"
|
|
7
|
-
version = "0.4.
|
|
7
|
+
version = "0.4.1"
|
|
8
8
|
description = "A lightweight native webview widget for PySide6."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -69,6 +69,7 @@ sdist.include = [
|
|
|
69
69
|
"scripts/build_linux.sh",
|
|
70
70
|
"scripts/build_windows.ps1",
|
|
71
71
|
"scripts/validate_distribution.py",
|
|
72
|
+
"scripts/validate_windows_native_bounds.py",
|
|
72
73
|
"scripts/validate_pull_request_title.py",
|
|
73
74
|
"src/sideview/__init__.py",
|
|
74
75
|
"src/sideview/_backend.py",
|
|
@@ -30,6 +30,7 @@ SDIST_FILES = {
|
|
|
30
30
|
"release-please-config.json",
|
|
31
31
|
"scripts/validate_distribution.py",
|
|
32
32
|
"scripts/validate_pull_request_title.py",
|
|
33
|
+
"scripts/validate_windows_native_bounds.py",
|
|
33
34
|
"src/sideview/__init__.py",
|
|
34
35
|
"src/sideview/_backend.py",
|
|
35
36
|
"src/sideview/widget.py",
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import ctypes
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
import tempfile
|
|
7
|
+
from ctypes import wintypes
|
|
8
|
+
|
|
9
|
+
from PySide6 import QtCore, QtWidgets
|
|
10
|
+
|
|
11
|
+
from sideview import NativeWebView
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Rect(ctypes.Structure):
|
|
15
|
+
_fields_ = (
|
|
16
|
+
("left", wintypes.LONG),
|
|
17
|
+
("top", wintypes.LONG),
|
|
18
|
+
("right", wintypes.LONG),
|
|
19
|
+
("bottom", wintypes.LONG),
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _client_size(user32: ctypes.WinDLL, hwnd: int) -> tuple[int, int]:
|
|
24
|
+
rect = Rect()
|
|
25
|
+
if not user32.GetClientRect(hwnd, ctypes.byref(rect)):
|
|
26
|
+
raise ctypes.WinError(ctypes.get_last_error())
|
|
27
|
+
return rect.right - rect.left, rect.bottom - rect.top
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _process_events_until(
|
|
31
|
+
app: QtWidgets.QApplication,
|
|
32
|
+
predicate,
|
|
33
|
+
*,
|
|
34
|
+
timeout_ms: int,
|
|
35
|
+
) -> bool:
|
|
36
|
+
deadline = QtCore.QDeadlineTimer(timeout_ms)
|
|
37
|
+
while not deadline.hasExpired():
|
|
38
|
+
app.processEvents(QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 20)
|
|
39
|
+
if predicate():
|
|
40
|
+
return True
|
|
41
|
+
QtCore.QThread.msleep(10)
|
|
42
|
+
return predicate()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def main() -> int:
|
|
46
|
+
if sys.platform != "win32":
|
|
47
|
+
raise RuntimeError("Native bounds validation only supports Windows.")
|
|
48
|
+
|
|
49
|
+
user32 = ctypes.WinDLL("user32", use_last_error=True)
|
|
50
|
+
user32.GetClientRect.argtypes = [wintypes.HWND, ctypes.POINTER(Rect)]
|
|
51
|
+
user32.GetClientRect.restype = wintypes.BOOL
|
|
52
|
+
user32.FindWindowExW.argtypes = (
|
|
53
|
+
wintypes.HWND,
|
|
54
|
+
wintypes.HWND,
|
|
55
|
+
wintypes.LPCWSTR,
|
|
56
|
+
wintypes.LPCWSTR,
|
|
57
|
+
)
|
|
58
|
+
user32.FindWindowExW.restype = wintypes.HWND
|
|
59
|
+
|
|
60
|
+
app = QtWidgets.QApplication([])
|
|
61
|
+
data_root = tempfile.TemporaryDirectory(
|
|
62
|
+
prefix="sideview-native-bounds-",
|
|
63
|
+
ignore_cleanup_errors=True,
|
|
64
|
+
)
|
|
65
|
+
window = QtWidgets.QMainWindow()
|
|
66
|
+
view = NativeWebView(session_data_root=data_root.name)
|
|
67
|
+
window.setCentralWidget(view)
|
|
68
|
+
window.resize(800, 600)
|
|
69
|
+
|
|
70
|
+
ready = False
|
|
71
|
+
|
|
72
|
+
def mark_ready() -> None:
|
|
73
|
+
nonlocal ready
|
|
74
|
+
ready = True
|
|
75
|
+
|
|
76
|
+
view.ready.connect(mark_ready)
|
|
77
|
+
window.show()
|
|
78
|
+
|
|
79
|
+
try:
|
|
80
|
+
if not _process_events_until(app, lambda: ready, timeout_ms=15_000):
|
|
81
|
+
raise RuntimeError("Native WebView did not become ready.")
|
|
82
|
+
|
|
83
|
+
parent_hwnd = int(view.winId())
|
|
84
|
+
child_hwnd = int(user32.FindWindowExW(parent_hwnd, 0, "Static", None))
|
|
85
|
+
if not child_hwnd:
|
|
86
|
+
raise RuntimeError("SideView native child HWND was not created.")
|
|
87
|
+
|
|
88
|
+
window.resize(960, 640)
|
|
89
|
+
if not _process_events_until(
|
|
90
|
+
app,
|
|
91
|
+
lambda: _client_size(user32, child_hwnd) == _client_size(user32, parent_hwnd),
|
|
92
|
+
timeout_ms=5_000,
|
|
93
|
+
):
|
|
94
|
+
parent_size = _client_size(user32, parent_hwnd)
|
|
95
|
+
child_size = _client_size(user32, child_hwnd)
|
|
96
|
+
raise RuntimeError(
|
|
97
|
+
"Native child bounds do not match the Qt host: "
|
|
98
|
+
f"parent={parent_size}, child={child_size}."
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
result = {
|
|
102
|
+
"device_pixel_ratio": view.devicePixelRatioF(),
|
|
103
|
+
"logical_size": [view.width(), view.height()],
|
|
104
|
+
"native_size": list(_client_size(user32, parent_hwnd)),
|
|
105
|
+
}
|
|
106
|
+
print(json.dumps(result, sort_keys=True))
|
|
107
|
+
return 0
|
|
108
|
+
finally:
|
|
109
|
+
view.dispose()
|
|
110
|
+
window.close()
|
|
111
|
+
app.processEvents()
|
|
112
|
+
data_root.cleanup()
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
if __name__ == "__main__":
|
|
116
|
+
raise SystemExit(main())
|
|
@@ -15,6 +15,11 @@ from ._backend import NativeBackend, NativeCookie, NativeOptions, NativeWebViewE
|
|
|
15
15
|
DownloadPolicy = Callable[[str], bool]
|
|
16
16
|
MIN_ZOOM_FACTOR = 0.25
|
|
17
17
|
MAX_ZOOM_FACTOR = 5.0
|
|
18
|
+
_DEVICE_PIXEL_RATIO_CHANGE = getattr(
|
|
19
|
+
QtCore.QEvent.Type,
|
|
20
|
+
"DevicePixelRatioChange",
|
|
21
|
+
None,
|
|
22
|
+
)
|
|
18
23
|
|
|
19
24
|
|
|
20
25
|
class _EventBridge(QtCore.QObject):
|
|
@@ -67,6 +72,8 @@ class NativeWebView(QtWidgets.QWidget):
|
|
|
67
72
|
self._native_container: QtWidgets.QWidget | None = None
|
|
68
73
|
self._native_surface_visible = True
|
|
69
74
|
self._lifecycle_parent: QtCore.QObject | None = None
|
|
75
|
+
self._screen_change_window: QtGui.QWindow | None = None
|
|
76
|
+
self._native_bounds_sync_pending = False
|
|
70
77
|
self._pending_url = url
|
|
71
78
|
self._pending_html = html
|
|
72
79
|
self._pending_base_url: str | None = None
|
|
@@ -341,23 +348,31 @@ document.addEventListener("contextmenu", function(event) {
|
|
|
341
348
|
|
|
342
349
|
def showEvent(self, event: QtGui.QShowEvent) -> None: # type: ignore[name-defined]
|
|
343
350
|
super().showEvent(event)
|
|
351
|
+
self._bind_window_screen_changes()
|
|
344
352
|
self._schedule_ensure_created()
|
|
353
|
+
self._schedule_native_bounds_sync()
|
|
345
354
|
|
|
346
355
|
def event(self, event: QtCore.QEvent) -> bool:
|
|
347
|
-
|
|
356
|
+
event_type = event.type()
|
|
357
|
+
if event_type == QtCore.QEvent.Type.DeferredDelete:
|
|
348
358
|
self.dispose()
|
|
349
359
|
handled = super().event(event)
|
|
350
|
-
if
|
|
360
|
+
if event_type == QtCore.QEvent.Type.ParentChange and hasattr(self, "_lifecycle_parent"):
|
|
351
361
|
self._bind_parent_lifecycle()
|
|
362
|
+
self._bind_window_screen_changes()
|
|
363
|
+
self._schedule_native_bounds_sync()
|
|
364
|
+
elif (
|
|
365
|
+
_DEVICE_PIXEL_RATIO_CHANGE is not None
|
|
366
|
+
and event_type == _DEVICE_PIXEL_RATIO_CHANGE
|
|
367
|
+
and hasattr(self, "_native_bounds_sync_pending")
|
|
368
|
+
):
|
|
369
|
+
self._schedule_native_bounds_sync()
|
|
352
370
|
return handled
|
|
353
371
|
|
|
354
372
|
def resizeEvent(self, event: QtGui.QResizeEvent) -> None: # type: ignore[name-defined]
|
|
355
373
|
super().resizeEvent(event)
|
|
356
374
|
if self._created:
|
|
357
|
-
|
|
358
|
-
self._backend.resize(self._handle, size.width(), size.height())
|
|
359
|
-
if self._native_container is not None:
|
|
360
|
-
self._native_container.setGeometry(self.rect())
|
|
375
|
+
self._sync_native_bounds()
|
|
361
376
|
elif self.isVisible():
|
|
362
377
|
self._schedule_ensure_created()
|
|
363
378
|
|
|
@@ -370,6 +385,8 @@ document.addEventListener("contextmenu", function(event) {
|
|
|
370
385
|
return
|
|
371
386
|
self._disposed = True
|
|
372
387
|
self._create_pending = False
|
|
388
|
+
self._native_bounds_sync_pending = False
|
|
389
|
+
self._unbind_window_screen_changes()
|
|
373
390
|
if self._handle:
|
|
374
391
|
self._backend.stop_frame_stream(self._handle)
|
|
375
392
|
self._destroy_native_container()
|
|
@@ -407,8 +424,6 @@ document.addEventListener("contextmenu", function(event) {
|
|
|
407
424
|
|
|
408
425
|
self._create_pending = False
|
|
409
426
|
self.ensurePolished()
|
|
410
|
-
width = max(1, self.width())
|
|
411
|
-
height = max(1, self.height())
|
|
412
427
|
|
|
413
428
|
if self._backend.uses_foreign_window:
|
|
414
429
|
qt_platform = QtGui.QGuiApplication.platformName().lower()
|
|
@@ -456,7 +471,42 @@ document.addEventListener("contextmenu", function(event) {
|
|
|
456
471
|
self._created = True
|
|
457
472
|
self._backend.set_policy_callback(self._handle, self._handle_policy_request)
|
|
458
473
|
self._backend.set_capture_callback(self._handle, self._emit_capture_event)
|
|
459
|
-
self.
|
|
474
|
+
self._bind_window_screen_changes()
|
|
475
|
+
self._sync_native_bounds()
|
|
476
|
+
|
|
477
|
+
def _sync_native_bounds(self) -> None:
|
|
478
|
+
if self._disposed or not self._created or not self._handle:
|
|
479
|
+
return
|
|
480
|
+
size = self.size()
|
|
481
|
+
self._backend.resize(self._handle, size.width(), size.height())
|
|
482
|
+
if self._native_container is not None:
|
|
483
|
+
self._native_container.setGeometry(self.rect())
|
|
484
|
+
|
|
485
|
+
def _schedule_native_bounds_sync(self, *_args: object) -> None:
|
|
486
|
+
if self._disposed or not self._created or self._native_bounds_sync_pending:
|
|
487
|
+
return
|
|
488
|
+
self._native_bounds_sync_pending = True
|
|
489
|
+
QtCore.QTimer.singleShot(0, self._flush_native_bounds_sync)
|
|
490
|
+
|
|
491
|
+
def _flush_native_bounds_sync(self) -> None:
|
|
492
|
+
self._native_bounds_sync_pending = False
|
|
493
|
+
self._sync_native_bounds()
|
|
494
|
+
|
|
495
|
+
def _bind_window_screen_changes(self) -> None:
|
|
496
|
+
window_handle = self.windowHandle()
|
|
497
|
+
if window_handle is self._screen_change_window:
|
|
498
|
+
return
|
|
499
|
+
self._unbind_window_screen_changes()
|
|
500
|
+
self._screen_change_window = window_handle
|
|
501
|
+
if window_handle is not None:
|
|
502
|
+
window_handle.screenChanged.connect(self._schedule_native_bounds_sync)
|
|
503
|
+
|
|
504
|
+
def _unbind_window_screen_changes(self) -> None:
|
|
505
|
+
window_handle = self._screen_change_window
|
|
506
|
+
self._screen_change_window = None
|
|
507
|
+
if window_handle is not None:
|
|
508
|
+
with suppress(RuntimeError, TypeError):
|
|
509
|
+
window_handle.screenChanged.disconnect(self._schedule_native_bounds_sync)
|
|
460
510
|
|
|
461
511
|
def _destroy_native_container(self) -> None:
|
|
462
512
|
self.setFocusProxy(None)
|
|
@@ -521,6 +571,7 @@ document.addEventListener("contextmenu", function(event) {
|
|
|
521
571
|
return
|
|
522
572
|
if event_type == NativeBackend.EVENT_READY:
|
|
523
573
|
self._native_ready = True
|
|
574
|
+
self._sync_native_bounds()
|
|
524
575
|
self.ready.emit()
|
|
525
576
|
self._flush_pending_settings()
|
|
526
577
|
self._flush_pending_document_scripts()
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from PySide6 import QtCore, QtWidgets
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class _FakeBackend:
|
|
10
|
+
uses_foreign_window = False
|
|
11
|
+
|
|
12
|
+
def __init__(self) -> None:
|
|
13
|
+
self.resizes: list[tuple[int, int, int]] = []
|
|
14
|
+
|
|
15
|
+
def resize(self, handle: int, width: int, height: int) -> None:
|
|
16
|
+
self.resizes.append((handle, width, height))
|
|
17
|
+
|
|
18
|
+
def stop_frame_stream(self, _handle: int) -> None:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
def destroy(self, _handle: int) -> None:
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _created_view(monkeypatch) -> tuple[QtWidgets.QApplication, object, _FakeBackend]:
|
|
26
|
+
import sideview.widget as widget_module
|
|
27
|
+
|
|
28
|
+
backend = _FakeBackend()
|
|
29
|
+
monkeypatch.setenv("QT_QPA_PLATFORM", "offscreen")
|
|
30
|
+
monkeypatch.setattr(widget_module, "NativeBackend", lambda: backend)
|
|
31
|
+
app = QtWidgets.QApplication.instance() or QtWidgets.QApplication([])
|
|
32
|
+
view = widget_module.NativeWebView()
|
|
33
|
+
view._handle = 17
|
|
34
|
+
view._created = True
|
|
35
|
+
return app, view, backend
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_resize_synchronizes_native_bounds(monkeypatch):
|
|
39
|
+
app, view, backend = _created_view(monkeypatch)
|
|
40
|
+
view.show()
|
|
41
|
+
app.processEvents()
|
|
42
|
+
backend.resizes.clear()
|
|
43
|
+
|
|
44
|
+
view.resize(640, 360)
|
|
45
|
+
app.processEvents()
|
|
46
|
+
|
|
47
|
+
assert backend.resizes[-1] == (17, 640, 360)
|
|
48
|
+
view.dispose()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_device_pixel_ratio_change_schedules_native_bounds_sync(monkeypatch):
|
|
52
|
+
import sideview.widget as widget_module
|
|
53
|
+
|
|
54
|
+
if widget_module._DEVICE_PIXEL_RATIO_CHANGE is None:
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
app, view, backend = _created_view(monkeypatch)
|
|
58
|
+
view.resize(800, 450)
|
|
59
|
+
app.processEvents()
|
|
60
|
+
backend.resizes.clear()
|
|
61
|
+
|
|
62
|
+
event = QtCore.QEvent(widget_module._DEVICE_PIXEL_RATIO_CHANGE)
|
|
63
|
+
QtCore.QCoreApplication.sendEvent(view, event)
|
|
64
|
+
app.processEvents()
|
|
65
|
+
|
|
66
|
+
assert backend.resizes == [(17, 800, 450)]
|
|
67
|
+
view.dispose()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_windows_resize_uses_native_parent_client_rect():
|
|
71
|
+
source = (Path(__file__).parents[1] / "native" / "win32" / "webview_host.cpp").read_text(
|
|
72
|
+
encoding="utf-8"
|
|
73
|
+
)
|
|
74
|
+
resize_body = re.search(
|
|
75
|
+
r"NWV_EXPORT void nwv_resize\([^)]*\) \{(?P<body>.*?)\n\}",
|
|
76
|
+
source,
|
|
77
|
+
re.DOTALL,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
assert resize_body is not None
|
|
81
|
+
assert "sync_bounds_to_parent(host.get());" in resize_body.group("body")
|
|
82
|
+
assert "SetWindowPos" not in resize_body.group("body")
|
|
83
|
+
assert "GetClientRect(host->parent" in source
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|