Skip to content

Commit

Permalink
Add DisplayHandler.OnLoadingProgressChange (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomczak committed Aug 19, 2018
1 parent 5c15c72 commit be46962
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 34 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,11 @@ Additional information for v31.2 release:
* [DisplayHandler (interface)](api/DisplayHandler.md#displayhandler-interface)
* [OnAddressChange](api/DisplayHandler.md#onaddresschange)
* [OnAutoResize](api/DisplayHandler.md#onautoresize)
* [OnConsoleMessage](api/DisplayHandler.md#onconsolemessage)
* [OnLoadingProgressChange](api/DisplayHandler.md#onloadingprogresschange)
* [OnStatusMessage](api/DisplayHandler.md#onstatusmessage)
* [OnTitleChange](api/DisplayHandler.md#ontitlechange)
* [OnTooltip](api/DisplayHandler.md#ontooltip)
* [OnStatusMessage](api/DisplayHandler.md#onstatusmessage)
* [OnConsoleMessage](api/DisplayHandler.md#onconsolemessage)
* [DownloadHandler](api/DownloadHandler.md#downloadhandler)
* [DpiAware (class)](api/DpiAware.md#dpiaware-class)
* [CalculateWindowSize](api/DpiAware.md#calculatewindowsize)
Expand Down
5 changes: 3 additions & 2 deletions api/API-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,11 @@
* [DisplayHandler (interface)](DisplayHandler.md#displayhandler-interface)
* [OnAddressChange](DisplayHandler.md#onaddresschange)
* [OnAutoResize](DisplayHandler.md#onautoresize)
* [OnConsoleMessage](DisplayHandler.md#onconsolemessage)
* [OnLoadingProgressChange](DisplayHandler.md#onloadingprogresschange)
* [OnStatusMessage](DisplayHandler.md#onstatusmessage)
* [OnTitleChange](DisplayHandler.md#ontitlechange)
* [OnTooltip](DisplayHandler.md#ontooltip)
* [OnStatusMessage](DisplayHandler.md#onstatusmessage)
* [OnConsoleMessage](DisplayHandler.md#onconsolemessage)
* [DownloadHandler](DownloadHandler.md#downloadhandler)
* [DpiAware (class)](DpiAware.md#dpiaware-class)
* [CalculateWindowSize](DpiAware.md#calculatewindowsize)
Expand Down
66 changes: 39 additions & 27 deletions api/DisplayHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

# DisplayHandler (interface)

Implement this interface to handle events related to browser display state. The methods of this class will be called on the UI thread.

For an example of how to implement handler see [cefpython](cefpython.md).CreateBrowser(). For a list of all handler interfaces see [API > Client handlers](API#Client_handlers).
Implement this interface to handle events related to browser display
state. The methods of this class will be called on the UI thread.


Table of contents:
* [Callbacks](#callbacks)
* [OnAddressChange](#onaddresschange)
* [OnAutoResize](#onautoresize)
* [OnConsoleMessage](#onconsolemessage)
* [OnLoadingProgressChange](#onloadingprogresschange)
* [OnStatusMessage](#onstatusmessage)
* [OnTitleChange](#ontitlechange)
* [OnTooltip](#ontooltip)
* [OnStatusMessage](#onstatusmessage)
* [OnConsoleMessage](#onconsolemessage)


## Callbacks
Expand Down Expand Up @@ -49,31 +49,34 @@ Description from upstream CEF:
> default handling.

### OnTitleChange
### OnConsoleMessage

| Parameter | Type |
| --- | --- |
| browser | [Browser](Browser.md) |
| title | string |
| __Return__ | void |
| level | int |
| message | string |
| source | string |
| line | int |
| __Return__ | bool |

Called when the page title changes.
Called to display a console message. Return true to stop the message from
being output to the console.

|level| can be one of the same values as in ApplicationSettings.[log_severity](ApplicationSettings.md#log_severity).

### OnTooltip

### OnLoadingProgressChange

| Parameter | Type |
| --- | --- |
| browser | [Browser](Browser.md) |
| text_out | list |
| __Return__ | bool |
| progress | double |
| __Return__ | void |

Called when the browser is about to display a tooltip. `text_out[0]` contains the
text that will be displayed in the tooltip. To handle the display of the
tooltip yourself return true. Otherwise, you can optionally modify `text_out[0]`
and then return false to allow the browser to display the tooltip.
When window rendering is disabled the application is responsible for
drawing tooltips and the return value is ignored.
Description from upstream CEF:
> Called when the overall page loading progress has changed. |progress|
> ranges from 0.0 to 1.0.

### OnStatusMessage
Expand All @@ -87,19 +90,28 @@ drawing tooltips and the return value is ignored.
Called when the browser receives a status message.


### OnConsoleMessage
### OnTitleChange

| Parameter | Type |
| --- | --- |
| browser | [Browser](Browser.md) |
| level | int |
| message | string |
| source | string |
| line | int |
| __Return__ | bool |
| title | string |
| __Return__ | void |

Called to display a console message. Return true to stop the message from
being output to the console.
Called when the page title changes.

|level| can be one of the same values as in ApplicationSettings.[log_severity](ApplicationSettings.md#log_severity).

### OnTooltip

| Parameter | Type |
| --- | --- |
| browser | [Browser](Browser.md) |
| text_out | list |
| __Return__ | bool |

Called when the browser is about to display a tooltip. `text_out[0]` contains the
text that will be displayed in the tooltip. To handle the display of the
tooltip yourself return true. Otherwise, you can optionally modify `text_out[0]`
and then return false to allow the browser to display the tooltip.
When window rendering is disabled the application is responsible for
drawing tooltips and the return value is ignored.
3 changes: 2 additions & 1 deletion src/browser.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ cdef class PyBrowser:
# DisplayHandler
self.allowedClientCallbacks += [
"OnAddressChange", "OnTitleChange", "OnTooltip",
"OnStatusMessage", "OnConsoleMessage", "OnAutoResize"]
"OnStatusMessage", "OnConsoleMessage", "OnAutoResize",
"OnLoadingProgressChange"]
# KeyboardHandler
self.allowedClientCallbacks += ["OnPreKeyEvent", "OnKeyEvent"]
# RequestHandler
Expand Down
2 changes: 1 addition & 1 deletion src/cef_v59..v66_changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ cef_cookie.h

cef_display_handler.h
+ OnAutoResize
- OnLoadingProgressChange
+ OnLoadingProgressChange

cef_drag_data.h
+ GetImage (cross-platform)
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 @@ -54,3 +54,9 @@ bool DisplayHandler::OnAutoResize(CefRefPtr<CefBrowser> browser,
REQUIRE_UI_THREAD();
return DisplayHandler_OnAutoResize(browser, new_size);
}

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

void OnLoadingProgressChange(CefRefPtr<CefBrowser> browser,
double progress) override;

private:
IMPLEMENT_REFCOUNTING(DisplayHandler);
};
15 changes: 15 additions & 0 deletions src/handlers/display_handler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,18 @@ cdef public cpp_bool DisplayHandler_OnConsoleMessage(
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)

cdef public void DisplayHandler_OnLoadingProgressChange(
CefRefPtr[CefBrowser] cefBrowser,
double progress
) except * with gil:
cdef PyBrowser pyBrowser
cdef object callback
try:
pyBrowser = GetPyBrowser(cefBrowser, "OnLoadingProgressChange")
callback = pyBrowser.GetClientCallback("OnLoadingProgressChange")
if callback:
callback(browser=pyBrowser, progress=progress)
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
11 changes: 10 additions & 1 deletion unittests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ def test_main(self):
subtest_message("cef.CreateBrowserSync() ok")

# Client handlers
display_handler2 = DisplayHandler2(self)
client_handlers = [LoadHandler(self, g_datauri),
DisplayHandler(self),
DisplayHandler2(self)]
display_handler2]
for handler in client_handlers:
browser.SetClientHandler(handler)
subtest_message("browser.SetClientHandler() ok")
Expand Down Expand Up @@ -269,6 +270,8 @@ def test_main(self):
do_message_loop_work(25)

# Asserts before shutdown
self.assertEqual(display_handler2.OnLoadingProgressChange_Progress,
1.0)
# noinspection PyTypeChecker
check_auto_asserts(self, [] + client_handlers
+ [global_handler,
Expand All @@ -290,6 +293,8 @@ def __init__(self, test_case):
# Test whether asserts are working correctly.
self.test_for_True = True
self.OnAutoResize_True = False
self.OnLoadingProgressChange_True = False
self.OnLoadingProgressChange_Progress = 0.0

def OnAutoResize(self, new_size, **_):
self.OnAutoResize_True = True
Expand All @@ -298,6 +303,10 @@ def OnAutoResize(self, new_size, **_):
self.test_case.assertGreaterEqual(new_size[1], 600)
self.test_case.assertLessEqual(new_size[1], 768)

def OnLoadingProgressChange(self, progress, **_):
self.OnLoadingProgressChange_True = True
self.OnLoadingProgressChange_Progress = progress


class External(object):
"""Javascript 'window.external' object."""
Expand Down

0 comments on commit be46962

Please sign in to comment.