Skip to content

Commit

Permalink
Merge pull request sailfishos#228 from rainemak/resetHeightPick
Browse files Browse the repository at this point in the history
[sailfish-browser] Move resetHeight to the web page
  • Loading branch information
Raine Mäkeläinen committed Nov 6, 2014
2 parents 10d8da1 + f51a68c commit f81db4f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 26 deletions.
25 changes: 4 additions & 21 deletions src/declarativewebcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,13 @@ bool DeclarativeWebContainer::activatePage(int tabId, bool force)
WebPageActivationData activationData = m_webPages->page(tabId, m_model->newTabParentId());
activationData.webPage->disconnect(this);
setWebPage(activationData.webPage);
m_webPage->setChrome(true);
// Reset always height so that orentation change is taken into account.
resetHeight();
m_webPage->forceChrome(false);
m_webPage->setChrome(true);
setLoadProgress(m_webPage->loadProgress());

connect(m_webPage, SIGNAL(imeNotification(int,bool,int,int,QString)),
this, SLOT(imeNotificationChanged(int,bool,int,int,QString)), Qt::UniqueConnection);
connect(m_webPage, SIGNAL(contentHeightChanged()), this, SLOT(resetHeight()), Qt::UniqueConnection);
connect(m_webPage, SIGNAL(scrollableOffsetChanged()), this, SLOT(resetHeight()), Qt::UniqueConnection);
connect(m_webPage, SIGNAL(windowCloseRequested()), this, SLOT(closeWindow()), Qt::UniqueConnection);
connect(m_webPage, SIGNAL(urlChanged()), this, SLOT(onPageUrlChanged()), Qt::UniqueConnection);
connect(m_webPage, SIGNAL(loadingChanged()), this, SIGNAL(loadingChanged()), Qt::UniqueConnection);
Expand Down Expand Up @@ -448,26 +446,11 @@ bool DeclarativeWebContainer::eventFilter(QObject *obj, QEvent *event)

void DeclarativeWebContainer::resetHeight(bool respectContentHeight)
{
if (!m_webPage || !m_webPage->state().isEmpty()) {
if (!m_webPage) {
return;
}

// Application active
if (respectContentHeight) {
// Handle webPage height over here, BrowserPage.qml loading
// reset might be redundant as we have also loaded trigger
// reset. However, I'd leave it there for safety reasons.
// We need to reset height always back to short height when loading starts
// so that after tab change there is always initial short composited height.
// Height may expand when content is moved.
if (contentHeight() > (m_fullScreenHeight + m_toolbarHeight) || m_webPage->fullscreen()) {
m_webPage->setHeight(m_fullScreenHeight);
} else {
m_webPage->setHeight(m_fullScreenHeight - m_toolbarHeight);
}
} else {
m_webPage->setHeight(m_fullScreenHeight - m_toolbarHeight);
}
m_webPage->resetHeight(respectContentHeight);
}

void DeclarativeWebContainer::imeNotificationChanged(int state, bool open, int cause, int focusChange, const QString &type)
Expand Down
60 changes: 59 additions & 1 deletion src/declarativewebpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ DeclarativeWebPage::DeclarativeWebPage(QQuickItem *parent)
, m_loaded(false)
, m_userHasDraggedWhileLoading(false)
, m_fullscreen(false)
, m_forcedChrome(false)
, m_domContentLoaded(false)
, m_urlHasChanged(false)
, m_backForwardNavigation(false)
{
connect(this, SIGNAL(viewInitialized()), this, SLOT(onViewInitialized()));
connect(this, SIGNAL(recvAsyncMessage(const QString, const QVariant)),
this, SLOT(onRecvAsyncMessage(const QString&, const QVariant&)));
connect(this, SIGNAL(contentHeightChanged()), this, SLOT(resetHeight()));
connect(this, SIGNAL(scrollableOffsetChanged()), this, SLOT(resetHeight()));
}

DeclarativeWebPage::~DeclarativeWebPage()
Expand Down Expand Up @@ -117,6 +120,56 @@ void DeclarativeWebPage::loadTab(QString newUrl, bool force)
}
}

/**
* Use this to lock to chrome mode. This disables the gesture
* that normally enables fullscreen mode. The chromeGestureEnabled property
* is bound to this so that contentHeight changes do not re-enable the
* gesture.
*
* When gesture is allowed to be used again, unlock call by forceChrome(false).
*
* Used for instance when find-in-page view is active that is part of
* the new browser user interface.
*/
void DeclarativeWebPage::forceChrome(bool forcedChrome)
{
// This way we don't break chromeGestureEnabled and chrome bindings.
setChromeGestureEnabled(!forcedChrome);
if (forcedChrome) {
setChrome(forcedChrome);
}
// Without chrome respect content height.
resetHeight(!forcedChrome);
if (m_forcedChrome != forcedChrome) {
m_forcedChrome = forcedChrome;
emit forcedChromeChanged();
}
}

void DeclarativeWebPage::resetHeight(bool respectContentHeight)
{
if (!state().isEmpty()) {
return;
}

// Application active
if (respectContentHeight && !m_forcedChrome) {
// Handle webPage height over here, BrowserPage.qml loading
// reset might be redundant as we have also loaded trigger
// reset. However, I'd leave it there for safety reasons.
// We need to reset height always back to short height when loading starts
// so that after tab change there is always initial short composited height.
// Height may expand when content is moved.
if (contentHeight() > (m_fullScreenHeight + m_toolbarHeight) || fullscreen()) {
setHeight(m_fullScreenHeight);
} else {
setHeight(m_fullScreenHeight - m_toolbarHeight);
}
} else {
setHeight(m_fullScreenHeight - m_toolbarHeight);
}
}

void DeclarativeWebPage::componentComplete()
{
QuickMozView::componentComplete();
Expand All @@ -143,11 +196,16 @@ bool DeclarativeWebPage::fullscreen() const
return m_fullscreen;
}

bool DeclarativeWebPage::forcedChrome() const
{
return m_forcedChrome;
}

void DeclarativeWebPage::setFullscreen(const bool fullscreen)
{
if (m_fullscreen != fullscreen) {
m_fullscreen = fullscreen;
m_container->resetHeight();
resetHeight();
emit fullscreenChanged();
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/declarativewebpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ class DeclarativeWebPage : public QuickMozView {
Q_PROPERTY(bool loaded MEMBER m_loaded NOTIFY loadedChanged FINAL)
Q_PROPERTY(bool userHasDraggedWhileLoading MEMBER m_userHasDraggedWhileLoading NOTIFY userHasDraggedWhileLoadingChanged FINAL)
Q_PROPERTY(bool fullscreen READ fullscreen NOTIFY fullscreenChanged FINAL)
Q_PROPERTY(bool forcedChrome READ forcedChrome NOTIFY forcedChromeChanged FINAL)
Q_PROPERTY(QString favicon MEMBER m_favicon NOTIFY faviconChanged FINAL)
Q_PROPERTY(QVariant resurrectedContentRect READ resurrectedContentRect WRITE setResurrectedContentRect NOTIFY resurrectedContentRectChanged)

Q_PROPERTY(qreal fullscreenHeight MEMBER m_fullScreenHeight NOTIFY fullscreenHeightChanged FINAL)
Q_PROPERTY(qreal toolbarHeight MEMBER m_toolbarHeight NOTIFY toolbarHeightChanged FINAL)

public:
DeclarativeWebPage(QQuickItem *parent = 0);
~DeclarativeWebPage();
Expand All @@ -43,6 +47,7 @@ class DeclarativeWebPage : public QuickMozView {
void setResurrectedContentRect(QVariant resurrectedContentRect);

bool fullscreen() const;
bool forcedChrome() const;
bool domContentLoaded() const;

bool urlHasChanged() const;
Expand All @@ -54,6 +59,10 @@ class DeclarativeWebPage : public QuickMozView {
bool viewReady() const;

Q_INVOKABLE void loadTab(QString newUrl, bool force);
Q_INVOKABLE void forceChrome(bool forcedChrome);

public slots:
void resetHeight(bool respectContentHeight = true);

signals:
void containerChanged();
Expand All @@ -62,10 +71,14 @@ class DeclarativeWebPage : public QuickMozView {
void loadedChanged();
void userHasDraggedWhileLoadingChanged();
void fullscreenChanged();
void forcedChromeChanged();
void domContentLoadedChanged();
void faviconChanged();
void resurrectedContentRectChanged();

void fullscreenHeightChanged();
void toolbarHeightChanged();

protected:
void componentComplete();

Expand All @@ -81,11 +94,15 @@ private slots:
bool m_loaded;
bool m_userHasDraggedWhileLoading;
bool m_fullscreen;
bool m_forcedChrome;
bool m_domContentLoaded;
bool m_urlHasChanged;
bool m_backForwardNavigation;
QString m_favicon;
QVariant m_resurrectedContentRect;

qreal m_fullScreenHeight;
qreal m_toolbarHeight;
};

QDebug operator<<(QDebug, const DeclarativeWebPage *);
Expand Down
11 changes: 7 additions & 4 deletions src/pages/components/WebView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,18 @@ WebContainer {
property string iconType
readonly property bool activeWebPage: container.tabId == tabId

fullscreenHeight: container.fullscreenHeight
toolbarHeight: container.toolbarHeight

loaded: loadProgress === 100 && !loading
enabled: container.active
// Active could pause e.g. video in cover by anding
// Qt.application.active to visible
active: visible || activeWebPage

// There needs to be enough content for enabling chrome gesture
chromeGestureThreshold: container.toolbarHeight / 2
chromeGestureEnabled: contentHeight > container.fullscreenHeight + container.toolbarHeight
chromeGestureThreshold: toolbarHeight / 2
chromeGestureEnabled: (contentHeight > fullscreenHeight + toolbarHeight) && !forcedChrome

signal selectionRangeUpdated(variant data)
signal selectionCopied(variant data)
Expand Down Expand Up @@ -227,7 +230,7 @@ WebContainer {

onLoadedChanged: {
if (loaded && !userHasDraggedWhileLoading) {
container.resetHeight(false)
resetHeight(false)
if (resurrectedContentRect) {
sendAsyncMessage("embedui:zoomToRect",
{
Expand All @@ -254,8 +257,8 @@ WebContainer {
iconSize = 0
if (activeWebPage) {
container.loadProgress = 0
container.resetHeight(false)
}
resetHeight(false)
}
}

Expand Down

0 comments on commit f81db4f

Please sign in to comment.