Bug 974430 - Put the |input[type=number]| rule in forms.css into a separate sheet so we can make it respect the dom.forms.number pref. r=dbaron

--HG--
extra : rebase_source : 450ffd1ca743868d75dda6ce0f89078216934e79
This commit is contained in:
Jonathan Watt 2014-02-26 12:26:14 +00:00
parent b026c3cc67
commit a8ab69c5db
6 changed files with 67 additions and 7 deletions

View File

@ -2225,6 +2225,11 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
}
}
sheet = nsLayoutStylesheetCache::NumberControlSheet();
if (sheet) {
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
}
sheet = nsLayoutStylesheetCache::FormsSheet();
if (sheet) {
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);

View File

@ -901,13 +901,9 @@ input[type=range]::-moz-range-thumb {
-moz-user-select: none ! important;
}
input[type="number"] {
-moz-appearance: number-input;
/* Has to revert some properties applied by the generic input rule. */
-moz-binding: none;
width: 149px; /* to match type=text */
overflow-clip-box: content-box;
}
/* As a temporary workaround until bug 677302 the rule for input[type=number]
* has moved to number-control.css
*/
input[type=number]::-moz-number-wrapper {
/* Prevent styling that would change the type of frame we construct. */

View File

@ -10,6 +10,7 @@ toolkit.jar:
res/plaintext.css (plaintext.css)
res/viewsource.css (viewsource.css)
* res/forms.css (forms.css)
res/number-control.css (number-control.css)
res/arrow.gif (arrow.gif)
res/arrowd.gif (arrowd.gif)

View File

@ -8,6 +8,7 @@
#include "nsAppDirectoryServiceDefs.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Preferences.h"
#include "mozilla/css/Loader.h"
#include "nsIFile.h"
#include "nsNetUtil.h"
@ -16,6 +17,12 @@
#include "nsIXULRuntime.h"
#include "nsCSSStyleSheet.h"
using namespace mozilla;
static bool sNumberControlEnabled;
#define NUMBER_CONTROL_PREF "dom.forms.number"
NS_IMPL_ISUPPORTS2(
nsLayoutStylesheetCache, nsIObserver, nsIMemoryReporter)
@ -35,6 +42,7 @@ nsLayoutStylesheetCache::Observe(nsISupports* aSubject,
strcmp(aTopic, "chrome-flush-caches") == 0) {
mScrollbarsSheet = nullptr;
mFormsSheet = nullptr;
mNumberControlSheet = nullptr;
}
else {
NS_NOTREACHED("Unexpected observer topic.");
@ -85,6 +93,31 @@ nsLayoutStylesheetCache::FormsSheet()
return gStyleCache->mFormsSheet;
}
nsCSSStyleSheet*
nsLayoutStylesheetCache::NumberControlSheet()
{
EnsureGlobal();
if (!gStyleCache)
return nullptr;
if (!sNumberControlEnabled) {
return nullptr;
}
if (!gStyleCache->mNumberControlSheet) {
nsCOMPtr<nsIURI> sheetURI;
NS_NewURI(getter_AddRefs(sheetURI),
NS_LITERAL_CSTRING("resource://gre-resources/number-control.css"));
if (sheetURI)
LoadSheet(sheetURI, gStyleCache->mNumberControlSheet, false);
NS_ASSERTION(gStyleCache->mNumberControlSheet, "Could not load number-control.css");
}
return gStyleCache->mNumberControlSheet;
}
nsCSSStyleSheet*
nsLayoutStylesheetCache::UserContentSheet()
{
@ -164,6 +197,7 @@ nsLayoutStylesheetCache::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
MEASURE(mScrollbarsSheet);
MEASURE(mFormsSheet);
MEASURE(mNumberControlSheet);
MEASURE(mUserContentSheet);
MEASURE(mUserChromeSheet);
MEASURE(mUASheet);
@ -237,6 +271,9 @@ nsLayoutStylesheetCache::EnsureGlobal()
NS_ADDREF(gStyleCache);
gStyleCache->InitMemoryReporter();
Preferences::AddBoolVarCache(&sNumberControlEnabled, NUMBER_CONTROL_PREF,
true);
}
void

View File

@ -33,6 +33,9 @@ class nsLayoutStylesheetCache MOZ_FINAL
static nsCSSStyleSheet* ScrollbarsSheet();
static nsCSSStyleSheet* FormsSheet();
// This function is expected to return nullptr when the dom.forms.number
// pref is disabled.
static nsCSSStyleSheet* NumberControlSheet();
static nsCSSStyleSheet* UserContentSheet();
static nsCSSStyleSheet* UserChromeSheet();
static nsCSSStyleSheet* UASheet();
@ -58,6 +61,7 @@ private:
static mozilla::css::Loader* gCSSLoader;
nsRefPtr<nsCSSStyleSheet> mScrollbarsSheet;
nsRefPtr<nsCSSStyleSheet> mFormsSheet;
nsRefPtr<nsCSSStyleSheet> mNumberControlSheet;
nsRefPtr<nsCSSStyleSheet> mUserContentSheet;
nsRefPtr<nsCSSStyleSheet> mUserChromeSheet;
nsRefPtr<nsCSSStyleSheet> mUASheet;

View File

@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* This file exists purely because we need the styling for input[type=number]
* to apply only if the pref dom.forms.number is true. Once bug 677302 is
* fixed this rule can move back to forms.css.
*/
input[type="number"] {
-moz-appearance: number-input;
/* Has to revert some properties applied by the generic input rule. */
-moz-binding: none;
width: 149px; /* to match type=text */
overflow-clip-box: content-box;
}