bool update_media_lists(media_features features) { var update_styles = false; foreach (var iter in _media_lists) { if (iter.apply_media_features(features)) { update_styles = true; } } return(update_styles); }
public bool apply_media_features(media_features features) // returns true if the _is_used changed { var apply = false; foreach (var iter in _queries) { if (iter.check(features)) { apply = true; break; } } var ret = apply != _is_used; _is_used = apply; return(ret); }
public bool check(media_features features) { var res = false; if (_media_type == media_type.all || _media_type == features.type) { res = true; foreach (var expr in _expressions) { if (!expr.check(features)) { res = false; break; } } } if (_not) { res = !res; } return(res); }
public void get_media_features(media_features media) { }
public void MediaQueryCheckTest() { media_query_expression e; media_features k; e = new media_query_expression { feature = media_feature.width, val = 100 }; k = new media_features { width = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { width = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { width = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_width, val = 100 }; k = new media_features { width = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { width = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { width = 500 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_width, val = 100 }; k = new media_features { width = 0 }; Assert.IsTrue(e.check(k)); k = new media_features { width = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { width = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.height, val = 100 }; k = new media_features { height = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { height = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_height, val = 100 }; k = new media_features { height = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { height = 500 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_height, val = 100 }; k = new media_features { height = 0 }; Assert.IsTrue(e.check(k)); k = new media_features { height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { height = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.depth, val = 100 }; k = new media_features { depth = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { depth = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { depth = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_depth, val = 100 }; k = new media_features { depth = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { depth = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { depth = 500 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_depth, val = 100 }; k = new media_features { depth = 0 }; Assert.IsTrue(e.check(k)); k = new media_features { depth = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { depth = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.device_width, val = 100 }; k = new media_features { device_width = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { device_width = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_width = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_device_width, val = 100 }; k = new media_features { device_width = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { device_width = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_width = 500 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_device_width, val = 100 }; k = new media_features { device_width = 0 }; Assert.IsTrue(e.check(k)); k = new media_features { device_width = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_width = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.device_height, val = 100 }; k = new media_features { device_height = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { device_height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_height = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_device_height, val = 100 }; k = new media_features { device_height = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { device_height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_height = 500 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_device_height, val = 100 }; k = new media_features { device_height = 0 }; Assert.IsTrue(e.check(k)); k = new media_features { device_height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_height = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.device_depth, val = 100 }; k = new media_features { device_depth = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { device_depth = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_depth = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_device_depth, val = 100 }; k = new media_features { device_depth = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { device_depth = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_depth = 500 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_device_depth, val = 100 }; k = new media_features { device_depth = 0 }; Assert.IsTrue(e.check(k)); k = new media_features { device_depth = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_depth = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.orientation, val = (int)media_orientation.portrait }; k = new media_features { width = 0, height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { width = 100, height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { width = 500, height = 100 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.orientation, val = (int)media_orientation.landscape }; k = new media_features { width = 0, height = 100 }; Assert.IsFalse(e.check(k)); k = new media_features { width = 100, height = 100 }; Assert.IsFalse(e.check(k)); k = new media_features { width = 500, height = 100 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.aspect_ratio, val = 100, val2 = 100 }; k = new media_features { width = 0, height = 100 }; Assert.IsFalse(e.check(k)); k = new media_features { width = 100, height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { width = 500, height = 100 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_aspect_ratio, val = 100, val2 = 100 }; k = new media_features { width = 0, height = 100 }; Assert.IsFalse(e.check(k)); k = new media_features { width = 100, height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { width = 500, height = 100 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_aspect_ratio, val = 100, val2 = 100 }; k = new media_features { width = 0, height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { width = 100, height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { width = 500, height = 100 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.device_aspect_ratio, val = 100, val2 = 100 }; k = new media_features { device_width = 0, device_height = 100 }; Assert.IsFalse(e.check(k)); k = new media_features { device_width = 100, device_height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_width = 500, device_height = 100 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_device_aspect_ratio, val = 100, val2 = 100 }; k = new media_features { device_width = 0, device_height = 100 }; Assert.IsFalse(e.check(k)); k = new media_features { device_width = 100, device_height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_width = 500, device_height = 100 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_device_aspect_ratio, val = 100, val2 = 100 }; k = new media_features { device_width = 0, device_height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_width = 100, device_height = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { device_width = 500, device_height = 100 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.color, val = 100 }; k = new media_features { color = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { color = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { color = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_color, val = 100 }; k = new media_features { color = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { color = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { color = 500 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_color, val = 100 }; k = new media_features { color = 0 }; Assert.IsTrue(e.check(k)); k = new media_features { color = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { color = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.color_index, val = 100 }; k = new media_features { color_index = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { color_index = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { color_index = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_color_index, val = 100 }; k = new media_features { color_index = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { color_index = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { color_index = 500 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_color_index, val = 100 }; k = new media_features { color_index = 0 }; Assert.IsTrue(e.check(k)); k = new media_features { color_index = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { color_index = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.monochrome, val = 100 }; k = new media_features { monochrome = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { monochrome = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { monochrome = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_monochrome, val = 100 }; k = new media_features { monochrome = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { monochrome = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { monochrome = 500 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_monochrome, val = 100 }; k = new media_features { monochrome = 0 }; Assert.IsTrue(e.check(k)); k = new media_features { monochrome = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { monochrome = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.resolution, val = 100 }; k = new media_features { resolution = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { resolution = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { resolution = 500 }; Assert.IsFalse(e.check(k)); e = new media_query_expression { feature = media_feature.min_resolution, val = 100 }; k = new media_features { resolution = 0 }; Assert.IsFalse(e.check(k)); k = new media_features { resolution = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { resolution = 500 }; Assert.IsTrue(e.check(k)); e = new media_query_expression { feature = media_feature.max_resolution, val = 100 }; k = new media_features { resolution = 0 }; Assert.IsTrue(e.check(k)); k = new media_features { resolution = 100 }; Assert.IsTrue(e.check(k)); k = new media_features { resolution = 500 }; Assert.IsFalse(e.check(k)); }
public bool check(media_features features) { switch (feature) { case media_feature.width: if (check_as_bool) { return(features.width != 0); } else if (features.width == val) { return(true); } break; case media_feature.min_width: if (features.width >= val) { return(true); } break; case media_feature.max_width: if (features.width <= val) { return(true); } break; case media_feature.height: if (check_as_bool) { return(features.height != 0); } else if (features.height == val) { return(true); } break; case media_feature.min_height: if (features.height >= val) { return(true); } break; case media_feature.max_height: if (features.height <= val) { return(true); } break; case media_feature.depth: if (check_as_bool) { return(features.depth != 0); } else if (features.depth == val) { return(true); } break; case media_feature.min_depth: if (features.depth >= val) { return(true); } break; case media_feature.max_depth: if (features.depth <= val) { return(true); } break; case media_feature.device_width: if (check_as_bool) { return(features.device_width != 0); } else if (features.device_width == val) { return(true); } break; case media_feature.min_device_width: if (features.device_width >= val) { return(true); } break; case media_feature.max_device_width: if (features.device_width <= val) { return(true); } break; case media_feature.device_height: if (check_as_bool) { return(features.device_height != 0); } else if (features.device_height == val) { return(true); } break; case media_feature.min_device_height: if (features.device_height >= val) { return(true); } break; case media_feature.max_device_height: if (features.device_height <= val) { return(true); } break; case media_feature.device_depth: if (check_as_bool) { return(features.device_depth != 0); } else if (features.device_depth == val) { return(true); } break; case media_feature.min_device_depth: if (features.device_depth >= val) { return(true); } break; case media_feature.max_device_depth: if (features.device_depth <= val) { return(true); } break; case media_feature.orientation: if (features.height >= features.width) { if ((media_orientation)val == media_orientation.portrait) { return(true); } } else { if ((media_orientation)val == media_orientation.landscape) { return(true); } } break; case media_feature.aspect_ratio: if (features.height != 0 && val2 != 0) { var ratio_this = (int)Math.Round(val / (double)val2 * 100); var ratio_feat = (int)Math.Round(features.width / (double)features.height * 100.0); if (ratio_this == ratio_feat) { return(true); } } break; case media_feature.min_aspect_ratio: if (features.height != 0 && val2 != 0) { var ratio_this = (int)Math.Round(val / (double)val2 * 100); var ratio_feat = (int)Math.Round(features.width / (double)features.height * 100.0); if (ratio_feat >= ratio_this) { return(true); } } break; case media_feature.max_aspect_ratio: if (features.height != 0 && val2 != 0) { var ratio_this = (int)Math.Round(val / (double)val2 * 100); var ratio_feat = (int)Math.Round(features.width / (double)features.height * 100.0); if (ratio_feat <= ratio_this) { return(true); } } break; case media_feature.device_aspect_ratio: if (features.device_height != 0 && val2 != 0) { var ratio_this = (int)Math.Round(val / (double)val2 * 100); var ratio_feat = (int)Math.Round(features.device_width / (double)features.device_height * 100.0); if (ratio_feat == ratio_this) { return(true); } } break; case media_feature.min_device_aspect_ratio: if (features.device_height != 0 && val2 != 0) { var ratio_this = (int)Math.Round(val / (double)val2 * 100); var ratio_feat = (int)Math.Round(features.device_width / (double)features.device_height * 100.0); if (ratio_feat >= ratio_this) { return(true); } } break; case media_feature.max_device_aspect_ratio: if (features.device_height != 0 && val2 != 0) { var ratio_this = (int)Math.Round(val / (double)val2 * 100); var ratio_feat = (int)Math.Round(features.device_width / (double)features.device_height * 100.0); if (ratio_feat <= ratio_this) { return(true); } } break; case media_feature.color: if (check_as_bool) { return(features.color != 0); } else if (features.color == val) { return(true); } break; case media_feature.min_color: if (features.color >= val) { return(true); } break; case media_feature.max_color: if (features.color <= val) { return(true); } break; case media_feature.color_index: if (check_as_bool) { return(features.color_index != 0); } else if (features.color_index == val) { return(true); } break; case media_feature.min_color_index: if (features.color_index >= val) { return(true); } break; case media_feature.max_color_index: if (features.color_index <= val) { return(true); } break; case media_feature.monochrome: if (check_as_bool) { return(features.monochrome != 0); } else if (features.monochrome == val) { return(true); } break; case media_feature.min_monochrome: if (features.monochrome >= val) { return(true); } break; case media_feature.max_monochrome: if (features.monochrome <= val) { return(true); } break; case media_feature.resolution: if (features.resolution == val) { return(true); } break; case media_feature.min_resolution: if (features.resolution >= val) { return(true); } break; case media_feature.max_resolution: if (features.resolution <= val) { return(true); } break; default: return(false); } return(false); }