Bug 890195 - device-width media queries should use the page width, not the actual device width. r=bz
This commit is contained in:
@@ -181,6 +181,12 @@ function ResponsiveUI(aWindow, aTab)
|
|||||||
this.buildUI();
|
this.buildUI();
|
||||||
this.checkMenus();
|
this.checkMenus();
|
||||||
|
|
||||||
|
this.docShell = this.browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIWebNavigation)
|
||||||
|
.QueryInterface(Ci.nsIDocShell);
|
||||||
|
|
||||||
|
this.docShell.deviceSizeIsPageSize = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (Services.prefs.getBoolPref("devtools.responsiveUI.rotate")) {
|
if (Services.prefs.getBoolPref("devtools.responsiveUI.rotate")) {
|
||||||
this.rotate();
|
this.rotate();
|
||||||
@@ -249,6 +255,8 @@ ResponsiveUI.prototype = {
|
|||||||
return;
|
return;
|
||||||
this.closing = true;
|
this.closing = true;
|
||||||
|
|
||||||
|
this.docShell.deviceSizeIsPageSize = false;
|
||||||
|
|
||||||
this.browser.removeEventListener("load", this.bound_onPageLoad, true);
|
this.browser.removeEventListener("load", this.bound_onPageLoad, true);
|
||||||
this.browser.removeEventListener("unload", this.bound_onPageUnload, true);
|
this.browser.removeEventListener("unload", this.bound_onPageUnload, true);
|
||||||
|
|
||||||
@@ -288,6 +296,7 @@ ResponsiveUI.prototype = {
|
|||||||
this.container.removeAttribute("responsivemode");
|
this.container.removeAttribute("responsivemode");
|
||||||
this.stack.removeAttribute("responsivemode");
|
this.stack.removeAttribute("responsivemode");
|
||||||
|
|
||||||
|
delete this.docShell;
|
||||||
delete this.tab.__responsiveUI;
|
delete this.tab.__responsiveUI;
|
||||||
if (this.touchEventHandler)
|
if (this.touchEventHandler)
|
||||||
this.touchEventHandler.stop();
|
this.touchEventHandler.stop();
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ support-files =
|
|||||||
[browser_responsiveui.js]
|
[browser_responsiveui.js]
|
||||||
[browser_responsiveui_touch.js]
|
[browser_responsiveui_touch.js]
|
||||||
[browser_responsiveuiaddcustompreset.js]
|
[browser_responsiveuiaddcustompreset.js]
|
||||||
|
[browser_responsive_devicewidth.js]
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
let instance;
|
||||||
|
let mgr = ResponsiveUI.ResponsiveUIManager;
|
||||||
|
|
||||||
|
waitForExplicitFinish();
|
||||||
|
|
||||||
|
gBrowser.selectedTab = gBrowser.addTab();
|
||||||
|
gBrowser.selectedBrowser.addEventListener("load", function onload() {
|
||||||
|
gBrowser.selectedBrowser.removeEventListener("load", onload, true);
|
||||||
|
waitForFocus(startTest, content);
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
content.location = "data:text/html,mop";
|
||||||
|
|
||||||
|
function startTest() {
|
||||||
|
mgr.once("on", function() {executeSoon(onUIOpen)});
|
||||||
|
document.getElementById("Tools:ResponsiveUI").doCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onUIOpen() {
|
||||||
|
instance = gBrowser.selectedTab.__responsiveUI;
|
||||||
|
instance.stack.setAttribute("notransition", "true");
|
||||||
|
ok(instance, "instance of the module is attached to the tab.");
|
||||||
|
|
||||||
|
instance.setSize(110, 500);
|
||||||
|
ok(content.innerWidth, 110, "initial width is valid");
|
||||||
|
|
||||||
|
let mql = content.matchMedia("(max-device-width:100px)")
|
||||||
|
|
||||||
|
ok(!mql.matches, "media query doesn't match.");
|
||||||
|
|
||||||
|
mql.addListener(onMediaChange);
|
||||||
|
instance.setSize(90, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMediaChange(mql) {
|
||||||
|
mql.removeListener(onMediaChange);
|
||||||
|
ok(mql.matches, "media query matches.");
|
||||||
|
ok(window.screen.width != content.screen.width, "screen.width is not the size of the screen.");
|
||||||
|
is(content.screen.width, 90, "screen.width is the width of the page.");
|
||||||
|
is(content.screen.height, 500, "screen.height is the height of the page.");
|
||||||
|
|
||||||
|
|
||||||
|
let docShell = content.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIWebNavigation)
|
||||||
|
.QueryInterface(Ci.nsIDocShell);
|
||||||
|
|
||||||
|
mql.addListener(onMediaChange2);
|
||||||
|
docShell.deviceSizeIsPageSize = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMediaChange2(mql) {
|
||||||
|
mql.removeListener(onMediaChange);
|
||||||
|
ok(!mql.matches, "media query has been re-evaluated.");
|
||||||
|
ok(window.screen.width == content.screen.width, "screen.width is not the size of the screen.");
|
||||||
|
instance.stack.removeAttribute("notransition");
|
||||||
|
document.getElementById("Tools:ResponsiveUI").doCommand();
|
||||||
|
gBrowser.removeCurrentTab();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -755,6 +755,7 @@ nsDocShell::nsDocShell():
|
|||||||
mIsAppTab(false),
|
mIsAppTab(false),
|
||||||
mUseGlobalHistory(false),
|
mUseGlobalHistory(false),
|
||||||
mInPrivateBrowsing(false),
|
mInPrivateBrowsing(false),
|
||||||
|
mDeviceSizeIsPageSize(false),
|
||||||
mFiredUnloadEvent(false),
|
mFiredUnloadEvent(false),
|
||||||
mEODForCurrentDocument(false),
|
mEODForCurrentDocument(false),
|
||||||
mURIResultedInDocument(false),
|
mURIResultedInDocument(false),
|
||||||
@@ -3920,6 +3921,27 @@ nsDocShell::GetCurrentSHEntry(nsISHEntry** aEntry, bool* aOSHE)
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDocShell::SetDeviceSizeIsPageSize(bool aValue)
|
||||||
|
{
|
||||||
|
if (mDeviceSizeIsPageSize != aValue) {
|
||||||
|
mDeviceSizeIsPageSize = aValue;
|
||||||
|
nsRefPtr<nsPresContext> presContext;
|
||||||
|
GetPresContext(getter_AddRefs(presContext));
|
||||||
|
if (presContext) {
|
||||||
|
presContext->MediaFeatureValuesChanged(presContext->eAlwaysRebuildStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDocShell::GetDeviceSizeIsPageSize(bool* aValue)
|
||||||
|
{
|
||||||
|
*aValue = mDeviceSizeIsPageSize;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsDocShell::ClearFrameHistory(nsISHEntry* aEntry)
|
nsDocShell::ClearFrameHistory(nsISHEntry* aEntry)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -815,6 +815,7 @@ protected:
|
|||||||
bool mIsAppTab;
|
bool mIsAppTab;
|
||||||
bool mUseGlobalHistory;
|
bool mUseGlobalHistory;
|
||||||
bool mInPrivateBrowsing;
|
bool mInPrivateBrowsing;
|
||||||
|
bool mDeviceSizeIsPageSize;
|
||||||
|
|
||||||
// This boolean is set to true right before we fire pagehide and generally
|
// This boolean is set to true right before we fire pagehide and generally
|
||||||
// unset when we embed a new content viewer. While it's true no navigation
|
// unset when we embed a new content viewer. While it's true no navigation
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ interface nsIReflowObserver;
|
|||||||
|
|
||||||
typedef unsigned long nsLoadFlags;
|
typedef unsigned long nsLoadFlags;
|
||||||
|
|
||||||
[scriptable, builtinclass, uuid(1470A132-99B2-44C3-B37D-D8093B2E29BF)]
|
[scriptable, builtinclass, uuid(77aca3ee-7417-4cd2-994e-9bd95ca1d98a)]
|
||||||
interface nsIDocShell : nsIDocShellTreeItem
|
interface nsIDocShell : nsIDocShellTreeItem
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -907,4 +907,12 @@ interface nsIDocShell : nsIDocShellTreeItem
|
|||||||
*/
|
*/
|
||||||
[noscript, notxpcom] bool IsInvisible();
|
[noscript, notxpcom] bool IsInvisible();
|
||||||
[noscript, notxpcom] void SetInvisible(in bool aIsInvisibleDochsell);
|
[noscript, notxpcom] void SetInvisible(in bool aIsInvisibleDochsell);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If deviceSizeIsPageSize is set to true, device-width/height media queries
|
||||||
|
* will be calculated from the page size, not the device size.
|
||||||
|
*
|
||||||
|
* Used by the Responsive Design View.
|
||||||
|
*/
|
||||||
|
[infallible] attribute boolean deviceSizeIsPageSize;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -390,6 +390,19 @@ nsScreen::SlowMozUnlockOrientation()
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
nsScreen::IsDeviceSizePageSize()
|
||||||
|
{
|
||||||
|
nsPIDOMWindow* owner = GetOwner();
|
||||||
|
if (owner) {
|
||||||
|
nsIDocShell* docShell = owner->GetDocShell();
|
||||||
|
if (docShell) {
|
||||||
|
return docShell->GetDeviceSizeIsPageSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* virtual */
|
/* virtual */
|
||||||
JSObject*
|
JSObject*
|
||||||
nsScreen::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
nsScreen::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
||||||
|
|||||||
@@ -51,6 +51,15 @@ public:
|
|||||||
int32_t GetWidth(ErrorResult& aRv)
|
int32_t GetWidth(ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
nsRect rect;
|
nsRect rect;
|
||||||
|
if (IsDeviceSizePageSize()) {
|
||||||
|
nsCOMPtr<nsPIDOMWindow> owner = GetOwner();
|
||||||
|
if (owner) {
|
||||||
|
int32_t innerWidth = 0;
|
||||||
|
aRv = owner->GetInnerWidth(&innerWidth);
|
||||||
|
return innerWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
aRv = GetRect(rect);
|
aRv = GetRect(rect);
|
||||||
return rect.width;
|
return rect.width;
|
||||||
}
|
}
|
||||||
@@ -58,6 +67,15 @@ public:
|
|||||||
int32_t GetHeight(ErrorResult& aRv)
|
int32_t GetHeight(ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
nsRect rect;
|
nsRect rect;
|
||||||
|
if (IsDeviceSizePageSize()) {
|
||||||
|
nsCOMPtr<nsPIDOMWindow> owner = GetOwner();
|
||||||
|
if (owner) {
|
||||||
|
int32_t innerHeight = 0;
|
||||||
|
aRv = owner->GetInnerHeight(&innerHeight);
|
||||||
|
return innerHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
aRv = GetRect(rect);
|
aRv = GetRect(rect);
|
||||||
return rect.height;
|
return rect.height;
|
||||||
}
|
}
|
||||||
@@ -137,6 +155,8 @@ private:
|
|||||||
|
|
||||||
LockPermission GetLockOrientationPermission() const;
|
LockPermission GetLockOrientationPermission() const;
|
||||||
|
|
||||||
|
bool IsDeviceSizePageSize();
|
||||||
|
|
||||||
nsRefPtr<FullScreenEventListener> mEventListener;
|
nsRefPtr<FullScreenEventListener> mEventListener;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2688,6 +2688,17 @@ nsPresContext::AppUnitsToGfxUnits(nscoord aAppUnits) const
|
|||||||
return mDeviceContext->AppUnitsToGfxUnits(aAppUnits);
|
return mDeviceContext->AppUnitsToGfxUnits(aAppUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
nsPresContext::IsDeviceSizePageSize()
|
||||||
|
{
|
||||||
|
bool isDeviceSizePageSize = false;
|
||||||
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
|
||||||
|
if (docShell) {
|
||||||
|
isDeviceSizePageSize = docShell->GetDeviceSizeIsPageSize();
|
||||||
|
}
|
||||||
|
return isDeviceSizePageSize;
|
||||||
|
}
|
||||||
|
|
||||||
nsRootPresContext::nsRootPresContext(nsIDocument* aDocument,
|
nsRootPresContext::nsRootPresContext(nsIDocument* aDocument,
|
||||||
nsPresContextType aType)
|
nsPresContextType aType)
|
||||||
: nsPresContext(aDocument, aType),
|
: nsPresContext(aDocument, aType),
|
||||||
|
|||||||
@@ -1000,6 +1000,8 @@ public:
|
|||||||
mExistThrottledUpdates = aExistThrottledUpdates;
|
mExistThrottledUpdates = aExistThrottledUpdates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsDeviceSizePageSize();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class nsRunnableMethod<nsPresContext>;
|
friend class nsRunnableMethod<nsPresContext>;
|
||||||
NS_HIDDEN_(void) ThemeChangedInternal();
|
NS_HIDDEN_(void) ThemeChangedInternal();
|
||||||
|
|||||||
@@ -113,14 +113,18 @@ static nsSize
|
|||||||
GetDeviceSize(nsPresContext* aPresContext)
|
GetDeviceSize(nsPresContext* aPresContext)
|
||||||
{
|
{
|
||||||
nsSize size;
|
nsSize size;
|
||||||
if (aPresContext->IsRootPaginatedDocument())
|
|
||||||
|
if (aPresContext->IsDeviceSizePageSize()) {
|
||||||
|
size = GetSize(aPresContext);
|
||||||
|
} else if (aPresContext->IsRootPaginatedDocument()) {
|
||||||
// We want the page size, including unprintable areas and margins.
|
// We want the page size, including unprintable areas and margins.
|
||||||
// XXX The spec actually says we want the "page sheet size", but
|
// XXX The spec actually says we want the "page sheet size", but
|
||||||
// how is that different?
|
// how is that different?
|
||||||
size = aPresContext->GetPageSize();
|
size = aPresContext->GetPageSize();
|
||||||
else
|
} else {
|
||||||
GetDeviceContextFor(aPresContext)->
|
GetDeviceContextFor(aPresContext)->
|
||||||
GetDeviceSurfaceDimensions(size.width, size.height);
|
GetDeviceSurfaceDimensions(size.width, size.height);
|
||||||
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user