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

fix: white screen and flicker #356

Merged
merged 1 commit into from
Dec 6, 2023
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
15 changes: 14 additions & 1 deletion include/QCefSetting.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#pragma region qt_headers
#include <QColor>
#include <QScopedPointer>
#include <QSize>
#include <QString>
#pragma endregion qt_headers

Expand Down Expand Up @@ -52,11 +53,23 @@ class QCEFVIEW_EXPORT QCefSetting
/// </summary>
~QCefSetting();

/// <summary>
/// Sets the initial size of the browser
/// </summary>
/// <param name="size">The initial size</param>
void setInitSize(const QSize& size);

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

/// <summary>
/// Sets the standard font family
/// </summary>
/// <param name="value">The font family</param>
void setStandardFontFamily(const QString value);
void setStandardFontFamily(const QString& value);

/// <summary>
/// Gets the standard font family
Expand Down
16 changes: 15 additions & 1 deletion src/QCefSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ QCefSetting::operator=(const QCefSetting& other)
QCefSetting::~QCefSetting() {}

void
QCefSetting::setStandardFontFamily(const QString value)
QCefSetting::setInitSize(const QSize& size)
{
Q_D(QCefSetting);
d->initSize_ = size;
}

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

void
QCefSetting::setStandardFontFamily(const QString& value)
{
Q_D(QCefSetting);
d->standardFontFamily_ = value.toStdString();
Expand Down
2 changes: 2 additions & 0 deletions src/details/QCefSettingPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class QCefSettingPrivate
public:
explicit QCefSettingPrivate();

QSize initSize_;

std::string standardFontFamily_;
std::string fixedFontFamily_;
std::string serifFontFamily_;
Expand Down
20 changes: 17 additions & 3 deletions src/details/QCefViewPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,27 @@ QCefViewPrivate::createCefBrowser(QCefView* view, const QString& url, const QCef
windowInfo.SetAsWindowless(0);
} else {
// create CEF browser parent window
auto initSize = q_ptr->size();
if (setting) {
initSize = setting->initSize();
}
qDebug() << "Browser init size:" << initSize;

ncw.qBrowserWindow_ = new QCefWindow();
ncw.qBrowserWindow_->resize(initSize);
ncw.qBrowserWindow_->setFlags(Qt::Window | Qt::FramelessWindowHint);

// use INT_MAX as the width and height to prevent black screen blink
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
qreal scaleFactor = q_ptr->devicePixelRatioF();
#else
qreal scaleFactor = q_ptr->devicePixelRatio();
#endif
auto width = initSize.width() * scaleFactor;
auto height = initSize.height() * scaleFactor;
#if CEF_VERSION_MAJOR > 85
windowInfo.SetAsChild((CefWindowHandle)ncw.qBrowserWindow_->winId(), { 0, 0, INT_MAX, INT_MAX });
windowInfo.SetAsChild((CefWindowHandle)ncw.qBrowserWindow_->winId(), { 0, 0, (int)width, (int)height });
#else
windowInfo.SetAsChild((CefWindowHandle)ncw.qBrowserWindow_->winId(), 0, 0, INT_MAX, INT_MAX);
windowInfo.SetAsChild((CefWindowHandle)ncw.qBrowserWindow_->winId(), 0, 0, (int)width, (int)height);
#endif
}

Expand Down Expand Up @@ -235,6 +248,7 @@ QCefViewPrivate::onCefBrowserCreated(CefRefPtr<CefBrowser> browser, QWindow* win
ncw.qBrowserWindow_->applyMask(q_ptr->mask());

// resize to eliminate flicker
qDebug() << "Host QCefView size:" << q_ptr->size();
ncw.qBrowserWidget_->resize(q_ptr->size());

// initialize the layout and add browser widget to the layout
Expand Down
3 changes: 2 additions & 1 deletion src/details/QCefWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
QCefWindow::QCefWindow()
: QWindow()
{
this->setFlag(Qt::FramelessWindowHint);
}

QCefWindow::~QCefWindow()
Expand Down Expand Up @@ -43,7 +42,9 @@ QCefWindow::detachCefWindow()

#else
cefWindow_->hide();
#if defined(Q_OS_LINUX)
cefWindow_->setParent(nullptr);
#endif
#endif
cefWindow_ = nullptr;
}
Expand Down
Loading