-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For now QtUi is a stub besides - getting the scale factor to verify things are hooked up correctly - detecting font changes to ensure the QT event loop is working Bug: 1317782 Change-Id: I8dec8a108ff6f877a89bdfcddc8a257476106abd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3601270 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Commit-Queue: Thomas Anderson <thomasanderson@chromium.org> Cr-Commit-Position: refs/heads/main@{#1002866}
- Loading branch information
1 parent
54ae9b1
commit 4a7dc21
Showing
14 changed files
with
679 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright 2022 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import("//build/config/chromecast_build.gni") | ||
import("//build/config/linux/pkg_config.gni") | ||
import("//ui/qt/qt.gni") | ||
|
||
assert(use_qt) | ||
assert(is_linux) | ||
assert(!is_chromecast) | ||
|
||
pkg_config("qt5_config") { | ||
packages = [ | ||
"Qt5Core", | ||
"Qt5Widgets", | ||
] | ||
} | ||
|
||
source_set("qt_interface") { | ||
visibility = [ ":*" ] | ||
|
||
# Since `:qt` depends on `qt_shim` via data_deps, gn check would error-out | ||
# if qt_interface.h was placed in `qt_shim`, so it's placed in a separate | ||
# target instead. | ||
public = [ "qt_interface.h" ] | ||
} | ||
|
||
shared_library("qt5_shim") { | ||
visibility = [ | ||
":qt", | ||
"//chrome/installer/linux:*", | ||
] | ||
|
||
# Since qt_shim is a shared library even in non-component builds, it shouldn't | ||
# depend on any other targets since that would duplicate code between binaries | ||
# leading to increased size and potential issues from duplicated global state. | ||
no_default_deps = true | ||
assert_no_deps = [ | ||
"//base", | ||
"//buildtools/third_party/libc++", | ||
] | ||
deps = [ ":qt_interface" ] | ||
|
||
# It's OK to depend on the system libstdc++ since it's a dependency of QT, so | ||
# it will get loaded into the process anyway. | ||
libs = [ "stdc++" ] | ||
|
||
configs += [ ":qt5_config" ] | ||
|
||
public = [] | ||
sources = [ | ||
"qt_shim.cc", | ||
"qt_shim.h", | ||
|
||
# This file is generated to avoid a dependency on `moc` during the build. | ||
# 1. $ build/linux/debian_bullseye_amd64-sysroot/usr/lib/qt5/bin/moc \ | ||
# ui/qt/qt_shim.h > ui/qt/qt_shim_moc.cc | ||
# 2. $ git cl format | ||
# 3. Manually add copyright header. | ||
"qt_shim_moc.cc", | ||
] | ||
} | ||
|
||
component("qt") { | ||
visibility = [ "//ui/views/linux_ui:linux_ui_factory" ] | ||
|
||
defines = [ "IS_QT_IMPL" ] | ||
|
||
# qt_shim is in data_deps since we want to load it manually. | ||
data_deps = [ ":qt5_shim" ] | ||
deps = [ | ||
":qt_interface", | ||
"//base", | ||
"//ui/shell_dialogs", | ||
"//ui/views", | ||
] | ||
|
||
sources = [ | ||
"qt_ui.cc", | ||
"qt_ui.h", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include_rules = [ | ||
"+ui/gfx", | ||
"+ui/shell_dialogs", | ||
"+ui/views", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
thestig@chromium.org | ||
thomasanderson@chromium.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright 2022 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
declare_args() { | ||
# https://crbug.com/1317782 enable QT UI by default on Linux. | ||
use_qt = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef UI_QT_QT_INTERFACE_H_ | ||
#define UI_QT_QT_INTERFACE_H_ | ||
|
||
// This file shouldn't include any standard C++ headers (directly or indirectly) | ||
|
||
namespace qt { | ||
|
||
class QtInterface { | ||
public: | ||
QtInterface() = default; | ||
QtInterface(const QtInterface&) = delete; | ||
QtInterface& operator=(const QtInterface&) = delete; | ||
virtual ~QtInterface() = default; | ||
|
||
virtual double GetScaleFactor() const = 0; | ||
}; | ||
|
||
} // namespace qt | ||
|
||
// This should be the only thing exported from qt_shim. | ||
extern "C" __attribute__((visibility("default"))) qt::QtInterface* | ||
CreateQtInterface(int* argc, char** argv); | ||
|
||
#endif // UI_QT_QT_INTERFACE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ui/qt/qt_shim.h" | ||
|
||
#include <stdio.h> | ||
|
||
#include <QApplication> | ||
|
||
namespace qt { | ||
|
||
QtShim::QtShim(int* argc, char** argv) : app_(*argc, argv) { | ||
connect(&app_, SIGNAL(fontChanged(const QFont&)), this, | ||
SLOT(FontChanged(const QFont&))); | ||
} | ||
|
||
QtShim::~QtShim() = default; | ||
|
||
double QtShim::GetScaleFactor() const { | ||
return app_.devicePixelRatio(); | ||
} | ||
|
||
void QtShim::FontChanged(const QFont& font) { | ||
// TODO(thomasanderson): implement this. | ||
} | ||
|
||
} // namespace qt | ||
|
||
qt::QtInterface* CreateQtInterface(int* argc, char** argv) { | ||
return new qt::QtShim(argc, argv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef UI_QT_QT_SHIM_H_ | ||
#define UI_QT_QT_SHIM_H_ | ||
|
||
#include <QApplication> | ||
#include <QObject> | ||
|
||
#include "ui/qt/qt_interface.h" | ||
|
||
namespace qt { | ||
|
||
// This class directly interacts with QT. It's required to be a QObject | ||
// to receive signals from QT via slots. | ||
class QtShim : public QObject, public QtInterface { | ||
Q_OBJECT | ||
|
||
public: | ||
QtShim(int* argc, char** argv); | ||
|
||
~QtShim() override; | ||
|
||
// QtShim: | ||
double GetScaleFactor() const override; | ||
|
||
private slots: | ||
void FontChanged(const QFont& font); | ||
|
||
private: | ||
QApplication app_; | ||
}; | ||
|
||
} // namespace qt | ||
|
||
#endif // UI_QT_QT_SHIM_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
/**************************************************************************** | ||
** Meta object code from reading C++ file 'qt_shim.h' | ||
** | ||
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.15.2) | ||
** | ||
** WARNING! All changes made in this file will be lost! | ||
*****************************************************************************/ | ||
|
||
#include <QtCore/qbytearray.h> | ||
#include <QtCore/qmetatype.h> | ||
#include <memory> | ||
#include "ui/qt/qt_shim.h" | ||
#if !defined(Q_MOC_OUTPUT_REVISION) | ||
#error "The header file 'qt_shim.h' doesn't include <QObject>." | ||
#elif Q_MOC_OUTPUT_REVISION != 67 | ||
#error "This file was generated using the moc from 5.15.2. It" | ||
#error "cannot be used with the include files from this version of Qt." | ||
#error "(The moc has changed too much.)" | ||
#endif | ||
|
||
QT_BEGIN_MOC_NAMESPACE | ||
QT_WARNING_PUSH | ||
QT_WARNING_DISABLE_DEPRECATED | ||
struct qt_meta_stringdata_qt__QtShim_t { | ||
QByteArrayData data[4]; | ||
char stringdata0[29]; | ||
}; | ||
#define QT_MOC_LITERAL(idx, ofs, len) \ | ||
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET( \ | ||
len, qptrdiff(offsetof(qt_meta_stringdata_qt__QtShim_t, stringdata0) + \ | ||
ofs - idx * sizeof(QByteArrayData))) | ||
static const qt_meta_stringdata_qt__QtShim_t qt_meta_stringdata_qt__QtShim = { | ||
{ | ||
QT_MOC_LITERAL(0, 0, 10), // "qt::QtShim" | ||
QT_MOC_LITERAL(1, 11, 11), // "FontChanged" | ||
QT_MOC_LITERAL(2, 23, 0), // "" | ||
QT_MOC_LITERAL(3, 24, 4) // "font" | ||
|
||
}, | ||
"qt::QtShim\0FontChanged\0\0font"}; | ||
#undef QT_MOC_LITERAL | ||
|
||
static const uint qt_meta_data_qt__QtShim[] = { | ||
|
||
// content: | ||
8, // revision | ||
0, // classname | ||
0, 0, // classinfo | ||
1, 14, // methods | ||
0, 0, // properties | ||
0, 0, // enums/sets | ||
0, 0, // constructors | ||
0, // flags | ||
0, // signalCount | ||
|
||
// slots: name, argc, parameters, tag, flags | ||
1, 1, 19, 2, 0x08 /* Private */, | ||
|
||
// slots: parameters | ||
QMetaType::Void, QMetaType::QFont, 3, | ||
|
||
0 // eod | ||
}; | ||
|
||
void qt::QtShim::qt_static_metacall(QObject* _o, | ||
QMetaObject::Call _c, | ||
int _id, | ||
void** _a) { | ||
if (_c == QMetaObject::InvokeMetaMethod) { | ||
auto* _t = static_cast<QtShim*>(_o); | ||
Q_UNUSED(_t) | ||
switch (_id) { | ||
case 0: | ||
_t->FontChanged((*reinterpret_cast<const QFont(*)>(_a[1]))); | ||
break; | ||
default:; | ||
} | ||
} | ||
} | ||
|
||
QT_INIT_METAOBJECT const QMetaObject qt::QtShim::staticMetaObject = { | ||
{QMetaObject::SuperData::link<QObject::staticMetaObject>(), | ||
qt_meta_stringdata_qt__QtShim.data, qt_meta_data_qt__QtShim, | ||
qt_static_metacall, nullptr, nullptr}}; | ||
|
||
const QMetaObject* qt::QtShim::metaObject() const { | ||
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() | ||
: &staticMetaObject; | ||
} | ||
|
||
void* qt::QtShim::qt_metacast(const char* _clname) { | ||
if (!_clname) | ||
return nullptr; | ||
if (!strcmp(_clname, qt_meta_stringdata_qt__QtShim.stringdata0)) | ||
return static_cast<void*>(this); | ||
if (!strcmp(_clname, "QtInterface")) | ||
return static_cast<QtInterface*>(this); | ||
return QObject::qt_metacast(_clname); | ||
} | ||
|
||
int qt::QtShim::qt_metacall(QMetaObject::Call _c, int _id, void** _a) { | ||
_id = QObject::qt_metacall(_c, _id, _a); | ||
if (_id < 0) | ||
return _id; | ||
if (_c == QMetaObject::InvokeMetaMethod) { | ||
if (_id < 1) | ||
qt_static_metacall(this, _c, _id, _a); | ||
_id -= 1; | ||
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { | ||
if (_id < 1) | ||
*reinterpret_cast<int*>(_a[0]) = -1; | ||
_id -= 1; | ||
} | ||
return _id; | ||
} | ||
QT_WARNING_POP | ||
QT_END_MOC_NAMESPACE |
Oops, something went wrong.