Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 620fa0a

Browse filesBrowse files
committed
move set_caption to the UI thread
1 parent 208cde0 commit 620fa0a
Copy full SHA for 620fa0a

File tree

Expand file treeCollapse file tree

4 files changed

+35
-10
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+35
-10
lines changed

‎src/webpage/html_host.h

Copy file name to clipboardExpand all lines: src/webpage/html_host.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace litebrowser
1616
virtual void update_cursor() = 0;
1717
virtual void scroll_to(int x, int y) = 0;
1818
virtual void get_client_rect(litehtml::position& client) const = 0;
19-
virtual void set_caption(const char* caption) = 0;
2019
virtual void redraw_boxes(const litehtml::position::vector& boxes) = 0;
2120
virtual int get_render_width() = 0;
2221
virtual double get_dpi() = 0;
@@ -33,6 +32,7 @@ namespace litebrowser
3332
virtual void redraw() = 0;
3433
virtual void render() = 0;
3534
virtual void update_state() = 0;
35+
virtual void on_set_caption(const std::string& caption_text) = 0;
3636
virtual void on_page_loaded(uint64_t web_page_id) = 0;
3737
};
3838

‎src/webpage/web_page.cpp

Copy file name to clipboardExpand all lines: src/webpage/web_page.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void litebrowser::web_page::import_css(litehtml::string& text, const litehtml::s
7777

7878
void litebrowser::web_page::set_caption(const char* caption)
7979
{
80-
m_html_host->set_caption(caption);
80+
m_notify->on_set_caption(caption);
8181
}
8282

8383
void litebrowser::web_page::set_base_url(const char* base_url)

‎src/widget/html_widget.cpp

Copy file name to clipboardExpand all lines: src/widget/html_widget.cpp
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ html_widget::html_widget()
1010
m_notifier->connect_render(sigc::mem_fun(*this, &html_widget::render));
1111
m_notifier->connect_update_state([this]() { m_sig_update_state.emit(get_state()); });
1212
m_notifier->connect_on_page_loaded(sigc::mem_fun(*this, &html_widget::on_page_loaded));
13+
m_notifier->connect_on_set_caption(sigc::mem_fun(*this, &html_widget::set_caption));
1314

1415
set_focusable(true);
1516

@@ -134,15 +135,15 @@ void html_widget::get_client_rect(litehtml::position& client) const
134135
client.height = (int) (m_vadjustment->get_page_size());
135136
}
136137

137-
void html_widget::set_caption(const char* caption)
138+
void html_widget::set_caption(const std::string& caption)
138139
{
139140
auto root = get_root();
140141
if(root)
141142
{
142143
auto window = dynamic_cast<Gtk::Window*>(root);
143144
if (window)
144145
{
145-
window->set_title(caption);
146+
window->set_title(caption.c_str());
146147
};
147148
}
148149
}

‎src/widget/html_widget.h

Copy file name to clipboardExpand all lines: src/widget/html_widget.h
+30-6Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,30 @@ class html_widget_notifier : public litebrowser::browser_notify_interface
2121
using render_func = std::function<void()>;
2222
using update_state_func = std::function<void()>;
2323
using on_page_loaded_func = std::function<void(uint64_t)>;
24+
using on_set_caption_func = std::function<void(const std::string&)>;
2425
private:
2526
enum func_type
2627
{
2728
func_type_none,
2829
func_type_redraw,
2930
func_type_render,
3031
func_type_update_state,
31-
func_type_on_page_loaded
32+
func_type_on_page_loaded,
33+
func_type_on_set_caption
3234
};
3335
struct queue_item
3436
{
3537
func_type type;
3638
uint64_t param;
39+
std::string str_param;
3740
};
3841

3942
Glib::Dispatcher m_dispatcher;
4043
redraw_func m_redraw_func;
4144
render_func m_render_func;
4245
update_state_func m_update_state_func;
4346
on_page_loaded_func m_on_page_loaded_func;
47+
on_set_caption_func m_on_set_caption_func;
4448

4549
std::mutex m_lock;
4650
bool m_disconnect = false;
@@ -79,13 +83,18 @@ class html_widget_notifier : public litebrowser::browser_notify_interface
7983
m_on_page_loaded_func = _on_page_loaded_func;
8084
}
8185

86+
void connect_on_set_caption(on_set_caption_func _on_set_caption_func)
87+
{
88+
m_on_set_caption_func = _on_set_caption_func;
89+
}
90+
8291
private:
8392

8493
void redraw() override
8594
{
8695
{
8796
std::lock_guard lock(m_lock);
88-
m_queue.push(queue_item{func_type_redraw, 0});
97+
m_queue.push(queue_item{func_type_redraw, 0, {}});
8998
}
9099
m_dispatcher.emit();
91100
}
@@ -94,7 +103,7 @@ class html_widget_notifier : public litebrowser::browser_notify_interface
94103
{
95104
{
96105
std::lock_guard lock(m_lock);
97-
m_queue.push(queue_item{func_type_render, 0});
106+
m_queue.push(queue_item{func_type_render, 0, {}});
98107
}
99108
m_dispatcher.emit();
100109
}
@@ -103,7 +112,7 @@ class html_widget_notifier : public litebrowser::browser_notify_interface
103112
{
104113
{
105114
std::lock_guard lock(m_lock);
106-
m_queue.push(queue_item{func_type_update_state, 0});
115+
m_queue.push(queue_item{func_type_update_state, 0, {}});
107116
}
108117
m_dispatcher.emit();
109118
}
@@ -112,7 +121,16 @@ class html_widget_notifier : public litebrowser::browser_notify_interface
112121
{
113122
{
114123
std::lock_guard lock(m_lock);
115-
m_queue.push(queue_item{func_type_on_page_loaded, web_page_id});
124+
m_queue.push(queue_item{func_type_on_page_loaded, web_page_id, {}});
125+
}
126+
m_dispatcher.emit();
127+
}
128+
129+
void on_set_caption(const std::string& caption) override
130+
{
131+
{
132+
std::lock_guard lock(m_lock);
133+
m_queue.push(queue_item{func_type_on_set_caption, 0, caption});
116134
}
117135
m_dispatcher.emit();
118136
}
@@ -164,6 +182,12 @@ class html_widget_notifier : public litebrowser::browser_notify_interface
164182
m_on_page_loaded_func(item.param);
165183
}
166184
break;
185+
case func_type_on_set_caption:
186+
if(m_on_set_caption_func)
187+
{
188+
m_on_set_caption_func(item.str_param);
189+
}
190+
break;
167191

168192
default:
169193
break;
@@ -452,7 +476,6 @@ class html_widget : public Gtk::Widget,
452476
int get_render_width() override;
453477
void scroll_to(int x, int y) override;
454478
void get_client_rect(litehtml::position& client) const override;
455-
void set_caption(const char* caption) override;
456479
cairo_surface_t* load_image(const std::string& path) override;
457480

458481
void snapshot_vfunc(const Glib::RefPtr<Gtk::Snapshot>& snapshot) override;
@@ -466,6 +489,7 @@ class html_widget : public Gtk::Widget,
466489
void size_allocate_vfunc(int width, int height, int baseline) override;
467490
void allocate_scrollbars(int width, int height);
468491

492+
void set_caption(const std::string& caption);
469493
void on_vadjustment_changed();
470494
void on_hadjustment_changed();
471495
void on_adjustments_changed();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.