Skip to content

Commit 88b670b

Browse files
committed
Render web tooltips in browser source Interact using Qt
This code was originally intended for Browser Docks, but CEF is supposed to handle it internally. OnTooltip never triggers outside of OSR. https://bitbucket.org/chromiumembedded/cef/issues/783/ Per documentation for this function, when using OSR it's up to the parent app (ie. OBS) to render a tooltip.
1 parent 80b0c82 commit 88b670b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

browser-client.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <obs-frontend-api.h>
2424
#include <obs.hpp>
2525
#include <util/platform.h>
26+
#include <QApplication>
27+
#include <QThread>
28+
#include <QToolTip>
2629

2730
using namespace json11;
2831

@@ -172,6 +175,16 @@ bool BrowserClient::GetViewRect(
172175
#endif
173176
}
174177

178+
bool BrowserClient::OnTooltip(CefRefPtr<CefBrowser>, CefString &text)
179+
{
180+
std::string str_text = text;
181+
QMetaObject::invokeMethod(
182+
QCoreApplication::instance()->thread(), [str_text]() {
183+
QToolTip::showText(QCursor::pos(), str_text.c_str());
184+
});
185+
return true;
186+
}
187+
175188
void BrowserClient::OnPaint(CefRefPtr<CefBrowser>, PaintElementType type,
176189
const RectList &, const void *buffer, int width,
177190
int height)

browser-client.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class BrowserClient : public CefClient,
9797
const CefString &message,
9898
const CefString &source,
9999
int line) override;
100+
virtual bool OnTooltip(CefRefPtr<CefBrowser> browser,
101+
CefString &text) override;
100102

101103
/* CefLifeSpanHandler */
102104
virtual bool

0 commit comments

Comments
 (0)