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

Quickmozview landscape fixes #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
39 changes: 18 additions & 21 deletions src/qmessagepump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -126,7 +123,7 @@ void MessagePumpQt::Quit()

void MessagePumpQt::ScheduleWork()
{
ScheduleWorkLocal();
scheduleWorkLocal();
}

void MessagePumpQt::ScheduleDelayedWork(const int aDelay)
Expand Down
18 changes: 10 additions & 8 deletions src/qmessagepump.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QTimer>
#include <QVariant>
#include <QStringList>

#include "mozilla/embedlite/EmbedLiteMessagePump.h"

namespace mozilla {
Expand All @@ -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()
{
Expand All @@ -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 {
Expand Down
24 changes: 15 additions & 9 deletions src/qmozextmaterialnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "qmozextmaterialnode.h"

#include <QGuiApplication>
#include <QScreen>
#include <QOpenGLContext>
#include <QOpenGLFunctions>

Expand All @@ -25,6 +28,7 @@ static void updateRectGeometry(QSGGeometry *g, const QRectF &rect,
}

MozMaterialNode::MozMaterialNode()
: m_orientation(qApp->primaryScreen()->primaryOrientation())
{
setFlag(UsePreprocess);

Expand Down Expand Up @@ -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());
Expand All @@ -121,7 +127,7 @@ void MozMaterialNode::preprocess()
}

if (height > textureSize.height()) {
if (landscape) {
if (transpose) {
geometryRect.setWidth(textureSize.height());
} else {
geometryRect.setHeight(textureSize.height());
Expand All @@ -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,
Expand All @@ -141,7 +148,7 @@ void MozMaterialNode::preprocess()
textureRect.bottomRight(),
textureRect.bottomLeft());
break;
case Qt::InvertedPortraitOrientation:
case 180:
updateRectGeometry(
&m_geometry,
geometryRect,
Expand All @@ -150,7 +157,7 @@ void MozMaterialNode::preprocess()
textureRect.bottomLeft(),
textureRect.topLeft());
break;
case Qt::InvertedLandscapeOrientation:
case 270:
updateRectGeometry(
&m_geometry,
geometryRect,
Expand All @@ -160,7 +167,6 @@ void MozMaterialNode::preprocess()
textureRect.topRight());
break;
default:
// Portrait / PrimaryOrientation
updateRectGeometry(
&m_geometry,
geometryRect,
Expand Down
2 changes: 1 addition & 1 deletion src/qmozextmaterialnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
6 changes: 2 additions & 4 deletions src/qmozsecurity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/qmozwindow_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions src/quickmozview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "mozilla/embedlite/EmbedLiteApp.h"
#include "mozilla/TimeStamp.h"

#include <QGuiApplication>
#include <QThread>
#include <QMutexLocker>
#include <QtQuick/qquickwindow.h>
Expand All @@ -36,7 +37,6 @@
using namespace mozilla;
using namespace mozilla::embedlite;


namespace {

class ObjectCleanup : public QRunnable
Expand All @@ -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<QuickMozView>(*this), this))
, mTexture(nullptr)
, mOrientation(Qt::PrimaryOrientation)
, mOrientation(qApp->primaryScreen()->primaryOrientation())
, mExplicitViewportWidth(false)
, mExplicitViewportHeight(false)
, mExplicitOrientation(false)
Expand Down