Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with app hanging during window resize when calling WindowUtils.OnSize. Expose new Browser.SetBounds method. #464

Closed
cztomczak opened this issue Aug 26, 2018 · 2 comments

Comments

@cztomczak
Copy link
Owner

cztomczak commented Aug 26, 2018

I noticed app sometimes hanging during window resize in the wxpython.py example. It occurs during the EVT_SIZE event when calling WindowUtils.OnSize. That function does not handle things properly and it should only be called when handling WM_SIZE message, as it makes calls to DefWindowProc.

The solution will be to expose Browser.SetBounds on Windows which will be a wrapper for SetWindowPos WIN32 API.

All examples should be updated to use the new Browser.SetBounds method.

In v49 release for WinXP/Vista there is WindowUtils.UpdateBrowserSize, so it needs to be added to Migration Guide doc that it is require to call Browser.SetBounds now..

Related issue: #345 ("Crash when resizing browser using WindowUtils.OnSize with multi-threaded message loop set to True").

window_utils_win.pyx

    @staticmethod
    def OnSize(WindowHandle windowHandle, long msg, long wparam, long lparam):
        cdef PyBrowser pyBrowser = GetBrowserByWindowHandle(windowHandle)
        if not pyBrowser:
            return DefWindowProc(<HWND>windowHandle, msg, wparam, lparam)

        cdef HWND innerHwnd = <HWND>pyBrowser.GetWindowHandle()
        if not innerHwnd:
            return DefWindowProc(<HWND>windowHandle, msg, wparam, lparam)

        cdef RECT rect2
        cdef BOOL result = GetClientRect(<HWND>windowHandle, &rect2)

        cdef HDWP hdwp
        if result != 0:
            hdwp = BeginDeferWindowPos(1)
            if hdwp:
                hdwp = DeferWindowPos(hdwp, innerHwnd, NULL,
                        rect2.left, rect2.top,
                        rect2.right - rect2.left,
                        rect2.bottom - rect2.top,
                        SWP_NOZORDER)
                if hdwp:
                    EndDeferWindowPos(hdwp)

        return DefWindowProc(<HWND>windowHandle, msg, wparam, lparam)

    @staticmethod
    def UpdateBrowserSize(WindowHandle parent_window_handle,
                          PyBrowser browser,
                          py_bool redraw=True):
        cdef HWND innerHwnd = <HWND>browser.GetWindowHandle()
        if not innerHwnd:
            return
        cdef RECT rect2
        cdef BOOL result = GetClientRect(<HWND>parent_window_handle, &rect2)
        cdef UINT flags = SWP_NOZORDER
        if not redraw:
            flags = SWP_NOZORDER | SWP_NOREDRAW
        if result != 0:
            SetWindowPos(innerHwnd, NULL,
                rect2.left, rect2.top,
                rect2.right - rect2.left,
                rect2.bottom - rect2.top,
                flags)

wxpython.py

WindowUtils.UpdateBrowserSize,(self.browser_panel.GetHandle(), self.browser)
cztomczak added a commit that referenced this issue Aug 29, 2018
This is a temporary fix to use ctypes until thw new
WindowUtils.UpdateBrowserSize utility func is exposed.
@cztomczak
Copy link
Owner Author

A temporary fix for the tkinter.py example in commit 38bcf0c. Using ctypes module to call SetWindowPos.

@cztomczak cztomczak changed the title Fix issues with app hanging during window resize when calling WindowUtils.OnSize Fix issues with app hanging during window resize when calling WindowUtils.OnSize. Expose new Browser.SetBounds method. Jan 23, 2020
cztomczak added a commit that referenced this issue Jan 28, 2020
update examples and documentation.

Fix event handling in qt.py example. Parent methods need to be called
when overriding events.

Fix screenshot.py example. Sometimes OnLoadingStateChange was called
before OnPaint resulting in error.
@cztomczak
Copy link
Owner Author

Fixes in commit de6bcd5 in the dev branch. Expose Browser.SetBounds method, update examples and documentation. There are still sometimes hangs (although rare) when resizing window in wxpython.py and qt.py examples. Needs retesting after updating to latest CEF version.

Berserker66 pushed a commit to Berserker66/cefpython that referenced this issue Nov 24, 2020
…thod,

update examples and documentation.

Fix event handling in qt.py example. Parent methods need to be called
when overriding events.

Fix screenshot.py example. Sometimes OnLoadingStateChange was called
before OnPaint resulting in error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant