Bug 1106905 - Modify mobile desktop mode implementation to use a desktop viewport. r=kats

This commit is contained in:
Mantaroh Yoshinaga 2015-03-12 12:14:55 -04:00
parent 2e29ef1a61
commit 46662b3fb2
6 changed files with 61 additions and 2 deletions

View File

@ -2375,6 +2375,18 @@ nsDOMWindowUtils::IsInModalState(bool *retval)
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::SetDesktopModeViewport(bool aDesktopMode)
{
MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome());
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_STATE(window);
static_cast<nsGlobalWindow*>(window.get())->SetDesktopModeViewport(aDesktopMode);
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetOuterWindowID(uint64_t *aWindowID)
{

View File

@ -7895,6 +7895,15 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
CSSToScreenScale defaultScale = layoutDeviceScale
* LayoutDeviceToScreenScale(1.0);
// Get requested Desktopmode
nsPIDOMWindow* win = GetWindow();
if (win && win->IsDesktopModeViewport())
{
return nsViewportInfo(aDisplaySize,
defaultScale,
/*allowZoom*/false,
/*allowDoubleTapZoom*/ true);
}
if (!Preferences::GetBool("dom.meta-viewport.enabled", false)) {
return nsViewportInfo(aDisplaySize,

View File

@ -580,7 +580,8 @@ nsPIDOMWindow::nsPIDOMWindow(nsPIDOMWindow *aOuterWindow)
mIsModalContentWindow(false),
mIsActive(false), mIsBackground(false),
mAudioMuted(false), mAudioVolume(1.0),
mInnerWindow(nullptr), mOuterWindow(aOuterWindow),
mDesktopModeViewport(false), mInnerWindow(nullptr),
mOuterWindow(aOuterWindow),
// Make sure no actual window ends up with mWindowID == 0
mWindowID(NextWindowID()), mHasNotifiedGlobalCreated(false),
mMarkedCCGeneration(0)

View File

@ -96,6 +96,17 @@ public:
}
// Outer windows only.
void SetDesktopModeViewport(bool aDesktopModeViewport)
{
MOZ_ASSERT(IsOuterWindow());
mDesktopModeViewport = aDesktopModeViewport;
}
bool IsDesktopModeViewport() const
{
MOZ_ASSERT(IsOuterWindow());
return mDesktopModeViewport;
}
virtual void SetIsBackground(bool aIsBackground)
{
MOZ_ASSERT(IsOuterWindow());
@ -783,6 +794,9 @@ protected:
bool mAudioMuted;
float mAudioVolume;
// current desktop mode flag.
bool mDesktopModeViewport;
// And these are the references between inner and outer windows.
nsPIDOMWindow* MOZ_NON_OWNING_REF mInnerWindow;
nsCOMPtr<nsPIDOMWindow> mOuterWindow;

View File

@ -50,7 +50,7 @@ interface nsITranslationNodeList;
interface nsIJSRAIIHelper;
interface nsIContentPermissionRequest;
[scriptable, uuid(6eaf87a1-b252-4c4e-a2fc-318120680335)]
[scriptable, uuid(aa7a399f-7178-4006-9e37-d3959afed2ee)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -1275,6 +1275,11 @@ interface nsIDOMWindowUtils : nsISupports {
*/
[noscript] boolean isInModalState();
/**
* Request set internal desktopMode flag change.
*/
void setDesktopModeViewport(in boolean aDesktopModeViewport);
/**
* Suspend/resume timeouts on this window and its descendant windows.
*/

View File

@ -3570,6 +3570,11 @@ Tab.prototype = {
* Reloads the tab with the desktop mode setting.
*/
reloadWithMode: function (aDesktopMode) {
// notify desktopmode for PIDOMWindow
let win = this.browser.contentWindow;
let dwi = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
dwi.setDesktopModeViewport(aDesktopMode);
// Set desktop mode for tab and send change to Java
if (this.desktopMode != aDesktopMode) {
this.desktopMode = aDesktopMode;
@ -6323,6 +6328,19 @@ var ViewportHandler = {
* Returns the ViewportMetadata object.
*/
getViewportMetadata: function getViewportMetadata(aWindow) {
let tab = BrowserApp.getTabForWindow(aWindow);
if (tab.desktopMode) {
return new ViewportMetadata({
minZoom: kViewportMinScale,
maxZoom: kViewportMaxScale,
width: kDefaultCSSViewportWidth,
height: kDefaultCSSViewportHeight,
allowZoom: true,
allowDoubleTapZoom: true,
isSpecified: false
});
}
let windowUtils = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
// viewport details found here