From 03c1939e54b7b222ff1fc3a3610cd0d001002b42 Mon Sep 17 00:00:00 2001 From: Luke Chang Date: Thu, 20 Apr 2017 17:44:14 +0800 Subject: [PATCH] Bug 1355438 - [Form Autofill] Implement an internal-only pseudo-class for highlighting elements with an autofilled value. r=heycam MozReview-Commit-ID: BUqAWSekPsh --HG-- extra : rebase_source : c3c9b7a98ca5895eb56c8b07b4c3845e6ac71de0 --- dom/base/nsDOMWindowUtils.cpp | 2 +- dom/events/EventStates.h | 4 +++- layout/style/nsCSSPseudoClassList.h | 4 ++++ layout/style/res/forms.css | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 398137eef88c..a6e8ec7aeb64 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -4230,7 +4230,7 @@ struct StateTableEntry }; static constexpr StateTableEntry kManuallyManagedStates[] = { - // none yet; but for example: { "highlight", NS_EVENT_STATE_HIGHLIGHT }, + { "-moz-autofill", NS_EVENT_STATE_AUTOFILL }, { nullptr, EventStates() }, }; diff --git a/dom/events/EventStates.h b/dom/events/EventStates.h index 66bb8b1cbcfb..6200f7d9e8aa 100644 --- a/dom/events/EventStates.h +++ b/dom/events/EventStates.h @@ -288,6 +288,8 @@ private: #define NS_EVENT_STATE_LTR NS_DEFINE_EVENT_STATE_MACRO(44) // Element is rtl (for :dir pseudo-class) #define NS_EVENT_STATE_RTL NS_DEFINE_EVENT_STATE_MACRO(45) +// Element is filled by Autofill feature. +#define NS_EVENT_STATE_AUTOFILL NS_DEFINE_EVENT_STATE_MACRO(50) // Event state that is used for values that need to be parsed but do nothing. #define NS_EVENT_STATE_IGNORE NS_DEFINE_EVENT_STATE_MACRO(63) @@ -306,7 +308,7 @@ private: // document (e.g. in BindToTree and UnbindFromTree), if that is an // appropriate thing to do for your state bit. #define MANUALLY_MANAGED_STATES ( \ - mozilla::EventStates() /* none so far */ \ + NS_EVENT_STATE_AUTOFILL \ ) // Event states that are managed externally to an element (by the diff --git a/layout/style/nsCSSPseudoClassList.h b/layout/style/nsCSSPseudoClassList.h index d84364ca1040..1249dda886e0 100644 --- a/layout/style/nsCSSPseudoClassList.h +++ b/layout/style/nsCSSPseudoClassList.h @@ -208,6 +208,10 @@ CSS_STATE_PSEUDO_CLASS(mozMathIncrementScriptLevel, ":-moz-math-increment-script-level", 0, "", NS_EVENT_STATE_INCREMENT_SCRIPT_LEVEL) +CSS_STATE_PSEUDO_CLASS(mozAutofill, ":-moz-autofill", + CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME, "", + NS_EVENT_STATE_AUTOFILL) + // CSS 3 UI // http://www.w3.org/TR/2004/CR-css3-ui-20040511/#pseudo-classes CSS_STATE_PSEUDO_CLASS(required, ":required", 0, "", NS_EVENT_STATE_REQUIRED) diff --git a/layout/style/res/forms.css b/layout/style/res/forms.css index 6e156b25a2a4..e1c8f531d6bd 100644 --- a/layout/style/res/forms.css +++ b/layout/style/res/forms.css @@ -1218,3 +1218,7 @@ input[type="number"] > div > div > div:hover { /* give some indication of hover state for the up/down buttons */ background-color: lightblue; } + +:-moz-autofill { + filter: grayscale(21%) brightness(88%) contrast(161%) invert(10%) sepia(40%) saturate(206%); +}