Add DisplayHandler.OnAutoResize and Browser.SetAutoResizeEnabled (#403) · pythonthings/cefpython@f8a460f · GitHub
Skip to content

Commit f8a460f

Browse files
committed
Add DisplayHandler.OnAutoResize and Browser.SetAutoResizeEnabled (cztomczak#403)
1 parent 1671a40 commit f8a460f

13 files changed

Lines changed: 179 additions & 61 deletions

README.md

Lines changed: 59 additions & 55 deletions

api/API-index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
* [HandleKeyEventAfterTextInputClient](Browser.md#handlekeyeventaftertextinputclient)
8080
* [HandleKeyEventBeforeTextInputClient](Browser.md#handlekeyeventbeforetextinputclient)
8181
* [HasDocument](Browser.md#hasdocument)
82+
* [Invalidate](Browser.md#invalidate)
8283
* [IsFullscreen](Browser.md#isfullscreen)
8384
* [IsLoading](Browser.md#isloading)
8485
* [IsMouseCursorChangeDisabled](Browser.md#ismousecursorchangedisabled)
@@ -93,6 +94,7 @@
9394
* [Reload](Browser.md#reload)
9495
* [ReloadIgnoreCache](Browser.md#reloadignorecache)
9596
* [ReplaceMisspelling](Browser.md#replacemisspelling)
97+
* [SetAutoResizeEnabled](Browser.md#setautoresizeenabled)
9698
* [SetBounds](Browser.md#setbounds)
9799
* [SendKeyEvent](Browser.md#sendkeyevent)
98100
* [SendMouseClickEvent](Browser.md#sendmouseclickevent)
@@ -207,6 +209,7 @@
207209
* [Visit](CookieVisitor.md#visit)
208210
* [DisplayHandler (interface)](DisplayHandler.md#displayhandler-interface)
209211
* [OnAddressChange](DisplayHandler.md#onaddresschange)
212+
* [OnAutoResize](DisplayHandler.md#onautoresize)
210213
* [OnTitleChange](DisplayHandler.md#ontitlechange)
211214
* [OnTooltip](DisplayHandler.md#ontooltip)
212215
* [OnStatusMessage](DisplayHandler.md#onstatusmessage)
@@ -358,6 +361,7 @@
358361
* [OnPaint](RenderHandler.md#onpaint)
359362
* [OnCursorChange](RenderHandler.md#oncursorchange)
360363
* [OnScrollOffsetChanged](RenderHandler.md#onscrolloffsetchanged)
364+
* [OnTextSelectionChanged](RenderHandler.md#ontextselectionchanged)
361365
* [StartDragging](RenderHandler.md#startdragging)
362366
* [UpdateDragCursor](RenderHandler.md#updatedragcursor)
363367
* [Request (class)](Request.md#request-class)

api/Browser.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Table of contents:
5555
* [HandleKeyEventAfterTextInputClient](#handlekeyeventaftertextinputclient)
5656
* [HandleKeyEventBeforeTextInputClient](#handlekeyeventbeforetextinputclient)
5757
* [HasDocument](#hasdocument)
58+
* [Invalidate](#invalidate)
5859
* [IsFullscreen](#isfullscreen)
5960
* [IsLoading](#isloading)
6061
* [IsMouseCursorChangeDisabled](#ismousecursorchangedisabled)
@@ -69,6 +70,7 @@ Table of contents:
6970
* [Reload](#reload)
7071
* [ReloadIgnoreCache](#reloadignorecache)
7172
* [ReplaceMisspelling](#replacemisspelling)
73+
* [SetAutoResizeEnabled](#setautoresizeenabled)
7274
* [SetBounds](#setbounds)
7375
* [SendKeyEvent](#sendkeyevent)
7476
* [SendMouseClickEvent](#sendmouseclickevent)
@@ -753,6 +755,21 @@ If a misspelled word is currently selected in an editable node calling
753755
this method will replace it with the specified |word|.
754756

755757

758+
### SetAutoResizeEnabled
759+
760+
| Parameter | Type |
761+
| --- | --- |
762+
| enabled | bool |
763+
| min_size | list[width, height] |
764+
| max_size | list[width, heifght] |
765+
| __Return__ | void |
766+
767+
Description from upstream CEF:
768+
> Enable notifications of auto resize via CefDisplayHandler::OnAutoResize.
769+
> Notifications are disabled by default. |min_size| and |max_size| define the
770+
> range of allowed sizes.
771+
772+
756773
### SetBounds
757774

758775
| Parameter | Type |

api/DisplayHandler.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ For an example of how to implement handler see [cefpython](cefpython.md).CreateB
1111
Table of contents:
1212
* [Callbacks](#callbacks)
1313
* [OnAddressChange](#onaddresschange)
14+
* [OnAutoResize](#onautoresize)
1415
* [OnTitleChange](#ontitlechange)
1516
* [OnTooltip](#ontooltip)
1617
* [OnStatusMessage](#onstatusmessage)
@@ -32,6 +33,22 @@ Table of contents:
3233
Called when a frame's address has changed.
3334

3435

36+
37+
### OnAutoResize
38+
39+
| Parameter | Type |
40+
| --- | --- |
41+
| browser | [Browser](Browser.md) |
42+
| new_size | list[width, height] |
43+
| __Return__ | bool |
44+
45+
Description from upstream CEF:
46+
> Called when auto-resize is enabled via CefBrowserHost::SetAutoResizeEnabled
47+
> and the contents have auto-resized. |new_size| will be the desired size in
48+
> view coordinates. Return true if the resize was handled or false for
49+
> default handling.
50+
51+
3552
### OnTitleChange
3653

3754
| Parameter | Type |

api/RenderHandler.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Table of contents:
2222
* [OnPaint](#onpaint)
2323
* [OnCursorChange](#oncursorchange)
2424
* [OnScrollOffsetChanged](#onscrolloffsetchanged)
25+
* [OnTextSelectionChanged](#ontextselectionchanged)
2526
* [StartDragging](#startdragging)
2627
* [UpdateDragCursor](#updatedragcursor)
2728

src/browser.pyx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ cdef class PyBrowser:
218218
# DisplayHandler
219219
self.allowedClientCallbacks += [
220220
"OnAddressChange", "OnTitleChange", "OnTooltip",
221-
"OnStatusMessage", "OnConsoleMessage"]
221+
"OnStatusMessage", "OnConsoleMessage", "OnAutoResize"]
222222
# KeyboardHandler
223223
self.allowedClientCallbacks += ["OnPreKeyEvent", "OnKeyEvent"]
224224
# RequestHandler
@@ -513,6 +513,17 @@ cdef class PyBrowser:
513513
PyToCefString(word, cef_word)
514514
self.GetCefBrowserHost().get().ReplaceMisspelling(cef_word)
515515

516+
cpdef py_void SetAutoResizeEnabled(self,
517+
py_bool enabled,
518+
list min_size,
519+
list max_size):
520+
self.GetCefBrowserHost().get().SetAutoResizeEnabled(
521+
bool(enabled),
522+
CefSize(min_size[0], min_size[1]),
523+
CefSize(max_size[0], max_size[1])
524+
)
525+
526+
516527
cpdef py_void SetBounds(self, int x, int y, int width, int height):
517528
IF UNAME_SYSNAME == "Linux":
518529
x11.SetX11WindowBounds(self.GetCefBrowser(), x, y, width, height)

src/cef_v59..v66_changes.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ cef_render_handler.h
9393

9494
cef_browser.h
9595
+ SetAccessibilityState
96-
- SetAutoResizeEnabled
96+
+ SetAutoResizeEnabled
9797
- GetExtension
9898
- IsBackgroundHost
9999

100100
cef_cookie.h
101101
- GetBlockingManager
102102

103103
cef_display_handler.h
104-
- OnAutoResize
104+
+ OnAutoResize
105105
- OnLoadingProgressChange
106106

107107
cef_drag_data.h

src/client_handler/display_handler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ bool DisplayHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
4848
return DisplayHandler_OnConsoleMessage(browser, level, message, source,
4949
line);
5050
}
51+
52+
bool DisplayHandler::OnAutoResize(CefRefPtr<CefBrowser> browser,
53+
const CefSize& new_size) {
54+
REQUIRE_UI_THREAD();
55+
return DisplayHandler_OnAutoResize(browser, new_size);
56+
}

src/client_handler/display_handler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class DisplayHandler : public CefDisplayHandler
3333
const CefString& source,
3434
int line) override;
3535

36+
bool OnAutoResize(CefRefPtr<CefBrowser> browser,
37+
const CefSize& new_size) override;
38+
3639
private:
3740
IMPLEMENT_REFCOUNTING(DisplayHandler);
3841
};

src/extern/cef/cef_browser.pxd

Lines changed: 5 additions & 2 deletions

0 commit comments

Comments
 (0)