Skip to content

Commit

Permalink
feat: update folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
tishion committed Oct 7, 2024
1 parent e4ebe5f commit 44761e7
Show file tree
Hide file tree
Showing 25 changed files with 396 additions and 234 deletions.
2 changes: 1 addition & 1 deletion cmake/CefViewCoreConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include(FetchContent)
FetchContent_Declare(
CefViewCore
GIT_REPOSITORY https://github.com/CefView/CefViewCore.git
GIT_TAG bec54fee976b029c1945414aa80882e4ee2fa0b4
GIT_TAG 6bb08e71d610671f2b2c0080fb61bcf534e4dcb2
)

# set CEF version to be used
Expand Down
6 changes: 3 additions & 3 deletions include/QCefSetting.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* File: QCefSetting.h
* Project: QCefView
* Created: 29th March 2016
Expand Down Expand Up @@ -57,13 +57,13 @@ class QCEFVIEW_EXPORT QCefSetting
/// Sets the initial size of the browser
/// </summary>
/// <param name="size">The initial size</param>
void setInitSize(const QSize& size);
void setWindowInitialSize(const QSize& size);

/// <summary>
/// Gets the initial size of the browser
/// </summary>
/// <returns></returns>
const QSize initSize() const;
const QSize windowInitialSize() const;

/// <summary>
/// Sets the standard font family
Expand Down
5 changes: 5 additions & 0 deletions include/QCefView.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ public slots:
void render(QPainter* painter);

protected:
/// <summary>
/// Please refer to QWidget::paintEngine
/// </summary>
QPaintEngine* paintEngine() const override;

/// <summary>
/// Please refer to QWidget::paintEvent
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion include/QCefView_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@
#define CEF_VERSION_MINOR 3
#define CEF_VERSION_PATCH 5


#endif // QCEFEVIEW_GLOBAL_H
1 change: 0 additions & 1 deletion include/QCefView_global.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@
#define CEF_VERSION_MINOR @CEF_VERSION_MINOR@
#define CEF_VERSION_PATCH @CEF_VERSION_PATCH@


#endif // QCEFEVIEW_GLOBAL_H
3 changes: 2 additions & 1 deletion src/QCefContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ QCefContext::addCookie(const QString& name, const QString& value, const QString&
}

bool
QCefContext::deleteAllCookies() {
QCefContext::deleteAllCookies()
{
Q_D(QCefContext);

return d->deleteAllCookies();
Expand Down
10 changes: 5 additions & 5 deletions src/QCefSetting.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "QCefSetting.h"
#include <QCefSetting.h>

#pragma region cef_headers
#include <include/cef_version.h>
Expand Down Expand Up @@ -30,17 +30,17 @@ QCefSetting::operator=(const QCefSetting& other)
QCefSetting::~QCefSetting() {}

void
QCefSetting::setInitSize(const QSize& size)
QCefSetting::setWindowInitialSize(const QSize& size)
{
Q_D(QCefSetting);
d->initSize_ = size;
d->windowInitialSize_ = size;
}

const QSize
QCefSetting::initSize() const
QCefSetting::windowInitialSize() const
{
Q_D(const QCefSetting);
return d->initSize_;
return d->windowInitialSize_;
}

void
Expand Down
79 changes: 22 additions & 57 deletions src/QCefView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QPainter>
#include <QPoint>
#include <QResizeEvent>
#include <QStyleOption>
#include <QVBoxLayout>
#include <QtDebug>
#pragma endregion qt_headers
Expand All @@ -26,20 +25,22 @@ QCefView::QCefView(const QString& url,
QWidget* parent /*= 0*/,
Qt::WindowFlags f /*= Qt::WindowFlags()*/)
: QWidget(parent, f)
, d_ptr(new QCefViewPrivate(QCefContext::instance()->d_func(), this, url, setting))
, d_ptr(new QCefViewPrivate(QCefContext::instance()->d_func(), this))
{

if (d_ptr->isOSRModeEnabled()) {
if (d_ptr->isOSRModeEnabled_) {
// OSR mode
setBackgroundRole(QPalette::Window);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
}

setMouseTracking(true);
setFocusPolicy(Qt::WheelFocus);

// create browser
d_ptr->createCefBrowser(this, url, setting);
d_ptr->createCefBrowser(this, url, setting ? setting->d_func() : nullptr);
}

QCefView::QCefView(QWidget* parent /*= 0*/, Qt::WindowFlags f /*= Qt::WindowFlags()*/)
Expand Down Expand Up @@ -355,7 +356,7 @@ QCefView::inputMethodQuery(Qt::InputMethodQuery query) const
{
Q_D(const QCefView);

if (d->isOSRModeEnabled()) {
if (d->isOSRModeEnabled_) {
// OSR mode
auto r = d->onViewInputMethodQuery(query);
if (r.isValid())
Expand All @@ -370,55 +371,26 @@ QCefView::render(QPainter* painter)
{
Q_D(QCefView);

if (d->isOSRModeEnabled()) {
// OSR mode
// 1. paint widget with its stylesheet
QStyleOption opt;
opt.initFrom(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, this);

// 2. paint the CEF view and popup
// get current scale factor
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
qreal scaleFactor = devicePixelRatioF();
#else
qreal scaleFactor = devicePixelRatio();
#endif
d->render(painter);
}

// perform the painting
{
// paint cef view
QMutexLocker lock(&(d->osr.qViewPaintLock_));
int width = d->osr.qCefViewFrame_.width() / scaleFactor;
int height = d->osr.qCefViewFrame_.height() / scaleFactor;
painter->drawImage(QRect{ 0, 0, width, height }, d->osr.qCefViewFrame_);
}
{
// paint cef popup
QMutexLocker lock(&(d->osr.qPopupPaintLock_));
if (d->osr.showPopup_) {
painter->drawImage(d->osr.qPopupRect_, d->osr.qCefPopupFrame_);
}
}
}
QPaintEngine*
QCefView::paintEngine() const
{
Q_D(const QCefView);

auto engine = QWidget::paintEngine();
d->onPaintEngine(engine);

return engine;
}

void
QCefView::paintEvent(QPaintEvent* event)
{
// 1. construct painter for current widget
QPainter painter(this);

// 2. paint background with background role
// for OSR mode, this makes sure the surface will be cleared before a new drawing
// for NCW mode, this makes sure QCefView will not be treated as transparent background
painter.fillRect(rect(), palette().color(backgroundRole()));

// 3. render self
render(&painter);
Q_D(QCefView);

// 4. call base paintEvent (empty implementation)
QWidget::paintEvent(event);
d->onPaintEvent(event);
}

void
Expand Down Expand Up @@ -519,14 +491,7 @@ QCefView::wheelEvent(QWheelEvent* event)
void
QCefView::contextMenuEvent(QContextMenuEvent* event)
{
FLog();

Q_D(const QCefView);

if (d->isOSRModeEnabled()) {
// OSR mode
if (d->osr.isShowingContextMenu_) {
d->osr.contextMenu_->popup(mapToGlobal(event->pos()));
}
}
Q_D(QCefView);
d->onContextMenuEvent(mapToGlobal(event->pos()));
QWidget::contextMenuEvent(event);
}
3 changes: 3 additions & 0 deletions src/details/QCefContextPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const int64_t kCefWorkerIntervalMs = (1000 / 60); // 60 fps
QCefContextPrivate::QCefContextPrivate(QCoreApplication* app, int argc, char** argv)
: argc_(argc)
, argv_(argv)
, config_(nullptr)
{
#if defined(Q_OS_MACOS) || defined(CEF_USE_QT_EVENT_LOOP)
cefWorkerTimer_.setTimerType(Qt::PreciseTimer);
Expand All @@ -42,6 +43,8 @@ bool
QCefContextPrivate::initialize(const QCefConfig* config)
{
config_ = config;

// initialize CEF
if (!initializeCef(config)) {
return false;
}
Expand Down
37 changes: 35 additions & 2 deletions src/details/QCefContextPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,58 @@ class QCefContextPrivate : public QObject
Q_OBJECT

private:
/// <summary>
///
/// </summary>
int argc_;

/// <summary>
///
/// </summary>
char** argv_;

private:
/// <summary>
///
/// </summary>
const QCefConfig* config_;

/// <summary>
///
/// </summary>
QList<FolderResourceMapping> folderResourceMappingList_;

/// <summary>
///
/// </summary>
QList<ArchiveResourceMapping> archiveResourceMappingList_;

#if defined(Q_OS_MACOS) || defined(CEF_USE_QT_EVENT_LOOP)
/// <summary>
///
/// </summary>
QTimer cefWorkerTimer_;
#endif

#if defined(Q_OS_WINDOWS)
/// <summary>
///
/// </summary>
HANDLE windowsJobHandle_ = nullptr;

/// <summary>
///
/// </summary>
QString windowsJobName_;
#endif

private:
/// <summary>
///
/// </summary>
CefRefPtr<CefViewBrowserApp> pApp_;

/// <summary>
///
/// </summary>
CCefAppDelegate::RefPtr pAppDelegate_;

public:
Expand Down
Loading

0 comments on commit 44761e7

Please sign in to comment.