Bug 611556 - Add persistent zoom history sessions. r=roc, r=snorp

This commit is contained in:
Eugen Sawin 2014-04-07 13:43:58 +02:00
Родитель 38bf8096d0
Коммит 8c4799afd5
6 изменённых файлов: 120 добавлений и 20 удалений

Просмотреть файл

@ -538,8 +538,17 @@ nsDOMWindowUtils::SetResolution(float aXResolution, float aYResolution)
}
nsIPresShell* presShell = GetPresShell();
return presShell ? presShell->SetResolution(aXResolution, aYResolution)
: NS_ERROR_FAILURE;
if (!presShell) {
return NS_ERROR_FAILURE;
}
nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollable();
if (sf) {
sf->SetResolution(gfxSize(aXResolution, aYResolution));
presShell->SetResolution(aXResolution, aYResolution);
}
return NS_OK;
}
NS_IMETHODIMP
@ -550,13 +559,21 @@ nsDOMWindowUtils::GetResolution(float* aXResolution, float* aYResolution)
}
nsIPresShell* presShell = GetPresShell();
if (!presShell) {
return NS_ERROR_FAILURE;
}
if (presShell) {
nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollable();
if (sf) {
const gfxSize& res = sf->GetResolution();
*aXResolution = res.width;
*aYResolution = res.height;
} else {
*aXResolution = presShell->GetXResolution();
*aYResolution = presShell->GetYResolution();
return NS_OK;
}
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP

Просмотреть файл

@ -12,6 +12,7 @@
#define nsPresState_h_
#include "nsPoint.h"
#include "gfxPoint.h"
#include "nsAutoPtr.h"
class nsPresState
@ -20,6 +21,7 @@ public:
nsPresState()
: mContentData(nullptr)
, mScrollState(0, 0)
, mResolution(1.0, 1.0)
, mDisabledSet(false)
, mDisabled(false)
{}
@ -29,18 +31,28 @@ public:
mScrollState = aState;
}
nsPoint GetScrollState()
nsPoint GetScrollState() const
{
return mScrollState;
}
void SetResolution(const gfxSize& aSize)
{
mResolution = aSize;
}
gfxSize GetResolution() const
{
return mResolution;
}
void ClearNonScrollState()
{
mContentData = nullptr;
mDisabledSet = false;
}
bool GetDisabled()
bool GetDisabled() const
{
return mDisabled;
}
@ -51,12 +63,12 @@ public:
mDisabledSet = true;
}
bool IsDisabledSet()
bool IsDisabledSet() const
{
return mDisabledSet;
}
nsISupports* GetStateProperty()
nsISupports* GetStateProperty() const
{
return mContentData;
}
@ -70,6 +82,7 @@ public:
protected:
nsCOMPtr<nsISupports> mContentData;
nsPoint mScrollState;
gfxSize mResolution;
bool mDisabledSet;
bool mDisabled;
};

Просмотреть файл

@ -1600,6 +1600,7 @@ ScrollFrameHelper::ScrollFrameHelper(nsContainerFrame* aOuter,
, mScrollPosAtLastPaint(0, 0)
, mRestorePos(-1, -1)
, mLastPos(-1, -1)
, mResolution(1.0, 1.0)
, mScrollPosForLayerPixelAlignment(-1, -1)
, mLastUpdateImagesPos(-1, -1)
, mNeverHasVerticalScrollbar(false)
@ -2786,6 +2787,18 @@ ScrollFrameHelper::GetScrollPositionClampingScrollPortSize() const
return mScrollPort.Size();
}
gfxSize
ScrollFrameHelper::GetResolution() const
{
return mResolution;
}
void
ScrollFrameHelper::SetResolution(const gfxSize& aResolution)
{
mResolution = aResolution;
}
static void
AdjustForWholeDelta(int32_t aDelta, nscoord* aCoord)
{
@ -4486,7 +4499,7 @@ ScrollFrameHelper::GetCoordAttribute(nsIFrame* aBox, nsIAtom* aAtom,
}
nsPresState*
ScrollFrameHelper::SaveState()
ScrollFrameHelper::SaveState() const
{
nsIScrollbarMediator* mediator = do_QueryFrame(GetScrolledFrame());
if (mediator) {
@ -4511,6 +4524,7 @@ ScrollFrameHelper::SaveState()
pt = mRestorePos;
}
state->SetScrollState(pt);
state->SetResolution(mResolution);
return state;
}
@ -4520,6 +4534,11 @@ ScrollFrameHelper::RestoreState(nsPresState* aState)
mRestorePos = aState->GetScrollState();
mDidHistoryRestore = true;
mLastPos = mScrolledFrame ? GetLogicalScrollPosition() : nsPoint(0,0);
mResolution = aState->GetResolution();
if (mIsRoot) {
mOuter->PresContext()->PresShell()->SetResolution(mResolution.width, mResolution.height);
}
}
void

Просмотреть файл

@ -163,6 +163,9 @@ public:
// Get the scroll range assuming the scrollport has size (aWidth, aHeight).
nsRect GetScrollRange(nscoord aWidth, nscoord aHeight) const;
nsSize GetScrollPositionClampingScrollPortSize() const;
gfxSize GetResolution() const;
void SetResolution(const gfxSize& aResolution);
protected:
nsRect GetScrollRangeForClamping() const;
@ -207,7 +210,7 @@ public:
nsSize GetLineScrollAmount() const;
nsSize GetPageScrollAmount() const;
nsPresState* SaveState();
nsPresState* SaveState() const;
void RestoreState(nsPresState* aState);
nsIFrame* GetScrolledFrame() const { return mScrolledFrame; }
@ -348,6 +351,9 @@ public:
// other than trying to restore mRestorePos.
nsPoint mLastPos;
// The current resolution derived from the zoom level and device pixel ratio.
gfxSize mResolution;
nsExpirationState mActivityExpirationState;
nsCOMPtr<nsITimer> mScrollActivityTimer;
@ -577,6 +583,12 @@ public:
virtual nsSize GetScrollPositionClampingScrollPortSize() const MOZ_OVERRIDE {
return mHelper.GetScrollPositionClampingScrollPortSize();
}
virtual gfxSize GetResolution() const MOZ_OVERRIDE {
return mHelper.GetResolution();
}
virtual void SetResolution(const gfxSize& aResolution) MOZ_OVERRIDE {
return mHelper.SetResolution(aResolution);
}
virtual nsSize GetLineScrollAmount() const MOZ_OVERRIDE {
return mHelper.GetLineScrollAmount();
}
@ -887,6 +899,12 @@ public:
virtual nsSize GetScrollPositionClampingScrollPortSize() const MOZ_OVERRIDE {
return mHelper.GetScrollPositionClampingScrollPortSize();
}
virtual gfxSize GetResolution() const MOZ_OVERRIDE {
return mHelper.GetResolution();
}
virtual void SetResolution(const gfxSize& aResolution) MOZ_OVERRIDE {
return mHelper.SetResolution(aResolution);
}
virtual nsSize GetLineScrollAmount() const MOZ_OVERRIDE {
return mHelper.GetLineScrollAmount();
}

Просмотреть файл

@ -134,7 +134,14 @@ public:
* position.
*/
virtual nsSize GetScrollPositionClampingScrollPortSize() const = 0;
/**
* Get the element resolution.
*/
virtual gfxSize GetResolution() const = 0;
/**
* Set the element resolution.
*/
virtual void SetResolution(const gfxSize& aResolution) = 0;
/**
* Return how much we would try to scroll by in each direction if
* asked to scroll by one "line" vertically and horizontally.

Просмотреть файл

@ -2882,6 +2882,7 @@ function Tab(aURL, aParams) {
this.lastTouchedAt = Date.now();
this._zoom = 1.0;
this._drawZoom = 1.0;
this._restoreZoom = false;
this._fixedMarginLeft = 0;
this._fixedMarginTop = 0;
this._fixedMarginRight = 0;
@ -3486,6 +3487,7 @@ Tab.prototype = {
let win = this.browser.contentWindow;
win.scrollTo(x, y);
this.saveSessionZoom(aViewport.zoom);
this.userScrollPos.x = win.scrollX;
this.userScrollPos.y = win.scrollY;
@ -3535,12 +3537,13 @@ Tab.prototype = {
getViewport: function() {
let screenW = gScreenWidth - gViewportMargins.left - gViewportMargins.right;
let screenH = gScreenHeight - gViewportMargins.top - gViewportMargins.bottom;
let zoom = this.restoredSessionZoom() || this._zoom;
let viewport = {
width: screenW,
height: screenH,
cssWidth: screenW / this._zoom,
cssHeight: screenH / this._zoom,
cssWidth: screenW / zoom,
cssHeight: screenH / zoom,
pageLeft: 0,
pageTop: 0,
pageRight: screenW,
@ -3548,13 +3551,13 @@ Tab.prototype = {
// We make up matching css page dimensions
cssPageLeft: 0,
cssPageTop: 0,
cssPageRight: screenW / this._zoom,
cssPageBottom: screenH / this._zoom,
cssPageRight: screenW / zoom,
cssPageBottom: screenH / zoom,
fixedMarginLeft: this._fixedMarginLeft,
fixedMarginTop: this._fixedMarginTop,
fixedMarginRight: this._fixedMarginRight,
fixedMarginBottom: this._fixedMarginBottom,
zoom: this._zoom,
zoom: zoom,
};
// Set the viewport offset to current scroll offset
@ -4186,6 +4189,9 @@ Tab.prototype = {
tabID: this.id,
};
// Restore zoom only when moving in session history, not for new page loads.
this._restoreZoom = aMessage != "New";
if (aParams) {
if ("url" in aParams)
message.url = aParams.url;
@ -4198,6 +4204,22 @@ Tab.prototype = {
sendMessageToJava(message);
},
saveSessionZoom: function(aZoom) {
let cwu = this.browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
cwu.setResolution(aZoom / window.devicePixelRatio, aZoom / window.devicePixelRatio);
},
restoredSessionZoom: function() {
if (!this._restoreZoom) {
return null;
}
let cwu = this.browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
let res = {x: {}, y: {}};
cwu.getResolution(res.x, res.y);
return res.x.value * window.devicePixelRatio;
},
OnHistoryNewEntry: function(aUri) {
this._sendHistoryEvent("New", { url: aUri.spec });
},
@ -4322,8 +4344,11 @@ Tab.prototype = {
// In all of these cases, we maintain how much actual content is visible
// within the screen width. Note that "actual content" may be different
// with respect to CSS pixels because of the CSS viewport size changing.
let zoomScale = (screenW * oldBrowserWidth) / (aOldScreenWidth * viewportW);
let zoom = (aInitialLoad && metadata.defaultZoom) ? metadata.defaultZoom : this.clampZoom(this._zoom * zoomScale);
let zoom = this.restoredSessionZoom() || metadata.defaultZoom;
if (!zoom || !aInitialLoad) {
let zoomScale = (screenW * oldBrowserWidth) / (aOldScreenWidth * viewportW);
zoom = this.clampZoom(this._zoom * zoomScale);
}
this.setResolution(zoom, false);
this.setScrollClampingSize(zoom);
@ -4459,7 +4484,8 @@ Tab.prototype = {
// and zoom when calculating the new ones, so we need to reset these
// things here before calling updateMetadata.
this.setBrowserSize(kDefaultCSSViewportWidth, kDefaultCSSViewportHeight);
this.setResolution(gScreenWidth / this.browserWidth, false);
let zoom = this.restoredSessionZoom() || gScreenWidth / this.browserWidth;
this.setResolution(zoom, true);
ViewportHandler.updateMetadata(this, true);
// Note that if we draw without a display-port, things can go wrong. By the