Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加faviconURLChanged,faviconChanged事件 #105

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/QCefView.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// <param name="title">The title</param>
void titleChanged(const QString& title);

/// <summary>
/// Gets called on title changed
/// </summary>
/// <param name="urls">The urls</param>
void faviconURLChanged(const QStringList& urls);

/// <summary>
/// Gets called on title changed
/// </summary>
/// <param name="icon">The icon</param>
void faviconChanged(const QIcon &icon);

/// <summary>
/// Gets called on fullscreen mode changed
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/details/CCefClientDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class CCefClientDelegate : public CefViewBrowserClientDelegateInterface
const std::vector<CefDraggableRegion>& regions) override;
virtual void addressChanged(CefRefPtr<CefBrowser>& browser, int64_t frameId, const std::string& url) override;
virtual void titleChanged(CefRefPtr<CefBrowser>& browser, const std::string& title) override;
virtual void faviconURLChanged(CefRefPtr<CefBrowser> browser, const std::vector<CefString>& icon_urls) override;
virtual void faviconChanged(CefRefPtr<CefImage> image) override;
virtual void fullscreenModeChanged(CefRefPtr<CefBrowser>& browser, bool fullscreen) override;
virtual bool tooltipMessage(CefRefPtr<CefBrowser>& browser, const std::string& text) override;
virtual void statusMessage(CefRefPtr<CefBrowser>& browser, const std::string& value) override;
Expand Down
42 changes: 41 additions & 1 deletion src/details/CCefClientDelegate_DisplayHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "CCefClientDelegate.h"

#include <QCursor>

#include <QtGui>
#include <QtCore>
#include "QCefViewPrivate.h"

Qt::CursorShape
Expand Down Expand Up @@ -104,6 +105,45 @@ CCefClientDelegate::titleChanged(CefRefPtr<CefBrowser>& browser, const std::stri
pCefViewPrivate_->q_ptr->titleChanged(t);
}

void
CCefClientDelegate::faviconURLChanged(CefRefPtr<CefBrowser> browser, const std::vector<CefString>& icon_urls)
{
if (!IsValidBrowser(browser))
return;

QStringList urls;
for (int i = 0; i < icon_urls.size(); i++)
{
urls.append(QString::fromStdString(icon_urls.at(i).ToString()));
}
pCefViewPrivate_->q_ptr->faviconURLChanged(urls);
}

void
CCefClientDelegate::faviconChanged(CefRefPtr<CefImage> image)
{
QIcon icon;

//图像转换
int width = 0;
int height = 0;
CefRefPtr<CefBinaryValue> data = image->GetAsPNG(1.0, true, width, height);
int bufsize = (int)data->GetSize();
if (bufsize > 0)
{
QByteArray buffer(bufsize + 4, char(0));
data->GetData(buffer.data(), bufsize, 0);

QBitmap bitmap;
bitmap.loadFromData(buffer);

icon = QIcon(bitmap);
}

//发出信号
pCefViewPrivate_->q_ptr->faviconChanged(icon);
}

void
CCefClientDelegate::fullscreenModeChanged(CefRefPtr<CefBrowser>& browser, bool fullscreen)
{
Expand Down