Skip to content

Commit

Permalink
Add DisplayHandler.OnAutoResize and Browser.SetAutoResizeEnabled (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomczak committed Aug 18, 2018
1 parent 1671a40 commit f8a460f
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 61 deletions.
114 changes: 59 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,61 +256,61 @@ Additional information for v31.2 release:

### API categories

#### Modules

* [cefpython](api/cefpython.md#cefpython) module


#### Settings

* [ApplicationSettings](api/ApplicationSettings.md#application-settings) dictionary
* [BrowserSettings](api/BrowserSettings.md#browser-settings) dictionary
* [CommandLineSwitches](api/CommandLineSwitches.md#command-line-switches) dictionary


#### Classes and objects

* [Browser](api/Browser.md#browser-object) object
* [Callback](api/Callback.md#callback-object) object
* [Cookie](api/Cookie.md#cookie-class) class
* [CookieManager](api/CookieManager.md#cookiemanager-class) class
* [DpiAware](api/DpiAware.md#dpiaware-class) class (Win)
* [DragData](api/DragData.md#dragdata-object) object
* [Frame](api/Frame.md#frame-object) object
* [Image](api/Image.md#image-object) object
* [JavascriptBindings](api/JavascriptBindings.md#javascriptbindings-class) class
* [JavascriptCallback](api/JavascriptCallback.md#javascriptcallback-object) object
* [PaintBuffer](api/PaintBuffer.md#paintbuffer-object) object
* [Request](api/Request.md#request-class) class
* [Response](api/Response.md#response-object) object
* [WebPluginInfo](api/WebPluginInfo.md#webplugininfo-object) object
* [WebRequest](api/WebRequest.md#webrequest-class) class
* [WindowInfo](api/WindowInfo.md#windowinfo-class) class
* [WindowUtils](api/WindowUtils.md#windowutils-class) class


#### Client handlers (interfaces)

* [AccessibilityHandler](api/AccessibilityHandler.md#accessibilityhandler-interface)
* [DisplayHandler](api/DisplayHandler.md#displayhandler-interface)
* [DownloadHandler](api/DownloadHandler.md#downloadhandler)
* [FocusHandler](api/FocusHandler.md#focushandler-interface)
* [JavascriptDialogHandler](api/JavascriptDialogHandler.md#javascriptdialoghandler-interface)
* [KeyboardHandler](api/KeyboardHandler.md#keyboardhandler-interface)
* [LifespanHandler](api/LifespanHandler.md#lifespanhandler-interface)
* [LoadHandler](api/LoadHandler.md#loadhandler-interface)
* [RenderHandler](api/RenderHandler.md#renderhandler-interface)
* [RequestHandler](api/RequestHandler.md#requesthandler-interface)
* [ResourceHandler](api/ResourceHandler.md#resourcehandler-interface)
* [V8ContextHandler](api/V8ContextHandler.md#v8contexthandler-interface)


#### Other interfaces

* [CookieVisitor](api/CookieVisitor.md#cookievisitor-interface) interface
* [StringVisitor](api/StringVisitor.md#stringvisitor-interface) interface
* [WebRequestClient](api/WebRequestClient.md#webrequestclient-interface) interface

#### Modules

* [cefpython](api/cefpython.md#cefpython) module


#### Settings

* [ApplicationSettings](api/ApplicationSettings.md#application-settings) dictionary
* [BrowserSettings](api/BrowserSettings.md#browser-settings) dictionary
* [CommandLineSwitches](api/CommandLineSwitches.md#command-line-switches) dictionary


#### Classes and objects

* [Browser](api/Browser.md#browser-object) object
* [Callback](api/Callback.md#callback-object) object
* [Cookie](api/Cookie.md#cookie-class) class
* [CookieManager](api/CookieManager.md#cookiemanager-class) class
* [DpiAware](api/DpiAware.md#dpiaware-class) class (Win)
* [DragData](api/DragData.md#dragdata-object) object
* [Frame](api/Frame.md#frame-object) object
* [Image](api/Image.md#image-object) object
* [JavascriptBindings](api/JavascriptBindings.md#javascriptbindings-class) class
* [JavascriptCallback](api/JavascriptCallback.md#javascriptcallback-object) object
* [PaintBuffer](api/PaintBuffer.md#paintbuffer-object) object
* [Request](api/Request.md#request-class) class
* [Response](api/Response.md#response-object) object
* [WebPluginInfo](api/WebPluginInfo.md#webplugininfo-object) object
* [WebRequest](api/WebRequest.md#webrequest-class) class
* [WindowInfo](api/WindowInfo.md#windowinfo-class) class
* [WindowUtils](api/WindowUtils.md#windowutils-class) class


#### Client handlers (interfaces)

* [AccessibilityHandler](api/AccessibilityHandler.md#accessibilityhandler-interface)
* [DisplayHandler](api/DisplayHandler.md#displayhandler-interface)
* [DownloadHandler](api/DownloadHandler.md#downloadhandler)
* [FocusHandler](api/FocusHandler.md#focushandler-interface)
* [JavascriptDialogHandler](api/JavascriptDialogHandler.md#javascriptdialoghandler-interface)
* [KeyboardHandler](api/KeyboardHandler.md#keyboardhandler-interface)
* [LifespanHandler](api/LifespanHandler.md#lifespanhandler-interface)
* [LoadHandler](api/LoadHandler.md#loadhandler-interface)
* [RenderHandler](api/RenderHandler.md#renderhandler-interface)
* [RequestHandler](api/RequestHandler.md#requesthandler-interface)
* [ResourceHandler](api/ResourceHandler.md#resourcehandler-interface)
* [V8ContextHandler](api/V8ContextHandler.md#v8contexthandler-interface)


#### Other interfaces

* [CookieVisitor](api/CookieVisitor.md#cookievisitor-interface) interface
* [StringVisitor](api/StringVisitor.md#stringvisitor-interface) interface
* [WebRequestClient](api/WebRequestClient.md#webrequestclient-interface) interface


### API index

Expand Down Expand Up @@ -391,6 +391,7 @@ Additional information for v31.2 release:
* [HandleKeyEventAfterTextInputClient](api/Browser.md#handlekeyeventaftertextinputclient)
* [HandleKeyEventBeforeTextInputClient](api/Browser.md#handlekeyeventbeforetextinputclient)
* [HasDocument](api/Browser.md#hasdocument)
* [Invalidate](api/Browser.md#invalidate)
* [IsFullscreen](api/Browser.md#isfullscreen)
* [IsLoading](api/Browser.md#isloading)
* [IsMouseCursorChangeDisabled](api/Browser.md#ismousecursorchangedisabled)
Expand All @@ -405,6 +406,7 @@ Additional information for v31.2 release:
* [Reload](api/Browser.md#reload)
* [ReloadIgnoreCache](api/Browser.md#reloadignorecache)
* [ReplaceMisspelling](api/Browser.md#replacemisspelling)
* [SetAutoResizeEnabled](api/Browser.md#setautoresizeenabled)
* [SetBounds](api/Browser.md#setbounds)
* [SendKeyEvent](api/Browser.md#sendkeyevent)
* [SendMouseClickEvent](api/Browser.md#sendmouseclickevent)
Expand Down Expand Up @@ -519,6 +521,7 @@ Additional information for v31.2 release:
* [Visit](api/CookieVisitor.md#visit)
* [DisplayHandler (interface)](api/DisplayHandler.md#displayhandler-interface)
* [OnAddressChange](api/DisplayHandler.md#onaddresschange)
* [OnAutoResize](api/DisplayHandler.md#onautoresize)
* [OnTitleChange](api/DisplayHandler.md#ontitlechange)
* [OnTooltip](api/DisplayHandler.md#ontooltip)
* [OnStatusMessage](api/DisplayHandler.md#onstatusmessage)
Expand Down Expand Up @@ -670,6 +673,7 @@ Additional information for v31.2 release:
* [OnPaint](api/RenderHandler.md#onpaint)
* [OnCursorChange](api/RenderHandler.md#oncursorchange)
* [OnScrollOffsetChanged](api/RenderHandler.md#onscrolloffsetchanged)
* [OnTextSelectionChanged](api/RenderHandler.md#ontextselectionchanged)
* [StartDragging](api/RenderHandler.md#startdragging)
* [UpdateDragCursor](api/RenderHandler.md#updatedragcursor)
* [Request (class)](api/Request.md#request-class)
Expand Down
4 changes: 4 additions & 0 deletions api/API-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
* [HandleKeyEventAfterTextInputClient](Browser.md#handlekeyeventaftertextinputclient)
* [HandleKeyEventBeforeTextInputClient](Browser.md#handlekeyeventbeforetextinputclient)
* [HasDocument](Browser.md#hasdocument)
* [Invalidate](Browser.md#invalidate)
* [IsFullscreen](Browser.md#isfullscreen)
* [IsLoading](Browser.md#isloading)
* [IsMouseCursorChangeDisabled](Browser.md#ismousecursorchangedisabled)
Expand All @@ -93,6 +94,7 @@
* [Reload](Browser.md#reload)
* [ReloadIgnoreCache](Browser.md#reloadignorecache)
* [ReplaceMisspelling](Browser.md#replacemisspelling)
* [SetAutoResizeEnabled](Browser.md#setautoresizeenabled)
* [SetBounds](Browser.md#setbounds)
* [SendKeyEvent](Browser.md#sendkeyevent)
* [SendMouseClickEvent](Browser.md#sendmouseclickevent)
Expand Down Expand Up @@ -207,6 +209,7 @@
* [Visit](CookieVisitor.md#visit)
* [DisplayHandler (interface)](DisplayHandler.md#displayhandler-interface)
* [OnAddressChange](DisplayHandler.md#onaddresschange)
* [OnAutoResize](DisplayHandler.md#onautoresize)
* [OnTitleChange](DisplayHandler.md#ontitlechange)
* [OnTooltip](DisplayHandler.md#ontooltip)
* [OnStatusMessage](DisplayHandler.md#onstatusmessage)
Expand Down Expand Up @@ -358,6 +361,7 @@
* [OnPaint](RenderHandler.md#onpaint)
* [OnCursorChange](RenderHandler.md#oncursorchange)
* [OnScrollOffsetChanged](RenderHandler.md#onscrolloffsetchanged)
* [OnTextSelectionChanged](RenderHandler.md#ontextselectionchanged)
* [StartDragging](RenderHandler.md#startdragging)
* [UpdateDragCursor](RenderHandler.md#updatedragcursor)
* [Request (class)](Request.md#request-class)
Expand Down
17 changes: 17 additions & 0 deletions api/Browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Table of contents:
* [HandleKeyEventAfterTextInputClient](#handlekeyeventaftertextinputclient)
* [HandleKeyEventBeforeTextInputClient](#handlekeyeventbeforetextinputclient)
* [HasDocument](#hasdocument)
* [Invalidate](#invalidate)
* [IsFullscreen](#isfullscreen)
* [IsLoading](#isloading)
* [IsMouseCursorChangeDisabled](#ismousecursorchangedisabled)
Expand All @@ -69,6 +70,7 @@ Table of contents:
* [Reload](#reload)
* [ReloadIgnoreCache](#reloadignorecache)
* [ReplaceMisspelling](#replacemisspelling)
* [SetAutoResizeEnabled](#setautoresizeenabled)
* [SetBounds](#setbounds)
* [SendKeyEvent](#sendkeyevent)
* [SendMouseClickEvent](#sendmouseclickevent)
Expand Down Expand Up @@ -753,6 +755,21 @@ If a misspelled word is currently selected in an editable node calling
this method will replace it with the specified |word|.


### SetAutoResizeEnabled

| Parameter | Type |
| --- | --- |
| enabled | bool |
| min_size | list[width, height] |
| max_size | list[width, heifght] |
| __Return__ | void |

Description from upstream CEF:
> Enable notifications of auto resize via CefDisplayHandler::OnAutoResize.
> Notifications are disabled by default. |min_size| and |max_size| define the
> range of allowed sizes.

### SetBounds

| Parameter | Type |
Expand Down
17 changes: 17 additions & 0 deletions api/DisplayHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For an example of how to implement handler see [cefpython](cefpython.md).CreateB
Table of contents:
* [Callbacks](#callbacks)
* [OnAddressChange](#onaddresschange)
* [OnAutoResize](#onautoresize)
* [OnTitleChange](#ontitlechange)
* [OnTooltip](#ontooltip)
* [OnStatusMessage](#onstatusmessage)
Expand All @@ -32,6 +33,22 @@ Table of contents:
Called when a frame's address has changed.



### OnAutoResize

| Parameter | Type |
| --- | --- |
| browser | [Browser](Browser.md) |
| new_size | list[width, height] |
| __Return__ | bool |

Description from upstream CEF:
> Called when auto-resize is enabled via CefBrowserHost::SetAutoResizeEnabled
> and the contents have auto-resized. |new_size| will be the desired size in
> view coordinates. Return true if the resize was handled or false for
> default handling.

### OnTitleChange

| Parameter | Type |
Expand Down
1 change: 1 addition & 0 deletions api/RenderHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Table of contents:
* [OnPaint](#onpaint)
* [OnCursorChange](#oncursorchange)
* [OnScrollOffsetChanged](#onscrolloffsetchanged)
* [OnTextSelectionChanged](#ontextselectionchanged)
* [StartDragging](#startdragging)
* [UpdateDragCursor](#updatedragcursor)

Expand Down
13 changes: 12 additions & 1 deletion src/browser.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ cdef class PyBrowser:
# DisplayHandler
self.allowedClientCallbacks += [
"OnAddressChange", "OnTitleChange", "OnTooltip",
"OnStatusMessage", "OnConsoleMessage"]
"OnStatusMessage", "OnConsoleMessage", "OnAutoResize"]
# KeyboardHandler
self.allowedClientCallbacks += ["OnPreKeyEvent", "OnKeyEvent"]
# RequestHandler
Expand Down Expand Up @@ -513,6 +513,17 @@ cdef class PyBrowser:
PyToCefString(word, cef_word)
self.GetCefBrowserHost().get().ReplaceMisspelling(cef_word)

cpdef py_void SetAutoResizeEnabled(self,
py_bool enabled,
list min_size,
list max_size):
self.GetCefBrowserHost().get().SetAutoResizeEnabled(
bool(enabled),
CefSize(min_size[0], min_size[1]),
CefSize(max_size[0], max_size[1])
)


cpdef py_void SetBounds(self, int x, int y, int width, int height):
IF UNAME_SYSNAME == "Linux":
x11.SetX11WindowBounds(self.GetCefBrowser(), x, y, width, height)
Expand Down
4 changes: 2 additions & 2 deletions src/cef_v59..v66_changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ cef_render_handler.h

cef_browser.h
+ SetAccessibilityState
- SetAutoResizeEnabled
+ SetAutoResizeEnabled
- GetExtension
- IsBackgroundHost

cef_cookie.h
- GetBlockingManager

cef_display_handler.h
- OnAutoResize
+ OnAutoResize
- OnLoadingProgressChange

cef_drag_data.h
Expand Down
6 changes: 6 additions & 0 deletions src/client_handler/display_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ bool DisplayHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
return DisplayHandler_OnConsoleMessage(browser, level, message, source,
line);
}

bool DisplayHandler::OnAutoResize(CefRefPtr<CefBrowser> browser,
const CefSize& new_size) {
REQUIRE_UI_THREAD();
return DisplayHandler_OnAutoResize(browser, new_size);
}
3 changes: 3 additions & 0 deletions src/client_handler/display_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class DisplayHandler : public CefDisplayHandler
const CefString& source,
int line) override;

bool OnAutoResize(CefRefPtr<CefBrowser> browser,
const CefSize& new_size) override;

private:
IMPLEMENT_REFCOUNTING(DisplayHandler);
};
7 changes: 5 additions & 2 deletions src/extern/cef/cef_browser.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ from libcpp cimport bool as cpp_bool
from libcpp.vector cimport vector as cpp_vector
from cef_frame cimport CefFrame
cimport cef_types
from cef_types cimport int64, cef_state_t, PaintElementType
from cef_types cimport int64, cef_state_t, CefSize
from cef_types cimport CefBrowserSettings, CefPoint
from cef_drag_data cimport CefDragData
from cef_types cimport CefMouseEvent
Expand Down Expand Up @@ -87,7 +87,10 @@ cdef extern from "include/cef_browser.h":
void AddWordToDictionary(const CefString& word)

void SetAccessibilityState(cef_state_t accessibility_state)
void Invalidate(cef_types.cef_paint_element_type_t type)
void Invalidate(cef_types.cef_paint_element_type_t element_type)
void SetAutoResizeEnabled(cpp_bool enabled,
const CefSize& min_size,
const CefSize& max_size)


cdef cppclass CefBrowser:
Expand Down
19 changes: 19 additions & 0 deletions src/handlers/display_handler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ cdef public void DisplayHandler_OnAddressChange(
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)


cdef public cpp_bool DisplayHandler_OnAutoResize(
CefRefPtr[CefBrowser] cef_browser,
const CefSize& new_size
) except * with gil:
cdef PyBrowser browser
cdef object callback
try:
browser = GetPyBrowser(cef_browser, "OnAutoResize")
callback = browser.GetClientCallback("OnAutoResize")
if callback:
return bool(callback(browser=browser, new_size=[new_size.width,
new_size.height]))
return False
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)


cdef public void DisplayHandler_OnTitleChange(
CefRefPtr[CefBrowser] cefBrowser,
const CefString& cefTitle
Expand Down
9 changes: 9 additions & 0 deletions unittests/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@

import base64
import os
import platform
import sys
import time

# Platforms
SYSTEM = platform.system().upper()
if SYSTEM == "DARWIN":
SYSTEM = "MAC"
WINDOWS = SYSTEM if SYSTEM == "WINDOWS" else False
LINUX = SYSTEM if SYSTEM == "LINUX" else False
MAC = SYSTEM if SYSTEM == "MAC" else False

# To show the window for an extended period of time increase this number.
MESSAGE_LOOP_RANGE = 100 # each iteration is 0.01 sec

Expand Down
Loading

0 comments on commit f8a460f

Please sign in to comment.