GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/cxx_webviews.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 97 0.0%
Functions: 0 24 0.0%
Branches: 0 38 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/ui/webviews.hpp"
30
31 namespace gate
32 {
33 namespace ui
34 {
35
36 Webview::Webview()
37 : Control(&impl.ctrl)
38 {
39 Mem::clear(&this->impl, sizeof(this->impl));
40 gate_ui_ctrl_init(&this->impl.ctrl);
41 }
42 Webview::~Webview() noexcept
43 {
44 if (this->isCreated())
45 {
46 this->destroy();
47 }
48 }
49 void Webview::create(ControlContainer& parent, Position const& pose, uint32_t flags)
50 {
51 this->failIfCreated("Webview::create");
52 result_t result = gate_ui_webview_create(&this->impl, *parent, &pose, flags, this);
53 GATEXX_CHECK_ERROR(result);
54
55 this->impl.on_navigate_start = &Webview::on_navigate_start;
56 this->impl.on_navigate_progress = &Webview::on_navigate_progress;
57 this->impl.on_navigate_complete = &Webview::on_navigate_complete;
58 this->impl.on_internal_state_changed = &Webview::on_internal_state_changed;
59 this->impl.on_title_text_changed = &Webview::on_title_text_changed;
60 this->impl.on_status_text_changed = &Webview::on_status_text_changed;
61 this->impl.on_new_window = &Webview::on_new_window;
62
63 this->attachNativeControl(&this->impl.ctrl);
64 }
65
66 void Webview::navigateTo(String const& address)
67 {
68 this->failIfNotCreated("Webview::navigateTo");
69 result_t result = gate_ui_webview_navigate_to(&this->impl, address.c_impl());
70 GATEXX_CHECK_EXCEPTION(result);
71 }
72
73 void Webview::execute(CommandEnum cmd)
74 {
75 gate_result_t result = gate_ui_webview_execute(&this->impl, (enumint_t)cmd);
76 GATEXX_CHECK_EXCEPTION(result);
77 }
78
79 void Webview::onNavigateStart(String const& url, bool_t& cancel)
80 {
81 NavigateStartArg arg;
82 arg.url = url;
83 arg.cancel = cancel;
84 this->NavigateStartEvent(this, &arg);
85 cancel = arg.cancel;
86 }
87 void Webview::onNavigateProgress(int32_t progress, int32_t progressMax)
88 {
89 NavigateProgressArg arg;
90 arg.progress = progress;
91 arg.progressMax = progressMax;
92 this->NavigateProgressEvent(this, &arg);
93 }
94 void Webview::onNavigateComplete(String const& url)
95 {
96 this->NavigateCompleteEvent(this, &url);
97 }
98 void Webview::onInternalStateChanged(enumint_t stateId)
99 {
100 this->InternalStateChangedEvent(this, &stateId);
101 }
102 void Webview::onTitleTextChanged(String const& text)
103 {
104 this->TitleTextChangedEvent(this, &text);
105 }
106 void Webview::onStatusTextChanged(String const& text)
107 {
108 this->StatusTextChangedEvent(this, &text);
109 }
110 void Webview::onNewWindow(Webview*& targetWebview)
111 {
112 this->NewWindowEvent(this, &targetWebview);
113 }
114
115 template<class A1>
116 void invokeWebviewEvent(gate_ui_ctrl_t* sender, void(Webview::* method)(A1), A1 a1)
117 {
118 Webview* wv = static_cast<Webview*>(gate_ui_ctrl_get_userparam(sender));
119 if (wv)
120 {
121 try
122 {
123 (wv->*method)(a1);
124 }
125 catch (...) {}
126 }
127 }
128
129 template<class A1, class A2>
130 void invokeWebviewEvent(gate_ui_ctrl_t* sender, void(Webview::* method)(A1, A2), A1 a1, A2 a2)
131 {
132 Webview* wv = static_cast<Webview*>(gate_ui_ctrl_get_userparam(sender));
133 if (wv)
134 {
135 try
136 {
137 (wv->*method)(a1, a2);
138 }
139 catch (...) {}
140 }
141 }
142
143
144 void Webview::on_navigate_start(gate_ui_ctrl_t* sender, gate_string_t const* url, gate_bool_t* cancel)
145 {
146 invokeWebviewEvent<String const&, bool_t&>(sender, &Webview::onNavigateStart,
147 String(*url), *cancel);
148 }
149 void Webview::on_navigate_progress(gate_ui_ctrl_t* sender, gate_int32_t progress, gate_int32_t progress_max)
150 {
151 invokeWebviewEvent<int32_t, int32_t>(sender, &Webview::onNavigateProgress,
152 progress, progress_max);
153 }
154 void Webview::on_navigate_complete(gate_ui_ctrl_t* sender, gate_string_t const* url)
155 {
156 invokeWebviewEvent<String const&>(sender, &Webview::onNavigateComplete,
157 String(*url));
158 }
159 void Webview::on_internal_state_changed(gate_ui_ctrl_t* sender, gate_enumint_t state)
160 {
161 invokeWebviewEvent<gate_enumint_t>(sender, &Webview::onInternalStateChanged,
162 state);
163 }
164 void Webview::on_title_text_changed(gate_ui_ctrl_t* sender, gate_string_t const* text)
165 {
166 invokeWebviewEvent<String const&>(sender, &Webview::onTitleTextChanged,
167 String(*text));
168 }
169 void Webview::on_status_text_changed(gate_ui_ctrl_t* sender, gate_string_t const* text)
170 {
171 invokeWebviewEvent<String const&>(sender, &Webview::onStatusTextChanged,
172 String(*text));
173 }
174 void Webview::on_new_window(gate_ui_ctrl_t* sender, struct gate_ui_webview_class** ptr_target_webview_ptr)
175 {
176 Webview* ptrView = NULL;
177 invokeWebviewEvent<Webview*&>(sender, &Webview::onNewWindow,
178 ptrView);
179 *ptr_target_webview_ptr = ptrView ? &ptrView->impl : NULL;
180 }
181
182
183 } // end of namespace ui
184 } // end of namespace gate
185
186