mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 815021 - Implement MediaRule.conditionText setter. r?
This commit is contained in:
parent
76405ff947
commit
557949bf7e
@ -1144,7 +1144,8 @@ CSSParserImpl::ParseMediaList(const nsSubstring& aBuffer,
|
||||
bool aHTMLMode)
|
||||
{
|
||||
// XXX Are there cases where the caller wants to keep what it already
|
||||
// has in case of parser error?
|
||||
// has in case of parser error? If GatherMedia ever changes to return
|
||||
// a value other than true, we probably should avoid modifying aMediaList.
|
||||
aMediaList->Clear();
|
||||
|
||||
// fake base URI since media lists don't have URIs in them
|
||||
@ -1166,7 +1167,9 @@ CSSParserImpl::ParseMediaList(const nsSubstring& aBuffer,
|
||||
// to a media query. (The main substative difference is the relative
|
||||
// precedence of commas and paretheses.)
|
||||
|
||||
GatherMedia(aMediaList, false);
|
||||
DebugOnly<bool> parsedOK = GatherMedia(aMediaList, false);
|
||||
NS_ASSERTION(parsedOK, "GatherMedia returned false; we probably want to avoid "
|
||||
"trashing aMediaList");
|
||||
|
||||
CLEAR_ERROR();
|
||||
ReleaseScanner();
|
||||
|
@ -665,7 +665,7 @@ GroupRule::EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const
|
||||
/*
|
||||
* The next two methods (DeleteStyleRuleAt and InsertStyleRulesAt)
|
||||
* should never be called unless you have first called WillDirty() on
|
||||
* the parents tylesheet. After they are called, DidDirty() needs to
|
||||
* the parents stylesheet. After they are called, DidDirty() needs to
|
||||
* be called on the sheet
|
||||
*/
|
||||
nsresult
|
||||
@ -940,7 +940,17 @@ MediaRule::GetConditionText(nsAString& aConditionText)
|
||||
NS_IMETHODIMP
|
||||
MediaRule::SetConditionText(const nsAString& aConditionText)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
if (!mMedia) {
|
||||
nsRefPtr<nsMediaList> media = new nsMediaList();
|
||||
media->SetStyleSheet(GetStyleSheet());
|
||||
nsresult rv = media->SetMediaText(aConditionText);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mMedia = media;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
return mMedia->SetMediaText(aConditionText);
|
||||
}
|
||||
|
||||
// nsIDOMCSSMediaRule methods
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
class nsXMLNameSpaceMap;
|
||||
class nsCSSRuleProcessor;
|
||||
class nsMediaList;
|
||||
class nsIPrincipal;
|
||||
class nsIURI;
|
||||
class nsMediaList;
|
||||
|
@ -93,6 +93,7 @@ MOCHITEST_FILES = test_acid3_test46.html \
|
||||
test_computed_style.html \
|
||||
test_computed_style_no_pseudo.html \
|
||||
test_condition_text.html \
|
||||
test_condition_text_assignment.html \
|
||||
test_default_computed_style.html \
|
||||
test_css_cross_domain.html \
|
||||
test_css_eof_handling.html \
|
||||
|
59
layout/style/test/test_condition_text_assignment.html
Normal file
59
layout/style/test/test_condition_text_assignment.html
Normal file
@ -0,0 +1,59 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=815021
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 815021</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<style id="style">
|
||||
#a { text-transform: none }
|
||||
@media all {
|
||||
#a { text-transform: lowercase }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=815021">Mozilla Bug 815021</a>
|
||||
<p id="display"><span id=a></span></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 815021 **/
|
||||
|
||||
var sheet = document.getElementById("style").sheet;
|
||||
var rule = sheet.cssRules[1];
|
||||
var a = document.getElementById("a");
|
||||
|
||||
function stylesApplied() {
|
||||
return window.getComputedStyle(a, "").textTransform == "lowercase";
|
||||
}
|
||||
|
||||
is(rule.type, CSSRule.MEDIA_RULE, "initial @media rule type");
|
||||
is(rule.conditionText, "all", "initial @media rule conditionText");
|
||||
ok(stylesApplied(), "initial @media rule applied");
|
||||
|
||||
// [value to set, value to check, whether styles should be applied]
|
||||
var media = [
|
||||
["not all", "not all", false],
|
||||
["ALL ", "all", true],
|
||||
["unknown", "unknown", false],
|
||||
["(min-width:1px)", "(min-width: 1px)", true],
|
||||
["(bad syntax", "not all", false],
|
||||
["(max-width: 1px), (color)", "(max-width: 1px), (color)", true]
|
||||
];
|
||||
|
||||
for (var i = 0; i < media.length; i++) {
|
||||
rule.conditionText = media[i][0];
|
||||
is(rule.conditionText, media[i][1], "value of conditionText #" + i);
|
||||
ok(rule.cssText.startsWith("@media " + media[i][1]), "value of cssText #" + i);
|
||||
ok(stylesApplied() == media[i][2], "styles applied #" + i);
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user