Ultralight C++ API 1.3.0
Loading...
Searching...
No Matches
Listener.h
Go to the documentation of this file.
1/******************************************************************************
2 * This file is a part of Ultralight, an ultra-portable web-browser engine. *
3 * *
4 * See <https://ultralig.ht> for licensing and more. *
5 * *
6 * (C) 2023 Ultralight, Inc. *
7 *****************************************************************************/
8#pragma once
10#include <Ultralight/String.h>
11#include <Ultralight/RefPtr.h>
12#include <Ultralight/Geometry.h>
13
14namespace ultralight {
15
16class View;
17
18///
19/// MessageSource types, @see ViewListener::OnAddConsoleMessage
20///
33};
34
35///
36/// MessageLevel types, @see ViewListener::OnAddConsoleMessage
37///
44};
45
46///
47/// Cursor types, @see ViewListener::OnChangeCursor
48///
49enum Cursor {
94};
95
96///
97/// User-defined interface to listen for View-specific events.
98///
99/// @see View::set_view_listener
100///
102 public:
103 virtual ~ViewListener() { }
104
105 ///
106 /// Called when the page title changes
107 ///
108 virtual void OnChangeTitle(ultralight::View* caller, const String& title) { }
109
110 ///
111 /// Called when the page URL changes
112 ///
113 virtual void OnChangeURL(ultralight::View* caller, const String& url) { }
114
115 ///
116 /// Called when the tooltip changes (usually as result of a mouse hover)
117 ///
118 virtual void OnChangeTooltip(ultralight::View* caller, const String& tooltip) { }
119
120 ///
121 /// Called when the mouse cursor changes
122 ///
123 virtual void OnChangeCursor(ultralight::View* caller, Cursor cursor) { }
124
125 ///
126 /// Called when a message is added to the console (useful for errors / debug)
127 ///
129 MessageLevel level, const String& message, uint32_t line_number,
130 uint32_t column_number, const String& source_id) { }
131
132 ///
133 /// Called when the page wants to create a new child View.
134 ///
135 /// This is usually the result of a user clicking a link with target="_blank"
136 /// or by JavaScript calling window.open(url).
137 ///
138 /// To allow creation of these new Views, you should create a new View in this callback (eg,
139 /// Renderer::CreateView()), resize it to your container, and return it. You are responsible for
140 /// displaying the returned View.
141 ///
142 /// @param caller The View that called this event.
143 ///
144 /// @param opener_url The URL of the page that initiated this request.
145 ///
146 /// @param target_url The URL that the new View will navigate to.
147 ///
148 /// @param is_popup Whether or not this was triggered by window.open().
149 ///
150 /// @param popup_rect Popups can optionally request certain dimensions and coordinates via
151 /// window.open(). You can choose to respect these or not by resizing/moving
152 /// the View to this rect.
153 ///
154 /// @return Returns a RefPtr to a created View to use to satisfy the the request (or return
155 /// nullptr if you want to block the action).
156 ///
157 virtual RefPtr<View> OnCreateChildView(ultralight::View* caller, const String& opener_url,
158 const String& target_url, bool is_popup,
159 const IntRect& popup_rect);
160
161 ///
162 /// Called when the page wants to create a new View to display the local inspector in.
163 ///
164 /// You should create a new View in this callback (eg, Renderer::CreateView()), resize it to your
165 /// container, and return it. You are responsible for displaying the returned View.
166 ///
167 /// @return Returns a RefPtr to a created View to use to satisfy the the request (or return
168 /// nullptr if you want to block the action).
169 ///
171 const String& inspected_url);
172
173 ///
174 /// Called when the page requests to be closed.
175 ///
176 virtual void OnRequestClose(ultralight::View* caller) { }
177
178};
179
180///
181/// User-defined interface to listen for load-related events for a View.
182///
183/// @see View::set_load_listener
184///
186 public:
187 virtual ~LoadListener() { }
188
189 ///
190 /// Called when the page begins loading a new URL into a frame.
191 ///
192 /// @param frame_id A unique ID for the frame.
193 ///
194 /// @param is_main_frame Whether or not this is the main frame.
195 ///
196 /// @param url The URL for the load.
197 ///
198 virtual void OnBeginLoading(ultralight::View* caller, uint64_t frame_id, bool is_main_frame,
199 const String& url) { }
200
201 ///
202 /// Called when the page finishes loading a URL into a frame.
203 ///
204 /// @param frame_id A unique ID for the frame.
205 ///
206 /// @param is_main_frame Whether or not this is the main frame.
207 ///
208 /// @param url The URL for the load.
209 ///
210 virtual void OnFinishLoading(ultralight::View* caller, uint64_t frame_id, bool is_main_frame,
211 const String& url) { }
212
213 ///
214 /// Called when an error occurs while loading a URL into a frame.
215 ///
216 /// @param frame_id A unique ID for the frame.
217 ///
218 /// @param is_main_frame Whether or not this is the main frame.
219 ///
220 /// @param url The URL for the load.
221 ///
222 /// @param description A human-readable description of the error.
223 ///
224 /// @param error_domain The name of the module that triggered the error.
225 ///
226 /// @param error_code Internal error code generated by the module.
227 ///
228 virtual void OnFailLoading(ultralight::View* caller, uint64_t frame_id, bool is_main_frame,
229 const String& url, const String& description,
230 const String& error_domain, int error_code) { }
231
232 ///
233 /// Called when the JavaScript window object is reset for a new page load.
234 ///
235 /// This is called before any scripts are executed on the page and is the earliest time to setup
236 /// any initial JavaScript state or bindings.
237 ///
238 /// The document is not guaranteed to be loaded/parsed at this point. If you need to make any
239 /// JavaScript calls that are dependent on DOM elements or scripts on the page, use OnDOMReady
240 /// instead.
241 ///
242 /// The window object is lazily initialized (this will not be called on pages with no scripts).
243 ///
244 /// @param frame_id A unique ID for the frame.
245 ///
246 /// @param is_main_frame Whether or not this is the main frame.
247 ///
248 /// @param url The URL for the load.
249 ///
250 virtual void OnWindowObjectReady(ultralight::View* caller, uint64_t frame_id, bool is_main_frame,
251 const String& url) { }
252
253 ///
254 /// Called when all JavaScript has been parsed and the document is ready.
255 ///
256 /// This is the best time to make any JavaScript calls that are dependent on DOM elements or
257 /// scripts on the page.
258 ///
259 /// @param frame_id A unique ID for the frame.
260 ///
261 /// @param is_main_frame Whether or not this is the main frame.
262 ///
263 /// @param url The URL for the load.
264 ///
265 virtual void OnDOMReady(ultralight::View* caller, uint64_t frame_id, bool is_main_frame,
266 const String& url) { }
267
268 ///
269 /// Called when the session history (back/forward state) is modified.
270 ///
271 virtual void OnUpdateHistory(ultralight::View* caller) { }
272};
273
274} // namespace ultralight
#define UExport
Definition Defines.h:65
User-defined interface to listen for load-related events for a View.
Definition Listener.h:185
virtual void OnDOMReady(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const String &url)
Called when all JavaScript has been parsed and the document is ready.
Definition Listener.h:265
virtual void OnFinishLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const String &url)
Called when the page finishes loading a URL into a frame.
Definition Listener.h:210
virtual ~LoadListener()
Definition Listener.h:187
virtual void OnUpdateHistory(ultralight::View *caller)
Called when the session history (back/forward state) is modified.
Definition Listener.h:271
virtual void OnBeginLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const String &url)
Called when the page begins loading a new URL into a frame.
Definition Listener.h:198
virtual void OnFailLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const String &url, const String &description, const String &error_domain, int error_code)
Called when an error occurs while loading a URL into a frame.
Definition Listener.h:228
virtual void OnWindowObjectReady(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const String &url)
Called when the JavaScript window object is reset for a new page load.
Definition Listener.h:250
A nullable smart pointer.
Definition RefPtr.h:79
UTF-8 String container with conversions for UTF-16 and UTF-32.
Definition String.h:21
Web-page container rendered to an offscreen surface that you display yourself.
Definition View.h:114
User-defined interface to listen for View-specific events.
Definition Listener.h:101
virtual RefPtr< View > OnCreateInspectorView(ultralight::View *caller, bool is_local, const String &inspected_url)
Called when the page wants to create a new View to display the local inspector in.
virtual void OnChangeURL(ultralight::View *caller, const String &url)
Called when the page URL changes.
Definition Listener.h:113
virtual void OnChangeCursor(ultralight::View *caller, Cursor cursor)
Called when the mouse cursor changes.
Definition Listener.h:123
virtual void OnChangeTooltip(ultralight::View *caller, const String &tooltip)
Called when the tooltip changes (usually as result of a mouse hover)
Definition Listener.h:118
virtual RefPtr< View > OnCreateChildView(ultralight::View *caller, const String &opener_url, const String &target_url, bool is_popup, const IntRect &popup_rect)
Called when the page wants to create a new child View.
virtual void OnChangeTitle(ultralight::View *caller, const String &title)
Called when the page title changes.
Definition Listener.h:108
virtual ~ViewListener()
Definition Listener.h:103
virtual void OnRequestClose(ultralight::View *caller)
Called when the page requests to be closed.
Definition Listener.h:176
virtual void OnAddConsoleMessage(ultralight::View *caller, MessageSource source, MessageLevel level, const String &message, uint32_t line_number, uint32_t column_number, const String &source_id)
Called when a message is added to the console (useful for errors / debug)
Definition Listener.h:128
Definition App.h:14
MessageLevel
MessageLevel types,.
Definition Listener.h:38
@ kMessageLevel_Log
Definition Listener.h:39
@ kMessageLevel_Info
Definition Listener.h:43
@ kMessageLevel_Warning
Definition Listener.h:40
@ kMessageLevel_Debug
Definition Listener.h:42
@ kMessageLevel_Error
Definition Listener.h:41
MessageSource
MessageSource types,.
Definition Listener.h:21
@ kMessageSource_Rendering
Definition Listener.h:28
@ kMessageSource_Storage
Definition Listener.h:26
@ kMessageSource_Other
Definition Listener.h:32
@ kMessageSource_ConsoleAPI
Definition Listener.h:25
@ kMessageSource_JS
Definition Listener.h:23
@ kMessageSource_AppCache
Definition Listener.h:27
@ kMessageSource_Network
Definition Listener.h:24
@ kMessageSource_CSS
Definition Listener.h:29
@ kMessageSource_ContentBlocker
Definition Listener.h:31
@ kMessageSource_Security
Definition Listener.h:30
@ kMessageSource_XML
Definition Listener.h:22
Cursor
Cursor types,.
Definition Listener.h:49
@ kCursor_Custom
Definition Listener.h:93
@ kCursor_NorthWestSouthEastResize
Definition Listener.h:67
@ kCursor_SouthResize
Definition Listener.h:60
@ kCursor_None
Definition Listener.h:87
@ kCursor_EastResize
Definition Listener.h:56
@ kCursor_SouthWestPanning
Definition Listener.h:77
@ kCursor_EastPanning
Definition Listener.h:71
@ kCursor_Grab
Definition Listener.h:91
@ kCursor_SouthWestResize
Definition Listener.h:62
@ kCursor_NorthEastSouthWestResize
Definition Listener.h:66
@ kCursor_Copy
Definition Listener.h:86
@ kCursor_NorthEastResize
Definition Listener.h:58
@ kCursor_SouthEastPanning
Definition Listener.h:76
@ kCursor_Move
Definition Listener.h:79
@ kCursor_NorthWestPanning
Definition Listener.h:74
@ kCursor_ColumnResize
Definition Listener.h:68
@ kCursor_NorthEastPanning
Definition Listener.h:73
@ kCursor_Alias
Definition Listener.h:83
@ kCursor_Hand
Definition Listener.h:52
@ kCursor_IBeam
Definition Listener.h:53
@ kCursor_NorthSouthResize
Definition Listener.h:64
@ kCursor_ZoomOut
Definition Listener.h:90
@ kCursor_NorthPanning
Definition Listener.h:72
@ kCursor_Cross
Definition Listener.h:51
@ kCursor_ZoomIn
Definition Listener.h:89
@ kCursor_WestPanning
Definition Listener.h:78
@ kCursor_Grabbing
Definition Listener.h:92
@ kCursor_ContextMenu
Definition Listener.h:82
@ kCursor_NorthResize
Definition Listener.h:57
@ kCursor_SouthEastResize
Definition Listener.h:61
@ kCursor_NorthWestResize
Definition Listener.h:59
@ kCursor_MiddlePanning
Definition Listener.h:70
@ kCursor_Cell
Definition Listener.h:81
@ kCursor_Progress
Definition Listener.h:84
@ kCursor_NoDrop
Definition Listener.h:85
@ kCursor_Help
Definition Listener.h:55
@ kCursor_Wait
Definition Listener.h:54
@ kCursor_EastWestResize
Definition Listener.h:65
@ kCursor_WestResize
Definition Listener.h:63
@ kCursor_Pointer
Definition Listener.h:50
@ kCursor_NotAllowed
Definition Listener.h:88
@ kCursor_VerticalText
Definition Listener.h:80
@ kCursor_SouthPanning
Definition Listener.h:75
@ kCursor_RowResize
Definition Listener.h:69
Integer Rectangle Helper.
Definition Geometry.h:529