Skip to content

Commit

Permalink
Render web tooltips in browser source Interact using Qt
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
WizardCM committed Aug 7, 2021
1 parent 80b0c82 commit 88b670b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <obs-frontend-api.h>
#include <obs.hpp>
#include <util/platform.h>
#include <QApplication>
#include <QThread>
#include <QToolTip>

using namespace json11;

Expand Down Expand Up @@ -172,6 +175,16 @@ bool BrowserClient::GetViewRect(
#endif
}

bool BrowserClient::OnTooltip(CefRefPtr<CefBrowser>, CefString &text)
{
std::string str_text = text;
QMetaObject::invokeMethod(
QCoreApplication::instance()->thread(), [str_text]() {
QToolTip::showText(QCursor::pos(), str_text.c_str());
});
return true;
}

void BrowserClient::OnPaint(CefRefPtr<CefBrowser>, PaintElementType type,
const RectList &, const void *buffer, int width,
int height)
Expand Down
2 changes: 2 additions & 0 deletions browser-client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class BrowserClient : public CefClient,
const CefString &message,
const CefString &source,
int line) override;
virtual bool OnTooltip(CefRefPtr<CefBrowser> browser,
CefString &text) override;

/* CefLifeSpanHandler */
virtual bool
Expand Down

0 comments on commit 88b670b

Please sign in to comment.