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

Feature/update cef 106 #167

Merged
merged 8 commits into from
Oct 25, 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
32 changes: 28 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ else()
)
endif()

if(OS_MACOS)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.11)
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/$<CONFIG>/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/$<CONFIG>/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/$<CONFIG>/lib)
Expand All @@ -125,6 +121,34 @@ endforeach(CefViewWingTarget)

set_target_properties(libcef_dll_wrapper PROPERTIES FOLDER core)

# read CEF version from cef_version.h
file(READ "${CefViewCore_CEF_INCLUDE_DIR}/cef_version.h" cef_version_content)
string(REGEX MATCH "#define CEF_VERSION_MAJOR ([0-9]+)" _ ${cef_version_content})
set(CEF_VERSION_MAJOR ${CMAKE_MATCH_1})
message(STATUS "CEF_VERSION_MAJOR: ${CEF_VERSION_MAJOR}")

string(REGEX MATCH "#define CEF_VERSION_MINOR ([0-9]+)" _ ${cef_version_content})
set(CEF_VERSION_MINOR ${CMAKE_MATCH_1})
message(STATUS "CEF_VERSION_MINOR: ${CEF_VERSION_MINOR}")

string(REGEX MATCH "#define CEF_VERSION_PATCH ([0-9]+)" _ ${cef_version_content})
set(CEF_VERSION_PATCH ${CMAKE_MATCH_1})
message(STATUS "CEF_VERSION_PATCH: ${CEF_VERSION_PATCH}")

configure_file(
"${CMAKE_SOURCE_DIR}/src/QCefView_global.h.in"
"${CMAKE_SOURCE_DIR}/include/QCefView_global.h"
@ONLY
)

if(OS_MACOS)
if(CEF_VERSION_MAJOR LESS 104)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.11)
else()
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13)
endif()
endif()

# Config QCefView target
# ##############################################################
add_subdirectory(src)
Expand Down
2 changes: 1 addition & 1 deletion CefViewCore
4 changes: 4 additions & 0 deletions example/QCefViewTest/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ MainWindow::createCefView()
///*
// build settings for per QCefView
QCefSetting setting;

#if CEF_VERSION_MAJOR < 100
setting.setPlugins(false);
#endif

setting.setWindowlessFrameRate(60);
setting.setBackgroundColor(QColor::fromRgba(qRgba(255, 255, 220, 255)));
// setting.setBackgroundColor(Qt::blue);
Expand Down
2 changes: 1 addition & 1 deletion example/QCefViewTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ main(int argc, char* argv[])
config.setBackgroundColor(Qt::lightGray);

// WindowlessRenderingEnabled is set to true by default, set to false to disable the OSR mode
config.setWindowlessRenderingEnabled(false);
// config.setWindowlessRenderingEnabled(false);
// config.addCommandLineSwitch("disable-gpu");

// add command line args
Expand Down
2 changes: 2 additions & 0 deletions include/QCefSetting.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class QCEFVIEW_EXPORT QCefSetting
/// <returns>True to enalbe; false to disable</returns>
const QVariant javascriptDomPaste() const;

#if CEF_VERSION_MAJOR < 100
/// <summary>
/// Sets to enable or disable plugins
/// </summary>
Expand All @@ -279,6 +280,7 @@ class QCEFVIEW_EXPORT QCefSetting
/// </summary>
/// <returns>True to enalbe; false to disable</returns>
const QVariant plugins() const;
#endif

/// <summary>
/// Sets to enable or disable the permission of loading images
Expand Down
28 changes: 18 additions & 10 deletions include/QCefView_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,31 @@
#define QCEFEVIEW_GLOBAL_H
#pragma once

// clang-format off
#pragma region qt_headers
#include <QtCore/qglobal.h>

#include <QMetaType>
#pragma endregion qt_headers

#ifdef QCEFVIEW_STATIC
#define QCEFVIEW_EXPORT
#else
#ifdef QCEFVIEW_LIB
#define QCEFVIEW_EXPORT Q_DECL_EXPORT
// Static library, no need export
#define QCEFVIEW_EXPORT
#else
#define QCEFVIEW_EXPORT Q_DECL_IMPORT
#if _WIN32
#pragma comment(lib, "QCefView.lib")
#endif
#endif
// Dynamic library
#ifdef QCEFVIEW_LIB
// Build QCefView project, export API
#define QCEFVIEW_EXPORT Q_DECL_EXPORT
#else
// Referenced by other project, import API
#define QCEFVIEW_EXPORT Q_DECL_IMPORT
#if _WIN32
#pragma comment(lib, "QCefView.lib")
#endif
#endif
#endif

// CEF major version number
#define CEF_VERSION_MAJOR 106
// clang-format on

#endif // QCEFEVIEW_GLOBAL_H
9 changes: 8 additions & 1 deletion src/QCefSetting.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#include "QCefSetting.h"

#pragma region cef_headers
#include <include/cef_version.h>
#pragma endregion cef_headers

#include "details/QCefSettingPrivate.h"
#include "details/utils/CommonUtils.h"

REGISTER_METATYPE(QCefSetting);

QCefSetting::QCefSetting()
: d_ptr(new QCefSettingPrivate)
{}
{
}

QCefSetting::QCefSetting(const QCefSetting& other)
: d_ptr(new QCefSettingPrivate)
Expand Down Expand Up @@ -276,6 +281,7 @@ QCefSetting::javascriptDomPaste() const
return d->javascriptDomPaste_;
}

#if CEF_VERSION_MAJOR < 100
void
QCefSetting::setPlugins(const bool value)
{
Expand All @@ -289,6 +295,7 @@ QCefSetting::plugins() const
Q_D(const QCefSetting);
return d->plugins_;
}
#endif

void
QCefSetting::setImageLoading(const bool value)
Expand Down
40 changes: 40 additions & 0 deletions src/QCefView_global.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* File: QCefView_global.h
* Project: QCefView
* Created: 29th March 2016
* Author: Sheen
* Source: https://github.com/cefview/qcefview
* Docs: https://cefview.github.io/QCefView/
*/
#ifndef QCEFEVIEW_GLOBAL_H
#define QCEFEVIEW_GLOBAL_H
#pragma once

// clang-format off
#pragma region qt_headers
#include <QtCore/qglobal.h>
#include <QMetaType>
#pragma endregion qt_headers

#ifdef QCEFVIEW_STATIC
// Static library, no need export
#define QCEFVIEW_EXPORT
#else
// Dynamic library
#ifdef QCEFVIEW_LIB
// Build QCefView project, export API
#define QCEFVIEW_EXPORT Q_DECL_EXPORT
#else
// Referenced by other project, import API
#define QCEFVIEW_EXPORT Q_DECL_IMPORT
#if _WIN32
#pragma comment(lib, "QCefView.lib")
#endif
#endif
#endif

// CEF major version number
#cmakedefine CEF_VERSION_MAJOR @CEF_VERSION_MAJOR@
// clang-format on

#endif // QCEFEVIEW_GLOBAL_H
20 changes: 20 additions & 0 deletions src/details/QCefDownloadItemPrivate.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "QCefDownloadItemPrivate.h"

#pragma region cef_headers
#include <include/cef_version.h>
#pragma endregion cef_headers

#include <QCefDownloadItem.h>

QSharedPointer<QCefDownloadItem>
Expand All @@ -24,11 +28,19 @@ QCefDownloadItemPrivate::createQCefDownloadItem(CCefClientDelegate::RefPtr handl
double t = 0;
cef_time_t ct;

#if CEF_VERSION_MAJOR >= 104
cef_time_from_basetime(cefItem.GetStartTime(), &ct);
#else
ct = cefItem.GetStartTime();
#endif
if (cef_time_to_doublet(&ct, &t))
p->d_ptr->startTime = QDateTime::fromSecsSinceEpoch(t);

#if CEF_VERSION_MAJOR >= 104
cef_time_from_basetime(cefItem.GetEndTime(), &ct);
#else
ct = cefItem.GetEndTime();
#endif
if (cef_time_to_doublet(&ct, &t))
p->d_ptr->endTime = QDateTime::fromSecsSinceEpoch(t);

Expand Down Expand Up @@ -62,11 +74,19 @@ QCefDownloadItemPrivate::updateDownloadItem(QCefDownloadItem* p,
double t = 0;
cef_time_t ct;

#if CEF_VERSION_MAJOR >= 104
cef_time_from_basetime(cefItem.GetStartTime(), &ct);
#else
ct = cefItem.GetStartTime();
#endif
if (cef_time_to_doublet(&ct, &t))
p->d_ptr->startTime = QDateTime::fromSecsSinceEpoch(t);

#if CEF_VERSION_MAJOR >= 104
cef_time_from_basetime(cefItem.GetEndTime(), &ct);
#else
ct = cefItem.GetEndTime();
#endif
if (cef_time_to_doublet(&ct, &t))
p->d_ptr->endTime = QDateTime::fromSecsSinceEpoch(t);

Expand Down
8 changes: 8 additions & 0 deletions src/details/QCefSettingPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <QString>
#pragma endregion qt_headers

#pragma region cef_headers
#include <include/cef_version.h>
#pragma endregion cef_headers

#include <QCefContext.h>

#include <CefViewCoreProtocol.h>
Expand Down Expand Up @@ -64,8 +68,10 @@ QCefSettingPrivate::CopyFromCefBrowserSettings(QCefSetting* qs, const CefBrowser
if (cs->javascript_dom_paste != STATE_DEFAULT)
qs->d_ptr->javascriptDomPaste_ = cs->javascript_dom_paste == STATE_ENABLED;

#if CEF_VERSION_MAJOR < 100
if (cs->plugins != STATE_DEFAULT)
qs->d_ptr->plugins_ = cs->plugins == STATE_ENABLED;
#endif

if (cs->image_loading != STATE_DEFAULT)
qs->d_ptr->imageLoading_ = cs->image_loading == STATE_ENABLED;
Expand Down Expand Up @@ -157,8 +163,10 @@ QCefSettingPrivate::CopyToCefBrowserSettings(const QCefSetting* qs, CefBrowserSe
if (qs->d_ptr->javascriptDomPaste_.canConvert<bool>())
cs->javascript_dom_paste = qs->d_ptr->javascriptDomPaste_.toBool() ? STATE_ENABLED : STATE_DISABLED;

#if CEF_VERSION_MAJOR < 100
if (qs->d_ptr->plugins_.canConvert<bool>())
cs->plugins = qs->d_ptr->plugins_.toBool() ? STATE_ENABLED : STATE_DISABLED;
#endif

if (qs->d_ptr->imageLoading_.canConvert<bool>())
cs->image_loading = qs->d_ptr->imageLoading_.toBool() ? STATE_ENABLED : STATE_DISABLED;
Expand Down
2 changes: 2 additions & 0 deletions src/details/QCefSettingPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class QCefSettingPrivate
/* bool */ QVariant javascriptCloseWindows_;
/* bool */ QVariant javascriptAccessClipboard_;
/* bool */ QVariant javascriptDomPaste_;
#if CEF_VERSION_MAJOR < 100
/* bool */ QVariant plugins_;
#endif
/* bool */ QVariant imageLoading_;
/* bool */ QVariant imageShrinkStandaloneToFit_;
/* bool */ QVariant textAreaResize_;
Expand Down