diff --git a/src/qmessagepump.cpp b/src/qmessagepump.cpp index 369c588..63180a3 100644 --- a/src/qmessagepump.cpp +++ b/src/qmessagepump.cpp @@ -18,20 +18,21 @@ using namespace mozilla::embedlite; -namespace { // Cached QEvent user type, registered for our event system -static int sPokeEvent; -} // namespace +static int sPokeEvent = -1; MessagePumpQt::MessagePumpQt(EmbedLiteApp *aApp) : mApp(aApp) , mTimer(new QTimer(this)) - , mState(0) + , mState(nullptr) , mLastDelayedWorkTime(-1) { mEventLoopPrivate = mApp->CreateEmbedLiteMessagePump(this); + // Register our custom event type, to use in qApp event loop - sPokeEvent = QEvent::registerEventType(); + if (sPokeEvent == -1) { + sPokeEvent = QEvent::registerEventType(); + } connect(mTimer, &QTimer::timeout, this, &MessagePumpQt::dispatchDelayed); mTimer->setSingleShot(true); } @@ -44,17 +45,16 @@ MessagePumpQt::~MessagePumpQt() delete mEventLoopPrivate; } -bool -MessagePumpQt::event(QEvent *e) +bool MessagePumpQt::event(QEvent *e) { if (e->type() == sPokeEvent) { - HandleDispatch(); + handleDispatch(); return true; } return QObject::event(e); } -void MessagePumpQt::HandleDispatch() +void MessagePumpQt::handleDispatch() { if (mState->should_quit) { return; @@ -63,7 +63,7 @@ void MessagePumpQt::HandleDispatch() if (mEventLoopPrivate->DoWork(mState->delegate)) { // there might be more, see more_work_is_plausible // variable above, that's why we ScheduleWork() to keep going. - ScheduleWorkLocal(); + scheduleWorkLocal(); } if (mState->should_quit) { @@ -75,19 +75,17 @@ void MessagePumpQt::HandleDispatch() if (doIdleWork) { if (mEventLoopPrivate->DoIdleWork(mState->delegate)) { - ScheduleWorkLocal(); + scheduleWorkLocal(); } } } -void MessagePumpQt::ScheduleWorkLocal() +void MessagePumpQt::scheduleWorkLocal() { - QCoreApplication::postEvent(this, - new QEvent((QEvent::Type)sPokeEvent)); + QCoreApplication::postEvent(this, new QEvent((QEvent::Type)sPokeEvent)); } -void -MessagePumpQt::scheduleDelayedIfNeeded() +void MessagePumpQt::scheduleDelayedIfNeeded() { if (mLastDelayedWorkTime == -1) { return; @@ -100,10 +98,9 @@ MessagePumpQt::scheduleDelayedIfNeeded() mTimer->start(mLastDelayedWorkTime >= 0 ? mLastDelayedWorkTime : 0); } -void -MessagePumpQt::dispatchDelayed() +void MessagePumpQt::dispatchDelayed() { - HandleDispatch(); + handleDispatch(); } void MessagePumpQt::Run(void *delegate) @@ -113,7 +110,7 @@ void MessagePumpQt::Run(void *delegate) state->should_quit = false; state->run_depth = mState ? mState->run_depth + 1 : 1; mState = state; - HandleDispatch(); + handleDispatch(); } void MessagePumpQt::Quit() @@ -126,7 +123,7 @@ void MessagePumpQt::Quit() void MessagePumpQt::ScheduleWork() { - ScheduleWorkLocal(); + scheduleWorkLocal(); } void MessagePumpQt::ScheduleDelayedWork(const int aDelay) diff --git a/src/qmessagepump.h b/src/qmessagepump.h index aa07e4e..fe53a5b 100644 --- a/src/qmessagepump.h +++ b/src/qmessagepump.h @@ -10,6 +10,7 @@ #include #include #include + #include "mozilla/embedlite/EmbedLiteMessagePump.h" namespace mozilla { @@ -26,15 +27,12 @@ class MessagePumpQt : public QObject, public mozilla::embedlite::EmbedLiteMessag MessagePumpQt(mozilla::embedlite::EmbedLiteApp *aApp); ~MessagePumpQt(); - virtual bool event(QEvent *e); - void scheduleDelayedIfNeeded(); - void HandleDispatch(); - void ScheduleWork(); + bool event(QEvent *e) override; - virtual void Run(void *aDelegate); - virtual void Quit(); - virtual void ScheduleWorkLocal(); - virtual void ScheduleDelayedWork(const int aDelay); + void Run(void *aDelegate) override; + void Quit() override; + void ScheduleWork() override; + void ScheduleDelayedWork(const int aDelay) override; mozilla::embedlite::EmbedLiteMessagePump *EmbedLoop() { @@ -45,6 +43,10 @@ public Q_SLOTS: void dispatchDelayed(); private: + void scheduleWorkLocal(); + void scheduleDelayedIfNeeded(); + void handleDispatch(); + // We may make recursive calls to Run, so we save state that needs to be // separate between them in this structure type. struct RunState { diff --git a/src/qmozextmaterialnode.cpp b/src/qmozextmaterialnode.cpp index 189596f..c7d1aaa 100644 --- a/src/qmozextmaterialnode.cpp +++ b/src/qmozextmaterialnode.cpp @@ -4,6 +4,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "qmozextmaterialnode.h" + +#include +#include #include #include @@ -25,6 +28,7 @@ static void updateRectGeometry(QSGGeometry *g, const QRectF &rect, } MozMaterialNode::MozMaterialNode() + : m_orientation(qApp->primaryScreen()->primaryOrientation()) { setFlag(UsePreprocess); @@ -106,12 +110,14 @@ void MozMaterialNode::preprocess() QRectF textureRect = m_normalizedTextureSubRect; const bool landscape = m_orientation & (Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation); - const qreal width = landscape ? m_rect.height() : m_rect.width(); - const qreal height = landscape ? m_rect.width() : m_rect.height(); + const bool transpose = (landscape + == (qApp->primaryScreen()->primaryOrientation() == Qt::PortraitOrientation)); + const qreal width = transpose ? m_rect.height() : m_rect.width(); + const qreal height = transpose ? m_rect.width() : m_rect.height(); const QSizeF textureSize = m_texture ? QSizeF(m_texture->textureSize()) : QSizeF(width, height); if (width > textureSize.width()) { - if (landscape) { + if (transpose) { geometryRect.setHeight(textureSize.width()); } else { geometryRect.setWidth(textureSize.width()); @@ -121,7 +127,7 @@ void MozMaterialNode::preprocess() } if (height > textureSize.height()) { - if (landscape) { + if (transpose) { geometryRect.setWidth(textureSize.height()); } else { geometryRect.setHeight(textureSize.height()); @@ -131,8 +137,9 @@ void MozMaterialNode::preprocess() } // and then texture coordinates - switch (m_orientation) { - case Qt::LandscapeOrientation: + int rotation = qApp->primaryScreen()->angleBetween(m_orientation, qApp->primaryScreen()->primaryOrientation()); + switch (rotation) { + case 90: updateRectGeometry( &m_geometry, geometryRect, @@ -141,7 +148,7 @@ void MozMaterialNode::preprocess() textureRect.bottomRight(), textureRect.bottomLeft()); break; - case Qt::InvertedPortraitOrientation: + case 180: updateRectGeometry( &m_geometry, geometryRect, @@ -150,7 +157,7 @@ void MozMaterialNode::preprocess() textureRect.bottomLeft(), textureRect.topLeft()); break; - case Qt::InvertedLandscapeOrientation: + case 270: updateRectGeometry( &m_geometry, geometryRect, @@ -160,7 +167,6 @@ void MozMaterialNode::preprocess() textureRect.topRight()); break; default: - // Portrait / PrimaryOrientation updateRectGeometry( &m_geometry, geometryRect, diff --git a/src/qmozextmaterialnode.h b/src/qmozextmaterialnode.h index a3bc393..41ef1dd 100644 --- a/src/qmozextmaterialnode.h +++ b/src/qmozextmaterialnode.h @@ -37,7 +37,7 @@ class MozMaterialNode : public QSGGeometryNode QRectF m_rect { 0, 0, 0, 0 }; QRectF m_normalizedTextureSubRect { 0, 0, 1, 1 }; QSGTexture *m_texture = nullptr; - Qt::ScreenOrientation m_orientation = Qt::PortraitOrientation; + Qt::ScreenOrientation m_orientation; bool m_geometryChanged = true; bool m_textureChanged = true; }; diff --git a/src/qmozsecurity.cpp b/src/qmozsecurity.cpp index 4f82637..78c584c 100644 --- a/src/qmozsecurity.cpp +++ b/src/qmozsecurity.cpp @@ -229,8 +229,7 @@ void QMozSecurity::importState(const char *aStatus, unsigned int aState) // If the status is empty, leave it as it was if (aStatus && *aStatus && context) { embedSecurity = context->GetApp()->CreateSecurity(aStatus, aState); - } - else { + } else { if (!aStatus || !*aStatus) { qCDebug(lcEmbedLiteExt) << "Security state could not be imported: empty status"; } @@ -278,8 +277,7 @@ void QMozSecurity::importState(const char *aStatus, unsigned int aState) m_serverCertificate = serverCertificate; emissions << &QMozSecurity::serverCertificateChanged; } - } - else { + } else { // There was a deserialisation error resetStatus(&emissions); qCDebug(lcEmbedLiteExt) << "Security state change: deserialisation failed"; diff --git a/src/qmozwindow_p.cpp b/src/qmozwindow_p.cpp index 2eb0b7f..977b7d1 100644 --- a/src/qmozwindow_p.cpp +++ b/src/qmozwindow_p.cpp @@ -68,7 +68,7 @@ QMozWindowPrivate::QMozWindowPrivate(QMozWindow &window, const QSize &size) , mReadyToPaint(true) , mSize(size) , mOrientation(Qt::PrimaryOrientation) - , mPrimaryOrientation(Qt::PortraitOrientation) + , mPrimaryOrientation(qApp->primaryScreen()->primaryOrientation()) , mPendingOrientation(Qt::PrimaryOrientation) , mOrientationFilterTimer(0) , mReserved(false) diff --git a/src/quickmozview.cpp b/src/quickmozview.cpp index 3cb963d..4a2b76c 100644 --- a/src/quickmozview.cpp +++ b/src/quickmozview.cpp @@ -16,6 +16,7 @@ #include "mozilla/embedlite/EmbedLiteApp.h" #include "mozilla/TimeStamp.h" +#include #include #include #include @@ -36,7 +37,6 @@ using namespace mozilla; using namespace mozilla::embedlite; - namespace { class ObjectCleanup : public QRunnable @@ -56,23 +56,24 @@ class ObjectCleanup : public QRunnable QObject * const m_object; }; -} - QSizeF webContentWindowSize(Qt::ScreenOrientation orientation, const QSizeF &size) { - // Set size for EmbedLiteWindow in "portrait" - QSizeF s = size; - if (orientation == Qt::LandscapeOrientation || orientation == Qt::InvertedLandscapeOrientation) { - s.transpose(); + // Set size for EmbedLiteWindow in screen native orientation + QSizeF result = size; + if ((qApp->primaryScreen()->primaryOrientation() == Qt::PortraitOrientation) + == (orientation == Qt::LandscapeOrientation || orientation == Qt::InvertedLandscapeOrientation)) { + result.transpose(); } - return s; + return result; +} + } QuickMozView::QuickMozView(QQuickItem *parent) : QQuickItem(parent) , d(new QMozViewPrivate(new IMozQView(*this), this)) , mTexture(nullptr) - , mOrientation(Qt::PrimaryOrientation) + , mOrientation(qApp->primaryScreen()->primaryOrientation()) , mExplicitViewportWidth(false) , mExplicitViewportHeight(false) , mExplicitOrientation(false)