Bug 618016 - Make a new media query for device orientation [r=dbaron a=blassey]

This commit is contained in:
Mark Finkle 2010-12-10 13:35:36 -05:00
parent dabc82dc8e
commit 45373efb36
3 changed files with 50 additions and 0 deletions

View File

@ -1789,3 +1789,4 @@ GK_ATOM(_moz_touch_enabled, "-moz-touch-enabled")
GK_ATOM(_moz_maemo_classic, "-moz-maemo-classic")
GK_ATOM(_moz_menubar_drag, "-moz-menubar-drag")
GK_ATOM(_moz_device_pixel_ratio, "-moz-device-pixel-ratio")
GK_ATOM(_moz_device_orientation, "-moz-device-orientation")

View File

@ -176,6 +176,23 @@ GetOrientation(nsPresContext* aPresContext, const nsMediaFeature*,
return NS_OK;
}
static nsresult
GetDeviceOrientation(nsPresContext* aPresContext, const nsMediaFeature*,
nsCSSValue& aResult)
{
nsSize size = GetDeviceSize(aPresContext);
PRInt32 orientation;
if (size.width > size.height) {
orientation = NS_STYLE_ORIENTATION_LANDSCAPE;
} else {
// Per spec, square viewports should be 'portrait'
orientation = NS_STYLE_ORIENTATION_PORTRAIT;
}
aResult.SetIntValue(orientation, eCSSUnit_Enumerated);
return NS_OK;
}
// Helper for two features below
static nsresult
MakeArray(const nsSize& aSize, nsCSSValue& aResult)
@ -435,6 +452,13 @@ nsMediaFeatures::features[] = {
{ nsnull },
GetDevicePixelRatio
},
{
&nsGkAtoms::_moz_device_orientation,
nsMediaFeature::eMinMaxNotAllowed,
nsMediaFeature::eEnumerated,
{ kOrientationKeywords },
GetDeviceOrientation
},
{
&nsGkAtoms::_moz_scrollbar_start_backward,
nsMediaFeature::eMinMaxNotAllowed,

View File

@ -168,6 +168,13 @@ function run() {
query_should_be_parseable("not all and (orientation)");
query_should_be_parseable("only all and (orientation)");
query_should_be_parseable("(-moz-device-orientation)");
query_should_not_be_parseable("not (-moz-device-orientation)");
query_should_not_be_parseable("only (-moz-device-orientation)");
query_should_be_parseable("all and (-moz-device-orientation)");
query_should_be_parseable("not all and (-moz-device-orientation)");
query_should_be_parseable("only all and (-moz-device-orientation)");
var features = [ "width", "height", "device-width", "device-height" ];
var feature;
var i;
@ -282,6 +289,24 @@ function run() {
should_apply("not all and (orientation: landscape)");
should_apply("(orientation: portrait)");
expression_should_be_parseable("-moz-device-orientation");
expression_should_be_parseable("-moz-device-orientation: portrait");
expression_should_be_parseable("-moz-device-orientation: landscape");
expression_should_not_be_parseable("min--moz-device-orientation");
expression_should_not_be_parseable("min--moz-device-orientation: portrait");
expression_should_not_be_parseable("min--moz-device-orientation: landscape");
expression_should_not_be_parseable("max--moz-device-orientation");
expression_should_not_be_parseable("max--moz-device-orientation: portrait");
expression_should_not_be_parseable("max--moz-device-orientation: landscape");
// determine the actual configuration of the screen and test against it
var device_orientation = (device_width > device_height) ? "landscape" : "portrait";
var not_device_orientation = (device_orientation == "landscape") ? "portrait" : "landscape";
should_apply("(-moz-device-orientation)");
should_apply("(-moz-device-orientation: " + device_orientation + ")");
should_not_apply("(-moz-device-orientation: " + not_device_orientation + ")");
should_apply("not all and (-moz-device-orientation: " + not_device_orientation + ")");
should_apply("(aspect-ratio: 59/80)");
should_not_apply("(aspect-ratio: 58/80)");
should_not_apply("(aspect-ratio: 59/81)");