Skip to content

Commit be46962

Browse files
committed
Add DisplayHandler.OnLoadingProgressChange (cztomczak#403)
1 parent 5c15c72 commit be46962

File tree

9 files changed

+82
-34
lines changed

9 files changed

+82
-34
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,11 @@ Additional information for v31.2 release:
527527
* [DisplayHandler (interface)](api/DisplayHandler.md#displayhandler-interface)
528528
* [OnAddressChange](api/DisplayHandler.md#onaddresschange)
529529
* [OnAutoResize](api/DisplayHandler.md#onautoresize)
530+
* [OnConsoleMessage](api/DisplayHandler.md#onconsolemessage)
531+
* [OnLoadingProgressChange](api/DisplayHandler.md#onloadingprogresschange)
532+
* [OnStatusMessage](api/DisplayHandler.md#onstatusmessage)
530533
* [OnTitleChange](api/DisplayHandler.md#ontitlechange)
531534
* [OnTooltip](api/DisplayHandler.md#ontooltip)
532-
* [OnStatusMessage](api/DisplayHandler.md#onstatusmessage)
533-
* [OnConsoleMessage](api/DisplayHandler.md#onconsolemessage)
534535
* [DownloadHandler](api/DownloadHandler.md#downloadhandler)
535536
* [DpiAware (class)](api/DpiAware.md#dpiaware-class)
536537
* [CalculateWindowSize](api/DpiAware.md#calculatewindowsize)

api/API-index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,11 @@
215215
* [DisplayHandler (interface)](DisplayHandler.md#displayhandler-interface)
216216
* [OnAddressChange](DisplayHandler.md#onaddresschange)
217217
* [OnAutoResize](DisplayHandler.md#onautoresize)
218+
* [OnConsoleMessage](DisplayHandler.md#onconsolemessage)
219+
* [OnLoadingProgressChange](DisplayHandler.md#onloadingprogresschange)
220+
* [OnStatusMessage](DisplayHandler.md#onstatusmessage)
218221
* [OnTitleChange](DisplayHandler.md#ontitlechange)
219222
* [OnTooltip](DisplayHandler.md#ontooltip)
220-
* [OnStatusMessage](DisplayHandler.md#onstatusmessage)
221-
* [OnConsoleMessage](DisplayHandler.md#onconsolemessage)
222223
* [DownloadHandler](DownloadHandler.md#downloadhandler)
223224
* [DpiAware (class)](DpiAware.md#dpiaware-class)
224225
* [CalculateWindowSize](DpiAware.md#calculatewindowsize)

api/DisplayHandler.md

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33

44
# DisplayHandler (interface)
55

6-
Implement this interface to handle events related to browser display state. The methods of this class will be called on the UI thread.
7-
8-
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).
6+
Implement this interface to handle events related to browser display
7+
state. The methods of this class will be called on the UI thread.
98

109

1110
Table of contents:
1211
* [Callbacks](#callbacks)
1312
* [OnAddressChange](#onaddresschange)
1413
* [OnAutoResize](#onautoresize)
14+
* [OnConsoleMessage](#onconsolemessage)
15+
* [OnLoadingProgressChange](#onloadingprogresschange)
16+
* [OnStatusMessage](#onstatusmessage)
1517
* [OnTitleChange](#ontitlechange)
1618
* [OnTooltip](#ontooltip)
17-
* [OnStatusMessage](#onstatusmessage)
18-
* [OnConsoleMessage](#onconsolemessage)
1919

2020

2121
## Callbacks
@@ -49,31 +49,34 @@ Description from upstream CEF:
4949
> default handling.
5050
5151

52-
### OnTitleChange
52+
### OnConsoleMessage
5353

5454
| Parameter | Type |
5555
| --- | --- |
5656
| browser | [Browser](Browser.md) |
57-
| title | string |
58-
| __Return__ | void |
57+
| level | int |
58+
| message | string |
59+
| source | string |
60+
| line | int |
61+
| __Return__ | bool |
5962

60-
Called when the page title changes.
63+
Called to display a console message. Return true to stop the message from
64+
being output to the console.
6165

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

63-
### OnTooltip
68+
69+
### OnLoadingProgressChange
6470

6571
| Parameter | Type |
6672
| --- | --- |
6773
| browser | [Browser](Browser.md) |
68-
| text_out | list |
69-
| __Return__ | bool |
74+
| progress | double |
75+
| __Return__ | void |
7076

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

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

8992

90-
### OnConsoleMessage
93+
### OnTitleChange
9194

9295
| Parameter | Type |
9396
| --- | --- |
9497
| browser | [Browser](Browser.md) |
95-
| level | int |
96-
| message | string |
97-
| source | string |
98-
| line | int |
99-
| __Return__ | bool |
98+
| title | string |
99+
| __Return__ | void |
100100

101-
Called to display a console message. Return true to stop the message from
102-
being output to the console.
101+
Called when the page title changes.
103102

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

104+
### OnTooltip
105+
106+
| Parameter | Type |
107+
| --- | --- |
108+
| browser | [Browser](Browser.md) |
109+
| text_out | list |
110+
| __Return__ | bool |
111+
112+
Called when the browser is about to display a tooltip. `text_out[0]` contains the
113+
text that will be displayed in the tooltip. To handle the display of the
114+
tooltip yourself return true. Otherwise, you can optionally modify `text_out[0]`
115+
and then return false to allow the browser to display the tooltip.
116+
When window rendering is disabled the application is responsible for
117+
drawing tooltips and the return value is ignored.

src/browser.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ cdef class PyBrowser:
235235
# DisplayHandler
236236
self.allowedClientCallbacks += [
237237
"OnAddressChange", "OnTitleChange", "OnTooltip",
238-
"OnStatusMessage", "OnConsoleMessage", "OnAutoResize"]
238+
"OnStatusMessage", "OnConsoleMessage", "OnAutoResize",
239+
"OnLoadingProgressChange"]
239240
# KeyboardHandler
240241
self.allowedClientCallbacks += ["OnPreKeyEvent", "OnKeyEvent"]
241242
# RequestHandler

src/cef_v59..v66_changes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ cef_cookie.h
107107

108108
cef_display_handler.h
109109
+ OnAutoResize
110-
- OnLoadingProgressChange
110+
+ OnLoadingProgressChange
111111

112112
cef_drag_data.h
113113
+ GetImage (cross-platform)

src/client_handler/display_handler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,9 @@ bool DisplayHandler::OnAutoResize(CefRefPtr<CefBrowser> browser,
5454
REQUIRE_UI_THREAD();
5555
return DisplayHandler_OnAutoResize(browser, new_size);
5656
}
57+
58+
void DisplayHandler::OnLoadingProgressChange(CefRefPtr<CefBrowser> browser,
59+
double progress) {
60+
REQUIRE_UI_THREAD();
61+
return DisplayHandler_OnLoadingProgressChange(browser, progress);
62+
}

src/client_handler/display_handler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class DisplayHandler : public CefDisplayHandler
3636
bool OnAutoResize(CefRefPtr<CefBrowser> browser,
3737
const CefSize& new_size) override;
3838

39+
void OnLoadingProgressChange(CefRefPtr<CefBrowser> browser,
40+
double progress) override;
41+
3942
private:
4043
IMPLEMENT_REFCOUNTING(DisplayHandler);
4144
};

src/handlers/display_handler.pyx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,18 @@ cdef public cpp_bool DisplayHandler_OnConsoleMessage(
128128
except:
129129
(exc_type, exc_value, exc_trace) = sys.exc_info()
130130
sys.excepthook(exc_type, exc_value, exc_trace)
131+
132+
cdef public void DisplayHandler_OnLoadingProgressChange(
133+
CefRefPtr[CefBrowser] cefBrowser,
134+
double progress
135+
) except * with gil:
136+
cdef PyBrowser pyBrowser
137+
cdef object callback
138+
try:
139+
pyBrowser = GetPyBrowser(cefBrowser, "OnLoadingProgressChange")
140+
callback = pyBrowser.GetClientCallback("OnLoadingProgressChange")
141+
if callback:
142+
callback(browser=pyBrowser, progress=progress)
143+
except:
144+
(exc_type, exc_value, exc_trace) = sys.exc_info()
145+
sys.excepthook(exc_type, exc_value, exc_trace)

unittests/main_test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ def test_main(self):
168168
subtest_message("cef.CreateBrowserSync() ok")
169169

170170
# Client handlers
171+
display_handler2 = DisplayHandler2(self)
171172
client_handlers = [LoadHandler(self, g_datauri),
172173
DisplayHandler(self),
173-
DisplayHandler2(self)]
174+
display_handler2]
174175
for handler in client_handlers:
175176
browser.SetClientHandler(handler)
176177
subtest_message("browser.SetClientHandler() ok")
@@ -269,6 +270,8 @@ def test_main(self):
269270
do_message_loop_work(25)
270271

271272
# Asserts before shutdown
273+
self.assertEqual(display_handler2.OnLoadingProgressChange_Progress,
274+
1.0)
272275
# noinspection PyTypeChecker
273276
check_auto_asserts(self, [] + client_handlers
274277
+ [global_handler,
@@ -290,6 +293,8 @@ def __init__(self, test_case):
290293
# Test whether asserts are working correctly.
291294
self.test_for_True = True
292295
self.OnAutoResize_True = False
296+
self.OnLoadingProgressChange_True = False
297+
self.OnLoadingProgressChange_Progress = 0.0
293298

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

306+
def OnLoadingProgressChange(self, progress, **_):
307+
self.OnLoadingProgressChange_True = True
308+
self.OnLoadingProgressChange_Progress = progress
309+
301310

302311
class External(object):
303312
"""Javascript 'window.external' object."""

0 commit comments

Comments
 (0)