diff --git a/Cargo.lock b/Cargo.lock index fb72b0664146..24cc3c1dea54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1460,6 +1460,13 @@ dependencies = [ "smallbitvec", ] +[[package]] +name = "dom" +version = "0.1.0" +dependencies = [ + "bitflags", +] + [[package]] name = "dtoa" version = "0.4.8" @@ -2077,6 +2084,7 @@ dependencies = [ "bincode", "cssparser", "cstr", + "dom", "gecko-profiler", "libc", "log", @@ -2162,6 +2170,7 @@ dependencies = [ "cubeb-coreaudio", "cubeb-pulse", "cubeb-sys", + "dom", "encoding_glue", "fluent", "fluent-fallback", @@ -3126,6 +3135,7 @@ version = "0.0.1" dependencies = [ "app_units", "cssparser", + "dom", "euclid", "selectors", "servo_arc", @@ -4996,6 +5006,7 @@ dependencies = [ "byteorder", "cssparser", "derive_more", + "dom", "euclid", "fxhash", "gecko-profiler", diff --git a/Cargo.toml b/Cargo.toml index 92f9c5a25085..199c8d50b352 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ exclude = [ "xpcom/rust/gkrust_utils", "tools/lint/test/files/clippy", "tools/fuzzing/rust", + "dom/base/rust", "dom/origin-trials/ffi", ] diff --git a/accessible/generic/DocAccessible.cpp b/accessible/generic/DocAccessible.cpp index 51d076648d05..2e2667639d93 100644 --- a/accessible/generic/DocAccessible.cpp +++ b/accessible/generic/DocAccessible.cpp @@ -44,7 +44,6 @@ #include "mozilla/ArrayUtils.h" #include "mozilla/Assertions.h" #include "mozilla/EditorBase.h" -#include "mozilla/EventStates.h" #include "mozilla/HTMLEditor.h" #include "mozilla/PresShell.h" #include "mozilla/StaticPrefs_accessibility.h" @@ -866,14 +865,14 @@ void DocAccessible::ContentAppended(nsIContent* aFirstNewContent) { void DocAccessible::ContentStateChanged(dom::Document* aDocument, nsIContent* aContent, - EventStates aStateMask) { - if (aStateMask.HasState(NS_EVENT_STATE_READWRITE) && + dom::ElementState aStateMask) { + if (aStateMask.HasState(dom::ElementState::READWRITE) && aContent == mDocumentNode->GetRootElement()) { // This handles changes to designMode. contentEditable is handled by // LocalAccessible::AttributeChangesState and // LocalAccessible::DOMAttributeChanged. const bool isEditable = - aContent->AsElement()->State().HasState(NS_EVENT_STATE_READWRITE); + aContent->AsElement()->State().HasState(dom::ElementState::READWRITE); RefPtr event = new AccStateChangeEvent(this, states::EDITABLE, isEditable); FireDelayedEvent(event); @@ -884,11 +883,11 @@ void DocAccessible::ContentStateChanged(dom::Document* aDocument, LocalAccessible* accessible = GetAccessible(aContent); if (!accessible) return; - if (aStateMask.HasState(NS_EVENT_STATE_CHECKED)) { + if (aStateMask.HasState(dom::ElementState::CHECKED)) { LocalAccessible* widget = accessible->ContainerWidget(); if (widget && widget->IsSelect()) { AccSelChangeEvent::SelChangeType selChangeType = - aContent->AsElement()->State().HasState(NS_EVENT_STATE_CHECKED) + aContent->AsElement()->State().HasState(dom::ElementState::CHECKED) ? AccSelChangeEvent::eSelectionAdd : AccSelChangeEvent::eSelectionRemove; RefPtr event = @@ -899,31 +898,32 @@ void DocAccessible::ContentStateChanged(dom::Document* aDocument, RefPtr event = new AccStateChangeEvent( accessible, states::CHECKED, - aContent->AsElement()->State().HasState(NS_EVENT_STATE_CHECKED)); + aContent->AsElement()->State().HasState(dom::ElementState::CHECKED)); FireDelayedEvent(event); } - if (aStateMask.HasState(NS_EVENT_STATE_INVALID)) { + if (aStateMask.HasState(dom::ElementState::INVALID)) { RefPtr event = new AccStateChangeEvent(accessible, states::INVALID, true); FireDelayedEvent(event); } - if (aStateMask.HasState(NS_EVENT_STATE_REQUIRED)) { + if (aStateMask.HasState(dom::ElementState::REQUIRED)) { RefPtr event = new AccStateChangeEvent(accessible, states::REQUIRED); FireDelayedEvent(event); } - if (aStateMask.HasState(NS_EVENT_STATE_VISITED)) { + if (aStateMask.HasState(dom::ElementState::VISITED)) { RefPtr event = new AccStateChangeEvent(accessible, states::TRAVERSED, true); FireDelayedEvent(event); } - // We only expose NS_EVENT_STATE_DEFAULT on buttons, but we can get + // We only expose dom::ElementState::DEFAULT on buttons, but we can get // notifications for other controls like checkboxes. - if (aStateMask.HasState(NS_EVENT_STATE_DEFAULT) && accessible->IsButton()) { + if (aStateMask.HasState(dom::ElementState::DEFAULT) && + accessible->IsButton()) { RefPtr event = new AccStateChangeEvent(accessible, states::DEFAULT); FireDelayedEvent(event); diff --git a/accessible/generic/HyperTextAccessible.cpp b/accessible/generic/HyperTextAccessible.cpp index b0639165b32e..8a361e3a38dd 100644 --- a/accessible/generic/HyperTextAccessible.cpp +++ b/accessible/generic/HyperTextAccessible.cpp @@ -38,7 +38,6 @@ #include "mozilla/Assertions.h" #include "mozilla/BinarySearch.h" #include "mozilla/EditorBase.h" -#include "mozilla/EventStates.h" #include "mozilla/HTMLEditor.h" #include "mozilla/IntegerRange.h" #include "mozilla/MathAlgorithms.h" @@ -188,7 +187,7 @@ role HyperTextAccessible::NativeRole() const { uint64_t HyperTextAccessible::NativeState() const { uint64_t states = AccessibleWrap::NativeState(); - if (mContent->AsElement()->State().HasState(NS_EVENT_STATE_READWRITE)) { + if (mContent->AsElement()->State().HasState(dom::ElementState::READWRITE)) { states |= states::EDITABLE; } else if (mContent->IsHTMLElement(nsGkAtoms::article)) { diff --git a/accessible/generic/LocalAccessible.cpp b/accessible/generic/LocalAccessible.cpp index 09655f9e8679..3f98c6a51f5e 100644 --- a/accessible/generic/LocalAccessible.cpp +++ b/accessible/generic/LocalAccessible.cpp @@ -75,7 +75,6 @@ #include "mozilla/BasicEvents.h" #include "mozilla/Components.h" #include "mozilla/ErrorResult.h" -#include "mozilla/EventStates.h" #include "mozilla/FloatingPoint.h" #include "mozilla/MouseEvents.h" #include "mozilla/PresShell.h" @@ -393,11 +392,13 @@ uint64_t LocalAccessible::NativeState() const { if (!IsInDocument()) state |= states::STALE; if (HasOwnContent() && mContent->IsElement()) { - EventStates elementState = mContent->AsElement()->State(); + dom::ElementState elementState = mContent->AsElement()->State(); - if (elementState.HasState(NS_EVENT_STATE_INVALID)) state |= states::INVALID; + if (elementState.HasState(dom::ElementState::INVALID)) { + state |= states::INVALID; + } - if (elementState.HasState(NS_EVENT_STATE_REQUIRED)) { + if (elementState.HasState(dom::ElementState::REQUIRED)) { state |= states::REQUIRED; } diff --git a/accessible/html/HTMLFormControlAccessible.cpp b/accessible/html/HTMLFormControlAccessible.cpp index d5e579059670..a2a38138554a 100644 --- a/accessible/html/HTMLFormControlAccessible.cpp +++ b/accessible/html/HTMLFormControlAccessible.cpp @@ -23,7 +23,6 @@ #include "mozilla/dom/ScriptSettings.h" #include "mozilla/EditorBase.h" -#include "mozilla/EventStates.h" #include "mozilla/FloatingPoint.h" #include "mozilla/Preferences.h" #include "mozilla/TextEditor.h" @@ -181,8 +180,8 @@ uint64_t HTMLButtonAccessible::State() { uint64_t HTMLButtonAccessible::NativeState() const { uint64_t state = HyperTextAccessibleWrap::NativeState(); - EventStates elmState = mContent->AsElement()->State(); - if (elmState.HasState(NS_EVENT_STATE_DEFAULT)) state |= states::DEFAULT; + ElementState elmState = mContent->AsElement()->State(); + if (elmState.HasState(ElementState::DEFAULT)) state |= states::DEFAULT; return state; } diff --git a/accessible/html/HTMLLinkAccessible.cpp b/accessible/html/HTMLLinkAccessible.cpp index c8578d030f0a..7662833c8587 100644 --- a/accessible/html/HTMLLinkAccessible.cpp +++ b/accessible/html/HTMLLinkAccessible.cpp @@ -12,7 +12,6 @@ #include "States.h" #include "nsContentUtils.h" -#include "mozilla/EventStates.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/MutationEventBinding.h" @@ -39,10 +38,10 @@ uint64_t HTMLLinkAccessible::NativeState() const { } uint64_t HTMLLinkAccessible::NativeLinkState() const { - EventStates eventState = mContent->AsElement()->State(); - if (eventState.HasState(NS_EVENT_STATE_UNVISITED)) return states::LINKED; + dom::ElementState eventState = mContent->AsElement()->State(); + if (eventState.HasState(dom::ElementState::UNVISITED)) return states::LINKED; - if (eventState.HasState(NS_EVENT_STATE_VISITED)) { + if (eventState.HasState(dom::ElementState::VISITED)) { return states::LINKED | states::TRAVERSED; } @@ -128,7 +127,6 @@ already_AddRefed HTMLLinkAccessible::AnchorURIAt( // HTMLLinkAccessible bool HTMLLinkAccessible::IsLinked() const { - EventStates state = mContent->AsElement()->State(); - return state.HasAtLeastOneOfStates(NS_EVENT_STATE_VISITED | - NS_EVENT_STATE_UNVISITED); + dom::ElementState state = mContent->AsElement()->State(); + return state.HasAtLeastOneOfStates(dom::ElementState::VISITED_OR_UNVISITED); } diff --git a/build/moz.configure/bindgen.configure b/build/moz.configure/bindgen.configure index 193e1ad8d1af..02b4ba818900 100644 --- a/build/moz.configure/bindgen.configure +++ b/build/moz.configure/bindgen.configure @@ -22,7 +22,7 @@ option(env="CBINDGEN", nargs=1, when=cbindgen_is_needed, help="Path to cbindgen" def check_cbindgen_version(cbindgen, fatal=False): log.debug("trying cbindgen: %s" % cbindgen) - cbindgen_min_version = Version("0.23.0") + cbindgen_min_version = Version("0.24.2") # cbindgen x.y.z version = Version(check_cmd_output(cbindgen, "--version").strip().split(" ")[1]) diff --git a/devtools/client/inspector/test/shared-head.js b/devtools/client/inspector/test/shared-head.js index 2539849ff1ca..29289066bb74 100644 --- a/devtools/client/inspector/test/shared-head.js +++ b/devtools/client/inspector/test/shared-head.js @@ -783,7 +783,7 @@ async function waitUntilVisitedState(tab, selectors) { tab.linkedBrowser, selectors, args => { - const NS_EVENT_STATE_VISITED = 1 << 19; + const ELEMENT_STATE_VISITED = 1 << 19; for (const selector of args) { const target = content.wrappedJSObject.document.querySelector( @@ -792,7 +792,7 @@ async function waitUntilVisitedState(tab, selectors) { if ( !( target && - InspectorUtils.getContentState(target) & NS_EVENT_STATE_VISITED + InspectorUtils.getContentState(target) & ELEMENT_STATE_VISITED ) ) { return false; diff --git a/devtools/server/actors/accessibility/walker.js b/devtools/server/actors/accessibility/walker.js index 8d40afa42e06..5e5219db9025 100644 --- a/devtools/server/actors/accessibility/walker.js +++ b/devtools/server/actors/accessibility/walker.js @@ -60,7 +60,7 @@ loader.lazyRequireGetter( true ); -const kStateHover = 0x00000004; // NS_EVENT_STATE_HOVER +const kStateHover = 0x00000004; // ElementState::HOVER const { EVENT_TEXT_CHANGED, diff --git a/devtools/server/actors/emulation/touch-simulator.js b/devtools/server/actors/emulation/touch-simulator.js index c784fbd096c8..06ae6828994a 100644 --- a/devtools/server/actors/emulation/touch-simulator.js +++ b/devtools/server/actors/emulation/touch-simulator.js @@ -43,7 +43,7 @@ const EVENTS_TO_HANDLE = [ "mouseleave", ]; -const kStateHover = 0x00000004; // NS_EVENT_STATE_HOVER +const kStateHover = 0x00000004; // ElementState::HOVER /** * Simulate touch events for platforms where they aren't generally available. diff --git a/devtools/shared/inspector/css-logic.js b/devtools/shared/inspector/css-logic.js index 3c6c4f8d5f04..6726db2aad48 100644 --- a/devtools/shared/inspector/css-logic.js +++ b/devtools/shared/inspector/css-logic.js @@ -532,10 +532,10 @@ function hasVisitedState(node) { return false; } - const NS_EVENT_STATE_VISITED = 1 << 19; + const ELEMENT_STATE_VISITED = 1 << 19; return ( - !!(InspectorUtils.getContentState(node) & NS_EVENT_STATE_VISITED) || + !!(InspectorUtils.getContentState(node) & ELEMENT_STATE_VISITED) || InspectorUtils.hasPseudoClassLock(node, ":visited") ); } diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index d47e8056fde5..3448ee901432 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -2993,7 +2993,7 @@ void BrowsingContext::DidSet(FieldIndex, // for all in-process documents. PreOrderWalk([isActivateEvent](BrowsingContext* aContext) { if (RefPtr doc = aContext->GetExtantDocument()) { - doc->UpdateDocumentStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE, true); + doc->UpdateDocumentStates(DocumentState::WINDOW_INACTIVE, true); RefPtr win = doc->GetInnerWindow(); RefPtr devices; diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index ce88a8d510cc..47464830c860 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -7677,7 +7677,7 @@ void Document::SetContainer(nsDocShell* aContainer) { // IsTopLevelWindowInactive depends on the docshell, so // update the cached value now that it's available. - UpdateDocumentStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE, false); + UpdateDocumentStates(DocumentState::WINDOW_INACTIVE, false); if (!aContainer) { return; } @@ -8236,7 +8236,7 @@ void Document::UnblockDOMContentLoaded() { } void Document::ContentStateChanged(nsIContent* aContent, - EventStates aStateMask) { + ElementState aStateMask) { MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(), "Someone forgot a scriptblocker"); NS_DOCUMENT_NOTIFY_OBSERVERS(ContentStateChanged, @@ -12492,36 +12492,36 @@ void Document::ForgetImagePreload(nsIURI* aURI) { } } -void Document::UpdateDocumentStates(EventStates aMaybeChangedStates, +void Document::UpdateDocumentStates(DocumentState aMaybeChangedStates, bool aNotify) { - const EventStates oldStates = mDocumentState; + const DocumentState oldStates = mDocumentState; if (aMaybeChangedStates.HasAtLeastOneOfStates( - NS_DOCUMENT_STATE_ALL_LOCALEDIR_BITS)) { - mDocumentState &= ~NS_DOCUMENT_STATE_ALL_LOCALEDIR_BITS; + DocumentState::ALL_LOCALEDIR_BITS)) { + mDocumentState &= ~DocumentState::ALL_LOCALEDIR_BITS; if (IsDocumentRightToLeft()) { - mDocumentState |= NS_DOCUMENT_STATE_RTL_LOCALE; + mDocumentState |= DocumentState::RTL_LOCALE; } else { - mDocumentState |= NS_DOCUMENT_STATE_LTR_LOCALE; + mDocumentState |= DocumentState::LTR_LOCALE; } } - if (aMaybeChangedStates.HasAtLeastOneOfStates(NS_DOCUMENT_STATE_LWTHEME)) { + if (aMaybeChangedStates.HasAtLeastOneOfStates(DocumentState::LWTHEME)) { if (ComputeDocumentLWTheme()) { - mDocumentState |= NS_DOCUMENT_STATE_LWTHEME; + mDocumentState |= DocumentState::LWTHEME; } else { - mDocumentState &= ~NS_DOCUMENT_STATE_LWTHEME; + mDocumentState &= ~DocumentState::LWTHEME; } } - if (aMaybeChangedStates.HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) { + if (aMaybeChangedStates.HasState(DocumentState::WINDOW_INACTIVE)) { if (IsTopLevelWindowInactive()) { - mDocumentState |= NS_DOCUMENT_STATE_WINDOW_INACTIVE; + mDocumentState |= DocumentState::WINDOW_INACTIVE; } else { - mDocumentState &= ~NS_DOCUMENT_STATE_WINDOW_INACTIVE; + mDocumentState &= ~DocumentState::WINDOW_INACTIVE; } } - EventStates changedStates = oldStates ^ mDocumentState; + const DocumentState changedStates = oldStates ^ mDocumentState; if (aNotify && !changedStates.IsEmpty()) { if (PresShell* ps = GetObservingPresShell()) { ps->DocumentStatesChanged(changedStates); @@ -12583,7 +12583,7 @@ void Document::ResetDocumentDirection() { if (!nsContentUtils::IsChromeDoc(this)) { return; } - UpdateDocumentStates(NS_DOCUMENT_STATE_ALL_LOCALEDIR_BITS, true); + UpdateDocumentStates(DocumentState::ALL_LOCALEDIR_BITS, true); } bool Document::IsDocumentRightToLeft() { @@ -14202,7 +14202,7 @@ size_t Document::CountFullscreenElements() const { size_t count = 0; for (const nsWeakPtr& ptr : mTopLayer) { if (nsCOMPtr elem = do_QueryReferent(ptr)) { - if (elem->State().HasState(NS_EVENT_STATE_FULLSCREEN)) { + if (elem->State().HasState(ElementState::FULLSCREEN)) { count++; } } @@ -14570,15 +14570,15 @@ void Document::CleanupFullscreenState() { bool Document::PopFullscreenElement() { Element* removedElement = TopLayerPop([](Element* element) -> bool { - return element->State().HasState(NS_EVENT_STATE_FULLSCREEN); + return element->State().HasState(ElementState::FULLSCREEN); }); if (!removedElement) { return false; } - MOZ_ASSERT(removedElement->State().HasState(NS_EVENT_STATE_FULLSCREEN)); - removedElement->RemoveStates(NS_EVENT_STATE_FULLSCREEN); + MOZ_ASSERT(removedElement->State().HasState(ElementState::FULLSCREEN)); + removedElement->RemoveStates(ElementState::FULLSCREEN); NotifyFullScreenChangedForMediaElement(*removedElement); // Reset iframe fullscreen flag. if (auto* iframe = HTMLIFrameElement::FromNode(removedElement)) { @@ -14589,16 +14589,16 @@ bool Document::PopFullscreenElement() { } void Document::SetFullscreenElement(Element& aElement) { - aElement.AddStates(NS_EVENT_STATE_FULLSCREEN); + aElement.AddStates(ElementState::FULLSCREEN); TopLayerPush(aElement); NotifyFullScreenChangedForMediaElement(aElement); UpdateViewportScrollbarOverrideForFullscreen(this); } -static EventStates TopLayerModalStates() { - EventStates modalStates = NS_EVENT_STATE_MODAL_DIALOG; +static ElementState TopLayerModalStates() { + ElementState modalStates = ElementState::MODAL_DIALOG; if (StaticPrefs::dom_fullscreen_modal()) { - modalStates |= NS_EVENT_STATE_FULLSCREEN; + modalStates |= ElementState::FULLSCREEN; } return modalStates; } @@ -14616,14 +14616,14 @@ void Document::TopLayerPush(Element& aElement) { NS_ASSERTION(GetTopLayerTop() == &aElement, "Should match"); if (modal) { - aElement.AddStates(NS_EVENT_STATE_TOPMOST_MODAL); + aElement.AddStates(ElementState::TOPMOST_MODAL); bool foundExistingModalElement = false; for (const nsWeakPtr& weakPtr : Reversed(mTopLayer)) { nsCOMPtr element(do_QueryReferent(weakPtr)); if (element && element != &aElement && - element->State().HasState(NS_EVENT_STATE_TOPMOST_MODAL)) { - element->RemoveStates(NS_EVENT_STATE_TOPMOST_MODAL); + element->State().HasState(ElementState::TOPMOST_MODAL)) { + element->RemoveStates(ElementState::TOPMOST_MODAL); foundExistingModalElement = true; break; } @@ -14635,14 +14635,14 @@ void Document::TopLayerPush(Element& aElement) { if (&aElement != root) { // Add inert to the root element so that the inertness is applied to the // entire document. - root->AddStates(NS_EVENT_STATE_MOZINERT); + root->AddStates(ElementState::INERT); } } } } void Document::AddModalDialog(HTMLDialogElement& aDialogElement) { - aDialogElement.AddStates(NS_EVENT_STATE_MODAL_DIALOG); + aDialogElement.AddStates(ElementState::MODAL_DIALOG); TopLayerPush(aDialogElement); } @@ -14652,7 +14652,7 @@ void Document::RemoveModalDialog(HTMLDialogElement& aDialogElement) { }; DebugOnly removedElement = TopLayerPop(predicate); MOZ_ASSERT(removedElement == &aDialogElement); - aDialogElement.RemoveStates(NS_EVENT_STATE_MODAL_DIALOG); + aDialogElement.RemoveStates(ElementState::MODAL_DIALOG); } Element* Document::TopLayerPop(FunctionRef aPredicate) { @@ -14693,16 +14693,16 @@ Element* Document::TopLayerPop(FunctionRef aPredicate) { return nullptr; } - const EventStates modalStates = TopLayerModalStates(); + const ElementState modalStates = TopLayerModalStates(); const bool modal = removedElement->State().HasAtLeastOneOfStates(modalStates); if (modal) { - removedElement->RemoveStates(NS_EVENT_STATE_TOPMOST_MODAL); + removedElement->RemoveStates(ElementState::TOPMOST_MODAL); bool foundExistingModalElement = false; for (const nsWeakPtr& weakPtr : Reversed(mTopLayer)) { nsCOMPtr element(do_QueryReferent(weakPtr)); if (element && element->State().HasAtLeastOneOfStates(modalStates)) { - element->AddStates(NS_EVENT_STATE_TOPMOST_MODAL); + element->AddStates(ElementState::TOPMOST_MODAL); foundExistingModalElement = true; break; } @@ -14711,7 +14711,7 @@ Element* Document::TopLayerPop(FunctionRef aPredicate) { if (!foundExistingModalElement) { Element* root = GetRootElement(); if (root && !root->GetBoolAttr(nsGkAtoms::inert)) { - root->RemoveStates(NS_EVENT_STATE_MOZINERT); + root->RemoveStates(ElementState::INERT); } } } @@ -14844,7 +14844,7 @@ Element* Document::GetUnretargetedFullScreenElement() const { nsCOMPtr element(do_QueryReferent(weakPtr)); // Per spec, the fullscreen element is the topmost element in the document’s // top layer whose fullscreen flag is set, if any, and null otherwise. - if (element && element->State().HasState(NS_EVENT_STATE_FULLSCREEN)) { + if (element && element->State().HasState(ElementState::FULLSCREEN)) { return element; } } diff --git a/dom/base/Document.h b/dom/base/Document.h index 09e319c7c769..76fd478d5fa9 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -28,7 +28,6 @@ #include "mozilla/ContentBlockingNotifier.h" #include "mozilla/CORSMode.h" #include "mozilla/CallState.h" -#include "mozilla/EventStates.h" #include "mozilla/FlushType.h" #include "mozilla/FunctionRef.h" #include "mozilla/HashTable.h" @@ -350,22 +349,6 @@ enum class DeprecatedOperations : uint16_t { }; #undef DEPRECATED_OPERATION -// Document states - -// Window activation status -#define NS_DOCUMENT_STATE_WINDOW_INACTIVE NS_DEFINE_EVENT_STATE_MACRO(0) -// RTL locale: specific to the XUL localedir attribute. -#define NS_DOCUMENT_STATE_RTL_LOCALE NS_DEFINE_EVENT_STATE_MACRO(1) -// LTR locale: specific to the XUL localedir attribute. This is mutually -// exclusive with the RTL bit, but the style system invalidation code is simpler -// if we differentiate between the two states. -#define NS_DOCUMENT_STATE_LTR_LOCALE NS_DEFINE_EVENT_STATE_MACRO(2) -// Lightweight-theme status. -#define NS_DOCUMENT_STATE_LWTHEME NS_DEFINE_EVENT_STATE_MACRO(3) - -#define NS_DOCUMENT_STATE_ALL_LOCALEDIR_BITS \ - (NS_DOCUMENT_STATE_RTL_LOCALE | NS_DOCUMENT_STATE_LTR_LOCALE) - class ExternalResourceMap { using SubDocEnumFunc = FunctionRef; @@ -2078,14 +2061,14 @@ class Document : public nsINode, // notify that a content node changed state. This must happen under // a scriptblocker but NOT within a begin/end update. - void ContentStateChanged(nsIContent* aContent, EventStates aStateMask); + void ContentStateChanged(nsIContent* aContent, ElementState aStateMask); // Update a set of document states that may have changed. // This should only be called by callers whose state is also reflected in the // implementation of Document::GetDocumentState. // // aNotify controls whether we notify our DocumentStatesChanged observers. - void UpdateDocumentStates(EventStates aMaybeChangedStates, bool aNotify); + void UpdateDocumentStates(DocumentState aMaybeChangedStates, bool aNotify); void ResetDocumentDirection(); @@ -3054,7 +3037,7 @@ class Document : public nsINode, */ bool ComputeDocumentLWTheme() const; void ResetDocumentLWTheme() { - UpdateDocumentStates(NS_DOCUMENT_STATE_LWTHEME, true); + UpdateDocumentStates(DocumentState::LWTHEME, true); } // Whether we're a media document or not. @@ -3069,12 +3052,7 @@ class Document : public nsINode, return MediaDocumentKind::NotMedia; } - /** - * Returns the document state. - * Document state bits have the form NS_DOCUMENT_STATE_* and are declared in - * Document.h. - */ - EventStates GetDocumentState() const { return mDocumentState; } + DocumentState GetDocumentState() const { return mDocumentState; } nsISupports* GetCurrentContentSink(); @@ -4515,7 +4493,7 @@ class Document : public nsINode, // Last time we found any scroll linked effect in this document. TimeStamp mLastScrollLinkedEffectDetectionTime; - EventStates mDocumentState{NS_DOCUMENT_STATE_LTR_LOCALE}; + DocumentState mDocumentState{DocumentState::LTR_LOCALE}; RefPtr mReadyForIdle; diff --git a/dom/base/DocumentOrShadowRoot.cpp b/dom/base/DocumentOrShadowRoot.cpp index 0300ee4b3614..98723444ae57 100644 --- a/dom/base/DocumentOrShadowRoot.cpp +++ b/dom/base/DocumentOrShadowRoot.cpp @@ -314,7 +314,7 @@ Element* DocumentOrShadowRoot::GetFullscreenElement() const { } Element* element = AsNode().OwnerDoc()->GetUnretargetedFullScreenElement(); - NS_ASSERTION(!element || element->State().HasState(NS_EVENT_STATE_FULLSCREEN), + NS_ASSERTION(!element || element->State().HasState(ElementState::FULLSCREEN), "Fullscreen element should have fullscreen styles applied"); nsIContent* retargeted = Retarget(element); diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 9b64e8014dae..191428dff0e9 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -36,7 +36,6 @@ #include "mozilla/EventDispatcher.h" #include "mozilla/EventListenerManager.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/FloatingPoint.h" #include "mozilla/FullscreenChange.h" #include "mozilla/InternalMutationEvent.h" @@ -343,11 +342,11 @@ Element::QueryInterface(REFNSIID aIID, void** aInstancePtr) { return NS_NOINTERFACE; } -EventStates Element::IntrinsicState() const { - return IsEditable() ? NS_EVENT_STATE_READWRITE : NS_EVENT_STATE_READONLY; +ElementState Element::IntrinsicState() const { + return IsEditable() ? ElementState::READWRITE : ElementState::READONLY; } -void Element::NotifyStateChange(EventStates aStates) { +void Element::NotifyStateChange(ElementState aStates) { if (aStates.IsEmpty()) { return; } @@ -358,19 +357,18 @@ void Element::NotifyStateChange(EventStates aStates) { } } -void Element::UpdateLinkState(EventStates aState) { - MOZ_ASSERT(!aState.HasAtLeastOneOfStates( - ~(NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED)), +void Element::UpdateLinkState(ElementState aState) { + MOZ_ASSERT(!aState.HasAtLeastOneOfStates(~ElementState::VISITED_OR_UNVISITED), "Unexpected link state bits"); - mState = - (mState & ~(NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED)) | aState; + mState = (mState & ~ElementState::VISITED_OR_UNVISITED) | aState; } void Element::UpdateState(bool aNotify) { - EventStates oldState = mState; - mState = IntrinsicState() | (oldState & EXTERNALLY_MANAGED_STATES); + ElementState oldState = mState; + mState = + IntrinsicState() | (oldState & ElementState::EXTERNALLY_MANAGED_STATES); if (aNotify) { - EventStates changedStates = oldState ^ mState; + ElementState changedStates = oldState ^ mState; if (!changedStates.IsEmpty()) { Document* doc = GetComposedDoc(); if (doc) { @@ -418,11 +416,11 @@ void Element::UpdateEditableState(bool aNotify) { // insertion into the document and UpdateState can be slow for // some kinds of elements even when not notifying. if (IsEditable()) { - RemoveStatesSilently(NS_EVENT_STATE_READONLY); - AddStatesSilently(NS_EVENT_STATE_READWRITE); + RemoveStatesSilently(ElementState::READONLY); + AddStatesSilently(ElementState::READWRITE); } else { - RemoveStatesSilently(NS_EVENT_STATE_READWRITE); - AddStatesSilently(NS_EVENT_STATE_READONLY); + RemoveStatesSilently(ElementState::READWRITE); + AddStatesSilently(ElementState::READONLY); } } } @@ -501,17 +499,17 @@ void Element::Blur(mozilla::ErrorResult& aError) { } } -EventStates Element::StyleStateFromLocks() const { +ElementState Element::StyleStateFromLocks() const { StyleStateLocks locksAndValues = LockedStyleStates(); - EventStates locks = locksAndValues.mLocks; - EventStates values = locksAndValues.mValues; - EventStates state = (mState & ~locks) | (locks & values); + ElementState locks = locksAndValues.mLocks; + ElementState values = locksAndValues.mValues; + ElementState state = (mState & ~locks) | (locks & values); - if (state.HasState(NS_EVENT_STATE_VISITED)) { - return state & ~NS_EVENT_STATE_UNVISITED; + if (state.HasState(ElementState::VISITED)) { + return state & ~ElementState::UNVISITED; } - if (state.HasState(NS_EVENT_STATE_UNVISITED)) { - return state & ~NS_EVENT_STATE_VISITED; + if (state.HasState(ElementState::UNVISITED)) { + return state & ~ElementState::VISITED; } return state; @@ -526,7 +524,7 @@ Element::StyleStateLocks Element::LockedStyleStates() const { return StyleStateLocks(); } -void Element::NotifyStyleStateChange(EventStates aStates) { +void Element::NotifyStyleStateChange(ElementState aStates) { Document* doc = GetComposedDoc(); if (doc) { RefPtr presShell = doc->GetPresShell(); @@ -537,7 +535,7 @@ void Element::NotifyStyleStateChange(EventStates aStates) { } } -void Element::LockStyleStates(EventStates aStates, bool aEnabled) { +void Element::LockStyleStates(ElementState aStates, bool aEnabled) { StyleStateLocks* locks = new StyleStateLocks(LockedStyleStates()); locks->mLocks |= aStates; @@ -547,11 +545,11 @@ void Element::LockStyleStates(EventStates aStates, bool aEnabled) { locks->mValues &= ~aStates; } - if (aStates.HasState(NS_EVENT_STATE_VISITED)) { - locks->mLocks &= ~NS_EVENT_STATE_UNVISITED; + if (aStates.HasState(ElementState::VISITED)) { + locks->mLocks &= ~ElementState::UNVISITED; } - if (aStates.HasState(NS_EVENT_STATE_UNVISITED)) { - locks->mLocks &= ~NS_EVENT_STATE_VISITED; + if (aStates.HasState(ElementState::UNVISITED)) { + locks->mLocks &= ~ElementState::VISITED; } SetProperty(nsGkAtoms::lockedStyleStates, locks, @@ -561,7 +559,7 @@ void Element::LockStyleStates(EventStates aStates, bool aEnabled) { NotifyStyleStateChange(aStates); } -void Element::UnlockStyleStates(EventStates aStates) { +void Element::UnlockStyleStates(ElementState aStates) { StyleStateLocks* locks = new StyleStateLocks(LockedStyleStates()); locks->mLocks &= ~aStates; @@ -1900,7 +1898,7 @@ void Element::UnbindFromTree(bool aNullParent) { if (HasPointerLock()) { PointerLockManager::Unlock(); } - if (mState.HasState(NS_EVENT_STATE_FULLSCREEN)) { + if (mState.HasState(ElementState::FULLSCREEN)) { // The element being removed is an ancestor of the fullscreen element, // exit fullscreen state. nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "DOM"_ns, @@ -3339,7 +3337,7 @@ nsresult Element::CopyInnerTo(Element* aDst, ReparseAttributes aReparse) { if (dstNodeInfo->GetDocument()->IsStaticDocument()) { // Propagate :defined state to the static clone. - if (State().HasState(NS_EVENT_STATE_DEFINED)) { + if (State().HasState(ElementState::DEFINED)) { aDst->SetDefined(true); } } diff --git a/dom/base/Element.h b/dom/base/Element.h index a80332ea7ad1..bd4c2bb35984 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -26,7 +26,6 @@ #include "mozilla/Attributes.h" #include "mozilla/BasicEvents.h" #include "mozilla/CORSMode.h" -#include "mozilla/EventStates.h" #include "mozilla/FlushType.h" #include "mozilla/Maybe.h" #include "mozilla/PseudoStyleType.h" @@ -40,6 +39,7 @@ #include "mozilla/dom/FragmentOrElement.h" #include "mozilla/dom/NameSpaceConstants.h" #include "mozilla/dom/NodeInfo.h" +#include "mozilla/dom/RustTypes.h" #include "mozilla/dom/ShadowRootBinding.h" #include "nsAtom.h" #include "nsAttrValue.h" @@ -221,7 +221,7 @@ class Element : public FragmentOrElement { #ifdef MOZILLA_INTERNAL_API explicit Element(already_AddRefed&& aNodeInfo) : FragmentOrElement(std::move(aNodeInfo)), - mState(NS_EVENT_STATE_READONLY | NS_EVENT_STATE_DEFINED) { + mState(ElementState::READONLY | ElementState::DEFINED) { MOZ_ASSERT(mNodeInfo->NodeType() == ELEMENT_NODE, "Bad NodeType in aNodeInfo"); SetIsElement(); @@ -242,10 +242,10 @@ class Element : public FragmentOrElement { NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override; /** - * Method to get the full state of this element. See mozilla/EventStates.h - * for the possible bits that could be set here. + * Method to get the full state of this element. See dom/base/rust/lib.rs for + * the possible bits that could be set here. */ - EventStates State() const { + ElementState State() const { // mState is maintained by having whoever might have changed it // call UpdateState() or one of the other mState mutators. return mState; @@ -266,12 +266,12 @@ class Element : public FragmentOrElement { /** * Method to update mState with link state information. This does not notify. */ - void UpdateLinkState(EventStates aState); + void UpdateLinkState(ElementState aState); /** * Returns the current disabled state of the element. */ - bool IsDisabled() const { return State().HasState(NS_EVENT_STATE_DISABLED); } + bool IsDisabled() const { return State().HasState(ElementState::DISABLED); } virtual int32_t TabIndexDefault() { return -1; } @@ -316,7 +316,7 @@ class Element : public FragmentOrElement { * The style state of this element. This is the real state of the element * with any style locks applied for pseudo-class inspecting. */ - EventStates StyleState() const { + ElementState StyleState() const { if (!HasLockedStyleStates()) { return mState; } @@ -329,9 +329,9 @@ class Element : public FragmentOrElement { */ struct StyleStateLocks { // mLocks tracks which event states should be locked. - EventStates mLocks; + ElementState mLocks; // mValues tracks if the locked state should be on or off. - EventStates mValues; + ElementState mValues; }; /** @@ -343,12 +343,12 @@ class Element : public FragmentOrElement { * Add a style state lock on this element. * aEnabled is the value to lock the given state bits to. */ - void LockStyleStates(EventStates aStates, bool aEnabled); + void LockStyleStates(ElementState aStates, bool aEnabled); /** * Remove a style state lock on this element. */ - void UnlockStyleStates(EventStates aStates); + void UnlockStyleStates(ElementState aStates); /** * Clear all style state locks on this element. @@ -359,15 +359,15 @@ class Element : public FragmentOrElement { * Accessors for the state of our dir attribute. */ bool HasDirAuto() const { - return State().HasState(NS_EVENT_STATE_DIR_ATTR_LIKE_AUTO); + return State().HasState(ElementState::HAS_DIR_ATTR_LIKE_AUTO); } /** * Elements with dir="rtl" or dir="ltr". */ bool HasFixedDir() const { - return State().HasAtLeastOneOfStates(NS_EVENT_STATE_DIR_ATTR_LTR | - NS_EVENT_STATE_DIR_ATTR_RTL); + return State().HasAtLeastOneOfStates(ElementState::HAS_DIR_ATTR_LTR | + ElementState::HAS_DIR_ATTR_RTL); } /** @@ -478,21 +478,21 @@ class Element : public FragmentOrElement { inline void SetDirectionality(Directionality aDir, bool aNotify) { UnsetFlags(NODE_ALL_DIRECTION_FLAGS); if (!aNotify) { - RemoveStatesSilently(DIRECTION_STATES); + RemoveStatesSilently(ElementState::DIR_STATES); } switch (aDir) { case (eDir_RTL): SetFlags(NODE_HAS_DIRECTION_RTL); if (!aNotify) { - AddStatesSilently(NS_EVENT_STATE_RTL); + AddStatesSilently(ElementState::RTL); } break; case (eDir_LTR): SetFlags(NODE_HAS_DIRECTION_LTR); if (!aNotify) { - AddStatesSilently(NS_EVENT_STATE_LTR); + AddStatesSilently(ElementState::LTR); } break; @@ -601,9 +601,9 @@ class Element : public FragmentOrElement { void SetDefined(bool aSet) { if (aSet) { - AddStates(NS_EVENT_STATE_DEFINED); + AddStates(ElementState::DEFINED); } else { - RemoveStates(NS_EVENT_STATE_DEFINED); + RemoveStates(ElementState::DEFINED); } } @@ -657,10 +657,9 @@ class Element : public FragmentOrElement { /** * Method to get the _intrinsic_ content state of this element. This is the * state that is independent of the element's presentation. To get the full - * content state, use State(). See mozilla/EventStates.h for * the possible bits that could be set here. */ - virtual EventStates IntrinsicState() const; + virtual ElementState IntrinsicState() const; /** * Method to add state bits. This should be called from subclass @@ -668,7 +667,7 @@ class Element : public FragmentOrElement { * time and other places where we don't want to notify a state * change. */ - void AddStatesSilently(EventStates aStates) { mState |= aStates; } + void AddStatesSilently(ElementState aStates) { mState |= aStates; } /** * Method to remove state bits. This should be called from subclass @@ -676,7 +675,7 @@ class Element : public FragmentOrElement { * time and other places where we don't want to notify a state * change. */ - void RemoveStatesSilently(EventStates aStates) { mState &= ~aStates; } + void RemoveStatesSilently(ElementState aStates) { mState &= ~aStates; } already_AddRefed AttachShadowInternal(ShadowRootMode, ErrorResult& aError); @@ -701,12 +700,12 @@ class Element : public FragmentOrElement { // Also need to allow Link to call UpdateLinkState. friend class Link; - void NotifyStateChange(EventStates aStates); + void NotifyStateChange(ElementState aStates); - void NotifyStyleStateChange(EventStates aStates); + void NotifyStyleStateChange(ElementState aStates); // Style state computed from element's state and style locks. - EventStates StyleStateFromLocks() const; + ElementState StyleStateFromLocks() const; protected: // Methods for the ESM, nsGlobalWindow, focus manager and Document to @@ -714,22 +713,22 @@ class Element : public FragmentOrElement { // These will handle setting up script blockers when they notify, so no need // to do it in the callers unless desired. States passed here must only be // those in EXTERNALLY_MANAGED_STATES. - void AddStates(EventStates aStates) { - MOZ_ASSERT(!aStates.HasAtLeastOneOfStates(INTRINSIC_STATES), + void AddStates(ElementState aStates) { + MOZ_ASSERT(!aStates.HasAtLeastOneOfStates(ElementState::INTRINSIC_STATES), "Should only be adding externally-managed states here"); - EventStates old = mState; + ElementState old = mState; AddStatesSilently(aStates); NotifyStateChange(old ^ mState); } - void RemoveStates(EventStates aStates) { - MOZ_ASSERT(!aStates.HasAtLeastOneOfStates(INTRINSIC_STATES), + void RemoveStates(ElementState aStates) { + MOZ_ASSERT(!aStates.HasAtLeastOneOfStates(ElementState::INTRINSIC_STATES), "Should only be removing externally-managed states here"); - EventStates old = mState; + ElementState old = mState; RemoveStatesSilently(aStates); NotifyStateChange(old ^ mState); } - void ToggleStates(EventStates aStates, bool aNotify) { - MOZ_ASSERT(!aStates.HasAtLeastOneOfStates(INTRINSIC_STATES), + void ToggleStates(ElementState aStates, bool aNotify) { + MOZ_ASSERT(!aStates.HasAtLeastOneOfStates(ElementState::INTRINSIC_STATES), "Should only be removing externally-managed states here"); mState ^= aStates; if (aNotify) { @@ -739,13 +738,13 @@ class Element : public FragmentOrElement { public: // Public methods to manage state bits in MANUALLY_MANAGED_STATES. - void AddManuallyManagedStates(EventStates aStates) { - MOZ_ASSERT(MANUALLY_MANAGED_STATES.HasAllStates(aStates), + void AddManuallyManagedStates(ElementState aStates) { + MOZ_ASSERT(ElementState::MANUALLY_MANAGED_STATES.HasAllStates(aStates), "Should only be adding manually-managed states here"); AddStates(aStates); } - void RemoveManuallyManagedStates(EventStates aStates) { - MOZ_ASSERT(MANUALLY_MANAGED_STATES.HasAllStates(aStates), + void RemoveManuallyManagedStates(ElementState aStates) { + MOZ_ASSERT(ElementState::MANUALLY_MANAGED_STATES.HasAllStates(aStates), "Should only be removing manually-managed states here"); RemoveStates(aStates); } @@ -1970,8 +1969,8 @@ class Element : public FragmentOrElement { * :any-link pseudo-class. */ bool IsLink() const { - return mState.HasAtLeastOneOfStates(NS_EVENT_STATE_VISITED | - NS_EVENT_STATE_UNVISITED); + return mState.HasAtLeastOneOfStates(ElementState::VISITED | + ElementState::UNVISITED); } /** @@ -2047,7 +2046,7 @@ class Element : public FragmentOrElement { void AsElement() = delete; // Data members - EventStates mState; + ElementState mState; // Per-node data managed by Servo. // // There should not be data on nodes that are not in the flattened tree, or diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index d2a156c72550..36433eff4232 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -20,7 +20,6 @@ #include "mozilla/EffectSet.h" #include "mozilla/EventDispatcher.h" #include "mozilla/EventListenerManager.h" -#include "mozilla/EventStates.h" #include "mozilla/HTMLEditor.h" #include "mozilla/PresShell.h" #include "mozilla/RestyleManager.h" @@ -195,7 +194,7 @@ nsIContent::IMEState nsIContent::GetDesiredIMEState() { // Check for the special case where we're dealing with elements which don't // have the editable flag set, but are readwrite (such as text controls). if (!IsElement() || - !AsElement()->State().HasState(NS_EVENT_STATE_READWRITE)) { + !AsElement()->State().HasState(ElementState::READWRITE)) { return IMEState(IMEEnabled::Disabled); } } diff --git a/dom/base/GeneratedImageContent.h b/dom/base/GeneratedImageContent.h index d145ff3d65c7..28132c3c4312 100644 --- a/dom/base/GeneratedImageContent.h +++ b/dom/base/GeneratedImageContent.h @@ -32,10 +32,10 @@ class GeneratedImageContent final : public nsGenericHTMLElement { "Someone messed up our nodeinfo"); } - EventStates IntrinsicState() const override { - EventStates state = nsGenericHTMLElement::IntrinsicState(); + ElementState IntrinsicState() const override { + ElementState state = nsGenericHTMLElement::IntrinsicState(); if (mBroken) { - state |= NS_EVENT_STATE_BROKEN; + state |= ElementState::BROKEN; } return state; } diff --git a/dom/base/Link.cpp b/dom/base/Link.cpp index 637ab9f8186d..c36aa6ea3efe 100644 --- a/dom/base/Link.cpp +++ b/dom/base/Link.cpp @@ -6,7 +6,6 @@ #include "Link.h" -#include "mozilla/EventStates.h" #include "mozilla/MemoryReporting.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/SVGAElement.h" @@ -75,8 +74,8 @@ void Link::VisitedQueryFinished(bool aVisited) { // Set our current state as appropriate. mState = newState; - MOZ_ASSERT(LinkState() == NS_EVENT_STATE_VISITED || - LinkState() == NS_EVENT_STATE_UNVISITED, + MOZ_ASSERT(LinkState() == ElementState::VISITED || + LinkState() == ElementState::UNVISITED, "Unexpected state obtained from LinkState()!"); // Tell the element to update its visited state. @@ -90,7 +89,7 @@ void Link::VisitedQueryFinished(bool aVisited) { } } -EventStates Link::LinkState() const { +ElementState Link::LinkState() const { // We are a constant method, but we are just lazily doing things and have to // track that state. Cast away that constness! // @@ -125,14 +124,14 @@ EventStates Link::LinkState() const { // Otherwise, return our known state. if (mState == State::Visited) { - return NS_EVENT_STATE_VISITED; + return ElementState::VISITED; } if (mState == State::Unvisited) { - return NS_EVENT_STATE_UNVISITED; + return ElementState::UNVISITED; } - return EventStates(); + return ElementState(); } nsIURI* Link::GetURI() const { @@ -500,9 +499,9 @@ void Link::ResetLinkState(bool aNotify, bool aHasHref) { mElement->UpdateState(aNotify); } else { if (mState == State::Unvisited) { - mElement->UpdateLinkState(NS_EVENT_STATE_UNVISITED); + mElement->UpdateLinkState(ElementState::UNVISITED); } else { - mElement->UpdateLinkState(EventStates()); + mElement->UpdateLinkState(ElementState()); } } } diff --git a/dom/base/Link.h b/dom/base/Link.h index dd2e11705969..7d547d75ba06 100644 --- a/dom/base/Link.h +++ b/dom/base/Link.h @@ -13,12 +13,12 @@ #include "nsWrapperCache.h" // For nsWrapperCache::FlagsType #include "nsCOMPtr.h" +#include "mozilla/dom/RustTypes.h" class nsIURI; namespace mozilla { -class EventStates; class SizeOfState; namespace dom { @@ -56,11 +56,11 @@ class Link : public nsISupports { virtual void VisitedQueryFinished(bool aVisited); /** - * @return NS_EVENT_STATE_VISITED if this link is visited, - * NS_EVENT_STATE_UNVISTED if this link is not visited, or 0 if this + * @return ElementState::VISITED if this link is visited, + * ElementState::UNVISTED if this link is not visited, or 0 if this * link is not actually a link. */ - EventStates LinkState() const; + ElementState LinkState() const; /** * @return the URI this link is for, if available. diff --git a/dom/base/RustTypes.h b/dom/base/RustTypes.h new file mode 100644 index 000000000000..6531d02010fb --- /dev/null +++ b/dom/base/RustTypes.h @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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/. */ + +#ifndef mozilla_dom_RustTypes_h +#define mozilla_dom_RustTypes_h + +#include "nsDebug.h" + +#define STATE_HELPERS(Type) \ + using InternalType = decltype(bits); \ + \ + constexpr Type() : bits{0} {} \ + \ + explicit constexpr Type(InternalType aBits) : bits{aBits} {} \ + \ + bool IsEmpty() const { return bits == 0; } \ + \ + bool HasAtLeastOneOfStates(Type aStates) const { \ + return bool((*this) & aStates); \ + } \ + \ + bool HasState(Type aState) const { \ + NS_ASSERTION(!(aState.bits & (aState.bits - 1)), \ + "When calling HasState, " \ + "argument has to contain only one state!"); \ + return HasAtLeastOneOfStates(aState); \ + } \ + \ + bool HasAllStates(Type aStates) const { \ + return ((*this) & aStates) == aStates; \ + } \ + \ + InternalType GetInternalValue() const { return bits; } + +#include "mozilla/dom/rust_generated.h" + +#endif diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp index 1ac576944cd7..c108a7ee9f1a 100644 --- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -22,7 +22,6 @@ #include "mozilla/dom/SelectionBinding.h" #include "mozilla/dom/ShadowRoot.h" #include "mozilla/ErrorResult.h" -#include "mozilla/EventStates.h" #include "mozilla/HTMLEditor.h" #include "mozilla/IntegerRange.h" #include "mozilla/Logging.h" @@ -433,7 +432,7 @@ static bool IsEditorNode(const nsINode* aNode) { } auto* element = Element::FromNode(aNode); - return element && element->State().HasState(NS_EVENT_STATE_READWRITE); + return element && element->State().HasState(ElementState::READWRITE); } bool Selection::IsEditorSelection() const { diff --git a/dom/base/moz.build b/dom/base/moz.build index 229e06a54520..c1c6c95cc91f 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -294,6 +294,17 @@ if CONFIG["FUZZING"]: "FuzzingFunctions.h", ] +if CONFIG["COMPILE_ENVIRONMENT"]: + EXPORTS.mozilla.dom += [ + "!rust_generated.h", + "RustTypes.h", + ] + + CbindgenHeader( + "rust_generated.h", + inputs=["rust"], + ) + UNIFIED_SOURCES += [ "AbstractRange.cpp", "AnimationFrameProvider.cpp", diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 51c49a7e13a5..b1e7116444dc 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -4322,15 +4322,15 @@ nsDOMWindowUtils::GetGpuProcessPid(int32_t* aPid) { struct StateTableEntry { const char* mStateString; - EventStates mState; + ElementState mState; }; static constexpr StateTableEntry kManuallyManagedStates[] = { - {"autofill", NS_EVENT_STATE_AUTOFILL}, + {"autofill", ElementState::AUTOFILL}, // :-moz-autofill-preview implies :autofill. {"-moz-autofill-preview", - NS_EVENT_STATE_AUTOFILL_PREVIEW | NS_EVENT_STATE_AUTOFILL}, - {nullptr, EventStates()}, + ElementState::AUTOFILL_PREVIEW | ElementState::AUTOFILL}, + {nullptr, ElementState()}, }; static_assert(!kManuallyManagedStates[ArrayLength(kManuallyManagedStates) - 1] @@ -4338,14 +4338,14 @@ static_assert(!kManuallyManagedStates[ArrayLength(kManuallyManagedStates) - 1] "last kManuallyManagedStates entry must be a sentinel with " "mStateString == nullptr"); -static EventStates GetEventStateForString(const nsAString& aStateString) { +static ElementState GetEventStateForString(const nsAString& aStateString) { for (const StateTableEntry* entry = kManuallyManagedStates; entry->mStateString; ++entry) { if (aStateString.EqualsASCII(entry->mStateString)) { return entry->mState; } } - return EventStates(); + return ElementState(); } NS_IMETHODIMP @@ -4355,7 +4355,7 @@ nsDOMWindowUtils::AddManuallyManagedState(Element* aElement, return NS_ERROR_INVALID_ARG; } - EventStates state = GetEventStateForString(aStateString); + ElementState state = GetEventStateForString(aStateString); if (state.IsEmpty()) { return NS_ERROR_INVALID_ARG; } @@ -4371,7 +4371,7 @@ nsDOMWindowUtils::RemoveManuallyManagedState(Element* aElement, return NS_ERROR_INVALID_ARG; } - EventStates state = GetEventStateForString(aStateString); + ElementState state = GetEventStateForString(aStateString); if (state.IsEmpty()) { return NS_ERROR_INVALID_ARG; } diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index f3d624045c15..d1aadf776669 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -58,7 +58,6 @@ #include "mozilla/dom/WindowGlobalChild.h" #include "mozilla/EventDispatcher.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/HTMLEditor.h" #include "mozilla/IMEStateManager.h" #include "mozilla/LookAndFeel.h" @@ -1307,24 +1306,24 @@ void nsFocusManager::NotifyFocusStateChange(Element* aElement, } if (aGettingFocus) { - EventStates eventStateToAdd = NS_EVENT_STATE_FOCUS; + ElementState eventStateToAdd = ElementState::FOCUS; if (aShouldShowFocusRing) { - eventStateToAdd |= NS_EVENT_STATE_FOCUSRING; + eventStateToAdd |= ElementState::FOCUSRING; } aElement->AddStates(eventStateToAdd); for (nsIContent* host = aElement->GetContainingShadowHost(); host; host = host->GetContainingShadowHost()) { - host->AsElement()->AddStates(NS_EVENT_STATE_FOCUS); + host->AsElement()->AddStates(ElementState::FOCUS); } } else { - EventStates eventStateToRemove = - NS_EVENT_STATE_FOCUS | NS_EVENT_STATE_FOCUSRING; + ElementState eventStateToRemove = + ElementState::FOCUS | ElementState::FOCUSRING; aElement->RemoveStates(eventStateToRemove); for (nsIContent* host = aElement->GetContainingShadowHost(); host; host = host->GetContainingShadowHost()) { - host->AsElement()->RemoveStates(NS_EVENT_STATE_FOCUS); + host->AsElement()->RemoveStates(ElementState::FOCUS); } } @@ -1336,12 +1335,12 @@ void nsFocusManager::NotifyFocusStateChange(Element* aElement, } if (aGettingFocus) { - if (element->State().HasState(NS_EVENT_STATE_FOCUS_WITHIN)) { + if (element->State().HasState(ElementState::FOCUS_WITHIN)) { break; } - element->AddStates(NS_EVENT_STATE_FOCUS_WITHIN); + element->AddStates(ElementState::FOCUS_WITHIN); } else { - element->RemoveStates(NS_EVENT_STATE_FOCUS_WITHIN); + element->RemoveStates(ElementState::FOCUS_WITHIN); } } } diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index d98276d975b7..683285fe968a 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -107,7 +107,6 @@ #include "mozilla/Components.h" #include "mozilla/Debug.h" #include "mozilla/EventListenerManager.h" -#include "mozilla/EventStates.h" #include "mozilla/MouseEvents.h" #include "mozilla/PresShell.h" #include "mozilla/ProcessHangMonitor.h" @@ -6737,9 +6736,9 @@ void nsGlobalWindowOuter::SetKeyboardIndicators( oldShouldShowFocusRing != newShouldShowFocusRing) { // Update focusedNode's state. if (newShouldShowFocusRing) { - mInnerWindow->mFocusedElement->AddStates(NS_EVENT_STATE_FOCUSRING); + mInnerWindow->mFocusedElement->AddStates(ElementState::FOCUSRING); } else { - mInnerWindow->mFocusedElement->RemoveStates(NS_EVENT_STATE_FOCUSRING); + mInnerWindow->mFocusedElement->RemoveStates(ElementState::FOCUSRING); } } } diff --git a/dom/base/nsIDocumentObserver.h b/dom/base/nsIDocumentObserver.h index 6bf08fce9146..221d25aff2b0 100644 --- a/dom/base/nsIDocumentObserver.h +++ b/dom/base/nsIDocumentObserver.h @@ -8,10 +8,10 @@ #include "nsISupports.h" #include "nsIMutationObserver.h" +#include "mozilla/dom/RustTypes.h" class nsIContent; namespace mozilla { -class EventStates; namespace dom { class Document; @@ -72,7 +72,7 @@ class nsIDocumentObserver : public nsIMutationObserver { */ virtual void ContentStateChanged(mozilla::dom::Document*, nsIContent* aContent, - mozilla::EventStates aStateMask) = 0; + mozilla::dom::ElementState aStateMask) = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID) @@ -89,10 +89,10 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID) #define NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD \ virtual void EndLoad(mozilla::dom::Document*) override; -#define NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED \ - virtual void ContentStateChanged(mozilla::dom::Document*, \ - nsIContent* aContent, \ - mozilla::EventStates aStateMask) override; +#define NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED \ + virtual void ContentStateChanged( \ + mozilla::dom::Document*, nsIContent* aContent, \ + mozilla::dom::ElementState aStateMask) override; #define NS_DECL_NSIDOCUMENTOBSERVER \ NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \ @@ -114,7 +114,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID) #define NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(_class) \ void _class::ContentStateChanged(mozilla::dom::Document*, \ nsIContent* aContent, \ - mozilla::EventStates aStateMask) {} + mozilla::dom::ElementState aStateMask) {} #define NS_IMPL_NSIDOCUMENTOBSERVER_CONTENT(_class) \ NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class) diff --git a/dom/base/nsImageLoadingContent.cpp b/dom/base/nsImageLoadingContent.cpp index a218b6fc563b..490bfdac7342 100644 --- a/dom/base/nsImageLoadingContent.cpp +++ b/dom/base/nsImageLoadingContent.cpp @@ -39,7 +39,6 @@ #include "mozilla/AutoRestore.h" #include "mozilla/CycleCollectedJSContext.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/Preferences.h" #include "mozilla/PresShell.h" #include "mozilla/StaticPrefs_image.h" @@ -1194,9 +1193,9 @@ nsresult nsImageLoadingContent::LoadImage(nsIURI* aNewURI, bool aForce, } void nsImageLoadingContent::ForceImageState(bool aForce, - EventStates::InternalType aState) { + ElementState::InternalType aState) { mIsImageStateForced = aForce; - mForcedImageState = EventStates(aState); + mForcedImageState = ElementState(aState); } already_AddRefed nsImageLoadingContent::RecognizeCurrentImageText( @@ -1301,18 +1300,18 @@ CSSIntSize nsImageLoadingContent::GetWidthHeightForImage() { return size; } -EventStates nsImageLoadingContent::ImageState() const { +ElementState nsImageLoadingContent::ImageState() const { if (mIsImageStateForced) { return mForcedImageState; } - EventStates states; + ElementState states; if (mBroken) { - states |= NS_EVENT_STATE_BROKEN; + states |= ElementState::BROKEN; } if (mLoading) { - states |= NS_EVENT_STATE_LOADING; + states |= ElementState::LOADING; } return states; diff --git a/dom/base/nsImageLoadingContent.h b/dom/base/nsImageLoadingContent.h index e2bb05535e8f..36c6e8ef29ba 100644 --- a/dom/base/nsImageLoadingContent.h +++ b/dom/base/nsImageLoadingContent.h @@ -15,7 +15,6 @@ #include "imgINotificationObserver.h" #include "mozilla/CORSMode.h" -#include "mozilla/EventStates.h" #include "mozilla/TimeStamp.h" #include "nsCOMPtr.h" #include "nsIContentPolicy.h" @@ -23,6 +22,7 @@ #include "nsIRequest.h" #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/Promise.h" +#include "mozilla/dom/RustTypes.h" #include "nsAttrValue.h" #include "Units.h" @@ -97,7 +97,8 @@ class nsImageLoadingContent : public nsIImageLoadingContent { * nsImageLoadingContent::ImageState() to return |aState|. Call again with * |aForce| as false to revert ImageState() to its original behaviour. */ - void ForceImageState(bool aForce, mozilla::EventStates::InternalType aState); + void ForceImageState(bool aForce, + mozilla::dom::ElementState::InternalType aState); // Trigger text recognition for the current image request. already_AddRefed RecognizeCurrentImageText( @@ -134,15 +135,15 @@ class nsImageLoadingContent : public nsIImageLoadingContent { /** * ImageState is called by subclasses that are computing their content state. - * The return value will have the NS_EVENT_STATE_BROKEN bit set as needed. + * The return value will have the ElementState::BROKEN bit set as needed. * * Note that this state assumes that this node is "trying" to be an * image (so for example complete lack of attempt to load an image will lead - * to NS_EVENT_STATE_BROKEN being set). Subclasses that are not "trying" to + * to ElementState::BROKEN being set). Subclasses that are not "trying" to * be an image (eg an HTML of type other than "image") should just * not call this method when computing their intrinsic state. */ - mozilla::EventStates ImageState() const; + mozilla::dom::ElementState ImageState() const; /** * LoadImage is called by subclasses when the appropriate @@ -544,7 +545,7 @@ class nsImageLoadingContent : public nsIImageLoadingContent { * When mIsImageStateForced is true, this holds the ImageState that we'll * return in ImageState(). */ - mozilla::EventStates mForcedImageState; + mozilla::dom::ElementState mForcedImageState; mozilla::TimeStamp mMostRecentRequestChange; diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index 7e55d2a68952..16f093c0fc66 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -79,7 +79,6 @@ #include "mozilla/dom/PluginCrashedEvent.h" #include "mozilla/AsyncEventDispatcher.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/IMEStateManager.h" #include "mozilla/widget/IMEData.h" #include "mozilla/IntegerPrintfMacros.h" @@ -814,10 +813,10 @@ nsObjectLoadingContent::AsyncOnChannelRedirect( } // -EventStates nsObjectLoadingContent::ObjectState() const { +ElementState nsObjectLoadingContent::ObjectState() const { switch (mType) { case eType_Loading: - return NS_EVENT_STATE_LOADING; + return ElementState::LOADING; case eType_Image: return ImageState(); case eType_FakePlugin: @@ -825,16 +824,16 @@ EventStates nsObjectLoadingContent::ObjectState() const { // These are OK. If documents start to load successfully, they display // something, and are thus not broken in this sense. The same goes for // plugins. - return EventStates(); + return ElementState(); case eType_Fallback: // This may end up handled as TYPE_NULL or as a "special" type, as // chosen by the layout.use-plugin-fallback pref. - return EventStates(); + return ElementState(); case eType_Null: - return NS_EVENT_STATE_BROKEN; + return ElementState::BROKEN; } MOZ_ASSERT_UNREACHABLE("unknown type?"); - return NS_EVENT_STATE_LOADING; + return ElementState::LOADING; } void nsObjectLoadingContent::MaybeRewriteYoutubeEmbed(nsIURI* aURI, @@ -1442,7 +1441,7 @@ nsresult nsObjectLoadingContent::LoadObject(bool aNotify, bool aForceLoad, } // Save these for NotifyStateChanged(); - EventStates oldState = ObjectState(); + ElementState oldState = ObjectState(); ObjectType oldType = mType; ParameterUpdateFlags stateChange = UpdateObjectParameters(); @@ -1997,7 +1996,7 @@ void nsObjectLoadingContent::UnloadObject(bool aResetState) { } void nsObjectLoadingContent::NotifyStateChanged(ObjectType aOldType, - EventStates aOldState, + ElementState aOldState, bool aNotify) { LOG(("OBJLC [%p]: NotifyStateChanged: (%u, %" PRIx64 ") -> (%u, %" PRIx64 ")" " (notify %i)", @@ -2025,7 +2024,7 @@ void nsObjectLoadingContent::NotifyStateChanged(ObjectType aOldType, return; // Nothing to do } - const EventStates newState = ObjectState(); + const ElementState newState = ObjectState(); if (newState == aOldState && mType == aOldType) { return; // Also done. } diff --git a/dom/base/nsObjectLoadingContent.h b/dom/base/nsObjectLoadingContent.h index 72eaac7f247c..47e9e9f169ab 100644 --- a/dom/base/nsObjectLoadingContent.h +++ b/dom/base/nsObjectLoadingContent.h @@ -88,7 +88,7 @@ class nsObjectLoadingContent : public nsImageLoadingContent, * Object state. This is a bitmask of NS_EVENT_STATEs epresenting the * current state of the object. */ - mozilla::EventStates ObjectState() const; + mozilla::dom::ElementState ObjectState() const; ObjectType Type() const { return mType; } @@ -447,8 +447,8 @@ class nsObjectLoadingContent : public nsImageLoadingContent, * * @param aNotify if false, only need to update the state of our element. */ - void NotifyStateChanged(ObjectType aOldType, mozilla::EventStates aOldState, - bool aNotify); + void NotifyStateChanged(ObjectType aOldType, + mozilla::dom::ElementState aOldState, bool aNotify); /** * Returns a ObjectType value corresponding to the type of content we would diff --git a/dom/base/nsStubDocumentObserver.cpp b/dom/base/nsStubDocumentObserver.cpp index 55bb9c3aae34..36b8e1fe2e15 100644 --- a/dom/base/nsStubDocumentObserver.cpp +++ b/dom/base/nsStubDocumentObserver.cpp @@ -13,8 +13,6 @@ #include "nsStubDocumentObserver.h" -#include "mozilla/EventStates.h" - NS_IMPL_NSIDOCUMENTOBSERVER_CORE_STUB(nsStubDocumentObserver) NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(nsStubDocumentObserver) NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(nsStubDocumentObserver) diff --git a/dom/base/rust/Cargo.toml b/dom/base/rust/Cargo.toml new file mode 100644 index 000000000000..efc42a2df573 --- /dev/null +++ b/dom/base/rust/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "dom" +version = "0.1.0" +edition = "2021" +authors = [ + "Emilio Cobos Álvarez ", +] +license = "MPL-2.0" + +[lib] +path = "lib.rs" + +[dependencies] +bitflags = "1.0" diff --git a/dom/base/rust/cbindgen.toml b/dom/base/rust/cbindgen.toml new file mode 100644 index 000000000000..99edb2cd8a91 --- /dev/null +++ b/dom/base/rust/cbindgen.toml @@ -0,0 +1,40 @@ +header = """/* 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 https://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_RustTypes_h +#error "Don't include this file directly, include mozilla/dom/RustTypes.h instead" +#endif +""" +include_guard = "mozilla_dom_rust_generated_h" +include_version = true +language = "C++" +namespaces = ["mozilla", "dom"] +includes = ["mozilla/Assertions.h"] + +[enum] +derive_helper_methods = true +derive_const_casts = true +cast_assert_name = "MOZ_DIAGNOSTIC_ASSERT" + +[struct] +associated_constants_in_body = true +derive_eq = true +derive_neq = true + +[macro_expansion] +bitflags = true + +[export] +include = [ + "ElementState", + "DocumentState", +] + +[export.body] +"ElementState" = """ + STATE_HELPERS(ElementState) +""" +"DocumentState" = """ + STATE_HELPERS(DocumentState) +""" diff --git a/servo/components/style/element_state.rs b/dom/base/rust/lib.rs similarity index 54% rename from servo/components/style/element_state.rs rename to dom/base/rust/lib.rs index f8f4629ef9b7..bb447c076f98 100644 --- a/servo/components/style/element_state.rs +++ b/dom/base/rust/lib.rs @@ -2,143 +2,180 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -//! States elements can be in. +//! DOM types to be shared between Rust and C++. + +use bitflags::bitflags; bitflags! { /// Event-based element states. - /// - /// NB: Is important for this to remain in sync with Gecko's - /// dom/events/EventStates.h. - /// - /// Please keep in that order in order for this to be easily auditable. - /// - /// TODO(emilio): We really really want to use the NS_EVENT_STATE bindings - /// for this. - #[derive(MallocSizeOf)] + #[repr(C)] pub struct ElementState: u64 { /// The mouse is down on this element. /// /// FIXME(#7333): set/unset this when appropriate - const IN_ACTIVE_STATE = 1 << 0; + const ACTIVE = 1 << 0; /// This element has focus. /// - const IN_FOCUS_STATE = 1 << 1; + const FOCUS = 1 << 1; /// The mouse is hovering over this element. /// - const IN_HOVER_STATE = 1 << 2; + const HOVER = 1 << 2; /// Content is enabled (and can be disabled). /// - const IN_ENABLED_STATE = 1 << 3; + const ENABLED = 1 << 3; /// Content is disabled. /// - const IN_DISABLED_STATE = 1 << 4; + const DISABLED = 1 << 4; /// Content is checked. /// - const IN_CHECKED_STATE = 1 << 5; + const CHECKED = 1 << 5; /// - const IN_INDETERMINATE_STATE = 1 << 6; + const INDETERMINATE = 1 << 6; /// - const IN_PLACEHOLDER_SHOWN_STATE = 1 << 7; + const PLACEHOLDER_SHOWN = 1 << 7; /// - const IN_TARGET_STATE = 1 << 8; + const URLTARGET = 1 << 8; /// - const IN_FULLSCREEN_STATE = 1 << 9; + const FULLSCREEN = 1 << 9; /// - const IN_VALID_STATE = 1 << 10; + const VALID = 1 << 10; /// - const IN_INVALID_STATE = 1 << 11; + const INVALID = 1 << 11; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-ui-valid - const IN_MOZ_UI_VALID_STATE = 1 << 12; + const MOZ_UI_VALID = 1 << 12; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-ui-invalid - const IN_MOZ_UI_INVALID_STATE = 1 << 13; + const MOZ_UI_INVALID = 1 << 13; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-broken - const IN_BROKEN_STATE = 1 << 14; + const BROKEN = 1 << 14; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-loading - const IN_LOADING_STATE = 1 << 15; + const LOADING = 1 << 15; /// - const IN_REQUIRED_STATE = 1 << 16; + const REQUIRED = 1 << 16; /// - const IN_OPTIONAL_STATE = 1 << 17; + /// We use an underscore to workaround a silly windows.h define. + const OPTIONAL_ = 1 << 17; /// - const IN_DEFINED_STATE = 1 << 18; + const DEFINED = 1 << 18; /// - const IN_VISITED_STATE = 1 << 19; + const VISITED = 1 << 19; /// - const IN_UNVISITED_STATE = 1 << 20; + const UNVISITED = 1 << 20; /// - const IN_VISITED_OR_UNVISITED_STATE = ElementState::IN_VISITED_STATE.bits | - ElementState::IN_UNVISITED_STATE.bits; + const VISITED_OR_UNVISITED = Self::VISITED.bits | Self::UNVISITED.bits; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-drag-over - const IN_DRAGOVER_STATE = 1 << 21; + const DRAGOVER = 1 << 21; /// - const IN_INRANGE_STATE = 1 << 22; + const INRANGE = 1 << 22; /// - const IN_OUTOFRANGE_STATE = 1 << 23; + const OUTOFRANGE = 1 << 23; /// - const IN_READONLY_STATE = 1 << 24; + const READONLY = 1 << 24; /// - const IN_READWRITE_STATE = 1 << 25; + const READWRITE = 1 << 25; /// - const IN_DEFAULT_STATE = 1 << 26; + const DEFAULT = 1 << 26; /// Non-standard & undocumented. - const IN_OPTIMUM_STATE = 1 << 28; + const OPTIMUM = 1 << 28; /// Non-standard & undocumented. - const IN_SUB_OPTIMUM_STATE = 1 << 29; + const SUB_OPTIMUM = 1 << 29; /// Non-standard & undocumented. - const IN_SUB_SUB_OPTIMUM_STATE = 1 << 30; + const SUB_SUB_OPTIMUM = 1 << 30; /// Non-standard & undocumented. - const IN_INCREMENT_SCRIPT_LEVEL_STATE = 1 << 31; + const INCREMENT_SCRIPT_LEVEL = 1u64 << 31; /// - const IN_FOCUSRING_STATE = 1 << 32; + const FOCUSRING = 1u64 << 32; /// - const IN_FOCUS_WITHIN_STATE = 1 << 33; + const FOCUS_WITHIN = 1u64 << 33; /// :dir matching; the states are used for dynamic change detection. /// State that elements that match :dir(ltr) are in. - const IN_LTR_STATE = 1 << 34; + const LTR = 1u64 << 34; /// State that elements that match :dir(rtl) are in. - const IN_RTL_STATE = 1 << 35; + const RTL = 1u64 << 35; /// State that HTML elements that have a "dir" attr are in. - const IN_HAS_DIR_ATTR_STATE = 1 << 36; + const HAS_DIR_ATTR = 1u64 << 36; /// State that HTML elements with dir="ltr" (or something /// case-insensitively equal to "ltr") are in. - const IN_HAS_DIR_ATTR_LTR_STATE = 1 << 37; + const HAS_DIR_ATTR_LTR = 1u64 << 37; /// State that HTML elements with dir="rtl" (or something /// case-insensitively equal to "rtl") are in. - const IN_HAS_DIR_ATTR_RTL_STATE = 1 << 38; + const HAS_DIR_ATTR_RTL = 1u64 << 38; /// State that HTML elements without a valid-valued "dir" attr or /// any HTML elements (including ) with dir="auto" (or something /// case-insensitively equal to "auto") are in. - const IN_HAS_DIR_ATTR_LIKE_AUTO_STATE = 1 << 39; + const HAS_DIR_ATTR_LIKE_AUTO = 1u64 << 39; /// Non-standard & undocumented. - const IN_AUTOFILL_STATE = 1 << 40; + const AUTOFILL = 1u64 << 40; /// Non-standard & undocumented. - const IN_AUTOFILL_PREVIEW_STATE = 1 << 41; + const AUTOFILL_PREVIEW = 1u64 << 41; /// State that dialog element is modal, for centered alignment /// - const IN_MODAL_DIALOG_STATE = 1 << 42; + const MODAL_DIALOG = 1u64 << 42; /// - const IN_MOZINERT_STATE = 1 << 43; + const INERT = 1u64 << 43; /// State for the topmost modal element in top layer - const IN_TOPMOST_MODAL_TOP_LAYER_STATE = 1 << 44; + const TOPMOST_MODAL = 1u64 << 44; /// Initially used for the devtools highlighter, but now somehow only /// used for the devtools accessibility inspector. - const IN_DEVTOOLS_HIGHLIGHTED_STATE = 1 << 45; + const DEVTOOLS_HIGHLIGHTED = 1u64 << 45; /// Used for the devtools style editor. Probably should go away. - const IN_STYLEEDITOR_TRANSITIONING_STATE = 1 << 46; + const STYLEEDITOR_TRANSITIONING = 1u64 << 46; /// For :-moz-value-empty (to show widgets like the reveal password /// button or the clear button). - const IN_VALUE_EMPTY_STATE = 1 << 47; + const VALUE_EMPTY = 1u64 << 47; /// For :-moz-revealed. - const IN_REVEALED_STATE = 1 << 48; + const REVEALED = 1u64 << 48; + + /// Some convenience unions. + const DIR_STATES = Self::LTR.bits | Self::RTL.bits; + + const DIR_ATTR_STATES = Self::HAS_DIR_ATTR.bits | + Self::HAS_DIR_ATTR_LTR.bits | + Self::HAS_DIR_ATTR_RTL.bits | + Self::HAS_DIR_ATTR_LIKE_AUTO.bits; + + const DISABLED_STATES = Self::DISABLED.bits | Self::ENABLED.bits; + + const REQUIRED_STATES = Self::REQUIRED.bits | Self::OPTIONAL_.bits; + + /// Event states that can be added and removed through + /// Element::{Add,Remove}ManuallyManagedStates. + /// + /// Take care when manually managing state bits. You are responsible + /// for setting or clearing the bit when an Element is added or removed + /// from a document (e.g. in BindToTree and UnbindFromTree), if that is + /// an appropriate thing to do for your state bit. + const MANUALLY_MANAGED_STATES = Self::AUTOFILL.bits | Self::AUTOFILL_PREVIEW.bits; + + /// Event states that are managed externally to an element (by the + /// EventStateManager, or by other code). As opposed to those in + /// INTRINSIC_STATES, which are are computed by the element itself + /// and returned from Element::IntrinsicState. + const EXTERNALLY_MANAGED_STATES = + Self::MANUALLY_MANAGED_STATES.bits | + Self::DIR_ATTR_STATES.bits | + Self::DISABLED_STATES.bits | + Self::REQUIRED_STATES.bits | + Self::ACTIVE.bits | + Self::DEFINED.bits | + Self::DRAGOVER.bits | + Self::FOCUS.bits | + Self::FOCUSRING.bits | + Self::FOCUS_WITHIN.bits | + Self::FULLSCREEN.bits | + Self::HOVER.bits | + Self::URLTARGET.bits | + Self::MODAL_DIALOG.bits | + Self::INERT.bits | + Self::TOPMOST_MODAL.bits | + Self::REVEALED.bits; + + const INTRINSIC_STATES = !Self::EXTERNALLY_MANAGED_STATES.bits; } } bitflags! { /// Event-based document states. - /// - /// NB: Is important for this to remain in sync with Gecko's - /// dom/base/Document.h. - #[derive(MallocSizeOf)] + #[repr(C)] pub struct DocumentState: u64 { /// Window activation status const WINDOW_INACTIVE = 1 << 0; @@ -148,5 +185,7 @@ bitflags! { const LTR_LOCALE = 1 << 2; /// LWTheme status const LWTHEME = 1 << 3; + + const ALL_LOCALEDIR_BITS = Self::LTR_LOCALE.bits | Self::RTL_LOCALE.bits; } } diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index ac199cf96f72..e5ed8b656e6c 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -3119,7 +3119,7 @@ void CanvasRenderingContext2D::DrawFocusIfNeeded( } bool CanvasRenderingContext2D::DrawCustomFocusRing(Element& aElement) { - if (!aElement.State().HasState(NS_EVENT_STATE_FOCUSRING)) { + if (!aElement.State().HasState(ElementState::FOCUSRING)) { return false; } diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index e498f7063770..7993fa17c52a 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -11,7 +11,6 @@ #include "mozilla/EditorBase.h" #include "mozilla/EventDispatcher.h" #include "mozilla/EventForwards.h" -#include "mozilla/EventStates.h" #include "mozilla/Hal.h" #include "mozilla/HTMLEditor.h" #include "mozilla/IMEStateManager.h" @@ -3922,7 +3921,7 @@ nsresult EventStateManager::PostHandleEvent(nsPresContext* aPresContext, nsCOMPtr targetContent; mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(targetContent)); - SetContentState(targetContent, NS_EVENT_STATE_HOVER); + SetContentState(targetContent, ElementState::HOVER); } break; @@ -3978,7 +3977,7 @@ void EventStateManager::NotifyDestroyPresContext(nsPresContext* aPresContext) { // Reset the hover state so that if we're recreating the presentation, // we won't have the old hover state still set in the new presentation, // as if the new presentation is resized, a new element may be hovered. - SetContentState(nullptr, NS_EVENT_STATE_HOVER); + SetContentState(nullptr, ElementState::HOVER); } mPointersEnterLeaveHelper.Clear(); PointerEventHandler::NotifyDestroyPresContext(presContext); @@ -4598,7 +4597,7 @@ void EventStateManager::NotifyMouseOut(WidgetMouseEvent* aMouseEvent, bool isPointer = aMouseEvent->mClass == ePointerEventClass; if (!aMovingInto && !isPointer) { // Unset :hover - SetContentState(nullptr, NS_EVENT_STATE_HOVER); + SetContentState(nullptr, ElementState::HOVER); } EnterLeaveDispatcher leaveDispatcher(this, wrapper->mLastOverElement, @@ -4670,7 +4669,7 @@ void EventStateManager::NotifyMouseOver(WidgetMouseEvent* aMouseEvent, isPointer ? ePointerEnter : eMouseEnter); if (!isPointer) { - SetContentState(aContent, NS_EVENT_STATE_HOVER); + SetContentState(aContent, ElementState::HOVER); } NotifyMouseOut(aMouseEvent, aContent); @@ -5079,7 +5078,7 @@ void EventStateManager::FireDragEnterOrExit(nsPresContext* aPresContext, // drag exit if (status == nsEventStatus_eConsumeNoDefault || aMessage == eDragExit) { SetContentState((aMessage == eDragEnter) ? aTargetContent : nullptr, - NS_EVENT_STATE_DRAGOVER); + ElementState::DRAGOVER); } // collect any changes to moz cursor settings stored in the event's @@ -5555,7 +5554,7 @@ static Element* GetLabelTarget(nsIContent* aPossibleLabel) { /* static */ inline void EventStateManager::DoStateChange(Element* aElement, - EventStates aState, + ElementState aState, bool aAddState) { if (aAddState) { aElement->AddStates(aState); @@ -5566,7 +5565,7 @@ inline void EventStateManager::DoStateChange(Element* aElement, /* static */ inline void EventStateManager::DoStateChange(nsIContent* aContent, - EventStates aState, + ElementState aState, bool aStateAdded) { if (aContent->IsElement()) { DoStateChange(aContent->AsElement(), aState, aStateAdded); @@ -5576,7 +5575,7 @@ inline void EventStateManager::DoStateChange(nsIContent* aContent, /* static */ void EventStateManager::UpdateAncestorState(nsIContent* aStartNode, nsIContent* aStopBefore, - EventStates aState, + ElementState aState, bool aAddState) { for (; aStartNode && aStartNode != aStopBefore; aStartNode = aStartNode->GetFlattenedTreeParent()) { @@ -5629,14 +5628,14 @@ bool CanContentHaveActiveState(nsIContent& aContent) { } bool EventStateManager::SetContentState(nsIContent* aContent, - EventStates aState) { + ElementState aState) { MOZ_ASSERT(ManagesState(aState), "Unexpected state"); nsCOMPtr notifyContent1; nsCOMPtr notifyContent2; bool updateAncestors; - if (aState == NS_EVENT_STATE_HOVER || aState == NS_EVENT_STATE_ACTIVE) { + if (aState == ElementState::HOVER || aState == ElementState::ACTIVE) { // Hover and active are hierarchical updateAncestors = true; @@ -5647,7 +5646,7 @@ bool EventStateManager::SetContentState(nsIContent* aContent, return false; } - if (aState == NS_EVENT_STATE_ACTIVE) { + if (aState == ElementState::ACTIVE) { if (aContent && !CanContentHaveActiveState(*aContent)) { aContent = nullptr; } @@ -5657,7 +5656,7 @@ bool EventStateManager::SetContentState(nsIContent* aContent, mActiveContent = aContent; } } else { - NS_ASSERTION(aState == NS_EVENT_STATE_HOVER, "How did that happen?"); + NS_ASSERTION(aState == ElementState::HOVER, "How did that happen?"); nsIContent* newHover; if (mPresContext->IsDynamic()) { @@ -5685,13 +5684,13 @@ bool EventStateManager::SetContentState(nsIContent* aContent, } } else { updateAncestors = false; - if (aState == NS_EVENT_STATE_DRAGOVER) { + if (aState == ElementState::DRAGOVER) { if (aContent != sDragOverContent) { notifyContent1 = aContent; notifyContent2 = sDragOverContent; sDragOverContent = aContent; } - } else if (aState == NS_EVENT_STATE_URLTARGET) { + } else if (aState == ElementState::URLTARGET) { if (aContent != mURLTargetContent) { notifyContent1 = aContent; notifyContent2 = mURLTargetContent; @@ -5754,17 +5753,17 @@ void EventStateManager::ResetLastOverForContent( } } -void EventStateManager::RemoveNodeFromChainIfNeeded(EventStates aState, +void EventStateManager::RemoveNodeFromChainIfNeeded(ElementState aState, nsIContent* aContentRemoved, bool aNotify) { - MOZ_ASSERT(aState == NS_EVENT_STATE_HOVER || aState == NS_EVENT_STATE_ACTIVE); + MOZ_ASSERT(aState == ElementState::HOVER || aState == ElementState::ACTIVE); if (!aContentRemoved->IsElement() || !aContentRemoved->AsElement()->State().HasState(aState)) { return; } nsCOMPtr& leaf = - aState == NS_EVENT_STATE_HOVER ? mHoverContent : mActiveContent; + aState == ElementState::HOVER ? mHoverContent : mActiveContent; MOZ_ASSERT(leaf); // These two NS_ASSERTIONS below can fail for Shadow DOM sometimes, and it's @@ -5788,14 +5787,14 @@ void EventStateManager::RemoveNodeFromChainIfNeeded(EventStates aState, // Also, NAC is not observable and NAC being removed will go away soon. leaf = newLeaf; } - MOZ_ASSERT(leaf == newLeaf || (aState == NS_EVENT_STATE_ACTIVE && !leaf && + MOZ_ASSERT(leaf == newLeaf || (aState == ElementState::ACTIVE && !leaf && !CanContentHaveActiveState(*newLeaf))); } void EventStateManager::NativeAnonymousContentRemoved(nsIContent* aContent) { MOZ_ASSERT(aContent->IsRootOfNativeAnonymousSubtree()); - RemoveNodeFromChainIfNeeded(NS_EVENT_STATE_HOVER, aContent, false); - RemoveNodeFromChainIfNeeded(NS_EVENT_STATE_ACTIVE, aContent, false); + RemoveNodeFromChainIfNeeded(ElementState::HOVER, aContent, false); + RemoveNodeFromChainIfNeeded(ElementState::ACTIVE, aContent, false); if (mLastLeftMouseDownContent && nsContentUtils::ContentIsFlattenedTreeDescendantOf( @@ -5825,7 +5824,7 @@ void EventStateManager::ContentRemoved(Document* aDocument, */ if (aContent->IsAnyOfHTMLElements(nsGkAtoms::a, nsGkAtoms::area) && (aContent->AsElement()->State().HasAtLeastOneOfStates( - NS_EVENT_STATE_FOCUS | NS_EVENT_STATE_HOVER))) { + ElementState::FOCUS | ElementState::HOVER))) { Element* element = aContent->AsElement(); element->LeaveLink(element->GetPresContext(Element::eForComposedDoc)); } @@ -5843,8 +5842,8 @@ void EventStateManager::ContentRemoved(Document* aDocument, fm->ContentRemoved(aDocument, aContent); } - RemoveNodeFromChainIfNeeded(NS_EVENT_STATE_HOVER, aContent, true); - RemoveNodeFromChainIfNeeded(NS_EVENT_STATE_ACTIVE, aContent, true); + RemoveNodeFromChainIfNeeded(ElementState::HOVER, aContent, true); + RemoveNodeFromChainIfNeeded(ElementState::ACTIVE, aContent, true); if (sDragOverContent && sDragOverContent->OwnerDoc() == aContent->OwnerDoc() && @@ -6178,23 +6177,23 @@ nsresult EventStateManager::DoContentCommandScrollEvent( void EventStateManager::SetActiveManager(EventStateManager* aNewESM, nsIContent* aContent) { if (sActiveESM && aNewESM != sActiveESM) { - sActiveESM->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE); + sActiveESM->SetContentState(nullptr, ElementState::ACTIVE); } sActiveESM = aNewESM; if (sActiveESM && aContent) { - sActiveESM->SetContentState(aContent, NS_EVENT_STATE_ACTIVE); + sActiveESM->SetContentState(aContent, ElementState::ACTIVE); } } void EventStateManager::ClearGlobalActiveContent(EventStateManager* aClearer) { if (aClearer) { - aClearer->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE); + aClearer->SetContentState(nullptr, ElementState::ACTIVE); if (sDragOverContent) { - aClearer->SetContentState(nullptr, NS_EVENT_STATE_DRAGOVER); + aClearer->SetContentState(nullptr, ElementState::DRAGOVER); } } if (sActiveESM && aClearer != sActiveESM) { - sActiveESM->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE); + sActiveESM->SetContentState(nullptr, ElementState::ACTIVE); } sActiveESM = nullptr; } diff --git a/dom/events/EventStateManager.h b/dom/events/EventStateManager.h index 55fd4269b117..959fd4b436aa 100644 --- a/dom/events/EventStateManager.h +++ b/dom/events/EventStateManager.h @@ -38,7 +38,6 @@ namespace mozilla { class EditorBase; class EnterLeaveDispatcher; -class EventStates; class IMEContentObserver; class ScrollbarsForWheel; class TextControlElement; @@ -81,6 +80,8 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver { friend class mozilla::ScrollbarsForWheel; friend class mozilla::WheelTransaction; + using ElementState = dom::ElementState; + virtual ~EventStateManager(); public: @@ -139,16 +140,16 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver { already_AddRefed GetEventTargetContent(WidgetEvent* aEvent); // We manage 4 states here: ACTIVE, HOVER, DRAGOVER, URLTARGET - static bool ManagesState(EventStates aState) { - return aState == NS_EVENT_STATE_ACTIVE || aState == NS_EVENT_STATE_HOVER || - aState == NS_EVENT_STATE_DRAGOVER || - aState == NS_EVENT_STATE_URLTARGET; + static bool ManagesState(ElementState aState) { + return aState == ElementState::ACTIVE || aState == ElementState::HOVER || + aState == ElementState::DRAGOVER || + aState == ElementState::URLTARGET; } /** - * Notify that the given NS_EVENT_STATE_* bit has changed for this content. + * Notify that the given ElementState::* bit has changed for this content. * @param aContent Content which has changed states - * @param aState Corresponding state flags such as NS_EVENT_STATE_FOCUS + * @param aState Corresponding state flags such as ElementState::FOCUS * @return Whether the content was able to change all states. Returns false * if a resulting DOM event causes the content node passed in * to not change states. Note, the frame for the content may @@ -156,7 +157,7 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver { * frame reconstructions that may occur, but this does not * affect the return value. */ - bool SetContentState(nsIContent* aContent, EventStates aState); + bool SetContentState(nsIContent* aContent, ElementState aState); void NativeAnonymousContentRemoved(nsIContent* aAnonContent); MOZ_CAN_RUN_SCRIPT_BOUNDARY void ContentRemoved(dom::Document* aDocument, @@ -1102,17 +1103,17 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver { // // Only meant to be called from ContentRemoved and // NativeAnonymousContentRemoved. - void RemoveNodeFromChainIfNeeded(EventStates aState, + void RemoveNodeFromChainIfNeeded(ElementState aState, nsIContent* aContentRemoved, bool aNotify); bool IsEventOutsideDragThreshold(WidgetInputEvent* aEvent) const; - static inline void DoStateChange(dom::Element* aElement, EventStates aState, + static inline void DoStateChange(dom::Element* aElement, ElementState aState, bool aAddState); - static inline void DoStateChange(nsIContent* aContent, EventStates aState, + static inline void DoStateChange(nsIContent* aContent, ElementState aState, bool aAddState); static void UpdateAncestorState(nsIContent* aStartNode, - nsIContent* aStopBefore, EventStates aState, + nsIContent* aStopBefore, ElementState aState, bool aAddState); static void ResetLastOverForContent( const uint32_t& aIdx, const RefPtr& aChunk, diff --git a/dom/events/EventStates.h b/dom/events/EventStates.h deleted file mode 100644 index 9ae56b52e06f..000000000000 --- a/dom/events/EventStates.h +++ /dev/null @@ -1,323 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#ifndef mozilla_EventStates_h_ -#define mozilla_EventStates_h_ - -#include "mozilla/Attributes.h" -#include "nsDebug.h" - -namespace mozilla { - -/** - * EventStates is the class used to represent the event states of nsIContent - * instances. These states are calculated by IntrinsicState() and - * ContentStatesChanged() has to be called when one of them changes thus - * informing the layout/style engine of the change. - * Event states are associated with pseudo-classes. - */ -class EventStates { - public: - typedef uint64_t InternalType; - typedef uint64_t ServoType; - - constexpr EventStates() : mStates(0) {} - - // NOTE: the ideal scenario would be to have the default constructor public - // setting mStates to 0 and this constructor (without = 0) private. - // In that case, we could be sure that only macros at the end were creating - // EventStates instances with mStates set to something else than 0. - // Unfortunately, this constructor is needed at at least two places now. - explicit constexpr EventStates(InternalType aStates) : mStates(aStates) {} - - EventStates constexpr operator|(const EventStates& aEventStates) const { - return EventStates(mStates | aEventStates.mStates); - } - - EventStates& operator|=(const EventStates& aEventStates) { - mStates |= aEventStates.mStates; - return *this; - } - - // NOTE: calling if (eventStates1 & eventStates2) will not build. - // This might work correctly if operator bool() is defined - // but using HasState, HasAllStates or HasAtLeastOneOfStates is recommended. - EventStates constexpr operator&(const EventStates& aEventStates) const { - return EventStates(mStates & aEventStates.mStates); - } - - EventStates& operator&=(const EventStates& aEventStates) { - mStates &= aEventStates.mStates; - return *this; - } - - bool operator==(const EventStates& aEventStates) const { - return mStates == aEventStates.mStates; - } - - bool operator!=(const EventStates& aEventStates) const { - return mStates != aEventStates.mStates; - } - - EventStates operator~() const { return EventStates(~mStates); } - - EventStates operator^(const EventStates& aEventStates) const { - return EventStates(mStates ^ aEventStates.mStates); - } - - EventStates& operator^=(const EventStates& aEventStates) { - mStates ^= aEventStates.mStates; - return *this; - } - - /** - * Returns true if the EventStates instance is empty. - * A EventStates instance is empty if it contains no state. - * - * @return Whether if the object is empty. - */ - bool IsEmpty() const { return mStates == 0; } - - /** - * Returns true if the EventStates instance contains the state - * contained in aEventStates. - * @note aEventStates should contain only one state. - * - * @param aEventStates The state to check. - * - * @return Whether the object has the state from aEventStates - */ - bool HasState(EventStates aEventStates) const { -#ifdef DEBUG - // If aEventStates.mStates is a power of two, it contains only one state - // (or none, but we don't really care). - if ((aEventStates.mStates & (aEventStates.mStates - 1))) { - NS_ERROR( - "When calling HasState, " - "EventStates object has to contain only one state!"); - } -#endif // DEBUG - return mStates & aEventStates.mStates; - } - - /** - * Returns true if the EventStates instance contains one of the states - * contained in aEventStates. - * - * @param aEventStates The states to check. - * - * @return Whether the object has at least one state from aEventStates - */ - bool HasAtLeastOneOfStates(EventStates aEventStates) const { - return mStates & aEventStates.mStates; - } - - /** - * Returns true if the EventStates instance contains all states - * contained in aEventStates. - * - * @param aEventStates The states to check. - * - * @return Whether the object has all states from aEventStates - */ - bool HasAllStates(EventStates aEventStates) const { - return (mStates & aEventStates.mStates) == aEventStates.mStates; - } - - // We only need that method for InspectorUtils::GetContentState. - // If InspectorUtils::GetContentState is removed, this method should - // be removed. - InternalType GetInternalValue() const { return mStates; } - - /** - * Method used to get the appropriate state representation for Servo. - */ - ServoType ServoValue() const { return mStates; } - - private: - InternalType mStates; -}; - -} // namespace mozilla - -/** - * The following macros are creating EventStates instance with different - * values depending of their meaning. - * Ideally, EventStates instance with values different than 0 should only be - * created that way. - */ - -// Helper to define a new EventStates macro. -#define NS_DEFINE_EVENT_STATE_MACRO(_val) \ - (mozilla::EventStates(mozilla::EventStates::InternalType(1) << _val)) - -/* - * In order to efficiently convert Gecko EventState values into Servo - * ElementState values [1], we maintain the invariant that the low bits of - * EventState can be masked off to form an ElementState (this works so - * long as Servo never supports a state that Gecko doesn't). - * - * This is unfortunately rather fragile for now, but we should soon have - * the infrastructure to statically-assert that these match up. If you - * need to change these, please notify somebody involved with Stylo. - * - * [1] - * https://github.com/servo/servo/blob/master/components/style/element_state.rs - */ - -// Mouse is down on content. -#define NS_EVENT_STATE_ACTIVE NS_DEFINE_EVENT_STATE_MACRO(0) -// Content has focus. -#define NS_EVENT_STATE_FOCUS NS_DEFINE_EVENT_STATE_MACRO(1) -// Mouse is hovering over content. -#define NS_EVENT_STATE_HOVER NS_DEFINE_EVENT_STATE_MACRO(2) -// Content is enabled (and can be disabled). -#define NS_EVENT_STATE_ENABLED NS_DEFINE_EVENT_STATE_MACRO(3) -// Content is disabled. -#define NS_EVENT_STATE_DISABLED NS_DEFINE_EVENT_STATE_MACRO(4) -// Content is checked. -#define NS_EVENT_STATE_CHECKED NS_DEFINE_EVENT_STATE_MACRO(5) -// Content is in the indeterminate state. -#define NS_EVENT_STATE_INDETERMINATE NS_DEFINE_EVENT_STATE_MACRO(6) -// Content shows its placeholder -#define NS_EVENT_STATE_PLACEHOLDERSHOWN NS_DEFINE_EVENT_STATE_MACRO(7) -// Content is URL's target (ref). -#define NS_EVENT_STATE_URLTARGET NS_DEFINE_EVENT_STATE_MACRO(8) -// Content is the full screen element, or a frame containing the -// current fullscreen element. -#define NS_EVENT_STATE_FULLSCREEN NS_DEFINE_EVENT_STATE_MACRO(9) -// Content is valid (and can be invalid). -#define NS_EVENT_STATE_VALID NS_DEFINE_EVENT_STATE_MACRO(10) -// Content is invalid. -#define NS_EVENT_STATE_INVALID NS_DEFINE_EVENT_STATE_MACRO(11) -// UI friendly version of :valid pseudo-class. -#define NS_EVENT_STATE_MOZ_UI_VALID NS_DEFINE_EVENT_STATE_MACRO(12) -// UI friendly version of :invalid pseudo-class. -#define NS_EVENT_STATE_MOZ_UI_INVALID NS_DEFINE_EVENT_STATE_MACRO(13) -// Content could not be rendered (image/object/etc). -#define NS_EVENT_STATE_BROKEN NS_DEFINE_EVENT_STATE_MACRO(14) -// Content is still loading such that there is nothing to show the -// user (eg an image which hasn't started coming in yet). -#define NS_EVENT_STATE_LOADING NS_DEFINE_EVENT_STATE_MACRO(15) -// Content is required. -#define NS_EVENT_STATE_REQUIRED NS_DEFINE_EVENT_STATE_MACRO(16) -// Content is optional (and can be required). -#define NS_EVENT_STATE_OPTIONAL NS_DEFINE_EVENT_STATE_MACRO(17) -// Element is either a defined custom element or uncustomized element. -#define NS_EVENT_STATE_DEFINED NS_DEFINE_EVENT_STATE_MACRO(18) -// Link has been visited. -#define NS_EVENT_STATE_VISITED NS_DEFINE_EVENT_STATE_MACRO(19) -// Link hasn't been visited. -#define NS_EVENT_STATE_UNVISITED NS_DEFINE_EVENT_STATE_MACRO(20) -// Drag is hovering over content. -#define NS_EVENT_STATE_DRAGOVER NS_DEFINE_EVENT_STATE_MACRO(21) -// Content value is in-range (and can be out-of-range). -#define NS_EVENT_STATE_INRANGE NS_DEFINE_EVENT_STATE_MACRO(22) -// Content value is out-of-range. -#define NS_EVENT_STATE_OUTOFRANGE NS_DEFINE_EVENT_STATE_MACRO(23) -// Content is read-only. -// TODO(emilio): This is always the inverse of READWRITE. With some style system -// work we could remove one of the two bits. -#define NS_EVENT_STATE_READONLY NS_DEFINE_EVENT_STATE_MACRO(24) -// Content is editable. -#define NS_EVENT_STATE_READWRITE NS_DEFINE_EVENT_STATE_MACRO(25) -// Content is the default one (meaning depends of the context). -#define NS_EVENT_STATE_DEFAULT NS_DEFINE_EVENT_STATE_MACRO(26) -// Free bit here. -// Content is in the optimum region. -#define NS_EVENT_STATE_OPTIMUM NS_DEFINE_EVENT_STATE_MACRO(28) -// Content is in the suboptimal region. -#define NS_EVENT_STATE_SUB_OPTIMUM NS_DEFINE_EVENT_STATE_MACRO(29) -// Content is in the sub-suboptimal region. -#define NS_EVENT_STATE_SUB_SUB_OPTIMUM NS_DEFINE_EVENT_STATE_MACRO(30) -#define NS_EVENT_STATE_INCREMENT_SCRIPT_LEVEL NS_DEFINE_EVENT_STATE_MACRO(31) -// Content has focus and should show a ring. -#define NS_EVENT_STATE_FOCUSRING NS_DEFINE_EVENT_STATE_MACRO(32) -// Element has focus-within. -#define NS_EVENT_STATE_FOCUS_WITHIN NS_DEFINE_EVENT_STATE_MACRO(33) -// Element is ltr (for :dir pseudo-class) -#define NS_EVENT_STATE_LTR NS_DEFINE_EVENT_STATE_MACRO(34) -// Element is rtl (for :dir pseudo-class) -#define NS_EVENT_STATE_RTL NS_DEFINE_EVENT_STATE_MACRO(35) -// States for tracking the state of the "dir" attribute for HTML elements. We -// use these to avoid having to get "dir" attributes all the time during -// selector matching for some parts of the UA stylesheet. -// -// These states are externally managed, because we also don't want to keep -// getting "dir" attributes in IntrinsicState. -// -// Element is HTML and has a "dir" attibute. This state might go away depending -// on how https://github.com/whatwg/html/issues/2769 gets resolved. The value -// could be anything. -#define NS_EVENT_STATE_HAS_DIR_ATTR NS_DEFINE_EVENT_STATE_MACRO(36) -// Element is HTML, has a "dir" attribute, and the attribute's value is -// case-insensitively equal to "ltr". -#define NS_EVENT_STATE_DIR_ATTR_LTR NS_DEFINE_EVENT_STATE_MACRO(37) -// Element is HTML, has a "dir" attribute, and the attribute's value is -// case-insensitively equal to "rtl". -#define NS_EVENT_STATE_DIR_ATTR_RTL NS_DEFINE_EVENT_STATE_MACRO(38) -// Element is HTML, and is either a element with no valid-valued "dir" -// attribute or any HTML element which has a "dir" attribute whose value is -// "auto". -#define NS_EVENT_STATE_DIR_ATTR_LIKE_AUTO NS_DEFINE_EVENT_STATE_MACRO(39) -// Element is filled by Autofill feature. -#define NS_EVENT_STATE_AUTOFILL NS_DEFINE_EVENT_STATE_MACRO(40) -// Element is filled with preview data by Autofill feature. -#define NS_EVENT_STATE_AUTOFILL_PREVIEW NS_DEFINE_EVENT_STATE_MACRO(41) -// Modal element -#define NS_EVENT_STATE_MODAL_DIALOG NS_DEFINE_EVENT_STATE_MACRO(42) -// Inert subtrees -#define NS_EVENT_STATE_MOZINERT NS_DEFINE_EVENT_STATE_MACRO(43) -// Topmost modal element in top layer -#define NS_EVENT_STATE_TOPMOST_MODAL NS_DEFINE_EVENT_STATE_MACRO(44) -// Devtools highlighter (but it's used for something else atm). -#define NS_EVENT_STATE_DEVTOOLS_HIGHLIGHTED NS_DEFINE_EVENT_STATE_MACRO(45) -// Devtools style inspector stuff. -#define NS_EVENT_STATE_STYLEEDITOR_TRANSITIONING NS_DEFINE_EVENT_STATE_MACRO(46) -// Element is an input with empty value (regardless of placeholder) -#define NS_EVENT_STATE_VALUE_EMPTY NS_DEFINE_EVENT_STATE_MACRO(47) -// Element is a password input which is revealed by the user. -#define NS_EVENT_STATE_REVEALED NS_DEFINE_EVENT_STATE_MACRO(48) -/** - * NOTE: do not go over 63 without updating EventStates::InternalType! - */ - -#define DIRECTION_STATES (NS_EVENT_STATE_LTR | NS_EVENT_STATE_RTL) - -#define DIR_ATTR_STATES \ - (NS_EVENT_STATE_HAS_DIR_ATTR | NS_EVENT_STATE_DIR_ATTR_LTR | \ - NS_EVENT_STATE_DIR_ATTR_RTL | NS_EVENT_STATE_DIR_ATTR_LIKE_AUTO) - -#define DISABLED_STATES (NS_EVENT_STATE_DISABLED | NS_EVENT_STATE_ENABLED) - -#define REQUIRED_STATES (NS_EVENT_STATE_REQUIRED | NS_EVENT_STATE_OPTIONAL) - -// Event states that can be added and removed through -// Element::{Add,Remove}ManuallyManagedStates. -// -// Take care when manually managing state bits. You are responsible for -// setting or clearing the bit when an Element is added or removed from a -// document (e.g. in BindToTree and UnbindFromTree), if that is an -// appropriate thing to do for your state bit. -#define MANUALLY_MANAGED_STATES \ - (NS_EVENT_STATE_AUTOFILL | NS_EVENT_STATE_AUTOFILL_PREVIEW) - -// Event states that are managed externally to an element (by the -// EventStateManager, or by other code). As opposed to those in -// INTRINSIC_STATES, which are are computed by the element itself -// and returned from Element::IntrinsicState. -#define EXTERNALLY_MANAGED_STATES \ - (MANUALLY_MANAGED_STATES | DIR_ATTR_STATES | DISABLED_STATES | \ - REQUIRED_STATES | NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_DEFINED | \ - NS_EVENT_STATE_DRAGOVER | NS_EVENT_STATE_FOCUS | NS_EVENT_STATE_FOCUSRING | \ - NS_EVENT_STATE_FOCUS_WITHIN | NS_EVENT_STATE_FULLSCREEN | \ - NS_EVENT_STATE_HOVER | NS_EVENT_STATE_URLTARGET | \ - NS_EVENT_STATE_MODAL_DIALOG | NS_EVENT_STATE_MOZINERT | \ - NS_EVENT_STATE_TOPMOST_MODAL | NS_EVENT_STATE_REVEALED) - -#define INTRINSIC_STATES (~EXTERNALLY_MANAGED_STATES) - -#endif // mozilla_EventStates_h_ diff --git a/dom/events/IMEStateManager.cpp b/dom/events/IMEStateManager.cpp index a3d70ae2e5d9..d9eafa5fb4e2 100644 --- a/dom/events/IMEStateManager.cpp +++ b/dom/events/IMEStateManager.cpp @@ -12,7 +12,6 @@ #include "mozilla/AutoRestore.h" #include "mozilla/EditorBase.h" #include "mozilla/EventListenerManager.h" -#include "mozilla/EventStates.h" #include "mozilla/EventStateManager.h" #include "mozilla/MouseEvents.h" #include "mozilla/PresShell.h" @@ -1996,7 +1995,7 @@ bool IMEStateManager::IsEditable(nsINode* node) { } // |node| might be readwrite (for example, a text control) if (node->IsElement() && - node->AsElement()->State().HasState(NS_EVENT_STATE_READWRITE)) { + node->AsElement()->State().HasState(ElementState::READWRITE)) { return true; } return false; diff --git a/dom/events/moz.build b/dom/events/moz.build index f8b79ea3b039..995e71859d71 100644 --- a/dom/events/moz.build +++ b/dom/events/moz.build @@ -39,7 +39,6 @@ EXPORTS.mozilla += [ "EventListenerManager.h", "EventNameList.h", "EventStateManager.h", - "EventStates.h", "GlobalKeyListener.h", "IMEContentObserver.h", "IMEStateManager.h", diff --git a/dom/html/HTMLAnchorElement.cpp b/dom/html/HTMLAnchorElement.cpp index 12f7269b4f28..cab653145261 100644 --- a/dom/html/HTMLAnchorElement.cpp +++ b/dom/html/HTMLAnchorElement.cpp @@ -10,7 +10,6 @@ #include "mozilla/dom/HTMLAnchorElementBinding.h" #include "mozilla/dom/HTMLDNSPrefetch.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/MemoryReporting.h" #include "nsCOMPtr.h" #include "nsContentUtils.h" @@ -225,7 +224,7 @@ nsresult HTMLAnchorElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, aNamespaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify); } -EventStates HTMLAnchorElement::IntrinsicState() const { +ElementState HTMLAnchorElement::IntrinsicState() const { return Link::LinkState() | nsGenericHTMLElement::IntrinsicState(); } diff --git a/dom/html/HTMLAnchorElement.h b/dom/html/HTMLAnchorElement.h index f5a0ab20a7e4..cf8a8ce20ccc 100644 --- a/dom/html/HTMLAnchorElement.h +++ b/dom/html/HTMLAnchorElement.h @@ -69,7 +69,7 @@ class HTMLAnchorElement final : public nsGenericHTMLElement, virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; // WebIDL API diff --git a/dom/html/HTMLAreaElement.cpp b/dom/html/HTMLAreaElement.cpp index 398827d36365..f63e5b3fa4dd 100644 --- a/dom/html/HTMLAreaElement.cpp +++ b/dom/html/HTMLAreaElement.cpp @@ -12,7 +12,6 @@ #include "mozilla/dom/HTMLAnchorElement.h" #include "mozilla/dom/HTMLAreaElementBinding.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/MemoryReporting.h" #include "nsWindowSizes.h" @@ -112,7 +111,7 @@ already_AddRefed HTMLAreaElement::GetHrefURI() const { return GetHrefURIForAnchors(); } -EventStates HTMLAreaElement::IntrinsicState() const { +ElementState HTMLAreaElement::IntrinsicState() const { return Link::LinkState() | nsGenericHTMLElement::IntrinsicState(); } diff --git a/dom/html/HTMLAreaElement.h b/dom/html/HTMLAreaElement.h index 05d952a7b92f..14a2d29d6d96 100644 --- a/dom/html/HTMLAreaElement.h +++ b/dom/html/HTMLAreaElement.h @@ -47,7 +47,7 @@ class HTMLAreaElement final : public nsGenericHTMLElement, public Link { virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; // WebIDL void GetAlt(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::alt, aValue); } diff --git a/dom/html/HTMLButtonElement.cpp b/dom/html/HTMLButtonElement.cpp index 728d2d33a640..64a26dbd5fb4 100644 --- a/dom/html/HTMLButtonElement.cpp +++ b/dom/html/HTMLButtonElement.cpp @@ -21,7 +21,6 @@ #include "mozilla/ContentEvents.h" #include "mozilla/EventDispatcher.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/MouseEvents.h" #include "mozilla/PresShell.h" #include "mozilla/TextEvents.h" @@ -60,7 +59,7 @@ HTMLButtonElement::HTMLButtonElement( mInInternalActivate(false), mInhibitStateRestoration(aFromParser & FROM_PARSER_FRAGMENT) { // Set up our default state: enabled - AddStatesSilently(NS_EVENT_STATE_ENABLED); + AddStatesSilently(ElementState::ENABLED); } HTMLButtonElement::~HTMLButtonElement() = default; @@ -394,15 +393,15 @@ bool HTMLButtonElement::RestoreState(PresState* aState) { return false; } -EventStates HTMLButtonElement::IntrinsicState() const { - EventStates state = +ElementState HTMLButtonElement::IntrinsicState() const { + ElementState state = nsGenericHTMLFormControlElementWithState::IntrinsicState(); if (IsCandidateForConstraintValidation()) { if (IsValid()) { - state |= NS_EVENT_STATE_VALID | NS_EVENT_STATE_MOZ_UI_VALID; + state |= ElementState::VALID | ElementState::MOZ_UI_VALID; } else { - state |= NS_EVENT_STATE_INVALID | NS_EVENT_STATE_MOZ_UI_INVALID; + state |= ElementState::INVALID | ElementState::MOZ_UI_INVALID; } } diff --git a/dom/html/HTMLButtonElement.h b/dom/html/HTMLButtonElement.h index b209f1f4d576..e6a8bb9e2be7 100644 --- a/dom/html/HTMLButtonElement.h +++ b/dom/html/HTMLButtonElement.h @@ -66,7 +66,7 @@ class HTMLButtonElement final : public nsGenericHTMLFormControlElementWithState, void UpdateBarredFromConstraintValidation(); // Element - EventStates IntrinsicState() const override; + ElementState IntrinsicState() const override; /** * Called when an attribute is about to be changed */ diff --git a/dom/html/HTMLDialogElement.cpp b/dom/html/HTMLDialogElement.cpp index 84e87f8244b7..558c0c233820 100644 --- a/dom/html/HTMLDialogElement.cpp +++ b/dom/html/HTMLDialogElement.cpp @@ -81,7 +81,7 @@ void HTMLDialogElement::Show() { } bool HTMLDialogElement::IsInTopLayer() const { - return State().HasState(NS_EVENT_STATE_MODAL_DIALOG); + return State().HasState(ElementState::MODAL_DIALOG); } void HTMLDialogElement::AddToTopLayerIfNeeded() { diff --git a/dom/html/HTMLElement.cpp b/dom/html/HTMLElement.cpp index e0c3ce7e84e4..41c6d35dc713 100644 --- a/dom/html/HTMLElement.cpp +++ b/dom/html/HTMLElement.cpp @@ -15,7 +15,7 @@ namespace mozilla::dom { HTMLElement::HTMLElement(already_AddRefed&& aNodeInfo) : nsGenericHTMLFormElement(std::move(aNodeInfo)) { if (NodeInfo()->Equals(nsGkAtoms::bdi)) { - AddStatesSilently(NS_EVENT_STATE_DIR_ATTR_LIKE_AUTO); + AddStatesSilently(ElementState::HAS_DIR_ATTR_LIKE_AUTO); } } @@ -198,14 +198,14 @@ nsresult HTMLElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, aNameSpaceID, aName, aValue, aOldValue, aMaybeScriptedPrincipal, aNotify); } -EventStates HTMLElement::IntrinsicState() const { - EventStates state = nsGenericHTMLFormElement::IntrinsicState(); +ElementState HTMLElement::IntrinsicState() const { + ElementState state = nsGenericHTMLFormElement::IntrinsicState(); if (ElementInternals* internals = GetElementInternals()) { if (internals->IsCandidateForConstraintValidation()) { if (internals->IsValid()) { - state |= NS_EVENT_STATE_VALID | NS_EVENT_STATE_MOZ_UI_VALID; + state |= ElementState::VALID | ElementState::MOZ_UI_VALID; } else { - state |= NS_EVENT_STATE_INVALID | NS_EVENT_STATE_MOZ_UI_INVALID; + state |= ElementState::INVALID | ElementState::MOZ_UI_INVALID; } } } diff --git a/dom/html/HTMLElement.h b/dom/html/HTMLElement.h index 3e7ea851691b..7355d3ab663f 100644 --- a/dom/html/HTMLElement.h +++ b/dom/html/HTMLElement.h @@ -55,7 +55,7 @@ class HTMLElement final : public nsGenericHTMLFormElement { const nsAttrValue* aValue, const nsAttrValue* aOldValue, nsIPrincipal* aMaybeScriptedPrincipal, bool aNotify) override; - EventStates IntrinsicState() const override; + ElementState IntrinsicState() const override; // nsGenericHTMLFormElement void SetFormInternal(HTMLFormElement* aForm, bool aBindToTree) override; diff --git a/dom/html/HTMLEmbedElement.cpp b/dom/html/HTMLEmbedElement.cpp index 267425b638b3..fc29bcd77ecc 100644 --- a/dom/html/HTMLEmbedElement.cpp +++ b/dom/html/HTMLEmbedElement.cpp @@ -4,7 +4,6 @@ * 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/. */ -#include "mozilla/EventStates.h" #include "mozilla/dom/BindContext.h" #include "mozilla/dom/HTMLEmbedElement.h" #include "mozilla/dom/HTMLEmbedElementBinding.h" @@ -33,7 +32,7 @@ HTMLEmbedElement::HTMLEmbedElement( SetIsNetworkCreated(aFromParser == FROM_PARSER_NETWORK); // By default we're in the loading state - AddStatesSilently(NS_EVENT_STATE_LOADING); + AddStatesSilently(ElementState::LOADING); } HTMLEmbedElement::~HTMLEmbedElement() { @@ -234,7 +233,7 @@ void HTMLEmbedElement::StartObjectLoad(bool aNotify, bool aForceLoad) { SetIsNetworkCreated(false); } -EventStates HTMLEmbedElement::IntrinsicState() const { +ElementState HTMLEmbedElement::IntrinsicState() const { return nsGenericHTMLElement::IntrinsicState() | ObjectState(); } diff --git a/dom/html/HTMLEmbedElement.h b/dom/html/HTMLEmbedElement.h index 3687233a9e15..47e13e054aca 100644 --- a/dom/html/HTMLEmbedElement.h +++ b/dom/html/HTMLEmbedElement.h @@ -48,7 +48,7 @@ class HTMLEmbedElement final : public nsGenericHTMLElement, virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override; NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; virtual void DestroyContent() override; // nsObjectLoadingContent diff --git a/dom/html/HTMLFieldSetElement.cpp b/dom/html/HTMLFieldSetElement.cpp index 6dbee32a2bef..a2481284e444 100644 --- a/dom/html/HTMLFieldSetElement.cpp +++ b/dom/html/HTMLFieldSetElement.cpp @@ -6,7 +6,6 @@ #include "mozilla/BasicEvents.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/Maybe.h" #include "mozilla/dom/CustomElementRegistry.h" #include "mozilla/dom/HTMLFieldSetElement.h" @@ -29,7 +28,7 @@ HTMLFieldSetElement::HTMLFieldSetElement( SetBarredFromConstraintValidation(true); // We start out enabled and valid. - AddStatesSilently(NS_EVENT_STATE_ENABLED | NS_EVENT_STATE_VALID); + AddStatesSilently(ElementState::ENABLED | ElementState::VALID); } HTMLFieldSetElement::~HTMLFieldSetElement() { @@ -305,13 +304,13 @@ void HTMLFieldSetElement::UpdateValidity(bool aElementValidity) { } } -EventStates HTMLFieldSetElement::IntrinsicState() const { - EventStates state = nsGenericHTMLFormControlElement::IntrinsicState(); +ElementState HTMLFieldSetElement::IntrinsicState() const { + ElementState state = nsGenericHTMLFormControlElement::IntrinsicState(); if (mInvalidElementsCount) { - state |= NS_EVENT_STATE_INVALID; + state |= ElementState::INVALID; } else { - state |= NS_EVENT_STATE_VALID; + state |= ElementState::VALID; } return state; diff --git a/dom/html/HTMLFieldSetElement.h b/dom/html/HTMLFieldSetElement.h index 179c51371cc0..5983bb6eb991 100644 --- a/dom/html/HTMLFieldSetElement.h +++ b/dom/html/HTMLFieldSetElement.h @@ -87,7 +87,7 @@ class HTMLFieldSetElement final : public nsGenericHTMLFormControlElement, // XPCOM SetCustomValidity is OK for us - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; /* * This method will update the fieldset's validity. This method has to be diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp index 185cfae9998d..ceea6d52bbae 100644 --- a/dom/html/HTMLFormElement.cpp +++ b/dom/html/HTMLFormElement.cpp @@ -15,7 +15,6 @@ #include "mozilla/Components.h" #include "mozilla/ContentEvents.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/PresShell.h" #include "mozilla/UniquePtr.h" #include "mozilla/dom/BindContext.h" @@ -120,7 +119,7 @@ HTMLFormElement::HTMLFormElement( mIsConstructingEntryList(false), mIsFiringSubmissionEvents(false) { // We start out valid. - AddStatesSilently(NS_EVENT_STATE_VALID); + AddStatesSilently(ElementState::VALID); } HTMLFormElement::~HTMLFormElement() { @@ -1916,7 +1915,7 @@ bool HTMLFormElement::CheckValidFormSubmission() { // for the anonymous textnode inside, but not the number control // itself. We can use the focus state, though, because that gets // synced to the number control by the anonymous text control. - mControls->mElements[i]->State().HasState(NS_EVENT_STATE_FOCUS)) { + mControls->mElements[i]->State().HasState(ElementState::FOCUS)) { static_cast(mControls->mElements[i]) ->UpdateValidityUIBits(true); } @@ -2034,13 +2033,13 @@ void HTMLFormElement::SetValueMissingState(const nsAString& aName, RadioGroupManager::SetValueMissingState(aName, aValue); } -EventStates HTMLFormElement::IntrinsicState() const { - EventStates state = nsGenericHTMLElement::IntrinsicState(); +ElementState HTMLFormElement::IntrinsicState() const { + ElementState state = nsGenericHTMLElement::IntrinsicState(); if (mInvalidElementsCount) { - state |= NS_EVENT_STATE_INVALID; + state |= ElementState::INVALID; } else { - state |= NS_EVENT_STATE_VALID; + state |= ElementState::VALID; } return state; diff --git a/dom/html/HTMLFormElement.h b/dom/html/HTMLFormElement.h index 919036e753bf..59cd049c31bb 100644 --- a/dom/html/HTMLFormElement.h +++ b/dom/html/HTMLFormElement.h @@ -76,7 +76,7 @@ class HTMLFormElement final : public nsGenericHTMLElement, virtual void SetValueMissingState(const nsAString& aName, bool aValue) override; - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; // EventTarget virtual void AsyncEventRunning(AsyncEventDispatcher* aEvent) override; diff --git a/dom/html/HTMLImageElement.cpp b/dom/html/HTMLImageElement.cpp index 54434bcd556c..81b62287a649 100644 --- a/dom/html/HTMLImageElement.cpp +++ b/dom/html/HTMLImageElement.cpp @@ -42,7 +42,6 @@ #include "mozilla/CycleCollectedJSContext.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/MappedDeclarations.h" #include "mozilla/Maybe.h" @@ -125,7 +124,7 @@ HTMLImageElement::HTMLImageElement( mInDocResponsiveContent(false), mCurrentDensity(1.0) { // We start out broken - AddStatesSilently(NS_EVENT_STATE_BROKEN); + AddStatesSilently(ElementState::BROKEN); } HTMLImageElement::~HTMLImageElement() { nsImageLoadingContent::Destroy(); } @@ -342,7 +341,7 @@ nsresult HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, bool forceReload = false; if (aName == nsGkAtoms::loading && - !ImageState().HasState(NS_EVENT_STATE_LOADING)) { + !ImageState().HasState(ElementState::LOADING)) { if (aValue && Loading(aValue->GetEnumValue()) == Loading::Lazy) { SetLazyLoading(); } else if (aOldValue && @@ -636,7 +635,7 @@ void HTMLImageElement::MaybeLoadImage(bool aAlwaysForceLoad) { } } -EventStates HTMLImageElement::IntrinsicState() const { +ElementState HTMLImageElement::IntrinsicState() const { return nsGenericHTMLElement::IntrinsicState() | nsImageLoadingContent::ImageState(); } diff --git a/dom/html/HTMLImageElement.h b/dom/html/HTMLImageElement.h index 2ce564b493c2..bf4b6307cb9e 100644 --- a/dom/html/HTMLImageElement.h +++ b/dom/html/HTMLImageElement.h @@ -76,7 +76,7 @@ class HTMLImageElement final : public nsGenericHTMLElement, virtual nsresult BindToTree(BindContext&, nsINode& aParent) override; virtual void UnbindFromTree(bool aNullParent) override; - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; virtual void NodeInfoChanged(Document* aOldDoc) override; diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 9fb48fd6d153..9b8ff042677c 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -71,7 +71,6 @@ #include "mozilla/ContentEvents.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/MappedDeclarations.h" #include "mozilla/InternalMutationEvent.h" #include "mozilla/TextControlState.h" @@ -997,8 +996,8 @@ HTMLInputElement::HTMLInputElement(already_AddRefed&& aNodeInfo, // right now), optional, and valid. We are NOT readwrite by default // until someone calls UpdateEditableState on us, apparently! Also // by default we don't have to show validity UI and so forth. - AddStatesSilently(NS_EVENT_STATE_ENABLED | NS_EVENT_STATE_OPTIONAL | - NS_EVENT_STATE_VALID); + AddStatesSilently(ElementState::ENABLED | ElementState::OPTIONAL_ | + ElementState::VALID); UpdateApzAwareFlag(); } @@ -2201,7 +2200,7 @@ void HTMLInputElement::SetFocusState(bool aIsFocused) { return; } - EventStates focusStates = NS_EVENT_STATE_FOCUS | NS_EVENT_STATE_FOCUSRING; + ElementState focusStates = ElementState::FOCUS | ElementState::FOCUSRING; if (aIsFocused) { AddStates(focusStates); } else { @@ -4471,9 +4470,9 @@ void HTMLInputElement::HandleTypeChange(FormControlType aNewType, bool isRequired = HasAttr(kNameSpaceID_None, nsGkAtoms::required); UpdateRequiredState(isRequired, aNotify); } else if (aNotify) { - RemoveStates(REQUIRED_STATES); + RemoveStates(ElementState::REQUIRED_STATES); } else { - RemoveStatesSilently(REQUIRED_STATES); + RemoveStatesSilently(ElementState::REQUIRED_STATES); } UpdateHasRange(); @@ -5913,22 +5912,22 @@ void HTMLInputElement::DestroyContent() { TextControlElement::DestroyContent(); } -EventStates HTMLInputElement::IntrinsicState() const { +ElementState HTMLInputElement::IntrinsicState() const { // If you add states here, and they're type-dependent, you need to add them // to the type case in AfterSetAttr. - EventStates state = + ElementState state = nsGenericHTMLFormControlElementWithState::IntrinsicState(); if (mType == FormControlType::InputCheckbox || mType == FormControlType::InputRadio) { // Check current checked state (:checked) if (mChecked) { - state |= NS_EVENT_STATE_CHECKED; + state |= ElementState::CHECKED; } // Check current indeterminate state (:indeterminate) if (mType == FormControlType::InputCheckbox && mIndeterminate) { - state |= NS_EVENT_STATE_INDETERMINATE; + state |= ElementState::INDETERMINATE; } if (mType == FormControlType::InputRadio) { @@ -5936,13 +5935,13 @@ EventStates HTMLInputElement::IntrinsicState() const { bool indeterminate = !selected && !mChecked; if (indeterminate) { - state |= NS_EVENT_STATE_INDETERMINATE; + state |= ElementState::INDETERMINATE; } } // Check whether we are the default checked element (:default) if (DefaultChecked()) { - state |= NS_EVENT_STATE_DEFAULT; + state |= ElementState::DEFAULT; } } else if (mType == FormControlType::InputImage) { state |= nsImageLoadingContent::ImageState(); @@ -5950,13 +5949,13 @@ EventStates HTMLInputElement::IntrinsicState() const { if (IsCandidateForConstraintValidation()) { if (IsValid()) { - state |= NS_EVENT_STATE_VALID; + state |= ElementState::VALID; } else { - state |= NS_EVENT_STATE_INVALID; + state |= ElementState::INVALID; if (GetValidityState(VALIDITY_STATE_CUSTOM_ERROR) || (mCanShowInvalidUI && ShouldShowValidityUI())) { - state |= NS_EVENT_STATE_MOZ_UI_INVALID; + state |= ElementState::MOZ_UI_INVALID; } } @@ -5968,9 +5967,9 @@ EventStates HTMLInputElement::IntrinsicState() const { // 3. The element has already been modified or the user tried to submit the // form owner while invalid. if (mCanShowValidUI && ShouldShowValidityUI() && - (IsValid() || (!state.HasState(NS_EVENT_STATE_MOZ_UI_INVALID) && + (IsValid() || (!state.HasState(ElementState::MOZ_UI_INVALID) && !mCanShowInvalidUI))) { - state |= NS_EVENT_STATE_MOZ_UI_VALID; + state |= ElementState::MOZ_UI_VALID; } // :in-range and :out-of-range only apply if the element currently has a @@ -5978,15 +5977,15 @@ EventStates HTMLInputElement::IntrinsicState() const { if (mHasRange) { state |= (GetValidityState(VALIDITY_STATE_RANGE_OVERFLOW) || GetValidityState(VALIDITY_STATE_RANGE_UNDERFLOW)) - ? NS_EVENT_STATE_OUTOFRANGE - : NS_EVENT_STATE_INRANGE; + ? ElementState::OUTOFRANGE + : ElementState::INRANGE; } } if (mType != FormControlType::InputFile && IsValueEmpty()) { - state |= NS_EVENT_STATE_VALUE_EMPTY; + state |= ElementState::VALUE_EMPTY; if (PlaceholderApplies() && HasAttr(nsGkAtoms::placeholder)) { - state |= NS_EVENT_STATE_PLACEHOLDERSHOWN; + state |= ElementState::PLACEHOLDER_SHOWN; } } @@ -6720,9 +6719,9 @@ void HTMLInputElement::SetRevealPassword(bool aValue) { return; } if (aValue) { - AddStates(NS_EVENT_STATE_REVEALED); + AddStates(ElementState::REVEALED); } else { - RemoveStates(NS_EVENT_STATE_REVEALED); + RemoveStates(ElementState::REVEALED); } } @@ -6730,7 +6729,7 @@ bool HTMLInputElement::RevealPassword() const { if (NS_WARN_IF(mType != FormControlType::InputPassword)) { return false; } - return State().HasState(NS_EVENT_STATE_REVEALED); + return State().HasState(ElementState::REVEALED); } void HTMLInputElement::FieldSetDisabledChanged(bool aNotify) { diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h index 7084495e814b..72aca2805a1f 100644 --- a/dom/html/HTMLInputElement.h +++ b/dom/html/HTMLInputElement.h @@ -201,7 +201,7 @@ class HTMLInputElement final : public TextControlElement, void DestroyContent() override; - EventStates IntrinsicState() const override; + ElementState IntrinsicState() const override; void SetLastValueChangeWasInteractive(bool); @@ -835,7 +835,7 @@ class HTMLInputElement final : public TextControlElement, * that @required attribute applies and the attribute is set; in contrast, * Required() returns true whenever @required attribute is set. */ - bool IsRequired() const { return State().HasState(NS_EVENT_STATE_REQUIRED); } + bool IsRequired() const { return State().HasState(ElementState::REQUIRED); } bool HasBeenTypePassword() const { return mHasBeenTypePassword; } diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp index 47e1634e800c..a5a4b49247cd 100644 --- a/dom/html/HTMLLinkElement.cpp +++ b/dom/html/HTMLLinkElement.cpp @@ -10,7 +10,6 @@ #include "mozilla/Attributes.h" #include "mozilla/Components.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/MemoryReporting.h" #include "mozilla/Preferences.h" #include "mozilla/StaticPrefs_dom.h" diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 2c794fb87a0a..2a76dfca6026 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -7667,7 +7667,7 @@ void HTMLMediaElement::NotifyMediaControlPlaybackStateChanged() { } bool HTMLMediaElement::IsInFullScreen() const { - return State().HasState(NS_EVENT_STATE_FULLSCREEN); + return State().HasState(ElementState::FULLSCREEN); } bool HTMLMediaElement::IsPlayable() const { diff --git a/dom/html/HTMLMeterElement.cpp b/dom/html/HTMLMeterElement.cpp index 546c6a9c9ad7..f0b0c3d040f5 100644 --- a/dom/html/HTMLMeterElement.cpp +++ b/dom/html/HTMLMeterElement.cpp @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "HTMLMeterElement.h" -#include "mozilla/EventStates.h" #include "mozilla/dom/HTMLMeterElementBinding.h" NS_IMPL_NS_NEW_HTML_ELEMENT(Meter) @@ -24,8 +23,8 @@ HTMLMeterElement::~HTMLMeterElement() = default; NS_IMPL_ELEMENT_CLONE(HTMLMeterElement) -EventStates HTMLMeterElement::IntrinsicState() const { - EventStates state = nsGenericHTMLElement::IntrinsicState(); +ElementState HTMLMeterElement::IntrinsicState() const { + ElementState state = nsGenericHTMLElement::IntrinsicState(); state |= GetOptimumState(); @@ -202,7 +201,7 @@ double HTMLMeterElement::Optimum() const { return std::min(optimum, max); } -EventStates HTMLMeterElement::GetOptimumState() const { +ElementState HTMLMeterElement::GetOptimumState() const { /* * If the optimum value is in [minimum, low[, * return if the value is in optimal, suboptimal or sub-suboptimal region @@ -220,27 +219,27 @@ EventStates HTMLMeterElement::GetOptimumState() const { if (optimum < low) { if (value < low) { - return NS_EVENT_STATE_OPTIMUM; + return ElementState::OPTIMUM; } if (value <= high) { - return NS_EVENT_STATE_SUB_OPTIMUM; + return ElementState::SUB_OPTIMUM; } - return NS_EVENT_STATE_SUB_SUB_OPTIMUM; + return ElementState::SUB_SUB_OPTIMUM; } if (optimum > high) { if (value > high) { - return NS_EVENT_STATE_OPTIMUM; + return ElementState::OPTIMUM; } if (value >= low) { - return NS_EVENT_STATE_SUB_OPTIMUM; + return ElementState::SUB_OPTIMUM; } - return NS_EVENT_STATE_SUB_SUB_OPTIMUM; + return ElementState::SUB_SUB_OPTIMUM; } // optimum in [low, high] if (value >= low && value <= high) { - return NS_EVENT_STATE_OPTIMUM; + return ElementState::OPTIMUM; } - return NS_EVENT_STATE_SUB_OPTIMUM; + return ElementState::SUB_OPTIMUM; } JSObject* HTMLMeterElement::WrapNode(JSContext* aCx, diff --git a/dom/html/HTMLMeterElement.h b/dom/html/HTMLMeterElement.h index 43b70f2eafb4..f4057639b256 100644 --- a/dom/html/HTMLMeterElement.h +++ b/dom/html/HTMLMeterElement.h @@ -21,7 +21,7 @@ class HTMLMeterElement final : public nsGenericHTMLElement { explicit HTMLMeterElement( already_AddRefed&& aNodeInfo); - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; @@ -86,15 +86,15 @@ class HTMLMeterElement final : public nsGenericHTMLElement { /** * Returns the optimum state of the element. - * NS_EVENT_STATE_OPTIMUM if the actual value is in the optimum region. - * NS_EVENT_STATE_SUB_OPTIMUM if the actual value is in the sub-optimal + * ElementState::OPTIMUM if the actual value is in the optimum region. + * ElementState::SUB_OPTIMUM if the actual value is in the sub-optimal * region. - * NS_EVENT_STATE_SUB_SUB_OPTIMUM if the actual value is in the + * ElementState::SUB_SUB_OPTIMUM if the actual value is in the * sub-sub-optimal region. * * @return the optimum state of the element. */ - EventStates GetOptimumState() const; + ElementState GetOptimumState() const; }; } // namespace mozilla::dom diff --git a/dom/html/HTMLObjectElement.cpp b/dom/html/HTMLObjectElement.cpp index fd5259189d13..6d48cc0dba4f 100644 --- a/dom/html/HTMLObjectElement.cpp +++ b/dom/html/HTMLObjectElement.cpp @@ -4,7 +4,6 @@ * 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/. */ -#include "mozilla/EventStates.h" #include "mozilla/dom/BindContext.h" #include "mozilla/dom/Document.h" #include "mozilla/dom/HTMLObjectElement.h" @@ -38,7 +37,7 @@ HTMLObjectElement::HTMLObjectElement( SetBarredFromConstraintValidation(true); // By default we're in the loading state - AddStatesSilently(NS_EVENT_STATE_LOADING); + AddStatesSilently(ElementState::LOADING); } HTMLObjectElement::~HTMLObjectElement() { @@ -284,7 +283,7 @@ void HTMLObjectElement::StartObjectLoad(bool aNotify, bool aForce) { SetIsNetworkCreated(false); } -EventStates HTMLObjectElement::IntrinsicState() const { +ElementState HTMLObjectElement::IntrinsicState() const { return nsGenericHTMLFormControlElement::IntrinsicState() | ObjectState(); } diff --git a/dom/html/HTMLObjectElement.h b/dom/html/HTMLObjectElement.h index ff71414bce74..969d2be38b61 100644 --- a/dom/html/HTMLObjectElement.h +++ b/dom/html/HTMLObjectElement.h @@ -60,7 +60,7 @@ class HTMLObjectElement final : public nsGenericHTMLFormControlElement, virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override; NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; virtual void DestroyContent() override; // nsObjectLoadingContent diff --git a/dom/html/HTMLOptGroupElement.cpp b/dom/html/HTMLOptGroupElement.cpp index f0fd466a3ebb..62f60895b1bc 100644 --- a/dom/html/HTMLOptGroupElement.cpp +++ b/dom/html/HTMLOptGroupElement.cpp @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/Maybe.h" #include "mozilla/dom/HTMLOptGroupElement.h" #include "mozilla/dom/HTMLOptGroupElementBinding.h" @@ -27,7 +26,7 @@ HTMLOptGroupElement::HTMLOptGroupElement( already_AddRefed&& aNodeInfo) : nsGenericHTMLElement(std::move(aNodeInfo)) { // We start off enabled - AddStatesSilently(NS_EVENT_STATE_ENABLED); + AddStatesSilently(ElementState::ENABLED); } HTMLOptGroupElement::~HTMLOptGroupElement() = default; @@ -80,15 +79,15 @@ nsresult HTMLOptGroupElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, nsIPrincipal* aSubjectPrincipal, bool aNotify) { if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::disabled) { - EventStates disabledStates; + ElementState disabledStates; if (aValue) { - disabledStates |= NS_EVENT_STATE_DISABLED; + disabledStates |= ElementState::DISABLED; } else { - disabledStates |= NS_EVENT_STATE_ENABLED; + disabledStates |= ElementState::ENABLED; } - EventStates oldDisabledStates = State() & DISABLED_STATES; - EventStates changedStates = disabledStates ^ oldDisabledStates; + ElementState oldDisabledStates = State() & ElementState::DISABLED_STATES; + ElementState changedStates = disabledStates ^ oldDisabledStates; if (!changedStates.IsEmpty()) { ToggleStates(changedStates, aNotify); diff --git a/dom/html/HTMLOptionElement.cpp b/dom/html/HTMLOptionElement.cpp index 2a86faa43116..47dc480b7f62 100644 --- a/dom/html/HTMLOptionElement.cpp +++ b/dom/html/HTMLOptionElement.cpp @@ -19,7 +19,6 @@ #include "mozilla/dom/Document.h" #include "nsNodeInfoManager.h" #include "nsCOMPtr.h" -#include "mozilla/EventStates.h" #include "nsContentCreatorFunctions.h" #include "mozAutoDocUpdate.h" #include "nsTextNode.h" @@ -39,7 +38,7 @@ HTMLOptionElement::HTMLOptionElement( mIsSelected(false), mIsInSetDefaultSelected(false) { // We start off enabled - AddStatesSilently(NS_EVENT_STATE_ENABLED); + AddStatesSilently(ElementState::ENABLED); } HTMLOptionElement::~HTMLOptionElement() = default; @@ -76,15 +75,15 @@ void HTMLOptionElement::UpdateDisabledState(bool aNotify) { } } - EventStates disabledStates; + ElementState disabledStates; if (isDisabled) { - disabledStates |= NS_EVENT_STATE_DISABLED; + disabledStates |= ElementState::DISABLED; } else { - disabledStates |= NS_EVENT_STATE_ENABLED; + disabledStates |= ElementState::ENABLED; } - EventStates oldDisabledStates = State() & DISABLED_STATES; - EventStates changedStates = disabledStates ^ oldDisabledStates; + ElementState oldDisabledStates = State() & ElementState::DISABLED_STATES; + ElementState changedStates = disabledStates ^ oldDisabledStates; if (!changedStates.IsEmpty()) { ToggleStates(changedStates, aNotify); @@ -263,13 +262,13 @@ void HTMLOptionElement::UnbindFromTree(bool aNullParent) { UpdateDisabledState(false); } -EventStates HTMLOptionElement::IntrinsicState() const { - EventStates state = nsGenericHTMLElement::IntrinsicState(); +ElementState HTMLOptionElement::IntrinsicState() const { + ElementState state = nsGenericHTMLElement::IntrinsicState(); if (Selected()) { - state |= NS_EVENT_STATE_CHECKED; + state |= ElementState::CHECKED; } if (DefaultSelected()) { - state |= NS_EVENT_STATE_DEFAULT; + state |= ElementState::DEFAULT; } return state; diff --git a/dom/html/HTMLOptionElement.h b/dom/html/HTMLOptionElement.h index 3428694c3c0d..537326080c68 100644 --- a/dom/html/HTMLOptionElement.h +++ b/dom/html/HTMLOptionElement.h @@ -68,7 +68,7 @@ class HTMLOptionElement final : public nsGenericHTMLElement { virtual void UnbindFromTree(bool aNullParent = true) override; // nsIContent - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; diff --git a/dom/html/HTMLOutputElement.cpp b/dom/html/HTMLOutputElement.cpp index 8322a84ab0c5..2a1a3bac6ca3 100644 --- a/dom/html/HTMLOutputElement.cpp +++ b/dom/html/HTMLOutputElement.cpp @@ -7,7 +7,6 @@ #include "mozilla/dom/HTMLOutputElement.h" #include "mozAutoDocUpdate.h" -#include "mozilla/EventStates.h" #include "mozilla/dom/HTMLFormElement.h" #include "mozilla/dom/HTMLOutputElementBinding.h" #include "nsContentUtils.h" diff --git a/dom/html/HTMLProgressElement.cpp b/dom/html/HTMLProgressElement.cpp index ea8a94bdd90c..eb15d139e0ec 100644 --- a/dom/html/HTMLProgressElement.cpp +++ b/dom/html/HTMLProgressElement.cpp @@ -4,7 +4,6 @@ * 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/. */ -#include "mozilla/EventStates.h" #include "mozilla/dom/HTMLProgressElement.h" #include "mozilla/dom/HTMLProgressElementBinding.h" @@ -20,19 +19,19 @@ HTMLProgressElement::HTMLProgressElement( already_AddRefed&& aNodeInfo) : nsGenericHTMLElement(std::move(aNodeInfo)) { // We start out indeterminate - AddStatesSilently(NS_EVENT_STATE_INDETERMINATE); + AddStatesSilently(ElementState::INDETERMINATE); } HTMLProgressElement::~HTMLProgressElement() = default; NS_IMPL_ELEMENT_CLONE(HTMLProgressElement) -EventStates HTMLProgressElement::IntrinsicState() const { - EventStates state = nsGenericHTMLElement::IntrinsicState(); +ElementState HTMLProgressElement::IntrinsicState() const { + ElementState state = nsGenericHTMLElement::IntrinsicState(); const nsAttrValue* attrValue = mAttrs.GetAttr(nsGkAtoms::value); if (!attrValue || attrValue->Type() != nsAttrValue::eDoubleValue) { - state |= NS_EVENT_STATE_INDETERMINATE; + state |= ElementState::INDETERMINATE; } return state; @@ -74,7 +73,7 @@ double HTMLProgressElement::Max() const { } double HTMLProgressElement::Position() const { - if (State().HasState(NS_EVENT_STATE_INDETERMINATE)) { + if (State().HasState(ElementState::INDETERMINATE)) { return kIndeterminatePosition; } diff --git a/dom/html/HTMLProgressElement.h b/dom/html/HTMLProgressElement.h index d42a874f7cce..94793b4bd5a4 100644 --- a/dom/html/HTMLProgressElement.h +++ b/dom/html/HTMLProgressElement.h @@ -20,7 +20,7 @@ class HTMLProgressElement final : public nsGenericHTMLElement { explicit HTMLProgressElement( already_AddRefed&& aNodeInfo); - EventStates IntrinsicState() const override; + ElementState IntrinsicState() const override; nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; diff --git a/dom/html/HTMLSelectElement.cpp b/dom/html/HTMLSelectElement.cpp index 7797563851b6..51124de91b98 100644 --- a/dom/html/HTMLSelectElement.cpp +++ b/dom/html/HTMLSelectElement.cpp @@ -10,7 +10,6 @@ #include "mozilla/Attributes.h" #include "mozilla/BasicEvents.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/FormData.h" #include "mozilla/dom/HTMLOptGroupElement.h" @@ -132,8 +131,8 @@ HTMLSelectElement::HTMLSelectElement( // otherwise it is // Set up our default state: enabled, optional, and valid. - AddStatesSilently(NS_EVENT_STATE_ENABLED | NS_EVENT_STATE_OPTIONAL | - NS_EVENT_STATE_VALID); + AddStatesSilently(ElementState::ENABLED | ElementState::OPTIONAL_ | + ElementState::VALID); } // ISupports @@ -1208,8 +1207,8 @@ nsresult HTMLSelectElement::PostHandleEvent(EventChainPostVisitor& aVisitor) { // UI while focused. mCanShowValidUI = ShouldShowValidityUI(); - // We don't have to update NS_EVENT_STATE_MOZ_UI_INVALID nor - // NS_EVENT_STATE_MOZ_UI_VALID given that the states should not change. + // We don't have to update ElementState::MOZ_UI_INVALID nor + // ElementState::MOZ_UI_VALID given that the states should not change. } else if (aVisitor.mEvent->mMessage == eBlur) { mCanShowInvalidUI = true; mCanShowValidUI = true; @@ -1220,19 +1219,19 @@ nsresult HTMLSelectElement::PostHandleEvent(EventChainPostVisitor& aVisitor) { return nsGenericHTMLFormControlElementWithState::PostHandleEvent(aVisitor); } -EventStates HTMLSelectElement::IntrinsicState() const { - EventStates state = +ElementState HTMLSelectElement::IntrinsicState() const { + ElementState state = nsGenericHTMLFormControlElementWithState::IntrinsicState(); if (IsCandidateForConstraintValidation()) { if (IsValid()) { - state |= NS_EVENT_STATE_VALID; + state |= ElementState::VALID; } else { - state |= NS_EVENT_STATE_INVALID; + state |= ElementState::INVALID; if (GetValidityState(VALIDITY_STATE_CUSTOM_ERROR) || (mCanShowInvalidUI && ShouldShowValidityUI())) { - state |= NS_EVENT_STATE_MOZ_UI_INVALID; + state |= ElementState::MOZ_UI_INVALID; } } @@ -1244,9 +1243,9 @@ EventStates HTMLSelectElement::IntrinsicState() const { // 3. The element has already been modified or the user tried to submit the // form owner while invalid. if (mCanShowValidUI && ShouldShowValidityUI() && - (IsValid() || (state.HasState(NS_EVENT_STATE_MOZ_UI_INVALID) && + (IsValid() || (state.HasState(ElementState::MOZ_UI_INVALID) && !mCanShowInvalidUI))) { - state |= NS_EVENT_STATE_MOZ_UI_VALID; + state |= ElementState::MOZ_UI_VALID; } } diff --git a/dom/html/HTMLSelectElement.h b/dom/html/HTMLSelectElement.h index ee57017c41b0..556cb468ee71 100644 --- a/dom/html/HTMLSelectElement.h +++ b/dom/html/HTMLSelectElement.h @@ -139,7 +139,7 @@ class HTMLSelectElement final : public nsGenericHTMLFormControlElementWithState, void SetName(const nsAString& aName, ErrorResult& aRv) { SetHTMLAttr(nsGkAtoms::name, aName, aRv); } - bool Required() const { return State().HasState(NS_EVENT_STATE_REQUIRED); } + bool Required() const { return State().HasState(ElementState::REQUIRED); } void SetRequired(bool aVal, ErrorResult& aRv) { SetHTMLBoolAttr(nsGkAtoms::required, aVal, aRv); } @@ -213,7 +213,7 @@ class HTMLSelectElement final : public nsGenericHTMLFormControlElementWithState, virtual void FieldSetDisabledChanged(bool aNotify) override; - EventStates IntrinsicState() const override; + ElementState IntrinsicState() const override; /** * To be called when stuff is added under a child of the select--but *before* diff --git a/dom/html/HTMLTextAreaElement.cpp b/dom/html/HTMLTextAreaElement.cpp index 54260155ba07..8ca0e2ac0785 100644 --- a/dom/html/HTMLTextAreaElement.cpp +++ b/dom/html/HTMLTextAreaElement.cpp @@ -13,7 +13,6 @@ #include "mozilla/dom/HTMLTextAreaElementBinding.h" #include "mozilla/dom/MutationEventBinding.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/MappedDeclarations.h" #include "mozilla/MouseEvents.h" #include "mozilla/PresState.h" @@ -68,8 +67,8 @@ HTMLTextAreaElement::HTMLTextAreaElement( // right now), optional, and valid. We are NOT readwrite by default // until someone calls UpdateEditableState on us, apparently! Also // by default we don't have to show validity UI and so forth. - AddStatesSilently(NS_EVENT_STATE_ENABLED | NS_EVENT_STATE_OPTIONAL | - NS_EVENT_STATE_VALID); + AddStatesSilently(ElementState::ENABLED | ElementState::OPTIONAL_ | + ElementState::VALID); } HTMLTextAreaElement::~HTMLTextAreaElement() { @@ -749,20 +748,20 @@ bool HTMLTextAreaElement::RestoreState(PresState* aState) { return false; } -EventStates HTMLTextAreaElement::IntrinsicState() const { - EventStates state = +ElementState HTMLTextAreaElement::IntrinsicState() const { + ElementState state = nsGenericHTMLFormControlElementWithState::IntrinsicState(); if (IsCandidateForConstraintValidation()) { if (IsValid()) { - state |= NS_EVENT_STATE_VALID; + state |= ElementState::VALID; } else { - state |= NS_EVENT_STATE_INVALID; + state |= ElementState::INVALID; // :-moz-ui-invalid always apply if the element suffers from a custom // error. if (GetValidityState(VALIDITY_STATE_CUSTOM_ERROR) || (mCanShowInvalidUI && ShouldShowValidityUI())) { - state |= NS_EVENT_STATE_MOZ_UI_INVALID; + state |= ElementState::MOZ_UI_INVALID; } } @@ -774,14 +773,14 @@ EventStates HTMLTextAreaElement::IntrinsicState() const { // 3. The element has already been modified or the user tried to submit the // form owner while invalid. if (mCanShowValidUI && ShouldShowValidityUI() && - (IsValid() || (state.HasState(NS_EVENT_STATE_MOZ_UI_INVALID) && + (IsValid() || (state.HasState(ElementState::MOZ_UI_INVALID) && !mCanShowInvalidUI))) { - state |= NS_EVENT_STATE_MOZ_UI_VALID; + state |= ElementState::MOZ_UI_VALID; } } if (HasAttr(nsGkAtoms::placeholder) && IsValueEmpty()) { - state |= NS_EVENT_STATE_PLACEHOLDERSHOWN; + state |= ElementState::PLACEHOLDER_SHOWN; } return state; diff --git a/dom/html/HTMLTextAreaElement.h b/dom/html/HTMLTextAreaElement.h index 4f322c4e333b..450d90fa5cae 100644 --- a/dom/html/HTMLTextAreaElement.h +++ b/dom/html/HTMLTextAreaElement.h @@ -27,7 +27,6 @@ namespace mozilla { class EventChainPostVisitor; class EventChainPreVisitor; -class EventStates; class PresState; namespace dom { @@ -70,7 +69,7 @@ class HTMLTextAreaElement final : public TextControlElement, virtual void FieldSetDisabledChanged(bool aNotify) override; - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; void SetLastValueChangeWasInteractive(bool); @@ -218,7 +217,7 @@ class HTMLTextAreaElement final : public TextControlElement, void SetReadOnly(bool aReadOnly, ErrorResult& aError) { SetHTMLBoolAttr(nsGkAtoms::readonly, aReadOnly, aError); } - bool Required() const { return State().HasState(NS_EVENT_STATE_REQUIRED); } + bool Required() const { return State().HasState(ElementState::REQUIRED); } MOZ_CAN_RUN_SCRIPT void SetRangeText(const nsAString& aReplacement, ErrorResult& aRv); diff --git a/dom/html/HTMLUnknownElement.h b/dom/html/HTMLUnknownElement.h index 0cb5aef2cee6..3bed35a4f6f1 100644 --- a/dom/html/HTMLUnknownElement.h +++ b/dom/html/HTMLUnknownElement.h @@ -7,7 +7,6 @@ #define mozilla_dom_HTMLUnknownElement_h #include "mozilla/Attributes.h" -#include "mozilla/EventStates.h" #include "nsGenericHTMLElement.h" namespace mozilla::dom { diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 50e879924b7d..826730b6a9b3 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -10,7 +10,6 @@ #include "mozilla/EventDispatcher.h" #include "mozilla/EventListenerManager.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/HTMLEditor.h" #include "mozilla/IMEContentObserver.h" #include "mozilla/IMEStateManager.h" @@ -422,17 +421,17 @@ void nsGenericHTMLElement::UpdateEditableState(bool aNotify) { nsStyledElement::UpdateEditableState(aNotify); } -EventStates nsGenericHTMLElement::IntrinsicState() const { - EventStates state = nsGenericHTMLElementBase::IntrinsicState(); +ElementState nsGenericHTMLElement::IntrinsicState() const { + ElementState state = nsGenericHTMLElementBase::IntrinsicState(); if (GetDirectionality() == eDir_RTL) { - state |= NS_EVENT_STATE_RTL; - state &= ~NS_EVENT_STATE_LTR; + state |= ElementState::RTL; + state &= ~ElementState::LTR; } else { // at least for HTML, directionality is exclusively LTR or RTL NS_ASSERTION(GetDirectionality() == eDir_LTR, "HTML element's directionality must be either RTL or LTR"); - state |= NS_EVENT_STATE_LTR; - state &= ~NS_EVENT_STATE_RTL; + state |= ElementState::LTR; + state &= ~ElementState::RTL; } return state; @@ -661,38 +660,38 @@ nsresult nsGenericHTMLElement::AfterSetAttr( // We don't want to have to keep getting the "dir" attribute in // IntrinsicState, so we manually recompute our dir-related event states // here and send the relevant update notifications. - EventStates dirStates; + ElementState dirStates; if (aValue && aValue->Type() == nsAttrValue::eEnum) { SetHasValidDir(); - dirStates |= NS_EVENT_STATE_HAS_DIR_ATTR; + dirStates |= ElementState::HAS_DIR_ATTR; Directionality dirValue = (Directionality)aValue->GetEnumValue(); if (dirValue == eDir_Auto) { - dirStates |= NS_EVENT_STATE_DIR_ATTR_LIKE_AUTO; + dirStates |= ElementState::HAS_DIR_ATTR_LIKE_AUTO; } else { dir = dirValue; SetDirectionality(dir, aNotify); if (dirValue == eDir_LTR) { - dirStates |= NS_EVENT_STATE_DIR_ATTR_LTR; + dirStates |= ElementState::HAS_DIR_ATTR_LTR; } else { MOZ_ASSERT(dirValue == eDir_RTL); - dirStates |= NS_EVENT_STATE_DIR_ATTR_RTL; + dirStates |= ElementState::HAS_DIR_ATTR_RTL; } } } else { if (aValue) { // We have a value, just not a valid one. - dirStates |= NS_EVENT_STATE_HAS_DIR_ATTR; + dirStates |= ElementState::HAS_DIR_ATTR; } ClearHasValidDir(); if (NodeInfo()->Equals(nsGkAtoms::bdi)) { - dirStates |= NS_EVENT_STATE_DIR_ATTR_LIKE_AUTO; + dirStates |= ElementState::HAS_DIR_ATTR_LIKE_AUTO; } else { recomputeDirectionality = true; } } // Now figure out what's changed about our dir states. - EventStates oldDirStates = State() & DIR_ATTR_STATES; - EventStates changedStates = dirStates ^ oldDirStates; + ElementState oldDirStates = State() & ElementState::DIR_ATTR_STATES; + ElementState changedStates = dirStates ^ oldDirStates; ToggleStates(changedStates, aNotify); if (recomputeDirectionality) { dir = RecomputeDirectionality(this, aNotify); @@ -717,9 +716,9 @@ nsresult nsGenericHTMLElement::AfterSetAttr( } else if (aName == nsGkAtoms::inert && StaticPrefs::html5_inert_enabled()) { if (aValue) { - AddStates(NS_EVENT_STATE_MOZINERT); + AddStates(ElementState::INERT); } else { - RemoveStates(NS_EVENT_STATE_MOZINERT); + RemoveStates(ElementState::INERT); } } else if (aName == nsGkAtoms::name) { if (aValue && !aValue->Equals(u""_ns, eIgnoreCase)) { @@ -1658,7 +1657,7 @@ bool nsGenericHTMLElement::IsFormControlDefaultFocusable( nsGenericHTMLFormElement::nsGenericHTMLFormElement( already_AddRefed&& aNodeInfo) : nsGenericHTMLElement(std::move(aNodeInfo)) { - // We should add the NS_EVENT_STATE_ENABLED bit here as needed, but + // We should add the ElementState::ENABLED bit here as needed, but // that depends on our type, which is not initialized yet. So we // have to do this in subclasses. } @@ -2087,11 +2086,11 @@ void nsGenericHTMLFormElement::UpdateDisabledState(bool aNotify) { const bool isDisabled = HasAttr(nsGkAtoms::disabled) || (fieldset && fieldset->IsDisabled()); - const EventStates disabledStates = - isDisabled ? NS_EVENT_STATE_DISABLED : NS_EVENT_STATE_ENABLED; + const ElementState disabledStates = + isDisabled ? ElementState::DISABLED : ElementState::ENABLED; - EventStates oldDisabledStates = State() & DISABLED_STATES; - EventStates changedStates = disabledStates ^ oldDisabledStates; + ElementState oldDisabledStates = State() & ElementState::DISABLED_STATES; + ElementState changedStates = disabledStates ^ oldDisabledStates; if (!changedStates.IsEmpty()) { ToggleStates(changedStates, aNotify); @@ -2538,24 +2537,24 @@ void nsGenericHTMLFormControlElement::ClearForm(bool aRemoveFromForm, nsGenericHTMLFormElement::ClearForm(aRemoveFromForm, aUnbindOrDelete); } -EventStates nsGenericHTMLFormControlElement::IntrinsicState() const { +ElementState nsGenericHTMLFormControlElement::IntrinsicState() const { // If you add attribute-dependent states here, you need to add them them to // AfterSetAttr too. And add them to AfterSetAttr for all subclasses that // implement IntrinsicState() and are affected by that attribute. - EventStates state = nsGenericHTMLFormElement::IntrinsicState(); + ElementState state = nsGenericHTMLFormElement::IntrinsicState(); if (mForm && mForm->IsDefaultSubmitElement(this)) { NS_ASSERTION(IsSubmitControl(), "Default submit element that isn't a submit control."); // We are the default submit element (:default) - state |= NS_EVENT_STATE_DEFAULT; + state |= ElementState::DEFAULT; } // Make the text controls read-write - if (!state.HasState(NS_EVENT_STATE_READWRITE) && DoesReadOnlyApply()) { + if (!state.HasState(ElementState::READWRITE) && DoesReadOnlyApply()) { if (!GetBoolAttr(nsGkAtoms::readonly) && !IsDisabled()) { - state |= NS_EVENT_STATE_READWRITE; - state &= ~NS_EVENT_STATE_READONLY; + state |= ElementState::READWRITE; + state &= ~ElementState::READONLY; } } @@ -2659,15 +2658,15 @@ void nsGenericHTMLFormControlElement::UpdateRequiredState(bool aIsRequired, } #endif - EventStates requiredStates; + ElementState requiredStates; if (aIsRequired) { - requiredStates |= NS_EVENT_STATE_REQUIRED; + requiredStates |= ElementState::REQUIRED; } else { - requiredStates |= NS_EVENT_STATE_OPTIONAL; + requiredStates |= ElementState::OPTIONAL_; } - EventStates oldRequiredStates = State() & REQUIRED_STATES; - EventStates changedStates = requiredStates ^ oldRequiredStates; + ElementState oldRequiredStates = State() & ElementState::REQUIRED_STATES; + ElementState changedStates = requiredStates ^ oldRequiredStates; if (!changedStates.IsEmpty()) { ToggleStates(changedStates, aNotify); diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index 3dae136ae42a..b9e01daa521a 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -32,7 +32,6 @@ class EventChainPostVisitor; class EventChainPreVisitor; class EventChainVisitor; class EventListenerManager; -class EventStates; class PresState; namespace dom { class ElementInternals; @@ -55,7 +54,7 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase { : nsGenericHTMLElementBase(std::move(aNodeInfo)) { NS_ASSERTION(mNodeInfo->NamespaceID() == kNameSpaceID_XHTML, "Unexpected namespace"); - AddStatesSilently(NS_EVENT_STATE_LTR); + AddStatesSilently(mozilla::dom::ElementState::LTR); SetFlags(NODE_HAS_DIRECTION_LTR); } @@ -316,7 +315,7 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase { virtual void UpdateEditableState(bool aNotify) override; - virtual mozilla::EventStates IntrinsicState() const override; + virtual mozilla::dom::ElementState IntrinsicState() const override; // Helper for setting our editable flag and notifying void DoSetEditableFlag(bool aEditable, bool aNotify) { @@ -1144,7 +1143,7 @@ class nsGenericHTMLFormControlElement : public nsGenericHTMLFormElement, virtual ~nsGenericHTMLFormControlElement(); // Element - virtual mozilla::EventStates IntrinsicState() const override; + virtual mozilla::dom::ElementState IntrinsicState() const override; virtual bool IsLabelable() const override; // nsGenericHTMLFormElement diff --git a/dom/html/nsIConstraintValidation.cpp b/dom/html/nsIConstraintValidation.cpp index 37415d8069d0..f4e6181c77db 100644 --- a/dom/html/nsIConstraintValidation.cpp +++ b/dom/html/nsIConstraintValidation.cpp @@ -85,7 +85,7 @@ bool nsIConstraintValidation::ReportValidity() { element->DispatchEvent(*event); auto* inputElement = HTMLInputElement::FromNode(element); - if (inputElement && inputElement->State().HasState(NS_EVENT_STATE_FOCUS)) { + if (inputElement && inputElement->State().HasState(ElementState::FOCUS)) { inputElement->UpdateValidityUIBits(true); } diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index 420dc4af627a..eb2dc61cb57b 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -2078,10 +2078,10 @@ interface nsIDOMWindowUtils : nsISupports { readonly attribute int32_t gpuProcessPid; /** - * Adds an EventStates bit to the element. + * Adds an ElementState bit to the element. * * The state string must be one of the following: - * * (none yet; but for example "higlighted" for NS_EVENT_STATE_HIGHLIGHTED) + * * (none yet; but for example "higlighted" for ElementState::HIGHLIGHTED) * * The supported state strings are defined in kManuallyManagedStates * in nsDOMWindowUtils.cpp. @@ -2090,7 +2090,7 @@ interface nsIDOMWindowUtils : nsISupports { in AString state); /** - * Removes the specified EventStates bits from the element. + * Removes the specified ElementState bits from the element. * * See above for the strings that can be passed for |state|. */ diff --git a/dom/mathml/MathMLElement.cpp b/dom/mathml/MathMLElement.cpp index af9be639e784..6a532c92dc22 100644 --- a/dom/mathml/MathMLElement.cpp +++ b/dom/mathml/MathMLElement.cpp @@ -27,7 +27,6 @@ #include "nsIURI.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/MappedDeclarations.h" #include "mozilla/dom/MathMLElementBinding.h" @@ -815,10 +814,10 @@ nsresult MathMLElement::PostHandleEvent(EventChainPostVisitor& aVisitor) { NS_IMPL_ELEMENT_CLONE(MathMLElement) -EventStates MathMLElement::IntrinsicState() const { +ElementState MathMLElement::IntrinsicState() const { return Link::LinkState() | MathMLElementBase::IntrinsicState() | - (mIncrementScriptLevel ? NS_EVENT_STATE_INCREMENT_SCRIPT_LEVEL - : EventStates()); + (mIncrementScriptLevel ? ElementState::INCREMENT_SCRIPT_LEVEL + : ElementState()); } bool MathMLElement::IsNodeOfType(uint32_t aFlags) const { return false; } diff --git a/dom/mathml/MathMLElement.h b/dom/mathml/MathMLElement.h index 780f351ee059..c5c5daf74a7a 100644 --- a/dom/mathml/MathMLElement.h +++ b/dom/mathml/MathMLElement.h @@ -66,7 +66,7 @@ class MathMLElement final : public MathMLElementBase, MOZ_CAN_RUN_SCRIPT nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override; nsresult Clone(mozilla::dom::NodeInfo*, nsINode** aResult) const override; - virtual mozilla::EventStates IntrinsicState() const override; + virtual mozilla::dom::ElementState IntrinsicState() const override; virtual bool IsNodeOfType(uint32_t aFlags) const override; // Set during reflow as necessary. Does a style change notification, diff --git a/dom/prototype/PrototypeDocumentContentSink.cpp b/dom/prototype/PrototypeDocumentContentSink.cpp index 4c82d61f9aa5..4cdfa0621f90 100644 --- a/dom/prototype/PrototypeDocumentContentSink.cpp +++ b/dom/prototype/PrototypeDocumentContentSink.cpp @@ -334,7 +334,7 @@ nsresult PrototypeDocumentContentSink::PrepareToWalk() { // TODO(emilio): Should this really notify? We don't notify of appends anyhow, // and we just appended the root so no styles can possibly depend on it. - mDocument->UpdateDocumentStates(NS_DOCUMENT_STATE_RTL_LOCALE, true); + mDocument->UpdateDocumentStates(DocumentState::RTL_LOCALE, true); nsContentUtils::AddScriptRunner( new nsDocElementCreatedNotificationRunner(mDocument)); diff --git a/dom/svg/SVGAElement.cpp b/dom/svg/SVGAElement.cpp index 7a71101ecd42..018e9eaa7802 100644 --- a/dom/svg/SVGAElement.cpp +++ b/dom/svg/SVGAElement.cpp @@ -8,7 +8,6 @@ #include "mozilla/Attributes.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/dom/BindContext.h" #include "mozilla/dom/DocumentInlines.h" #include "mozilla/dom/SVGAElementBinding.h" @@ -266,7 +265,7 @@ void SVGAElement::GetLinkTarget(nsAString& aTarget) { } } -EventStates SVGAElement::IntrinsicState() const { +ElementState SVGAElement::IntrinsicState() const { return Link::LinkState() | SVGAElementBase::IntrinsicState(); } diff --git a/dom/svg/SVGAElement.h b/dom/svg/SVGAElement.h index 2d2b1b1be047..8af2a7979076 100644 --- a/dom/svg/SVGAElement.h +++ b/dom/svg/SVGAElement.h @@ -58,7 +58,7 @@ class SVGAElement final : public SVGAElementBase, public Link { already_AddRefed GetHrefURI() const override; bool HasHref() const; - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, diff --git a/dom/svg/SVGFEImageElement.cpp b/dom/svg/SVGFEImageElement.cpp index e9d5c2f66a53..7aac0ad13341 100644 --- a/dom/svg/SVGFEImageElement.cpp +++ b/dom/svg/SVGFEImageElement.cpp @@ -6,7 +6,6 @@ #include "mozilla/dom/SVGFEImageElement.h" -#include "mozilla/EventStates.h" #include "mozilla/SVGObserverUtils.h" #include "mozilla/dom/Document.h" #include "mozilla/dom/BindContext.h" @@ -50,7 +49,7 @@ SVGFEImageElement::SVGFEImageElement( already_AddRefed&& aNodeInfo) : SVGFEImageElementBase(std::move(aNodeInfo)), mImageAnimationMode(0) { // We start out broken - AddStatesSilently(NS_EVENT_STATE_BROKEN); + AddStatesSilently(ElementState::BROKEN); } SVGFEImageElement::~SVGFEImageElement() { nsImageLoadingContent::Destroy(); } @@ -165,7 +164,7 @@ void SVGFEImageElement::UnbindFromTree(bool aNullParent) { SVGFEImageElementBase::UnbindFromTree(aNullParent); } -EventStates SVGFEImageElement::IntrinsicState() const { +ElementState SVGFEImageElement::IntrinsicState() const { return SVGFEImageElementBase::IntrinsicState() | nsImageLoadingContent::ImageState(); } diff --git a/dom/svg/SVGFEImageElement.h b/dom/svg/SVGFEImageElement.h index 08b3372f0763..f6d1b291704d 100644 --- a/dom/svg/SVGFEImageElement.h +++ b/dom/svg/SVGFEImageElement.h @@ -67,7 +67,7 @@ class SVGFEImageElement final : public SVGFEImageElementBase, bool aNotify) override; virtual nsresult BindToTree(BindContext&, nsINode& aParent) override; virtual void UnbindFromTree(bool aNullParent) override; - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; virtual void DestroyContent() override; NS_DECL_IMGINOTIFICATIONOBSERVER diff --git a/dom/svg/SVGImageElement.cpp b/dom/svg/SVGImageElement.cpp index 96d4614517e7..79f2a0d30d03 100644 --- a/dom/svg/SVGImageElement.cpp +++ b/dom/svg/SVGImageElement.cpp @@ -7,7 +7,6 @@ #include "mozilla/dom/SVGImageElement.h" #include "mozilla/ArrayUtils.h" -#include "mozilla/EventStates.h" #include "mozilla/gfx/2D.h" #include "nsCOMPtr.h" #include "nsIURI.h" @@ -61,7 +60,7 @@ SVGImageElement::SVGImageElement( already_AddRefed&& aNodeInfo) : SVGImageElementBase(std::move(aNodeInfo)) { // We start out broken - AddStatesSilently(NS_EVENT_STATE_BROKEN); + AddStatesSilently(ElementState::BROKEN); } SVGImageElement::~SVGImageElement() { nsImageLoadingContent::Destroy(); } @@ -231,7 +230,7 @@ void SVGImageElement::UnbindFromTree(bool aNullParent) { SVGImageElementBase::UnbindFromTree(aNullParent); } -EventStates SVGImageElement::IntrinsicState() const { +ElementState SVGImageElement::IntrinsicState() const { return SVGImageElementBase::IntrinsicState() | nsImageLoadingContent::ImageState(); } diff --git a/dom/svg/SVGImageElement.h b/dom/svg/SVGImageElement.h index 0956edee24a9..7177179428b5 100644 --- a/dom/svg/SVGImageElement.h +++ b/dom/svg/SVGImageElement.h @@ -65,7 +65,7 @@ class SVGImageElement : public SVGImageElementBase, virtual nsresult BindToTree(BindContext&, nsINode& aParent) override; virtual void UnbindFromTree(bool aNullParent) override; - virtual EventStates IntrinsicState() const override; + virtual ElementState IntrinsicState() const override; virtual void DestroyContent() override; diff --git a/dom/xul/nsXULPopupListener.cpp b/dom/xul/nsXULPopupListener.cpp index a1ade5076e60..31d533a2c016 100644 --- a/dom/xul/nsXULPopupListener.cpp +++ b/dom/xul/nsXULPopupListener.cpp @@ -23,7 +23,6 @@ #include "nsIObjectLoadingContent.h" #include "mozilla/BasePrincipal.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/Preferences.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/Event.h" // for Event @@ -215,7 +214,7 @@ nsresult nsXULPopupListener::FireFocusOnTargetContent( } EventStateManager* esm = context->EventStateManager(); - esm->SetContentState(newFocusElement, NS_EVENT_STATE_ACTIVE); + esm->SetContentState(newFocusElement, ElementState::ACTIVE); return NS_OK; } diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index e853703c0088..72fdb5cb45b2 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -22,8 +22,7 @@ #include "mozilla/ComposerCommandsUpdater.h" #include "mozilla/ContentIterator.h" #include "mozilla/DebugOnly.h" -#include "mozilla/Encoding.h" // for Encoding -#include "mozilla/EventStates.h" +#include "mozilla/Encoding.h" // for Encoding #include "mozilla/IntegerRange.h" // for IntegerRange #include "mozilla/InternalMutationEvent.h" #include "mozilla/mozInlineSpellChecker.h" @@ -712,7 +711,7 @@ Element* HTMLEditor::FindSelectionRoot(const nsINode& aNode) const { // If the content is in read-write state but is not editable itself, // return it as the selection root. if (content->IsElement() && - content->AsElement()->State().HasState(NS_EVENT_STATE_READWRITE)) { + content->AsElement()->State().HasState(ElementState::READWRITE)) { return content->AsElement(); } return nullptr; diff --git a/gfx/layers/apz/util/ActiveElementManager.cpp b/gfx/layers/apz/util/ActiveElementManager.cpp index 85ca3e1a4bfd..9ddc7f1df4af 100644 --- a/gfx/layers/apz/util/ActiveElementManager.cpp +++ b/gfx/layers/apz/util/ActiveElementManager.cpp @@ -6,7 +6,6 @@ #include "ActiveElementManager.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/PresShell.h" #include "mozilla/StaticPrefs_ui.h" #include "mozilla/dom/Element.h" @@ -132,7 +131,7 @@ void ActiveElementManager::SetActive(dom::Element* aTarget) { AEM_LOG("Setting active %p\n", aTarget); if (nsPresContext* pc = GetPresContextFor(aTarget)) { - pc->EventStateManager()->SetContentState(aTarget, NS_EVENT_STATE_ACTIVE); + pc->EventStateManager()->SetContentState(aTarget, dom::ElementState::ACTIVE); } } diff --git a/gfx/webrender_bindings/webrender_ffi.h b/gfx/webrender_bindings/webrender_ffi.h index b1d67b17a4bd..eb79974bdf43 100644 --- a/gfx/webrender_bindings/webrender_ffi.h +++ b/gfx/webrender_bindings/webrender_ffi.h @@ -73,8 +73,6 @@ struct WrPipelineInfo; struct WrPipelineIdAndEpoch; using WrPipelineIdEpochs = nsTArray; -const uint64_t ROOT_CLIP_CHAIN = ~0; - } // namespace wr } // namespace mozilla diff --git a/layout/base/PositionedEventTargeting.cpp b/layout/base/PositionedEventTargeting.cpp index f4b8c39b9d87..533f3e493204 100644 --- a/layout/base/PositionedEventTargeting.cpp +++ b/layout/base/PositionedEventTargeting.cpp @@ -7,7 +7,6 @@ #include "PositionedEventTargeting.h" #include "mozilla/EventListenerManager.h" -#include "mozilla/EventStates.h" #include "mozilla/MouseEvents.h" #include "mozilla/Preferences.h" #include "mozilla/PresShell.h" @@ -449,7 +448,7 @@ static nsIFrame* GetClosest(RelativeTo aRoot, nsIContent* content = f->GetContent(); if (content && content->IsElement() && content->AsElement()->State().HasState( - EventStates(NS_EVENT_STATE_VISITED))) { + ElementState(ElementState::VISITED))) { distance *= aPrefs.mVisitedWeight / 100.0f; } if (distance < bestDistance) { diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index b53d82c44481..b862633c4318 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -18,7 +18,6 @@ #include "mozilla/DisplayPortUtils.h" #include "mozilla/EventDispatcher.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/GeckoMVMContext.h" #include "mozilla/IMEStateManager.h" #include "mozilla/IntegerRange.h" @@ -3163,7 +3162,7 @@ nsresult PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll, // code-path as "top"! if (aAnchorName.IsEmpty()) { NS_ASSERTION(!aScroll, "can't scroll to empty anchor name"); - esm->SetContentState(nullptr, NS_EVENT_STATE_URLTARGET); + esm->SetContentState(nullptr, ElementState::URLTARGET); return NS_OK; } @@ -3226,7 +3225,7 @@ nsresult PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll, // target element to null. // 2.1. Set the Document's target element to null. // 3.2. Set the Document's target element to target. - esm->SetContentState(target, NS_EVENT_STATE_URLTARGET); + esm->SetContentState(target, ElementState::URLTARGET); // TODO: Spec probably needs a section to account for this. if (nsIScrollableFrame* rootScroll = GetRootScrollFrameAsScrollable()) { @@ -4429,7 +4428,7 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY void PresShell::CharacterDataChanged( } MOZ_CAN_RUN_SCRIPT_BOUNDARY void PresShell::ContentStateChanged( - Document* aDocument, nsIContent* aContent, EventStates aStateMask) { + Document* aDocument, nsIContent* aContent, ElementState aStateMask) { MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript()); MOZ_ASSERT(!mIsDocumentGone, "Unexpected ContentStateChanged"); MOZ_ASSERT(aDocument == mDocument, "Unexpected aDocument"); @@ -4440,7 +4439,7 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY void PresShell::ContentStateChanged( } } -void PresShell::DocumentStatesChanged(EventStates aStateMask) { +void PresShell::DocumentStatesChanged(DocumentState aStateMask) { MOZ_ASSERT(!mIsDocumentGone, "Unexpected DocumentStatesChanged"); MOZ_ASSERT(mDocument); MOZ_ASSERT(!aStateMask.IsEmpty()); @@ -4449,7 +4448,7 @@ void PresShell::DocumentStatesChanged(EventStates aStateMask) { StyleSet()->InvalidateStyleForDocumentStateChanges(aStateMask); } - if (aStateMask.HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) { + if (aStateMask.HasState(DocumentState::WINDOW_INACTIVE)) { if (nsIFrame* root = mFrameConstructor->GetRootFrame()) { root->SchedulePaint(); } diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h index 33941ef05e58..fc066c3ce9ed 100644 --- a/layout/base/PresShell.h +++ b/layout/base/PresShell.h @@ -96,7 +96,6 @@ class nsDisplayListBuilder; class FallbackRenderer; class AccessibleCaretEventHub; -class EventStates; class GeckoMVMContext; class OverflowChangedTracker; class StyleSheet; @@ -1362,7 +1361,7 @@ class PresShell final : public nsStubDocumentObserver, int16_t aEndOffset, bool* aRetval) override; // Notifies that the state of the document has changed. - void DocumentStatesChanged(EventStates); + void DocumentStatesChanged(dom::DocumentState); // nsIDocumentObserver NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index 549dead1383d..ed23bd269dab 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -463,8 +463,8 @@ void RestyleManager::ContentRemoved(nsIContent* aOldChild, static bool StateChangeMayAffectFrame(const Element& aElement, const nsIFrame& aFrame, - EventStates aStates) { - const bool brokenChanged = aStates.HasState(NS_EVENT_STATE_BROKEN); + ElementState aStates) { + const bool brokenChanged = aStates.HasState(ElementState::BROKEN); if (aFrame.IsGeneratedContentFrame()) { if (aElement.IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage)) { return brokenChanged; @@ -473,7 +473,7 @@ static bool StateChangeMayAffectFrame(const Element& aElement, return false; } - const bool loadingChanged = aStates.HasState(NS_EVENT_STATE_LOADING); + const bool loadingChanged = aStates.HasState(ElementState::LOADING); if (!brokenChanged && !loadingChanged) { return false; } @@ -497,7 +497,7 @@ static bool StateChangeMayAffectFrame(const Element& aElement, * change. */ static nsChangeHint ChangeForContentStateChange(const Element& aElement, - EventStates aStateMask) { + ElementState aStateMask) { auto changeHint = nsChangeHint(0); // Any change to a content state that affects which frames we construct @@ -528,7 +528,7 @@ static nsChangeHint ChangeForContentStateChange(const Element& aElement, primaryFrame->ContentStatesChanged(aStateMask); } - if (aStateMask.HasState(NS_EVENT_STATE_VISITED)) { + if (aStateMask.HasState(ElementState::VISITED)) { // Exposing information to the page about whether the link is // visited or not isn't really something we can worry about here. // FIXME: We could probably do this a bit better. @@ -536,7 +536,7 @@ static nsChangeHint ChangeForContentStateChange(const Element& aElement, } // This changes the applicable text-transform in the editor root. - if (aStateMask.HasState(NS_EVENT_STATE_REVEALED)) { + if (aStateMask.HasState(ElementState::REVEALED)) { // This is the same change hint as tweaking text-transform. changeHint |= NS_STYLE_HINT_REFLOW; } @@ -3221,7 +3221,7 @@ void RestyleManager::UpdateOnlyAnimationStyles() { } void RestyleManager::ContentStateChanged(nsIContent* aContent, - EventStates aChangedBits) { + ElementState aChangedBits) { MOZ_DIAGNOSTIC_ASSERT(!mInStyleRefresh); if (!aContent->IsElement()) { @@ -3230,8 +3230,8 @@ void RestyleManager::ContentStateChanged(nsIContent* aContent, Element& element = *aContent->AsElement(); - const EventStates kVisitedAndUnvisited = - NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED; + const ElementState kVisitedAndUnvisited = + ElementState::VISITED | ElementState::UNVISITED; // When visited links are disabled, they cannot influence style for obvious // reasons. @@ -3263,7 +3263,7 @@ void RestyleManager::ContentStateChanged(nsIContent* aContent, // We always take a snapshot for the LTR/RTL event states, since Servo doesn't // track those bits in the same way, and we know that :dir() rules are always // present in UA style sheets. - if (!aChangedBits.HasAtLeastOneOfStates(DIRECTION_STATES) && + if (!aChangedBits.HasAtLeastOneOfStates(ElementState::DIR_STATES) && !StyleSet()->HasStateDependency(element, aChangedBits)) { return; } @@ -3277,7 +3277,7 @@ void RestyleManager::ContentStateChanged(nsIContent* aContent, } ServoElementSnapshot& snapshot = SnapshotFor(element); - EventStates previousState = element.StyleState() ^ aChangedBits; + ElementState previousState = element.StyleState() ^ aChangedBits; snapshot.AddState(previousState); } diff --git a/layout/base/RestyleManager.h b/layout/base/RestyleManager.h index 5ba2c428ac51..72de351faad5 100644 --- a/layout/base/RestyleManager.h +++ b/layout/base/RestyleManager.h @@ -8,7 +8,6 @@ #define mozilla_RestyleManager_h #include "mozilla/AutoRestore.h" -#include "mozilla/EventStates.h" #include "mozilla/Maybe.h" #include "mozilla/OverflowChangedTracker.h" #include "mozilla/ServoElementSnapshot.h" @@ -28,7 +27,6 @@ class nsStyleChangeList; namespace mozilla { -class EventStates; class ServoStyleSet; namespace dom { @@ -362,7 +360,7 @@ class RestyleManager { void ProcessPendingRestyles(); void ProcessAllPendingAttributeAndStateInvalidations(); - void ContentStateChanged(nsIContent* aContent, EventStates aStateMask); + void ContentStateChanged(nsIContent* aContent, dom::ElementState aStateMask); void AttributeWillChange(Element* aElement, int32_t aNameSpaceID, nsAtom* aAttribute, int32_t aModType); void ClassAttributeWillBeChangedBySMIL(dom::Element* aElement); diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index db3de08e1c83..76864b8746e2 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -23,7 +23,6 @@ #include "mozilla/dom/HTMLSelectElement.h" #include "mozilla/dom/HTMLSharedListElement.h" #include "mozilla/dom/HTMLSummaryElement.h" -#include "mozilla/EventStates.h" #include "mozilla/Likely.h" #include "mozilla/LinkedList.h" #include "mozilla/MemoryReporting.h" @@ -3615,7 +3614,7 @@ nsCSSFrameConstructor::FindObjectData(const Element& aElement, // cases when the object is broken/suppressed/etc (e.g. a broken image), but // we want to treat those cases as TYPE_NULL uint32_t type; - if (aElement.State().HasState(NS_EVENT_STATE_BROKEN)) { + if (aElement.State().HasState(ElementState::BROKEN)) { type = nsIObjectLoadingContent::TYPE_NULL; } else { nsCOMPtr objContent = diff --git a/layout/forms/HTMLSelectEventListener.cpp b/layout/forms/HTMLSelectEventListener.cpp index 8ab77f9c40ad..1ff1e491afac 100644 --- a/layout/forms/HTMLSelectEventListener.cpp +++ b/layout/forms/HTMLSelectEventListener.cpp @@ -402,8 +402,8 @@ nsresult HTMLSelectEventListener::MouseDown(dom::Event* aMouseEvent) { MouseEvent* mouseEvent = aMouseEvent->AsMouseEvent(); NS_ENSURE_TRUE(mouseEvent, NS_ERROR_FAILURE); - EventStates eventStates = mElement->State(); - if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) { + ElementState eventStates = mElement->State(); + if (eventStates.HasState(ElementState::DISABLED)) { return NS_OK; } @@ -446,8 +446,8 @@ nsresult HTMLSelectEventListener::MouseUp(dom::Event* aMouseEvent) { mButtonDown = false; - EventStates eventStates = mElement->State(); - if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) { + ElementState eventStates = mElement->State(); + if (eventStates.HasState(ElementState::DISABLED)) { return NS_OK; } @@ -490,8 +490,8 @@ nsresult HTMLSelectEventListener::MouseMove(dom::Event* aMouseEvent) { nsresult HTMLSelectEventListener::KeyPress(dom::Event* aKeyEvent) { MOZ_ASSERT(aKeyEvent, "aKeyEvent is null."); - EventStates eventStates = mElement->State(); - if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) { + ElementState eventStates = mElement->State(); + if (eventStates.HasState(ElementState::DISABLED)) { return NS_OK; } @@ -653,8 +653,8 @@ nsresult HTMLSelectEventListener::KeyPress(dom::Event* aKeyEvent) { nsresult HTMLSelectEventListener::KeyDown(dom::Event* aKeyEvent) { MOZ_ASSERT(aKeyEvent, "aKeyEvent is null."); - EventStates eventStates = mElement->State(); - if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) { + ElementState eventStates = mElement->State(); + if (eventStates.HasState(ElementState::DISABLED)) { return NS_OK; } diff --git a/layout/forms/nsButtonFrameRenderer.cpp b/layout/forms/nsButtonFrameRenderer.cpp index 953be34c2339..1dc83ae3a9db 100644 --- a/layout/forms/nsButtonFrameRenderer.cpp +++ b/layout/forms/nsButtonFrameRenderer.cpp @@ -15,7 +15,6 @@ #include "nsDisplayList.h" #include "nsITheme.h" #include "nsIFrame.h" -#include "mozilla/EventStates.h" #include "mozilla/dom/Element.h" #include "Layers.h" diff --git a/layout/forms/nsComboboxControlFrame.cpp b/layout/forms/nsComboboxControlFrame.cpp index f4a569d733cc..1093c7b4c92a 100644 --- a/layout/forms/nsComboboxControlFrame.cpp +++ b/layout/forms/nsComboboxControlFrame.cpp @@ -47,7 +47,6 @@ #include #include "nsTextNode.h" #include "mozilla/AsyncEventDispatcher.h" -#include "mozilla/EventStates.h" #include "mozilla/LookAndFeel.h" #include "mozilla/MouseEvents.h" #include "mozilla/PresShell.h" @@ -632,8 +631,8 @@ nsresult nsComboboxControlFrame::HandleEvent(nsPresContext* aPresContext, return NS_OK; } - EventStates eventStates = mContent->AsElement()->State(); - if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) { + ElementState eventStates = mContent->AsElement()->State(); + if (eventStates.HasState(ElementState::DISABLED)) { return NS_OK; } @@ -917,7 +916,7 @@ void nsComboboxControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, } // draw a focus indicator only when focus rings should be drawn - if (mContent->AsElement()->State().HasState(NS_EVENT_STATE_FOCUSRING)) { + if (mContent->AsElement()->State().HasState(ElementState::FOCUSRING)) { nsPresContext* pc = PresContext(); const nsStyleDisplay* disp = StyleDisplay(); if (IsThemed(disp) && @@ -933,9 +932,9 @@ void nsComboboxControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, void nsComboboxControlFrame::PaintFocus(DrawTarget& aDrawTarget, nsPoint aPt) { /* Do we need to do anything? */ - EventStates eventStates = mContent->AsElement()->State(); - if (eventStates.HasState(NS_EVENT_STATE_DISABLED) || - !eventStates.HasState(NS_EVENT_STATE_FOCUS)) { + ElementState eventStates = mContent->AsElement()->State(); + if (eventStates.HasState(ElementState::DISABLED) || + !eventStates.HasState(ElementState::FOCUS)) { return; } diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp index b954d8c3461f..9ad531f0ef6f 100644 --- a/layout/forms/nsFileControlFrame.cpp +++ b/layout/forms/nsFileControlFrame.cpp @@ -21,7 +21,6 @@ #include "mozilla/dom/HTMLButtonElement.h" #include "mozilla/dom/HTMLInputElement.h" #include "mozilla/dom/MutationEventBinding.h" -#include "mozilla/EventStates.h" #include "mozilla/intl/Segmenter.h" #include "mozilla/Preferences.h" #include "mozilla/PresShell.h" @@ -532,8 +531,8 @@ nscoord nsFileControlFrame::GetPrefISize(gfxContext* aRenderingContext) { } void nsFileControlFrame::SyncDisabledState() { - EventStates eventStates = mContent->AsElement()->State(); - if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) { + ElementState eventStates = mContent->AsElement()->State(); + if (eventStates.HasState(ElementState::DISABLED)) { mBrowseFilesOrDirs->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, u""_ns, true); } else { @@ -541,8 +540,8 @@ void nsFileControlFrame::SyncDisabledState() { } } -void nsFileControlFrame::ContentStatesChanged(EventStates aStates) { - if (aStates.HasState(NS_EVENT_STATE_DISABLED)) { +void nsFileControlFrame::ContentStatesChanged(ElementState aStates) { + if (aStates.HasState(ElementState::DISABLED)) { nsContentUtils::AddScriptRunner(new SyncDisabledStateEvent(this)); } } diff --git a/layout/forms/nsFileControlFrame.h b/layout/forms/nsFileControlFrame.h index 27ba337b4ae6..551037ba85cf 100644 --- a/layout/forms/nsFileControlFrame.h +++ b/layout/forms/nsFileControlFrame.h @@ -59,7 +59,8 @@ class nsFileControlFrame final : public nsBlockFrame, virtual nsresult GetFrameName(nsAString& aResult) const override; #endif - virtual void ContentStatesChanged(mozilla::EventStates aStates) override; + virtual void ContentStatesChanged( + mozilla::dom::ElementState aStates) override; // nsIAnonymousContentCreator virtual nsresult CreateAnonymousContent( diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index 0208f93ca66e..7dfc29523550 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -25,7 +25,6 @@ #include "mozilla/dom/MouseEvent.h" #include "mozilla/dom/MouseEventBinding.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/LookAndFeel.h" #include "mozilla/MouseEvents.h" #include "mozilla/Preferences.h" diff --git a/layout/forms/nsNumberControlFrame.cpp b/layout/forms/nsNumberControlFrame.cpp index 6cbdb0c8232f..a2008d4b4b1e 100644 --- a/layout/forms/nsNumberControlFrame.cpp +++ b/layout/forms/nsNumberControlFrame.cpp @@ -7,7 +7,6 @@ #include "nsNumberControlFrame.h" #include "mozilla/BasicEvents.h" -#include "mozilla/EventStates.h" #include "mozilla/FloatingPoint.h" #include "mozilla/PresShell.h" #include "HTMLInputElement.h" diff --git a/layout/forms/nsRangeFrame.cpp b/layout/forms/nsRangeFrame.cpp index 7f5670e7a6c2..7b977977640f 100644 --- a/layout/forms/nsRangeFrame.cpp +++ b/layout/forms/nsRangeFrame.cpp @@ -6,7 +6,6 @@ #include "nsRangeFrame.h" -#include "mozilla/EventStates.h" #include "mozilla/PresShell.h" #include "mozilla/TouchEvents.h" diff --git a/layout/generic/nsFrameSelection.cpp b/layout/generic/nsFrameSelection.cpp index 3f6ca4b3d22c..af730a5d5db0 100644 --- a/layout/generic/nsFrameSelection.cpp +++ b/layout/generic/nsFrameSelection.cpp @@ -14,7 +14,6 @@ #include "mozilla/Attributes.h" #include "mozilla/AutoRestore.h" #include "mozilla/BasePrincipal.h" -#include "mozilla/EventStates.h" #include "mozilla/HTMLEditor.h" #include "mozilla/IntegerRange.h" #include "mozilla/Logging.h" diff --git a/layout/generic/nsIFrame.cpp b/layout/generic/nsIFrame.cpp index 2ec07766344e..80772ce7b295 100644 --- a/layout/generic/nsIFrame.cpp +++ b/layout/generic/nsIFrame.cpp @@ -121,7 +121,6 @@ #include "mozilla/EffectSet.h" #include "mozilla/EventListenerManager.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/Preferences.h" #include "mozilla/LookAndFeel.h" #include "mozilla/MouseEvents.h" @@ -444,7 +443,7 @@ void nsIFrame::FindCloserFrameForSelection( } } -void nsIFrame::ContentStatesChanged(mozilla::EventStates aStates) {} +void nsIFrame::ContentStatesChanged(mozilla::dom::ElementState aStates) {} void WeakFrame::Clear(mozilla::PresShell* aPresShell) { if (aPresShell) { diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h index 16b652cdf30c..113b7a4bc58a 100644 --- a/layout/generic/nsIFrame.h +++ b/layout/generic/nsIFrame.h @@ -139,7 +139,6 @@ class nsDisplayList; class nsDisplayListBuilder; class nsDisplayListSet; -class EventStates; class ServoRestyleState; class EffectSet; class LazyLogModule; @@ -2360,7 +2359,7 @@ class nsIFrame : public nsQueryFrame { * * @param aStates the changed states */ - virtual void ContentStatesChanged(mozilla::EventStates aStates); + virtual void ContentStatesChanged(mozilla::dom::ElementState aStates); /** * Continuation member functions diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index bd26b66e093a..3bbcc005060f 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -16,7 +16,6 @@ #include "mozilla/ComputedStyle.h" #include "mozilla/DebugOnly.h" #include "mozilla/Encoding.h" -#include "mozilla/EventStates.h" #include "mozilla/HTMLEditor.h" #include "mozilla/dom/ImageTracker.h" #include "mozilla/gfx/2D.h" @@ -820,8 +819,8 @@ nsRect nsImageFrame::SourceRectToDest(const nsIntRect& aRect) { return r; } -static bool ImageOk(EventStates aState) { - return !aState.HasState(NS_EVENT_STATE_BROKEN); +static bool ImageOk(ElementState aState) { + return !aState.HasState(ElementState::BROKEN); } static bool HasAltText(const Element& aElement) { diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 6763ef401d9f..0c46fd471cef 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -118,7 +118,7 @@ static bool NeedsToMaskPassword(nsTextFrame* aFrame) { nsLayoutUtils::GetClosestFrameOfType(aFrame, LayoutFrameType::TextInput); MOZ_ASSERT(frame, "How do we have a masked text node without a text input?"); return !frame || !frame->GetContent()->AsElement()->State().HasState( - NS_EVENT_STATE_REVEALED); + ElementState::REVEALED); } struct TabWidth { diff --git a/layout/inspector/InspectorUtils.cpp b/layout/inspector/InspectorUtils.cpp index 3544d96c2f13..6c2dc92112f1 100644 --- a/layout/inspector/InspectorUtils.cpp +++ b/layout/inspector/InspectorUtils.cpp @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/ArrayUtils.h" -#include "mozilla/EventStates.h" #include "inLayoutUtils.h" @@ -556,7 +555,7 @@ bool InspectorUtils::SetContentState(GlobalObject& aGlobalObject, ErrorResult& aRv) { RefPtr esm = inLayoutUtils::GetEventStateManagerFor(aElement); - EventStates state(aState); + ElementState state(aState); if (!esm || !EventStateManager::ManagesState(state)) { aRv.Throw(NS_ERROR_INVALID_ARG); return false; @@ -571,7 +570,7 @@ bool InspectorUtils::RemoveContentState(GlobalObject& aGlobalObject, ErrorResult& aRv) { RefPtr esm = inLayoutUtils::GetEventStateManagerFor(aElement); - EventStates state(aState); + ElementState state(aState); if (!esm || !EventStateManager::ManagesState(state)) { aRv.Throw(NS_ERROR_INVALID_ARG); return false; @@ -579,7 +578,7 @@ bool InspectorUtils::RemoveContentState(GlobalObject& aGlobalObject, bool result = esm->SetContentState(nullptr, state); - if (aClearActiveDocument && state == NS_EVENT_STATE_ACTIVE) { + if (aClearActiveDocument && state == ElementState::ACTIVE) { EventStateManager* activeESM = static_cast( EventStateManager::GetActiveEventStateManager()); if (activeESM == esm) { @@ -594,7 +593,7 @@ bool InspectorUtils::RemoveContentState(GlobalObject& aGlobalObject, uint64_t InspectorUtils::GetContentState(GlobalObject& aGlobalObject, Element& aElement) { // NOTE: if this method is removed, - // please remove GetInternalValue from EventStates + // please remove GetInternalValue from ElementState return aElement.State().GetInternalValue(); } @@ -612,12 +611,12 @@ void InspectorUtils::GetUsedFontFaces(GlobalObject& aGlobalObject, } } -static EventStates GetStatesForPseudoClass(const nsAString& aStatePseudo) { +static ElementState GetStatesForPseudoClass(const nsAString& aStatePseudo) { if (aStatePseudo.IsEmpty() || aStatePseudo[0] != u':') { - return EventStates(); + return ElementState(); } NS_ConvertUTF16toUTF8 statePseudo(Substring(aStatePseudo, 1)); - return EventStates(Servo_PseudoClass_GetStates(&statePseudo)); + return ElementState(Servo_PseudoClass_GetStates(&statePseudo)); } /* static */ @@ -643,7 +642,7 @@ void InspectorUtils::AddPseudoClassLock(GlobalObject& aGlobalObject, Element& aElement, const nsAString& aPseudoClass, bool aEnabled) { - EventStates state = GetStatesForPseudoClass(aPseudoClass); + ElementState state = GetStatesForPseudoClass(aPseudoClass); if (state.IsEmpty()) { return; } @@ -655,7 +654,7 @@ void InspectorUtils::AddPseudoClassLock(GlobalObject& aGlobalObject, void InspectorUtils::RemovePseudoClassLock(GlobalObject& aGlobal, Element& aElement, const nsAString& aPseudoClass) { - EventStates state = GetStatesForPseudoClass(aPseudoClass); + ElementState state = GetStatesForPseudoClass(aPseudoClass); if (state.IsEmpty()) { return; } @@ -667,12 +666,12 @@ void InspectorUtils::RemovePseudoClassLock(GlobalObject& aGlobal, bool InspectorUtils::HasPseudoClassLock(GlobalObject& aGlobalObject, Element& aElement, const nsAString& aPseudoClass) { - EventStates state = GetStatesForPseudoClass(aPseudoClass); + ElementState state = GetStatesForPseudoClass(aPseudoClass); if (state.IsEmpty()) { return false; } - EventStates locks = aElement.LockedStyleStates().mLocks; + ElementState locks = aElement.LockedStyleStates().mLocks; return locks.HasAllStates(state); } diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index dd0935db2465..28f6c6984659 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -68,7 +68,6 @@ #include "mozilla/AutoRestore.h" #include "mozilla/EffectCompositor.h" #include "mozilla/EffectSet.h" -#include "mozilla/EventStates.h" #include "mozilla/HashTable.h" #include "mozilla/LookAndFeel.h" #include "mozilla/OperatorNewExtensions.h" @@ -3769,8 +3768,8 @@ bool nsDisplayThemedBackground::CreateWebRenderCommands( } bool nsDisplayThemedBackground::IsWindowActive() const { - EventStates docState = mFrame->GetContent()->OwnerDoc()->GetDocumentState(); - return !docState.HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE); + DocumentState docState = mFrame->GetContent()->OwnerDoc()->GetDocumentState(); + return !docState.HasState(DocumentState::WINDOW_INACTIVE); } void nsDisplayThemedBackground::ComputeInvalidationRegion( diff --git a/layout/style/ComputedStyle.cpp b/layout/style/ComputedStyle.cpp index 40c736841d22..2d2cb33b7d31 100644 --- a/layout/style/ComputedStyle.cpp +++ b/layout/style/ComputedStyle.cpp @@ -185,9 +185,9 @@ nsChangeHint ComputedStyle::CalcStyleDifference(const ComputedStyle& aNewStyle, // Note that we do not check whether this->RelevantLinkVisited() != // aNewContext->RelevantLinkVisited(); we don't need to since // nsCSSFrameConstructor::DoContentStateChanged always adds - // nsChangeHint_RepaintFrame for NS_EVENT_STATE_VISITED changes (and + // nsChangeHint_RepaintFrame for ElementState::VISITED changes (and // needs to, since HasStateDependentStyle probably doesn't work right - // for NS_EVENT_STATE_VISITED). Hopefully this doesn't actually + // for ElementState::VISITED). Hopefully this doesn't actually // expose whether links are visited to performance tests since all // link coloring happens asynchronously at a time when it's hard for // the page to measure. diff --git a/layout/style/GeckoBindings.cpp b/layout/style/GeckoBindings.cpp index ebcd1e05f106..293895e011cf 100644 --- a/layout/style/GeckoBindings.cpp +++ b/layout/style/GeckoBindings.cpp @@ -46,7 +46,6 @@ #include "mozilla/DeclarationBlock.h" #include "mozilla/EffectCompositor.h" #include "mozilla/EffectSet.h" -#include "mozilla/EventStates.h" #include "mozilla/FontPropertyTypes.h" #include "mozilla/Keyframe.h" #include "mozilla/Mutex.h" @@ -253,8 +252,8 @@ bool Gecko_VisitedStylesEnabled(const Document* aDoc) { return true; } -EventStates::ServoType Gecko_ElementState(const Element* aElement) { - return aElement->StyleState().ServoValue(); +ElementState::InternalType Gecko_ElementState(const Element* aElement) { + return aElement->StyleState().GetInternalValue(); } bool Gecko_IsRootElement(const Element* aElement) { diff --git a/layout/style/ServoElementSnapshot.h b/layout/style/ServoElementSnapshot.h index a6a980453281..911b4aaca4cf 100644 --- a/layout/style/ServoElementSnapshot.h +++ b/layout/style/ServoElementSnapshot.h @@ -8,9 +8,9 @@ #define mozilla_ServoElementSnapshot_h #include "AttrArray.h" -#include "mozilla/EventStates.h" #include "mozilla/TypedEnumBits.h" #include "mozilla/dom/BorrowedAttrInfo.h" +#include "mozilla/dom/RustTypes.h" #include "nsAttrName.h" #include "nsAttrValue.h" #include "nsChangeHint.h" @@ -47,7 +47,10 @@ MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(ServoElementSnapshotFlags) class ServoElementSnapshot { typedef dom::BorrowedAttrInfo BorrowedAttrInfo; typedef dom::Element Element; - typedef EventStates::ServoType ServoStateType; + + // TODO: Now that the element state shares a representation with rust we + // should be able to do better and not use the internal type. + typedef dom::ElementState::InternalType ServoStateType; public: typedef ServoElementSnapshotFlags Flags; @@ -70,9 +73,9 @@ class ServoElementSnapshot { /** * Captures the given state (if not previously captured). */ - void AddState(EventStates aState) { + void AddState(dom::ElementState aState) { if (!HasAny(Flags::State)) { - mState = aState.ServoValue(); + mState = aState.GetInternalValue(); mContains |= Flags::State; } } @@ -87,7 +90,7 @@ class ServoElementSnapshot { /** * Captures some other pseudo-class matching state not included in - * EventStates. + * ElementState. */ void AddOtherPseudoClassState(const Element&); diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index 06ca17500010..cee74574f91c 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -175,7 +175,7 @@ void ServoStyleSet::RecordShadowStyleChange(ShadowRoot& aShadowRoot) { } void ServoStyleSet::InvalidateStyleForDocumentStateChanges( - EventStates aStatesChanged) { + DocumentState aStatesChanged) { MOZ_ASSERT(mDocument); MOZ_ASSERT(!aStatesChanged.IsEmpty()); @@ -200,8 +200,9 @@ void ServoStyleSet::InvalidateStyleForDocumentStateChanges( } }); - Servo_InvalidateStyleForDocStateChanges( - root, mRawSet.get(), &nonDocumentStyles, aStatesChanged.ServoValue()); + Servo_InvalidateStyleForDocStateChanges(root, mRawSet.get(), + &nonDocumentStyles, + aStatesChanged.GetInternalValue()); } static const MediaFeatureChangeReason kMediaFeaturesAffectingDefaultStyle = @@ -1326,14 +1327,15 @@ bool ServoStyleSet::MightHaveAttributeDependency(const Element& aElement, } bool ServoStyleSet::HasStateDependency(const Element& aElement, - EventStates aState) const { + dom::ElementState aState) const { return Servo_StyleSet_HasStateDependency(mRawSet.get(), &aElement, - aState.ServoValue()); + aState.GetInternalValue()); } -bool ServoStyleSet::HasDocumentStateDependency(EventStates aState) const { +bool ServoStyleSet::HasDocumentStateDependency( + dom::DocumentState aState) const { return Servo_StyleSet_HasDocumentStateDependency(mRawSet.get(), - aState.ServoValue()); + aState.GetInternalValue()); } already_AddRefed ServoStyleSet::ReparentComputedStyle( diff --git a/layout/style/ServoStyleSet.h b/layout/style/ServoStyleSet.h index 2ae812d3b04b..ed7350674b2f 100644 --- a/layout/style/ServoStyleSet.h +++ b/layout/style/ServoStyleSet.h @@ -10,11 +10,11 @@ #include "mozilla/AnonymousContentKey.h" #include "mozilla/AtomArray.h" #include "mozilla/EnumeratedArray.h" -#include "mozilla/EventStates.h" #include "mozilla/Maybe.h" #include "mozilla/PostTraversalTask.h" #include "mozilla/ServoBindingTypes.h" #include "mozilla/ServoUtils.h" +#include "mozilla/dom/RustTypes.h" #include "mozilla/UniquePtr.h" #include "MainThreadUtils.h" #include "nsCSSPseudoElements.h" @@ -125,7 +125,8 @@ class ServoStyleSet { void ImportRuleLoaded(dom::CSSImportRule&, StyleSheet&); // Runs style invalidation due to document state changes. - void InvalidateStyleForDocumentStateChanges(EventStates aStatesChanged); + void InvalidateStyleForDocumentStateChanges( + dom::DocumentState aStatesChanged); void RecordShadowStyleChange(dom::ShadowRoot&); @@ -428,13 +429,13 @@ class ServoStyleSet { * the changed state isn't depended upon by any pseudo-class selectors * in a style sheet. */ - bool HasStateDependency(const dom::Element&, EventStates) const; + bool HasStateDependency(const dom::Element&, dom::ElementState) const; /** * Returns true if a change in document state might require us to restyle the * document. */ - bool HasDocumentStateDependency(EventStates aState) const; + bool HasDocumentStateDependency(dom::DocumentState) const; /** * Get a new ComputedStyle that uses the same rules as the given ComputedStyle diff --git a/layout/style/nsHTMLStyleSheet.cpp b/layout/style/nsHTMLStyleSheet.cpp index 07c4bfae7f0a..e29797a9925f 100644 --- a/layout/style/nsHTMLStyleSheet.cpp +++ b/layout/style/nsHTMLStyleSheet.cpp @@ -13,7 +13,6 @@ #include "nsMappedAttributes.h" #include "nsGkAtoms.h" #include "nsPresContext.h" -#include "mozilla/EventStates.h" #include "mozilla/PresShell.h" #include "mozilla/dom/Document.h" #include "mozilla/dom/DocumentInlines.h" diff --git a/layout/xul/nsButtonBoxFrame.cpp b/layout/xul/nsButtonBoxFrame.cpp index 7579ffd51a51..966b6f10d4b8 100644 --- a/layout/xul/nsButtonBoxFrame.cpp +++ b/layout/xul/nsButtonBoxFrame.cpp @@ -16,7 +16,6 @@ #include "mozilla/dom/Event.h" #include "mozilla/dom/MouseEventBinding.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/MouseEvents.h" #include "mozilla/PresShell.h" #include "mozilla/TextEvents.h" @@ -105,8 +104,8 @@ nsresult nsButtonBoxFrame::HandleEvent(nsPresContext* aPresContext, if (NS_VK_SPACE == keyEvent->mKeyCode) { EventStateManager* esm = aPresContext->EventStateManager(); // :hover:active state - esm->SetContentState(mContent, NS_EVENT_STATE_HOVER); - esm->SetContentState(mContent, NS_EVENT_STATE_ACTIVE); + esm->SetContentState(mContent, ElementState::HOVER); + esm->SetContentState(mContent, ElementState::ACTIVE); mIsHandlingKeyEvent = true; } break; @@ -140,13 +139,13 @@ nsresult nsButtonBoxFrame::HandleEvent(nsPresContext* aPresContext, mIsHandlingKeyEvent = false; // only activate on keyup if we're already in the :hover:active state NS_ASSERTION(mContent->IsElement(), "How do we have a non-element?"); - EventStates buttonState = mContent->AsElement()->State(); - if (buttonState.HasAllStates(NS_EVENT_STATE_ACTIVE | - NS_EVENT_STATE_HOVER)) { + ElementState buttonState = mContent->AsElement()->State(); + if (buttonState.HasAllStates(ElementState::ACTIVE | + ElementState::HOVER)) { // return to normal state EventStateManager* esm = aPresContext->EventStateManager(); - esm->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE); - esm->SetContentState(nullptr, NS_EVENT_STATE_HOVER); + esm->SetContentState(nullptr, ElementState::ACTIVE); + esm->SetContentState(nullptr, ElementState::HOVER); MouseClicked(aEvent); } } @@ -170,13 +169,13 @@ nsresult nsButtonBoxFrame::HandleEvent(nsPresContext* aPresContext, void nsButtonBoxFrame::Blurred() { NS_ASSERTION(mContent->IsElement(), "How do we have a non-element?"); - EventStates buttonState = mContent->AsElement()->State(); + ElementState buttonState = mContent->AsElement()->State(); if (mIsHandlingKeyEvent && - buttonState.HasAllStates(NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER)) { + buttonState.HasAllStates(ElementState::ACTIVE | ElementState::HOVER)) { // return to normal state EventStateManager* esm = PresContext()->EventStateManager(); - esm->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE); - esm->SetContentState(nullptr, NS_EVENT_STATE_HOVER); + esm->SetContentState(nullptr, ElementState::ACTIVE); + esm->SetContentState(nullptr, ElementState::HOVER); } mIsHandlingKeyEvent = false; } diff --git a/layout/xul/nsMenuPopupFrame.cpp b/layout/xul/nsMenuPopupFrame.cpp index 884e82718c81..be6a342c3aec 100644 --- a/layout/xul/nsMenuPopupFrame.cpp +++ b/layout/xul/nsMenuPopupFrame.cpp @@ -46,7 +46,6 @@ #include "mozilla/BasePrincipal.h" #include "mozilla/EventDispatcher.h" #include "mozilla/EventStateManager.h" -#include "mozilla/EventStates.h" #include "mozilla/Preferences.h" #include "mozilla/LookAndFeel.h" #include "mozilla/MouseEvents.h" @@ -1110,11 +1109,9 @@ void nsMenuPopupFrame::HidePopup(bool aDeselectMenu, nsPopupState aNewState) { // current hover state, we should clear it manually. This code may not the // best solution, but we can leave it here until we find the better approach. NS_ASSERTION(mContent->IsElement(), "How do we have a non-element?"); - EventStates state = mContent->AsElement()->State(); - - if (state.HasState(NS_EVENT_STATE_HOVER)) { + if (mContent->AsElement()->State().HasState(dom::ElementState::HOVER)) { EventStateManager* esm = PresContext()->EventStateManager(); - esm->SetContentState(nullptr, NS_EVENT_STATE_HOVER); + esm->SetContentState(nullptr, dom::ElementState::HOVER); } nsMenuFrame* menuFrame = do_QueryFrame(GetParent()); diff --git a/layout/xul/tree/nsTreeBodyFrame.cpp b/layout/xul/tree/nsTreeBodyFrame.cpp index 1b9b56e8b378..846cc42e632a 100644 --- a/layout/xul/tree/nsTreeBodyFrame.cpp +++ b/layout/xul/tree/nsTreeBodyFrame.cpp @@ -2501,9 +2501,9 @@ class nsDisplayTreeBody final : public nsPaintedDisplayItem { } bool IsWindowActive() const { - EventStates docState = + DocumentState docState = mFrame->PresContext()->Document()->GetDocumentState(); - return !docState.HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE); + return !docState.HasState(DocumentState::WINDOW_INACTIVE); } void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder, diff --git a/servo/components/malloc_size_of/Cargo.toml b/servo/components/malloc_size_of/Cargo.toml index 40f376ada98b..c6270be9ecf1 100644 --- a/servo/components/malloc_size_of/Cargo.toml +++ b/servo/components/malloc_size_of/Cargo.toml @@ -32,6 +32,7 @@ app_units = "0.7" content-security-policy = { version = "0.4.0", features = ["serde"], optional = true } crossbeam-channel = { version = "0.4", optional = true } cssparser = "0.29" +dom = { path = "../../../dom/base/rust" } euclid = "0.22" hyper = { version = "0.12", optional = true } hyper_serde = { version = "0.11", optional = true } diff --git a/servo/components/malloc_size_of/lib.rs b/servo/components/malloc_size_of/lib.rs index 96847ebe5cb3..87468aa15efe 100644 --- a/servo/components/malloc_size_of/lib.rs +++ b/servo/components/malloc_size_of/lib.rs @@ -820,6 +820,8 @@ malloc_size_of_is_0!(app_units::Au); malloc_size_of_is_0!(cssparser::RGBA, cssparser::TokenSerializationType); +malloc_size_of_is_0!(dom::ElementState, dom::DocumentState); + #[cfg(feature = "servo")] malloc_size_of_is_0!(csp::Destination); diff --git a/servo/components/style/Cargo.toml b/servo/components/style/Cargo.toml index bf960781e88b..469e26057929 100644 --- a/servo/components/style/Cargo.toml +++ b/servo/components/style/Cargo.toml @@ -34,6 +34,7 @@ bitflags = "1.0" byteorder = "1.0" cssparser = "0.29" derive_more = "0.99" +dom = { path = "../../../dom/base/rust" } new_debug_unreachable = "1.0" encoding_rs = {version = "0.8", optional = true} euclid = "0.22" diff --git a/servo/components/style/dom.rs b/servo/components/style/dom.rs index 4f48298808e6..5bfed19ef939 100644 --- a/servo/components/style/dom.rs +++ b/servo/components/style/dom.rs @@ -12,7 +12,6 @@ use crate::context::SharedStyleContext; #[cfg(feature = "gecko")] use crate::context::{PostAnimationTasks, UpdateAnimationsTasks}; use crate::data::ElementData; -use crate::element_state::ElementState; use crate::font_metrics::FontMetricsProvider; use crate::media_queries::Device; use crate::properties::{AnimationDeclarations, ComputedValues, PropertyDeclarationBlock}; @@ -23,6 +22,7 @@ use crate::traversal_flags::TraversalFlags; use crate::values::AtomIdent; use crate::{LocalName, Namespace, WeakAtom}; use atomic_refcell::{AtomicRef, AtomicRefMut}; +use dom::ElementState; use selectors::matching::{QuirksMode, VisitedHandlingMode}; use selectors::sink::Push; use selectors::Element as SelectorsElement; diff --git a/servo/components/style/gecko/non_ts_pseudo_class_list.rs b/servo/components/style/gecko/non_ts_pseudo_class_list.rs index 672e8104fe70..d93fc95a509c 100644 --- a/servo/components/style/gecko/non_ts_pseudo_class_list.rs +++ b/servo/components/style/gecko/non_ts_pseudo_class_list.rs @@ -33,56 +33,56 @@ macro_rules! apply_non_ts_list { ("-moz-table-border-nonzero", MozTableBorderNonzero, _, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), ("-moz-browser-frame", MozBrowserFrame, _, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME), ("-moz-select-list-box", MozSelectListBox, _, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("link", Link, IN_UNVISITED_STATE, _), - ("any-link", AnyLink, IN_VISITED_OR_UNVISITED_STATE, _), - ("visited", Visited, IN_VISITED_STATE, _), - ("active", Active, IN_ACTIVE_STATE, _), - ("autofill", Autofill, IN_AUTOFILL_STATE, _), - ("checked", Checked, IN_CHECKED_STATE, _), - ("defined", Defined, IN_DEFINED_STATE, _), - ("disabled", Disabled, IN_DISABLED_STATE, _), - ("enabled", Enabled, IN_ENABLED_STATE, _), - ("focus", Focus, IN_FOCUS_STATE, _), - ("focus-within", FocusWithin, IN_FOCUS_WITHIN_STATE, _), - ("focus-visible", FocusVisible, IN_FOCUSRING_STATE, _), - ("hover", Hover, IN_HOVER_STATE, _), - ("-moz-drag-over", MozDragOver, IN_DRAGOVER_STATE, _), - ("target", Target, IN_TARGET_STATE, _), - ("indeterminate", Indeterminate, IN_INDETERMINATE_STATE, _), - ("-moz-inert", MozInert, IN_MOZINERT_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("-moz-devtools-highlighted", MozDevtoolsHighlighted, IN_DEVTOOLS_HIGHLIGHTED_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("-moz-styleeditor-transitioning", MozStyleeditorTransitioning, IN_STYLEEDITOR_TRANSITIONING_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("fullscreen", Fullscreen, IN_FULLSCREEN_STATE, _), - ("-moz-modal-dialog", MozModalDialog, IN_MODAL_DIALOG_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("-moz-topmost-modal", MozTopmostModal, IN_TOPMOST_MODAL_TOP_LAYER_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("-moz-broken", MozBroken, IN_BROKEN_STATE, _), - ("-moz-loading", MozLoading, IN_LOADING_STATE, _), - ("-moz-has-dir-attr", MozHasDirAttr, IN_HAS_DIR_ATTR_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("-moz-dir-attr-ltr", MozDirAttrLTR, IN_HAS_DIR_ATTR_LTR_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("-moz-dir-attr-rtl", MozDirAttrRTL, IN_HAS_DIR_ATTR_RTL_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("-moz-dir-attr-like-auto", MozDirAttrLikeAuto, IN_HAS_DIR_ATTR_LIKE_AUTO_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), + ("link", Link, UNVISITED, _), + ("any-link", AnyLink, VISITED_OR_UNVISITED, _), + ("visited", Visited, VISITED, _), + ("active", Active, ACTIVE, _), + ("autofill", Autofill, AUTOFILL, _), + ("checked", Checked, CHECKED, _), + ("defined", Defined, DEFINED, _), + ("disabled", Disabled, DISABLED, _), + ("enabled", Enabled, ENABLED, _), + ("focus", Focus, FOCUS, _), + ("focus-within", FocusWithin, FOCUS_WITHIN, _), + ("focus-visible", FocusVisible, FOCUSRING, _), + ("hover", Hover, HOVER, _), + ("-moz-drag-over", MozDragOver, DRAGOVER, _), + ("target", Target, URLTARGET, _), + ("indeterminate", Indeterminate, INDETERMINATE, _), + ("-moz-inert", MozInert, INERT, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), + ("-moz-devtools-highlighted", MozDevtoolsHighlighted, DEVTOOLS_HIGHLIGHTED, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), + ("-moz-styleeditor-transitioning", MozStyleeditorTransitioning, STYLEEDITOR_TRANSITIONING, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), + ("fullscreen", Fullscreen, FULLSCREEN, _), + ("-moz-modal-dialog", MozModalDialog, MODAL_DIALOG, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), + ("-moz-topmost-modal", MozTopmostModal, TOPMOST_MODAL, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), + ("-moz-broken", MozBroken, BROKEN, _), + ("-moz-loading", MozLoading, LOADING, _), + ("-moz-has-dir-attr", MozHasDirAttr, HAS_DIR_ATTR, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), + ("-moz-dir-attr-ltr", MozDirAttrLTR, HAS_DIR_ATTR_LTR, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), + ("-moz-dir-attr-rtl", MozDirAttrRTL, HAS_DIR_ATTR_RTL, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), + ("-moz-dir-attr-like-auto", MozDirAttrLikeAuto, HAS_DIR_ATTR_LIKE_AUTO, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("-moz-autofill-preview", MozAutofillPreview, IN_AUTOFILL_PREVIEW_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME), - ("-moz-value-empty", MozValueEmpty, IN_VALUE_EMPTY_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("-moz-revealed", MozRevealed, IN_REVEALED_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), + ("-moz-autofill-preview", MozAutofillPreview, AUTOFILL_PREVIEW, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME), + ("-moz-value-empty", MozValueEmpty, VALUE_EMPTY, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), + ("-moz-revealed", MozRevealed, REVEALED, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), - ("-moz-math-increment-script-level", MozMathIncrementScriptLevel, IN_INCREMENT_SCRIPT_LEVEL_STATE, _), + ("-moz-math-increment-script-level", MozMathIncrementScriptLevel, INCREMENT_SCRIPT_LEVEL, _), - ("required", Required, IN_REQUIRED_STATE, _), - ("optional", Optional, IN_OPTIONAL_STATE, _), - ("valid", Valid, IN_VALID_STATE, _), - ("invalid", Invalid, IN_INVALID_STATE, _), - ("in-range", InRange, IN_INRANGE_STATE, _), - ("out-of-range", OutOfRange, IN_OUTOFRANGE_STATE, _), - ("default", Default, IN_DEFAULT_STATE, _), - ("placeholder-shown", PlaceholderShown, IN_PLACEHOLDER_SHOWN_STATE, _), - ("read-only", ReadOnly, IN_READONLY_STATE, _), - ("read-write", ReadWrite, IN_READWRITE_STATE, _), - ("user-valid", UserValid, IN_MOZ_UI_VALID_STATE, _), - ("user-invalid", UserInvalid, IN_MOZ_UI_INVALID_STATE, _), - ("-moz-meter-optimum", MozMeterOptimum, IN_OPTIMUM_STATE, _), - ("-moz-meter-sub-optimum", MozMeterSubOptimum, IN_SUB_OPTIMUM_STATE, _), - ("-moz-meter-sub-sub-optimum", MozMeterSubSubOptimum, IN_SUB_SUB_OPTIMUM_STATE, _), + ("required", Required, REQUIRED, _), + ("optional", Optional, OPTIONAL_, _), + ("valid", Valid, VALID, _), + ("invalid", Invalid, INVALID, _), + ("in-range", InRange, INRANGE, _), + ("out-of-range", OutOfRange, OUTOFRANGE, _), + ("default", Default, DEFAULT, _), + ("placeholder-shown", PlaceholderShown, PLACEHOLDER_SHOWN, _), + ("read-only", ReadOnly, READONLY, _), + ("read-write", ReadWrite, READWRITE, _), + ("user-valid", UserValid, MOZ_UI_VALID, _), + ("user-invalid", UserInvalid, MOZ_UI_INVALID, _), + ("-moz-meter-optimum", MozMeterOptimum, OPTIMUM, _), + ("-moz-meter-sub-optimum", MozMeterSubOptimum, SUB_OPTIMUM, _), + ("-moz-meter-sub-sub-optimum", MozMeterSubSubOptimum, SUB_SUB_OPTIMUM, _), ("-moz-first-node", MozFirstNode, _, _), ("-moz-last-node", MozLastNode, _, _), diff --git a/servo/components/style/gecko/selector_parser.rs b/servo/components/style/gecko/selector_parser.rs index 7cfb01e27941..50de91d6c471 100644 --- a/servo/components/style/gecko/selector_parser.rs +++ b/servo/components/style/gecko/selector_parser.rs @@ -4,7 +4,6 @@ //! Gecko-specific bits for selector-parsing. -use crate::element_state::{DocumentState, ElementState}; use crate::gecko_bindings::structs::RawServoSelectorList; use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI}; use crate::invalidation::element::document_state::InvalidationMatchingData; @@ -14,6 +13,7 @@ use crate::string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; use crate::values::{AtomIdent, AtomString}; use cssparser::{BasicParseError, BasicParseErrorKind, Parser}; use cssparser::{CowRcStr, SourceLocation, ToCss, Token}; +use dom::{DocumentState, ElementState}; use selectors::parser::SelectorParseErrorKind; use selectors::SelectorList; use std::fmt; diff --git a/servo/components/style/gecko/snapshot.rs b/servo/components/style/gecko/snapshot.rs index 8ff794a4d8cd..84756406ed81 100644 --- a/servo/components/style/gecko/snapshot.rs +++ b/servo/components/style/gecko/snapshot.rs @@ -6,7 +6,6 @@ //! change in order to properly calculate restyle hints. use crate::dom::TElement; -use crate::element_state::ElementState; use crate::gecko::snapshot_helpers; use crate::gecko::wrapper::{GeckoElement, NamespaceConstraintHelpers}; use crate::gecko_bindings::bindings; @@ -19,6 +18,7 @@ use crate::string_cache::{Atom, Namespace}; use crate::values::{AtomIdent, AtomString}; use crate::LocalName; use crate::WeakAtom; +use dom::ElementState; use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator}; use selectors::attr::{CaseSensitivity, NamespaceConstraint}; diff --git a/servo/components/style/gecko/wrapper.rs b/servo/components/style/gecko/wrapper.rs index 9c37a5ef49d9..faa6ddbc49c9 100644 --- a/servo/components/style/gecko/wrapper.rs +++ b/servo/components/style/gecko/wrapper.rs @@ -19,7 +19,7 @@ use crate::author_styles::AuthorStyles; use crate::context::{PostAnimationTasks, QuirksMode, SharedStyleContext, UpdateAnimationsTasks}; use crate::data::ElementData; use crate::dom::{LayoutIterator, NodeInfo, OpaqueNode, TDocument, TElement, TNode, TShadowRoot}; -use crate::element_state::{DocumentState, ElementState}; +use dom::{DocumentState, ElementState}; use crate::font_metrics::{FontMetrics, FontMetricsOrientation, FontMetricsProvider}; use crate::gecko::data::GeckoStyleSheet; use crate::gecko::selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl}; @@ -737,14 +737,14 @@ impl<'le> GeckoElement<'le> { .as_node() .get_bool_flag(nsINode_BooleanFlag::ElementHasLockedStyleStates) { - return self.0.mState.mStates; + return self.0.mState.bits; } unsafe { Gecko_ElementState(self.0) } } #[inline] fn document_state(&self) -> DocumentState { - DocumentState::from_bits_truncate(self.as_node().owner_doc().0.mDocumentState.mStates) + DocumentState::from_bits_truncate(self.as_node().owner_doc().0.mDocumentState.bits) } #[inline] @@ -1471,7 +1471,7 @@ impl<'le> TElement for GeckoElement<'le> { } fn is_visited_link(&self) -> bool { - self.state().intersects(ElementState::IN_VISITED_STATE) + self.state().intersects(ElementState::VISITED) } /// This logic is duplicated in Gecko's nsINode::IsInNativeAnonymousSubtree. @@ -2242,8 +2242,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { #[inline] fn is_link(&self) -> bool { - self.state() - .intersects(ElementState::IN_VISITED_OR_UNVISITED_STATE) + self.state().intersects(ElementState::VISITED_OR_UNVISITED) } #[inline] diff --git a/servo/components/style/invalidation/element/document_state.rs b/servo/components/style/invalidation/element/document_state.rs index 358257feac0f..5b308cbdfa4d 100644 --- a/servo/components/style/invalidation/element/document_state.rs +++ b/servo/components/style/invalidation/element/document_state.rs @@ -5,12 +5,12 @@ //! An invalidation processor for style changes due to document state changes. use crate::dom::TElement; -use crate::element_state::DocumentState; use crate::invalidation::element::invalidation_map::Dependency; use crate::invalidation::element::invalidator::{DescendantInvalidationLists, InvalidationVector}; use crate::invalidation::element::invalidator::{Invalidation, InvalidationProcessor}; use crate::invalidation::element::state_and_attributes; use crate::stylist::CascadeData; +use dom::DocumentState; use selectors::matching::{MatchingContext, MatchingMode, QuirksMode, VisitedHandlingMode, NeedsSelectorFlags}; /// A struct holding the members necessary to invalidate document state diff --git a/servo/components/style/invalidation/element/element_wrapper.rs b/servo/components/style/invalidation/element/element_wrapper.rs index 84d0e5c351a3..b244f45d1c42 100644 --- a/servo/components/style/invalidation/element/element_wrapper.rs +++ b/servo/components/style/invalidation/element/element_wrapper.rs @@ -6,11 +6,11 @@ //! against a past state of the element. use crate::dom::TElement; -use crate::element_state::ElementState; use crate::selector_parser::{AttrValue, NonTSPseudoClass, PseudoElement, SelectorImpl}; use crate::selector_parser::{Snapshot, SnapshotMap}; use crate::values::AtomIdent; use crate::{CaseSensitivityExt, LocalName, Namespace, WeakAtom}; +use dom::ElementState; use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint}; use selectors::matching::{ElementSelectorFlags, MatchingContext}; use selectors::{Element, OpaqueElement}; @@ -252,7 +252,7 @@ where fn is_link(&self) -> bool { match self.snapshot().and_then(|s| s.state()) { - Some(state) => state.intersects(ElementState::IN_VISITED_OR_UNVISITED_STATE), + Some(state) => state.intersects(ElementState::VISITED_OR_UNVISITED), None => self.element.is_link(), } } diff --git a/servo/components/style/invalidation/element/invalidation_map.rs b/servo/components/style/invalidation/element/invalidation_map.rs index 0bba423a17fe..3783f2788021 100644 --- a/servo/components/style/invalidation/element/invalidation_map.rs +++ b/servo/components/style/invalidation/element/invalidation_map.rs @@ -5,13 +5,13 @@ //! Code for invalidations due to state or attribute changes. use crate::context::QuirksMode; -use crate::element_state::{DocumentState, ElementState}; use crate::selector_map::{ MaybeCaseInsensitiveHashMap, PrecomputedHashMap, SelectorMap, SelectorMapEntry, }; use crate::selector_parser::SelectorImpl; use crate::AllocErr; use crate::{Atom, LocalName, Namespace, ShrinkIfNeeded}; +use dom::{DocumentState, ElementState}; use selectors::attr::NamespaceConstraint; use selectors::parser::{Combinator, Component}; use selectors::parser::{Selector, SelectorIter}; diff --git a/servo/components/style/invalidation/element/state_and_attributes.rs b/servo/components/style/invalidation/element/state_and_attributes.rs index 1d02d52947b7..62642dec7615 100644 --- a/servo/components/style/invalidation/element/state_and_attributes.rs +++ b/servo/components/style/invalidation/element/state_and_attributes.rs @@ -8,7 +8,6 @@ use crate::context::SharedStyleContext; use crate::data::ElementData; use crate::dom::TElement; -use crate::element_state::ElementState; use crate::invalidation::element::element_wrapper::{ElementSnapshot, ElementWrapper}; use crate::invalidation::element::invalidation_map::*; use crate::invalidation::element::invalidator::{DescendantInvalidationLists, InvalidationVector}; @@ -18,6 +17,7 @@ use crate::selector_map::SelectorMap; use crate::selector_parser::Snapshot; use crate::stylesheets::origin::OriginSet; use crate::{Atom, WeakAtom}; +use dom::ElementState; use selectors::attr::CaseSensitivity; use selectors::matching::{matches_selector, MatchingContext, MatchingMode, VisitedHandlingMode, NeedsSelectorFlags}; use selectors::NthIndexCache; @@ -201,7 +201,7 @@ where // TODO(emilio): This piece of code should be removed when // layout.css.always-repaint-on-unvisited is true, since we cannot get // into this situation in that case. - if state_changes.contains(ElementState::IN_VISITED_OR_UNVISITED_STATE) { + if state_changes.contains(ElementState::VISITED_OR_UNVISITED) { trace!(" > visitedness change, force subtree restyle"); // We can't just return here because there may also be attribute // changes as well that imply additional hints for siblings. diff --git a/servo/components/style/lib.rs b/servo/components/style/lib.rs index 1e53b8a49bbd..c290047efae8 100644 --- a/servo/components/style/lib.rs +++ b/servo/components/style/lib.rs @@ -91,7 +91,6 @@ pub mod data; pub mod dom; pub mod dom_apis; pub mod driver; -pub mod element_state; #[cfg(feature = "servo")] mod encoding_support; pub mod error_reporting; diff --git a/servo/components/style/selector_parser.rs b/servo/components/style/selector_parser.rs index f29cab9735da..4586c33f4700 100644 --- a/servo/components/style/selector_parser.rs +++ b/servo/components/style/selector_parser.rs @@ -6,11 +6,11 @@ #![deny(missing_docs)] -use crate::element_state::ElementState; use crate::stylesheets::{Namespaces, Origin, UrlExtraData}; use crate::values::serialize_atom_identifier; use crate::Atom; use cssparser::{Parser as CssParser, ParserInput}; +use dom::ElementState; use selectors::parser::SelectorList; use std::fmt::{self, Debug, Write}; use style_traits::{CssWriter, ParseError, ToCss}; @@ -220,8 +220,8 @@ impl Direction { /// Gets the element state relevant to this :dir() selector. pub fn element_state(&self) -> ElementState { match self.as_horizontal_direction() { - Some(HorizontalDirection::Ltr) => ElementState::IN_LTR_STATE, - Some(HorizontalDirection::Rtl) => ElementState::IN_RTL_STATE, + Some(HorizontalDirection::Ltr) => ElementState::LTR, + Some(HorizontalDirection::Rtl) => ElementState::RTL, None => ElementState::empty(), } } diff --git a/servo/components/style/servo/selector_parser.rs b/servo/components/style/servo/selector_parser.rs index 996d3765b80c..f9504f85d4b5 100644 --- a/servo/components/style/servo/selector_parser.rs +++ b/servo/components/style/servo/selector_parser.rs @@ -8,7 +8,6 @@ use crate::attr::{AttrIdentifier, AttrValue}; use crate::dom::{OpaqueNode, TElement, TNode}; -use crate::element_state::{DocumentState, ElementState}; use crate::invalidation::element::document_state::InvalidationMatchingData; use crate::invalidation::element::element_wrapper::ElementSnapshot; use crate::properties::longhands::display::computed_value::T as Display; @@ -18,6 +17,7 @@ use crate::selector_parser::{PseudoElementCascadeType, SelectorParser}; use crate::values::{AtomIdent, AtomString}; use crate::{Atom, CaseSensitivityExt, LocalName, Namespace, Prefix}; use cssparser::{serialize_identifier, CowRcStr, Parser as CssParser, SourceLocation, ToCss}; +use dom::{DocumentState, ElementState}; use fxhash::FxHashMap; use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint}; use selectors::parser::SelectorParseErrorKind; diff --git a/servo/components/style/stylist.rs b/servo/components/style/stylist.rs index 03f11bc8d930..1c3062b65aa3 100644 --- a/servo/components/style/stylist.rs +++ b/servo/components/style/stylist.rs @@ -9,7 +9,6 @@ use crate::applicable_declarations::{ }; use crate::context::{CascadeInputs, QuirksMode}; use crate::dom::{TElement, TShadowRoot}; -use crate::element_state::{DocumentState, ElementState}; use crate::font_metrics::FontMetricsProvider; #[cfg(feature = "gecko")] use crate::gecko_bindings::structs::{ServoStyleSetSizes, StyleRuleInclusion}; @@ -43,6 +42,7 @@ use crate::stylesheets::{ use crate::stylesheets::{StyleRule, StylesheetContents, StylesheetInDocument}; use crate::AllocErr; use crate::{Atom, LocalName, Namespace, ShrinkIfNeeded, WeakAtom}; +use dom::{DocumentState, ElementState}; use fxhash::FxHashMap; use malloc_size_of::MallocSizeOf; #[cfg(feature = "gecko")] diff --git a/servo/ports/geckolib/Cargo.toml b/servo/ports/geckolib/Cargo.toml index f8f5a0e992d5..ee979c7b82b5 100644 --- a/servo/ports/geckolib/Cargo.toml +++ b/servo/ports/geckolib/Cargo.toml @@ -17,6 +17,7 @@ atomic_refcell = "0.1" bincode = "1.0" cssparser = "0.29" cstr = "0.2" +dom = { path = "../../../dom/base/rust" } gecko-profiler = { path = "../../../tools/profiler/rust-api" } libc = "0.2" log = {version = "0.4", features = ["release_max_level_info"]} diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 286fa413e8db..7b14d12916cd 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -7,6 +7,7 @@ use super::stylesheet_loader::{AsyncStylesheetParser, StylesheetLoader}; use bincode::{deserialize, serialize}; use cssparser::ToCss as ParserToCss; use cssparser::{ParseErrorKind, Parser, ParserInput, SourceLocation, UnicodeRange}; +use dom::{DocumentState, ElementState}; use malloc_size_of::MallocSizeOfOps; use nsstring::{nsCString, nsString}; use selectors::{NthIndexCache, SelectorList}; @@ -26,7 +27,6 @@ use style::counter_style; use style::data::{self, ElementStyles}; use style::dom::{ShowSubtreeData, TDocument, TElement, TNode}; use style::driver; -use style::element_state::{DocumentState, ElementState}; use style::error_reporting::{ContextualParseError, ParseErrorReporter}; use style::font_face::{self, ComputedFontStyleDescriptor, FontFaceSourceListComponent, Source}; use style::font_metrics::{get_metrics_provider_for_product, FontMetricsProvider}; diff --git a/servo/ports/geckolib/lib.rs b/servo/ports/geckolib/lib.rs index 05ee90808077..133c00bd2bad 100644 --- a/servo/ports/geckolib/lib.rs +++ b/servo/ports/geckolib/lib.rs @@ -6,6 +6,7 @@ extern crate bincode; extern crate cssparser; #[macro_use] extern crate cstr; +extern crate dom; #[macro_use] extern crate gecko_profiler; extern crate libc; diff --git a/taskcluster/ci/fetch/toolchains.yml b/taskcluster/ci/fetch/toolchains.yml index fd668168c52e..f9fd34baa929 100644 --- a/taskcluster/ci/fetch/toolchains.yml +++ b/taskcluster/ci/fetch/toolchains.yml @@ -245,12 +245,12 @@ wine: strip-components: 1 add-prefix: wine-source/ -cbindgen-0.23.0: +cbindgen-0.24.2: description: cbindgen source code fetch: type: git repo: https://github.com/eqrion/cbindgen - revision: 798cfab52bced65a749443faa16990ec3a8e0cfe + revision: 3d06ae1fc4984b82ada2d84ce74c7af06ffd499d cctools-port: description: cctools-port source code diff --git a/taskcluster/ci/toolchain/cbindgen.yml b/taskcluster/ci/toolchain/cbindgen.yml index 5be77f3c3d72..4d0425ea0533 100644 --- a/taskcluster/ci/toolchain/cbindgen.yml +++ b/taskcluster/ci/toolchain/cbindgen.yml @@ -16,7 +16,7 @@ job-defaults: fetch: # If you update this, make sure to update the minimum version in # build/moz.configure/bindgen.configure as well. - - cbindgen-0.23.0 + - cbindgen-0.24.2 linux64-cbindgen: treeherder: diff --git a/toolkit/actors/SelectChild.jsm b/toolkit/actors/SelectChild.jsm index 19df9a877438..8e192f13948f 100644 --- a/toolkit/actors/SelectChild.jsm +++ b/toolkit/actors/SelectChild.jsm @@ -23,8 +23,8 @@ ChromeUtils.defineModuleGetter( "resource://gre/modules/DeferredTask.jsm" ); -const kStateActive = 0x00000001; // NS_EVENT_STATE_ACTIVE -const kStateHover = 0x00000004; // NS_EVENT_STATE_HOVER +const kStateActive = 0x00000001; // ElementState::ACTIVE +const kStateHover = 0x00000004; // ElementState::HOVER // Duplicated in SelectParent.jsm // Please keep these lists in sync. diff --git a/toolkit/library/rust/shared/Cargo.toml b/toolkit/library/rust/shared/Cargo.toml index defceab74c3f..168f51dc02f8 100644 --- a/toolkit/library/rust/shared/Cargo.toml +++ b/toolkit/library/rust/shared/Cargo.toml @@ -68,6 +68,7 @@ regex-ffi = { path = "../../../components/regex-ffi" } rust_minidump_writer_linux = { path = "../../../crashreporter/rust_minidump_writer_linux", optional = true } gecko-profiler = { path = "../../../../tools/profiler/rust-api"} midir_impl = { path = "../../../../dom/midi/midir_impl", optional = true } +dom = { path = "../../../../dom/base/rust" } origin-trials-ffi = { path = "../../../../dom/origin-trials/ffi" } # Note: `modern_sqlite` means rusqlite's bindings file be for a sqlite with diff --git a/widget/ScrollbarDrawing.cpp b/widget/ScrollbarDrawing.cpp index af131c485002..f2360713ed65 100644 --- a/widget/ScrollbarDrawing.cpp +++ b/widget/ScrollbarDrawing.cpp @@ -55,17 +55,17 @@ bool ScrollbarDrawing::IsParentScrollbarRolledOver(nsIFrame* aFrame) { ? nsNativeTheme::CheckBooleanAttr(scrollbarFrame, nsGkAtoms::hover) : nsNativeTheme::GetContentState(scrollbarFrame, StyleAppearance::None) - .HasState(NS_EVENT_STATE_HOVER); + .HasState(ElementState::HOVER); } /*static*/ bool ScrollbarDrawing::IsParentScrollbarHoveredOrActive(nsIFrame* aFrame) { nsIFrame* scrollbarFrame = GetParentScrollbarFrame(aFrame); - return scrollbarFrame && scrollbarFrame->GetContent() - ->AsElement() - ->State() - .HasAtLeastOneOfStates(NS_EVENT_STATE_HOVER | - NS_EVENT_STATE_ACTIVE); + return scrollbarFrame && + scrollbarFrame->GetContent() + ->AsElement() + ->State() + .HasAtLeastOneOfStates(ElementState::HOVER | ElementState::ACTIVE); } /*static*/ @@ -112,7 +112,7 @@ bool ScrollbarDrawing::IsScrollbarTrackOpaque(nsIFrame* aFrame) { sRGBColor ScrollbarDrawing::ComputeScrollbarTrackColor( nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const Colors& aColors) { + const DocumentState& aDocumentState, const Colors& aColors) { if (aColors.HighContrast()) { return aColors.System(StyleSystemColor::Window); } @@ -126,10 +126,9 @@ sRGBColor ScrollbarDrawing::ComputeScrollbarTrackColor( static constexpr sRGBColor sDefaultTrackColor( gfx::sRGBColor::UnusualFromARGB(0xfff0f0f0)); - auto systemColor = - aDocumentState.HasAllStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE) - ? StyleSystemColor::ThemedScrollbarInactive - : StyleSystemColor::ThemedScrollbar; + auto systemColor = aDocumentState.HasAllStates(DocumentState::WINDOW_INACTIVE) + ? StyleSystemColor::ThemedScrollbarInactive + : StyleSystemColor::ThemedScrollbar; return aColors.SystemOrElse(systemColor, [&] { return aColors.IsDark() ? sDefaultDarkTrackColor : sDefaultTrackColor; }); @@ -140,7 +139,7 @@ sRGBColor ScrollbarDrawing::ComputeScrollbarTrackColor( // by default anyways. sRGBColor ScrollbarDrawing::ComputeScrollbarThumbColor( nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors) { const nsStyleUI* ui = aStyle.StyleUI(); if (ui->mScrollbarColor.IsColors()) { @@ -149,16 +148,16 @@ sRGBColor ScrollbarDrawing::ComputeScrollbarThumbColor( } auto systemColor = [&] { - if (aDocumentState.HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) { + if (aDocumentState.HasState(DocumentState::WINDOW_INACTIVE)) { return StyleSystemColor::ThemedScrollbarThumbInactive; } - if (aElementState.HasState(NS_EVENT_STATE_ACTIVE)) { + if (aElementState.HasState(ElementState::ACTIVE)) { if (aColors.HighContrast()) { return StyleSystemColor::Selecteditem; } return StyleSystemColor::ThemedScrollbarThumbActive; } - if (aElementState.HasState(NS_EVENT_STATE_HOVER)) { + if (aElementState.HasState(ElementState::HOVER)) { if (aColors.HighContrast()) { return StyleSystemColor::Selecteditem; } @@ -183,11 +182,11 @@ template bool ScrollbarDrawing::DoPaintDefaultScrollbar( PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { const bool overlay = aFrame->PresContext()->UseOverlayScrollbars(); - if (overlay && !aElementState.HasAtLeastOneOfStates(NS_EVENT_STATE_HOVER | - NS_EVENT_STATE_ACTIVE)) { + if (overlay && !aElementState.HasAtLeastOneOfStates(ElementState::HOVER | + ElementState::ACTIVE)) { return true; } const auto color = @@ -209,7 +208,7 @@ bool ScrollbarDrawing::DoPaintDefaultScrollbar( bool ScrollbarDrawing::PaintScrollbar( DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { return DoPaintDefaultScrollbar(aDrawTarget, aRect, aScrollbarKind, aFrame, aStyle, aElementState, aDocumentState, aColors, @@ -219,7 +218,7 @@ bool ScrollbarDrawing::PaintScrollbar( bool ScrollbarDrawing::PaintScrollbar( WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { return DoPaintDefaultScrollbar(aWrData, aRect, aScrollbarKind, aFrame, aStyle, aElementState, aDocumentState, aColors, @@ -230,7 +229,7 @@ template bool ScrollbarDrawing::DoPaintDefaultScrollCorner( PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const Colors& aColors, + const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { auto scrollbarColor = ComputeScrollbarTrackColor(aFrame, aStyle, aDocumentState, aColors); @@ -241,7 +240,7 @@ bool ScrollbarDrawing::DoPaintDefaultScrollCorner( bool ScrollbarDrawing::PaintScrollCorner( DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const Colors& aColors, + const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { return DoPaintDefaultScrollCorner(aDrawTarget, aRect, aScrollbarKind, aFrame, aStyle, aDocumentState, aColors, aDpiRatio); @@ -250,19 +249,19 @@ bool ScrollbarDrawing::PaintScrollCorner( bool ScrollbarDrawing::PaintScrollCorner( WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const Colors& aColors, + const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { return DoPaintDefaultScrollCorner(aWrData, aRect, aScrollbarKind, aFrame, aStyle, aDocumentState, aColors, aDpiRatio); } nscolor ScrollbarDrawing::GetScrollbarButtonColor(nscolor aTrackColor, - EventStates aStates) { + ElementState aStates) { // See numbers in GetScrollbarArrowColor. // This function is written based on ratios between values listed there. - bool isActive = aStates.HasState(NS_EVENT_STATE_ACTIVE); - bool isHover = aStates.HasState(NS_EVENT_STATE_HOVER); + bool isActive = aStates.HasState(ElementState::ACTIVE); + bool isHover = aStates.HasState(ElementState::HOVER); if (!isActive && !isHover) { return aTrackColor; } @@ -331,11 +330,11 @@ Maybe ScrollbarDrawing::GetScrollbarArrowColor(nscolor aButtonColor) { std::pair ScrollbarDrawing::ComputeScrollbarButtonColors( nsIFrame* aFrame, StyleAppearance aAppearance, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors) { if (aColors.HighContrast()) { - if (aElementState.HasAtLeastOneOfStates(NS_EVENT_STATE_ACTIVE | - NS_EVENT_STATE_HOVER)) { + if (aElementState.HasAtLeastOneOfStates(ElementState::ACTIVE | + ElementState::HOVER)) { return aColors.SystemPair(StyleSystemColor::Selecteditem, StyleSystemColor::Buttonface); } @@ -361,7 +360,7 @@ bool ScrollbarDrawing::PaintScrollbarButton( DrawTarget& aDrawTarget, StyleAppearance aAppearance, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio&) { auto [buttonColor, arrowColor] = ComputeScrollbarButtonColors( aFrame, aAppearance, aStyle, aElementState, aDocumentState, aColors); diff --git a/widget/ScrollbarDrawing.h b/widget/ScrollbarDrawing.h index 47fb0ec6f0e6..fa653d8b22f6 100644 --- a/widget/ScrollbarDrawing.h +++ b/widget/ScrollbarDrawing.h @@ -7,7 +7,7 @@ #ifndef mozilla_widget_ScrollbarDrawing_h #define mozilla_widget_ScrollbarDrawing_h -#include "mozilla/EventStates.h" +#include "mozilla/dom/RustTypes.h" #include "mozilla/gfx/2D.h" #include "nsColor.h" #include "nsITheme.h" @@ -20,7 +20,8 @@ namespace mozilla::widget { class ScrollbarDrawing { protected: using DPIRatio = mozilla::CSSToLayoutDeviceScale; - using EventStates = mozilla::EventStates; + using ElementState = dom::ElementState; + using DocumentState = dom::DocumentState; using DrawTarget = mozilla::gfx::DrawTarget; using sRGBColor = mozilla::gfx::sRGBColor; using Colors = ThemeColors; @@ -68,63 +69,55 @@ class ScrollbarDrawing { } bool IsScrollbarTrackOpaque(nsIFrame*); - virtual sRGBColor ComputeScrollbarTrackColor( - nsIFrame*, const ComputedStyle&, const EventStates& aDocumentState, - const Colors&); - virtual sRGBColor ComputeScrollbarThumbColor( - nsIFrame*, const ComputedStyle&, const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&); + virtual sRGBColor ComputeScrollbarTrackColor(nsIFrame*, const ComputedStyle&, + const DocumentState&, + const Colors&); + virtual sRGBColor ComputeScrollbarThumbColor(nsIFrame*, const ComputedStyle&, + const ElementState&, + const DocumentState&, + const Colors&); - nscolor GetScrollbarButtonColor(nscolor aTrackColor, EventStates); + nscolor GetScrollbarButtonColor(nscolor aTrackColor, ElementState); Maybe GetScrollbarArrowColor(nscolor aButtonColor); // Returned colors are button, arrow. virtual std::pair ComputeScrollbarButtonColors( - nsIFrame*, StyleAppearance, const ComputedStyle&, - const EventStates& aElementState, const EventStates& aDocumentState, - const Colors&); + nsIFrame*, StyleAppearance, const ComputedStyle&, const ElementState&, + const DocumentState&, const Colors&); virtual bool PaintScrollbarButton(DrawTarget&, StyleAppearance, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, + const ElementState&, const DocumentState&, const Colors&, const DPIRatio&); virtual bool PaintScrollbarThumb(DrawTarget&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, - const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, - const Colors&, const DPIRatio&) = 0; + const ComputedStyle&, const ElementState&, + const DocumentState&, const Colors&, + const DPIRatio&) = 0; virtual bool PaintScrollbarThumb(WebRenderBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, + const ElementState&, const DocumentState&, const Colors&, const DPIRatio&) = 0; template bool DoPaintDefaultScrollbar(PaintBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, - const DPIRatio&); + const ElementState&, const DocumentState&, + const Colors&, const DPIRatio&); bool PaintScrollbar(DrawTarget&, const LayoutDeviceRect&, ScrollbarKind, - nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, - const DPIRatio&); + nsIFrame*, const ComputedStyle&, const ElementState&, + const DocumentState&, const Colors&, const DPIRatio&); bool PaintScrollbar(WebRenderBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState&, const DocumentState&, const Colors&, const DPIRatio&); virtual bool PaintScrollbarTrack(DrawTarget&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, - const ComputedStyle&, - const EventStates& aDocumentState, + const ComputedStyle&, const DocumentState&, const Colors&, const DPIRatio&) { // Draw nothing by default. Subclasses can override this. return true; @@ -132,8 +125,8 @@ class ScrollbarDrawing { virtual bool PaintScrollbarTrack(WebRenderBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aDocumentState, - const Colors&, const DPIRatio&) { + const DocumentState&, const Colors&, + const DPIRatio&) { // Draw nothing by default. Subclasses can override this. return true; } @@ -141,17 +134,16 @@ class ScrollbarDrawing { template bool DoPaintDefaultScrollCorner(PaintBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, - const ComputedStyle&, - const EventStates& aDocumentState, + const ComputedStyle&, const DocumentState&, const Colors&, const DPIRatio&); virtual bool PaintScrollCorner(DrawTarget&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aDocumentState, - const Colors&, const DPIRatio&); + const DocumentState&, const Colors&, + const DPIRatio&); virtual bool PaintScrollCorner(WebRenderBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aDocumentState, - const Colors&, const DPIRatio&); + const DocumentState&, const Colors&, + const DPIRatio&); virtual void RecomputeScrollbarParams() = 0; diff --git a/widget/ScrollbarDrawingAndroid.cpp b/widget/ScrollbarDrawingAndroid.cpp index 1b6dc4407491..4c8addf35b69 100644 --- a/widget/ScrollbarDrawingAndroid.cpp +++ b/widget/ScrollbarDrawingAndroid.cpp @@ -37,7 +37,7 @@ template void ScrollbarDrawingAndroid::DoPaintScrollbarThumb( PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { // TODO(emilio): Maybe do like macOS and draw a stroke? const auto color = ComputeScrollbarThumbColor(aFrame, aStyle, aElementState, @@ -64,7 +64,7 @@ void ScrollbarDrawingAndroid::DoPaintScrollbarThumb( bool ScrollbarDrawingAndroid::PaintScrollbarThumb( DrawTarget& aDt, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { DoPaintScrollbarThumb(aDt, aRect, aScrollbarKind, aFrame, aStyle, aElementState, aDocumentState, aColors, aDpiRatio); @@ -74,7 +74,7 @@ bool ScrollbarDrawingAndroid::PaintScrollbarThumb( bool ScrollbarDrawingAndroid::PaintScrollbarThumb( WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { DoPaintScrollbarThumb(aWrData, aRect, aScrollbarKind, aFrame, aStyle, aElementState, aDocumentState, aColors, aDpiRatio); diff --git a/widget/ScrollbarDrawingAndroid.h b/widget/ScrollbarDrawingAndroid.h index c4e54b6b2aed..926aa76a80b3 100644 --- a/widget/ScrollbarDrawingAndroid.h +++ b/widget/ScrollbarDrawingAndroid.h @@ -27,20 +27,20 @@ class ScrollbarDrawingAndroid final : public ScrollbarDrawing { void DoPaintScrollbarThumb(PaintBackendData&, const LayoutDeviceRect& aRect, ScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&); bool PaintScrollbarThumb(DrawTarget&, const LayoutDeviceRect& aRect, ScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&) override; bool PaintScrollbarThumb(WebRenderBackendData&, const LayoutDeviceRect& aRect, ScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&) override; void RecomputeScrollbarParams() override; diff --git a/widget/ScrollbarDrawingCocoa.cpp b/widget/ScrollbarDrawingCocoa.cpp index 3454044bef84..18a79d23e3bb 100644 --- a/widget/ScrollbarDrawingCocoa.cpp +++ b/widget/ScrollbarDrawingCocoa.cpp @@ -386,7 +386,7 @@ template void ScrollbarDrawingCocoa::DoPaintScrollbarThumb( PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const DPIRatio& aDpiRatio) { ScrollbarParams params = ComputeScrollbarParams(aFrame, aStyle, aScrollbarKind); @@ -415,7 +415,7 @@ void ScrollbarDrawingCocoa::DoPaintScrollbarThumb( bool ScrollbarDrawingCocoa::PaintScrollbarThumb( DrawTarget& aDt, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors&, const DPIRatio& aDpiRatio) { // TODO: Maybe respect the UseSystemColors setting? DoPaintScrollbarThumb(aDt, aRect, aScrollbarKind, aFrame, aStyle, @@ -426,7 +426,7 @@ bool ScrollbarDrawingCocoa::PaintScrollbarThumb( bool ScrollbarDrawingCocoa::PaintScrollbarThumb( WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors&, const DPIRatio& aDpiRatio) { // TODO: Maybe respect the UseSystemColors setting? DoPaintScrollbarThumb(aWrData, aRect, aScrollbarKind, aFrame, aStyle, @@ -438,7 +438,7 @@ template void ScrollbarDrawingCocoa::DoPaintScrollbarTrack( PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const DPIRatio& aDpiRatio) { + const DocumentState& aDocumentState, const DPIRatio& aDpiRatio) { ScrollbarParams params = ComputeScrollbarParams(aFrame, aStyle, aScrollbarKind); ScrollbarTrackRects rects; @@ -453,7 +453,7 @@ void ScrollbarDrawingCocoa::DoPaintScrollbarTrack( bool ScrollbarDrawingCocoa::PaintScrollbarTrack( DrawTarget& aDt, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const Colors&, + const DocumentState& aDocumentState, const Colors&, const DPIRatio& aDpiRatio) { // TODO: Maybe respect the UseSystemColors setting? DoPaintScrollbarTrack(aDt, aRect, aScrollbarKind, aFrame, aStyle, @@ -464,7 +464,7 @@ bool ScrollbarDrawingCocoa::PaintScrollbarTrack( bool ScrollbarDrawingCocoa::PaintScrollbarTrack( WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const Colors&, + const DocumentState& aDocumentState, const Colors&, const DPIRatio& aDpiRatio) { // TODO: Maybe respect the UseSystemColors setting? DoPaintScrollbarTrack(aWrData, aRect, aScrollbarKind, aFrame, aStyle, @@ -476,7 +476,7 @@ template void ScrollbarDrawingCocoa::DoPaintScrollCorner( PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const DPIRatio& aDpiRatio) { + const DocumentState& aDocumentState, const DPIRatio& aDpiRatio) { ScrollbarParams params = ComputeScrollbarParams(aFrame, aStyle, aScrollbarKind); ScrollCornerRects rects; @@ -491,7 +491,7 @@ void ScrollbarDrawingCocoa::DoPaintScrollCorner( bool ScrollbarDrawingCocoa::PaintScrollCorner( DrawTarget& aDt, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const Colors&, + const DocumentState& aDocumentState, const Colors&, const DPIRatio& aDpiRatio) { // TODO: Maybe respect the UseSystemColors setting? DoPaintScrollCorner(aDt, aRect, aScrollbarKind, aFrame, aStyle, @@ -502,7 +502,7 @@ bool ScrollbarDrawingCocoa::PaintScrollCorner( bool ScrollbarDrawingCocoa::PaintScrollCorner( WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const Colors&, + const DocumentState& aDocumentState, const Colors&, const DPIRatio& aDpiRatio) { // TODO: Maybe respect the UseSystemColors setting? DoPaintScrollCorner(aWrData, aRect, aScrollbarKind, aFrame, aStyle, diff --git a/widget/ScrollbarDrawingCocoa.h b/widget/ScrollbarDrawingCocoa.h index f751bc0b2861..f1bb59d13a9f 100644 --- a/widget/ScrollbarDrawingCocoa.h +++ b/widget/ScrollbarDrawingCocoa.h @@ -34,46 +34,46 @@ class ScrollbarDrawingCocoa final : public ScrollbarDrawing { void DoPaintScrollbarThumb(PaintBackendData&, const LayoutDeviceRect& aRect, ScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, - const EventStates& aDocumentState, + const ElementState&, + const DocumentState&, const DPIRatio&); bool PaintScrollbarThumb(DrawTarget&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState&, + const DocumentState&, const Colors&, const DPIRatio&) override; bool PaintScrollbarThumb(WebRenderBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState&, + const DocumentState&, const Colors&, const DPIRatio&) override; template void DoPaintScrollbarTrack(PaintBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates&, const DPIRatio&); + const DocumentState&, const DPIRatio&); bool PaintScrollbarTrack(DrawTarget&, const LayoutDeviceRect& aRect, ScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const Colors&, + const DocumentState&, const Colors&, const DPIRatio&) override; bool PaintScrollbarTrack(WebRenderBackendData&, const LayoutDeviceRect& aRect, ScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const Colors&, + const DocumentState&, const Colors&, const DPIRatio&) override; template void DoPaintScrollCorner(PaintBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates&, const DPIRatio&); + const DocumentState&, const DPIRatio&); bool PaintScrollCorner(DrawTarget&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aDocumentState, const Colors&, + const DocumentState&, const Colors&, const DPIRatio&) override; bool PaintScrollCorner(WebRenderBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aDocumentState, const Colors&, + const DocumentState&, const Colors&, const DPIRatio&) override; void RecomputeScrollbarParams() override; diff --git a/widget/ScrollbarDrawingGTK.cpp b/widget/ScrollbarDrawingGTK.cpp index 355ecd623cf5..6877ed0c3b33 100644 --- a/widget/ScrollbarDrawingGTK.cpp +++ b/widget/ScrollbarDrawingGTK.cpp @@ -56,7 +56,7 @@ template bool ScrollbarDrawingGTK::DoPaintScrollbarThumb( PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { sRGBColor thumbColor = ComputeScrollbarThumbColor( aFrame, aStyle, aElementState, aDocumentState, aColors); @@ -99,7 +99,7 @@ bool ScrollbarDrawingGTK::DoPaintScrollbarThumb( bool ScrollbarDrawingGTK::PaintScrollbarThumb( DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { return DoPaintScrollbarThumb(aDrawTarget, aRect, aScrollbarKind, aFrame, aStyle, aElementState, aDocumentState, aColors, @@ -109,7 +109,7 @@ bool ScrollbarDrawingGTK::PaintScrollbarThumb( bool ScrollbarDrawingGTK::PaintScrollbarThumb( WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { return DoPaintScrollbarThumb(aWrData, aRect, aScrollbarKind, aFrame, aStyle, aElementState, aDocumentState, aColors, diff --git a/widget/ScrollbarDrawingGTK.h b/widget/ScrollbarDrawingGTK.h index 9fc05b4cc462..162997e127f5 100644 --- a/widget/ScrollbarDrawingGTK.h +++ b/widget/ScrollbarDrawingGTK.h @@ -27,19 +27,19 @@ class ScrollbarDrawingGTK final : public ScrollbarDrawing { template bool DoPaintScrollbarThumb(PaintBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&); bool PaintScrollbarThumb(DrawTarget&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle& aStyle, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&) override; bool PaintScrollbarThumb(WebRenderBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle& aStyle, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&) override; void RecomputeScrollbarParams() override; diff --git a/widget/ScrollbarDrawingWin.cpp b/widget/ScrollbarDrawingWin.cpp index 7019a27dafc1..6955d5527699 100644 --- a/widget/ScrollbarDrawingWin.cpp +++ b/widget/ScrollbarDrawingWin.cpp @@ -128,7 +128,7 @@ template bool ScrollbarDrawingWin::DoPaintScrollbarThumb( PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { sRGBColor thumbColor = ComputeScrollbarThumbColor( aFrame, aStyle, aElementState, aDocumentState, aColors); @@ -139,7 +139,7 @@ bool ScrollbarDrawingWin::DoPaintScrollbarThumb( bool ScrollbarDrawingWin::PaintScrollbarThumb( DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { return DoPaintScrollbarThumb(aDrawTarget, aRect, aScrollbarKind, aFrame, aStyle, aElementState, aDocumentState, aColors, @@ -149,7 +149,7 @@ bool ScrollbarDrawingWin::PaintScrollbarThumb( bool ScrollbarDrawingWin::PaintScrollbarThumb( WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { return DoPaintScrollbarThumb(aWrData, aRect, aScrollbarKind, aFrame, aStyle, aElementState, aDocumentState, aColors, diff --git a/widget/ScrollbarDrawingWin.h b/widget/ScrollbarDrawingWin.h index e3c704100d08..f44218d13e18 100644 --- a/widget/ScrollbarDrawingWin.h +++ b/widget/ScrollbarDrawingWin.h @@ -34,18 +34,18 @@ class ScrollbarDrawingWin : public ScrollbarDrawing { template bool DoPaintScrollbarThumb(PaintBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&); bool PaintScrollbarThumb(DrawTarget&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&) override; bool PaintScrollbarThumb(WebRenderBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&) override; void RecomputeScrollbarParams() override; diff --git a/widget/ScrollbarDrawingWin11.cpp b/widget/ScrollbarDrawingWin11.cpp index ff44035fd112..a1b9be351951 100644 --- a/widget/ScrollbarDrawingWin11.cpp +++ b/widget/ScrollbarDrawingWin11.cpp @@ -100,7 +100,7 @@ LayoutDeviceIntSize ScrollbarDrawingWin11::GetMinimumWidgetSize( sRGBColor ScrollbarDrawingWin11::ComputeScrollbarTrackColor( nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aDocumentState, const Colors& aColors) { + const DocumentState& aDocumentState, const Colors& aColors) { if (aColors.HighContrast()) { return ScrollbarDrawingWin::ComputeScrollbarTrackColor( aFrame, aStyle, aDocumentState, aColors); @@ -116,7 +116,7 @@ sRGBColor ScrollbarDrawingWin11::ComputeScrollbarTrackColor( sRGBColor ScrollbarDrawingWin11::ComputeScrollbarThumbColor( nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors) { if (aColors.HighContrast()) { return ScrollbarDrawingWin::ComputeScrollbarThumbColor( @@ -130,15 +130,15 @@ sRGBColor ScrollbarDrawingWin11::ComputeScrollbarThumbColor( return aColors.IsDark() ? NS_RGBA(149, 149, 149, 255) : NS_RGBA(133, 133, 133, 255); }(); - EventStates state = aElementState; + ElementState state = aElementState; if (!IsScrollbarWidthThin(aStyle)) { // non-thin scrollbars get hover feedback by changing thumb shape, so we // only provide active feedback (and we use the hover state for that as it's // more subtle). - state &= ~NS_EVENT_STATE_HOVER; - if (state.HasState(NS_EVENT_STATE_ACTIVE)) { - state &= ~NS_EVENT_STATE_ACTIVE; - state |= NS_EVENT_STATE_HOVER; + state &= ~ElementState::HOVER; + if (state.HasState(ElementState::ACTIVE)) { + state &= ~ElementState::ACTIVE; + state |= ElementState::HOVER; } } return sRGBColor::FromABGR( @@ -148,7 +148,7 @@ sRGBColor ScrollbarDrawingWin11::ComputeScrollbarThumbColor( std::pair ScrollbarDrawingWin11::ComputeScrollbarButtonColors( nsIFrame* aFrame, StyleAppearance aAppearance, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors) { if (aColors.HighContrast()) { return ScrollbarDrawingWin::ComputeScrollbarButtonColors( @@ -165,7 +165,7 @@ bool ScrollbarDrawingWin11::PaintScrollbarButton( DrawTarget& aDrawTarget, StyleAppearance aAppearance, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { if (!ScrollbarDrawing::IsParentScrollbarHoveredOrActive(aFrame)) { return true; @@ -215,10 +215,10 @@ bool ScrollbarDrawingWin11::PaintScrollbarButton( : float(kDefaultWinScrollbarSize); const int32_t arrowNumPoints = ArrayLength(arrowPolygonX); - if (aElementState.HasState(NS_EVENT_STATE_ACTIVE)) { + if (aElementState.HasState(ElementState::ACTIVE)) { arrowX = arrowPolygonXActive; arrowY = arrowPolygonYActive; - } else if (aElementState.HasState(NS_EVENT_STATE_HOVER)) { + } else if (aElementState.HasState(ElementState::HOVER)) { arrowX = arrowPolygonXHover; arrowY = arrowPolygonYHover; } @@ -262,7 +262,7 @@ template bool ScrollbarDrawingWin11::DoPaintScrollbarThumb( PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { sRGBColor thumbColor = ComputeScrollbarThumbColor( aFrame, aStyle, aElementState, aDocumentState, aColors); @@ -358,7 +358,7 @@ bool ScrollbarDrawingWin11::DoPaintScrollbarThumb( bool ScrollbarDrawingWin11::PaintScrollbarThumb( DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { return DoPaintScrollbarThumb(aDrawTarget, aRect, aScrollbarKind, aFrame, aStyle, aElementState, aDocumentState, aColors, @@ -368,7 +368,7 @@ bool ScrollbarDrawingWin11::PaintScrollbarThumb( bool ScrollbarDrawingWin11::PaintScrollbarThumb( WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors, const DPIRatio& aDpiRatio) { return DoPaintScrollbarThumb(aWrData, aRect, aScrollbarKind, aFrame, aStyle, aElementState, aDocumentState, aColors, diff --git a/widget/ScrollbarDrawingWin11.h b/widget/ScrollbarDrawingWin11.h index 329f3de9605d..49994cf86481 100644 --- a/widget/ScrollbarDrawingWin11.h +++ b/widget/ScrollbarDrawingWin11.h @@ -26,41 +26,41 @@ class ScrollbarDrawingWin11 final : public ScrollbarDrawingWin { nsIFrame* aFrame) override; sRGBColor ComputeScrollbarTrackColor(nsIFrame*, const ComputedStyle&, - const EventStates& aDocumentState, + const DocumentState& aDocumentState, const Colors&) override; sRGBColor ComputeScrollbarThumbColor(nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&) override; // Returned colors are button, arrow. std::pair ComputeScrollbarButtonColors( nsIFrame*, StyleAppearance, const ComputedStyle&, - const EventStates& aElementState, const EventStates& aDocumentState, + const ElementState& aElementState, const DocumentState& aDocumentState, const Colors&) override; bool PaintScrollbarButton(DrawTarget&, StyleAppearance, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&) override; template bool DoPaintScrollbarThumb(PaintBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&); bool PaintScrollbarThumb(DrawTarget&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&) override; bool PaintScrollbarThumb(WebRenderBackendData&, const LayoutDeviceRect&, ScrollbarKind, nsIFrame*, const ComputedStyle&, - const EventStates& aElementState, - const EventStates& aDocumentState, const Colors&, + const ElementState& aElementState, + const DocumentState& aDocumentState, const Colors&, const DPIRatio&) override; }; diff --git a/widget/Theme.cpp b/widget/Theme.cpp index 1175847fcf88..60a1238e0a65 100644 --- a/widget/Theme.cpp +++ b/widget/Theme.cpp @@ -212,15 +212,15 @@ static LayoutDeviceRect CheckBoxRadioRect(const LayoutDeviceRect& aRect) { } std::pair Theme::ComputeCheckboxColors( - const EventStates& aState, StyleAppearance aAppearance, + const ElementState& aState, StyleAppearance aAppearance, const Colors& aColors) { MOZ_ASSERT(aAppearance == StyleAppearance::Checkbox || aAppearance == StyleAppearance::Radio); - bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED); - bool isChecked = aState.HasState(NS_EVENT_STATE_CHECKED); + bool isDisabled = aState.HasState(ElementState::DISABLED); + bool isChecked = aState.HasState(ElementState::CHECKED); bool isIndeterminate = aAppearance == StyleAppearance::Checkbox && - aState.HasState(NS_EVENT_STATE_INDETERMINATE); + aState.HasState(ElementState::INDETERMINATE); if (isChecked || isIndeterminate) { if (isDisabled) { @@ -229,8 +229,8 @@ std::pair Theme::ComputeCheckboxColors( } bool isActive = - aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE); - bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER); + aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE); + bool isHovered = aState.HasState(ElementState::HOVER); const auto& color = isActive ? aColors.Accent().GetDarker() : isHovered ? aColors.Accent().GetDark() : aColors.Accent().Get(); @@ -240,29 +240,29 @@ std::pair Theme::ComputeCheckboxColors( return ComputeTextfieldColors(aState, aColors, OutlineCoversBorder::No); } -sRGBColor Theme::ComputeCheckmarkColor(const EventStates& aState, +sRGBColor Theme::ComputeCheckmarkColor(const ElementState& aState, const Colors& aColors) { if (aColors.HighContrast()) { return aColors.System(StyleSystemColor::Selecteditemtext); } - if (aState.HasState(NS_EVENT_STATE_DISABLED)) { + if (aState.HasState(ElementState::DISABLED)) { return sRGBColor::White(.8f); } return aColors.Accent().GetForeground(); } -sRGBColor Theme::ComputeBorderColor(const EventStates& aState, +sRGBColor Theme::ComputeBorderColor(const ElementState& aState, const Colors& aColors, OutlineCoversBorder aOutlineCoversBorder) { - bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED); + bool isDisabled = aState.HasState(ElementState::DISABLED); if (aColors.HighContrast()) { return aColors.System(isDisabled ? StyleSystemColor::Graytext : StyleSystemColor::Buttontext); } bool isActive = - aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE); - bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER); - bool isFocused = aState.HasState(NS_EVENT_STATE_FOCUSRING); + aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE); + bool isHovered = aState.HasState(ElementState::HOVER); + bool isFocused = aState.HasState(ElementState::FOCUSRING); if (isDisabled) { return sColorGrey40Alpha50; } @@ -286,11 +286,11 @@ sRGBColor Theme::ComputeBorderColor(const EventStates& aState, } std::pair Theme::ComputeButtonColors( - const EventStates& aState, const Colors& aColors, nsIFrame* aFrame) { + const ElementState& aState, const Colors& aColors, nsIFrame* aFrame) { bool isActive = - aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE); - bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED); - bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER); + aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE); + bool isDisabled = aState.HasState(ElementState::DISABLED); + bool isHovered = aState.HasState(ElementState::HOVER); nscolor backgroundColor = [&] { if (isDisabled) { @@ -305,7 +305,7 @@ std::pair Theme::ComputeButtonColors( return aColors.SystemNs(StyleSystemColor::Buttonface); }(); - if (aState.HasState(NS_EVENT_STATE_AUTOFILL)) { + if (aState.HasState(ElementState::AUTOFILL)) { backgroundColor = NS_ComposeColors( backgroundColor, aColors.SystemNs(StyleSystemColor::MozAutofillBackground)); @@ -317,16 +317,16 @@ std::pair Theme::ComputeButtonColors( } std::pair Theme::ComputeTextfieldColors( - const EventStates& aState, const Colors& aColors, + const ElementState& aState, const Colors& aColors, OutlineCoversBorder aOutlineCoversBorder) { nscolor backgroundColor = [&] { - if (aState.HasState(NS_EVENT_STATE_DISABLED)) { + if (aState.HasState(ElementState::DISABLED)) { return aColors.SystemNs(StyleSystemColor::MozDisabledfield); } return aColors.SystemNs(StyleSystemColor::Field); }(); - if (aState.HasState(NS_EVENT_STATE_AUTOFILL)) { + if (aState.HasState(ElementState::AUTOFILL)) { backgroundColor = NS_ComposeColors( backgroundColor, aColors.SystemNs(StyleSystemColor::MozAutofillBackground)); @@ -338,16 +338,16 @@ std::pair Theme::ComputeTextfieldColors( } std::pair Theme::ComputeRangeProgressColors( - const EventStates& aState, const Colors& aColors) { + const ElementState& aState, const Colors& aColors) { if (aColors.HighContrast()) { return aColors.SystemPair(StyleSystemColor::Selecteditem, StyleSystemColor::Buttontext); } bool isActive = - aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE); - bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED); - bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER); + aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE); + bool isDisabled = aState.HasState(ElementState::DISABLED); + bool isHovered = aState.HasState(ElementState::HOVER); if (isDisabled) { return std::make_pair(sColorGrey40Alpha50, sColorGrey40Alpha50); @@ -360,15 +360,15 @@ std::pair Theme::ComputeRangeProgressColors( } std::pair Theme::ComputeRangeTrackColors( - const EventStates& aState, const Colors& aColors) { + const ElementState& aState, const Colors& aColors) { if (aColors.HighContrast()) { return aColors.SystemPair(StyleSystemColor::Window, StyleSystemColor::Buttontext); } bool isActive = - aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE); - bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED); - bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER); + aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE); + bool isDisabled = aState.HasState(ElementState::DISABLED); + bool isHovered = aState.HasState(ElementState::HOVER); if (isDisabled) { return std::make_pair(sColorGrey10Alpha50, sColorGrey40Alpha50); @@ -380,16 +380,16 @@ std::pair Theme::ComputeRangeTrackColors( } std::pair Theme::ComputeRangeThumbColors( - const EventStates& aState, const Colors& aColors) { + const ElementState& aState, const Colors& aColors) { if (aColors.HighContrast()) { return aColors.SystemPair(StyleSystemColor::Selecteditemtext, StyleSystemColor::Selecteditem); } bool isActive = - aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE); - bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED); - bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER); + aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE); + bool isDisabled = aState.HasState(ElementState::DISABLED); + bool isHovered = aState.HasState(ElementState::HOVER); const sRGBColor& backgroundColor = [&] { if (isDisabled) { @@ -427,17 +427,17 @@ std::pair Theme::ComputeProgressTrackColors( } std::pair Theme::ComputeMeterchunkColors( - const EventStates& aMeterState, const Colors& aColors) { + const ElementState& aMeterState, const Colors& aColors) { if (aColors.HighContrast()) { return ComputeProgressColors(aColors); } sRGBColor borderColor = sColorMeterGreen20; sRGBColor chunkColor = sColorMeterGreen10; - if (aMeterState.HasState(NS_EVENT_STATE_SUB_OPTIMUM)) { + if (aMeterState.HasState(ElementState::SUB_OPTIMUM)) { borderColor = sColorMeterYellow20; chunkColor = sColorMeterYellow10; - } else if (aMeterState.HasState(NS_EVENT_STATE_SUB_SUB_OPTIMUM)) { + } else if (aMeterState.HasState(ElementState::SUB_SUB_OPTIMUM)) { borderColor = sColorMeterRed20; chunkColor = sColorMeterRed10; } @@ -510,7 +510,7 @@ void Theme::PaintRoundedFocusRect(PaintBackendData& aBackendData, void Theme::PaintCheckboxControl(DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, - const EventStates& aState, + const ElementState& aState, const Colors& aColors, DPIRatio aDpiRatio) { auto [backgroundColor, borderColor] = ComputeCheckboxColors(aState, StyleAppearance::Checkbox, aColors); @@ -525,13 +525,13 @@ void Theme::PaintCheckboxControl(DrawTarget& aDrawTarget, borderWidth, radius, aDpiRatio); } - if (aState.HasState(NS_EVENT_STATE_INDETERMINATE)) { + if (aState.HasState(ElementState::INDETERMINATE)) { PaintIndeterminateMark(aDrawTarget, aRect, aState, aColors); - } else if (aState.HasState(NS_EVENT_STATE_CHECKED)) { + } else if (aState.HasState(ElementState::CHECKED)) { PaintCheckMark(aDrawTarget, aRect, aState, aColors); } - if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) { + if (aState.HasState(ElementState::FOCUSRING)) { PaintRoundedFocusRect(aDrawTarget, aRect, aColors, aDpiRatio, 5.0f, 1.0f); } } @@ -542,7 +542,7 @@ constexpr CSSCoord kCheckboxRadioBorderBoxSize = void Theme::PaintCheckMark(DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, - const EventStates& aState, const Colors& aColors) { + const ElementState& aState, const Colors& aColors) { // Points come from the coordinates on a 14X14 (kCheckboxRadioBorderBoxSize) // unit box centered at 0,0 const float checkPolygonX[] = {-4.5f, -1.5f, -0.5f, 5.0f, 4.75f, @@ -569,7 +569,7 @@ void Theme::PaintCheckMark(DrawTarget& aDrawTarget, void Theme::PaintIndeterminateMark(DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, - const EventStates& aState, + const ElementState& aState, const Colors& aColors) { const CSSCoord borderWidth = 2.0f; const float scale = @@ -671,7 +671,7 @@ void Theme::PaintCircleShadow(DrawTarget& aDrawTarget, template void Theme::PaintRadioControl(PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, - const EventStates& aState, const Colors& aColors, + const ElementState& aState, const Colors& aColors, DPIRatio aDpiRatio) { auto [backgroundColor, borderColor] = ComputeCheckboxColors(aState, StyleAppearance::Radio, aColors); @@ -684,7 +684,7 @@ void Theme::PaintRadioControl(PaintBackendData& aPaintData, borderWidth, aDpiRatio); } - if (aState.HasState(NS_EVENT_STATE_CHECKED)) { + if (aState.HasState(ElementState::CHECKED)) { LayoutDeviceRect rect(aRect); auto width = LayoutDeviceCoord( ThemeDrawing::SnapBorderWidth(kCheckboxRadioBorderWidth, aDpiRatio)); @@ -695,7 +695,7 @@ void Theme::PaintRadioControl(PaintBackendData& aPaintData, kCheckboxRadioBorderWidth, aDpiRatio); } - if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) { + if (aState.HasState(ElementState::FOCUSRING)) { PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio, 5.0f, 1.0f); } } @@ -703,7 +703,7 @@ void Theme::PaintRadioControl(PaintBackendData& aPaintData, template void Theme::PaintTextField(PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, - const EventStates& aState, const Colors& aColors, + const ElementState& aState, const Colors& aColors, DPIRatio aDpiRatio) { auto [backgroundColor, borderColor] = ComputeTextfieldColors(aState, aColors, OutlineCoversBorder::Yes); @@ -714,7 +714,7 @@ void Theme::PaintTextField(PaintBackendData& aPaintData, borderColor, kTextFieldBorderWidth, radius, aDpiRatio); - if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) { + if (aState.HasState(ElementState::FOCUSRING)) { PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio, radius + kTextFieldBorderWidth, -kTextFieldBorderWidth); @@ -724,7 +724,7 @@ void Theme::PaintTextField(PaintBackendData& aPaintData, template void Theme::PaintListbox(PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, - const EventStates& aState, const Colors& aColors, + const ElementState& aState, const Colors& aColors, DPIRatio aDpiRatio) { const CSSCoord radius = 2.0f; auto [backgroundColor, borderColor] = @@ -734,7 +734,7 @@ void Theme::PaintListbox(PaintBackendData& aPaintData, borderColor, kMenulistBorderWidth, radius, aDpiRatio); - if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) { + if (aState.HasState(ElementState::FOCUSRING)) { PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio, radius + kMenulistBorderWidth, -kMenulistBorderWidth); } @@ -743,7 +743,7 @@ void Theme::PaintListbox(PaintBackendData& aPaintData, template void Theme::PaintMenulist(PaintBackendData& aDrawTarget, const LayoutDeviceRect& aRect, - const EventStates& aState, const Colors& aColors, + const ElementState& aState, const Colors& aColors, DPIRatio aDpiRatio) { const CSSCoord radius = 4.0f; auto [backgroundColor, borderColor] = ComputeButtonColors(aState, aColors); @@ -752,7 +752,7 @@ void Theme::PaintMenulist(PaintBackendData& aDrawTarget, borderColor, kMenulistBorderWidth, radius, aDpiRatio); - if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) { + if (aState.HasState(ElementState::FOCUSRING)) { PaintRoundedFocusRect(aDrawTarget, aRect, aColors, aDpiRatio, radius + kMenulistBorderWidth, -kMenulistBorderWidth); } @@ -760,7 +760,7 @@ void Theme::PaintMenulist(PaintBackendData& aDrawTarget, void Theme::PaintMenulistArrowButton(nsIFrame* aFrame, DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, - const EventStates& aState) { + const ElementState& aState) { // not const: these may be negated in-place below float polygonX[] = {-4.0f, -0.5f, 0.5f, 4.0f, 4.0f, 3.0f, 0.0f, 0.0f, -3.0f, -4.0f}; @@ -802,7 +802,7 @@ void Theme::PaintMenulistArrowButton(nsIFrame* aFrame, DrawTarget& aDrawTarget, void Theme::PaintSpinnerButton(nsIFrame* aFrame, DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, - const EventStates& aState, + const ElementState& aState, StyleAppearance aAppearance, const Colors& aColors, DPIRatio aDpiRatio) { auto [backgroundColor, borderColor] = ComputeButtonColors(aState, aColors); @@ -828,9 +828,9 @@ void Theme::PaintSpinnerButton(nsIFrame* aFrame, DrawTarget& aDrawTarget, template void Theme::PaintRange(nsIFrame* aFrame, PaintBackendData& aPaintData, - const LayoutDeviceRect& aRect, const EventStates& aState, - const Colors& aColors, DPIRatio aDpiRatio, - bool aHorizontal) { + const LayoutDeviceRect& aRect, + const ElementState& aState, const Colors& aColors, + DPIRatio aDpiRatio, bool aHorizontal) { nsRangeFrame* rangeFrame = do_QueryFrame(aFrame); if (!rangeFrame) { return; @@ -888,7 +888,7 @@ void Theme::PaintRange(nsIFrame* aFrame, PaintBackendData& aPaintData, trackColor, trackBorderColor, borderWidth, radius, aDpiRatio); - if (!aState.HasState(NS_EVENT_STATE_DISABLED)) { + if (!aState.HasState(ElementState::DISABLED)) { // Ensure the shadow doesn't expand outside of our overflow rect declared in // GetWidgetOverflow(). auto overflowRect = aRect; @@ -906,7 +906,7 @@ void Theme::PaintRange(nsIFrame* aFrame, PaintBackendData& aPaintData, PaintStrokedCircle(aPaintData, thumbRect, thumbColor, thumbBorderColor, thumbBorderWidth, aDpiRatio); - if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) { + if (aState.HasState(ElementState::FOCUSRING)) { PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio, radius, 1.0f); } } @@ -914,7 +914,7 @@ void Theme::PaintRange(nsIFrame* aFrame, PaintBackendData& aPaintData, template void Theme::PaintProgress(nsIFrame* aFrame, PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, - const EventStates& aState, const Colors& aColors, + const ElementState& aState, const Colors& aColors, DPIRatio aDpiRatio, bool aIsMeter) { const CSSCoord borderWidth = 1.0f; const CSSCoord radius = aIsMeter ? 6.0f : 3.0f; @@ -944,7 +944,7 @@ void Theme::PaintProgress(nsIFrame* aFrame, PaintBackendData& aPaintData, // Now paint the chunk, clipped as needed. LayoutDeviceRect clipRect = rect; - if (aState.HasState(NS_EVENT_STATE_INDETERMINATE)) { + if (aState.HasState(ElementState::INDETERMINATE)) { // For indeterminate progress, we paint an animated chunk of 1/3 of the // progress size. // @@ -1011,7 +1011,7 @@ void Theme::PaintProgress(nsIFrame* aFrame, PaintBackendData& aPaintData, template void Theme::PaintButton(nsIFrame* aFrame, PaintBackendData& aPaintData, const LayoutDeviceRect& aRect, - const EventStates& aState, const Colors& aColors, + const ElementState& aState, const Colors& aColors, DPIRatio aDpiRatio) { const CSSCoord radius = 4.0f; auto [backgroundColor, borderColor] = @@ -1021,7 +1021,7 @@ void Theme::PaintButton(nsIFrame* aFrame, PaintBackendData& aPaintData, borderColor, kButtonBorderWidth, radius, aDpiRatio); - if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) { + if (aState.HasState(ElementState::FOCUSRING)) { PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio, radius + kButtonBorderWidth, -kButtonBorderWidth); } @@ -1099,8 +1099,8 @@ bool Theme::DoDrawWidgetBackground(PaintBackendData& aPaintData, const nscoord twipsPerPixel = pc->AppUnitsPerDevPixel(); const auto devPxRect = ToSnappedRect(aRect, twipsPerPixel, aPaintData); - const EventStates docState = pc->Document()->GetDocumentState(); - EventStates eventState = GetContentState(aFrame, aAppearance); + const DocumentState docState = pc->Document()->GetDocumentState(); + ElementState eventState = GetContentState(aFrame, aAppearance); if (aAppearance == StyleAppearance::MozMenulistArrowButton) { bool isHTML = IsHTMLContent(aFrame); nsIFrame* parentFrame = aFrame->GetParent(); @@ -1117,9 +1117,9 @@ bool Theme::DoDrawWidgetBackground(PaintBackendData& aPaintData, // outline-style: auto. if (aDrawOverflow == DrawOverflow::Yes && aFrame->StyleOutline()->mOutlineStyle.IsAuto()) { - eventState |= NS_EVENT_STATE_FOCUSRING; + eventState |= ElementState::FOCUSRING; } else { - eventState &= ~NS_EVENT_STATE_FOCUSRING; + eventState &= ~ElementState::FOCUSRING; } // Hack to avoid skia fuzziness: Add a dummy clip if the widget doesn't @@ -1128,7 +1128,7 @@ bool Theme::DoDrawWidgetBackground(PaintBackendData& aPaintData, if constexpr (std::is_same_v) { if (aAppearance != StyleAppearance::FocusOutline && aAppearance != StyleAppearance::Range && - !eventState.HasState(NS_EVENT_STATE_FOCUSRING)) { + !eventState.HasState(ElementState::FOCUSRING)) { maybeClipRect.emplace(aPaintData, devPxRect); } } diff --git a/widget/Theme.h b/widget/Theme.h index 869a924d95d1..7045d5f71af6 100644 --- a/widget/Theme.h +++ b/widget/Theme.h @@ -31,6 +31,7 @@ class Theme : protected nsNativeTheme, public nsITheme { using RectCornerRadii = gfx::RectCornerRadii; using Colors = ThemeColors; using AccentColor = ThemeAccentColor; + using ElementState = dom::ElementState; public: explicit Theme(UniquePtr&& aScrollbarDrawing) @@ -103,30 +104,30 @@ class Theme : protected nsNativeTheme, public nsITheme { static DPIRatio GetDPIRatio(nsPresContext*, StyleAppearance); static DPIRatio GetDPIRatio(nsIFrame*, StyleAppearance); - std::pair ComputeCheckboxColors(const EventStates&, + std::pair ComputeCheckboxColors(const ElementState&, StyleAppearance, const Colors&); - sRGBColor ComputeCheckmarkColor(const EventStates&, const Colors&); + sRGBColor ComputeCheckmarkColor(const ElementState&, const Colors&); enum class OutlineCoversBorder : bool { No, Yes }; - sRGBColor ComputeBorderColor(const EventStates&, const Colors&, + sRGBColor ComputeBorderColor(const ElementState&, const Colors&, OutlineCoversBorder); - std::pair ComputeButtonColors(const EventStates&, + std::pair ComputeButtonColors(const ElementState&, const Colors&, nsIFrame* = nullptr); - std::pair ComputeTextfieldColors(const EventStates&, + std::pair ComputeTextfieldColors(const ElementState&, const Colors&, OutlineCoversBorder); - std::pair ComputeRangeProgressColors(const EventStates&, - const Colors&); - std::pair ComputeRangeTrackColors(const EventStates&, + std::pair ComputeRangeProgressColors( + const ElementState&, const Colors&); + std::pair ComputeRangeTrackColors(const ElementState&, const Colors&); - std::pair ComputeRangeThumbColors(const EventStates&, + std::pair ComputeRangeThumbColors(const ElementState&, const Colors&); std::pair ComputeProgressColors(const Colors&); std::pair ComputeProgressTrackColors(const Colors&); std::pair ComputeMeterchunkColors( - const EventStates& aMeterState, const Colors&); + const ElementState& aMeterState, const Colors&); std::array ComputeFocusRectColors(const Colors&); template @@ -138,11 +139,11 @@ class Theme : protected nsNativeTheme, public nsITheme { const LayoutDeviceRect&, const Colors&, DPIRatio); void PaintCheckboxControl(DrawTarget& aDrawTarget, const LayoutDeviceRect&, - const EventStates&, const Colors&, DPIRatio); - void PaintCheckMark(DrawTarget&, const LayoutDeviceRect&, const EventStates&, + const ElementState&, const Colors&, DPIRatio); + void PaintCheckMark(DrawTarget&, const LayoutDeviceRect&, const ElementState&, const Colors&); void PaintIndeterminateMark(DrawTarget&, const LayoutDeviceRect&, - const EventStates&, const Colors&); + const ElementState&, const Colors&); template void PaintStrokedCircle(PaintBackendData&, const LayoutDeviceRect&, @@ -160,35 +161,35 @@ class Theme : protected nsNativeTheme, public nsITheme { CSSCoord aShadowBlurStdDev, DPIRatio); template void PaintRadioControl(PaintBackendData&, const LayoutDeviceRect&, - const EventStates&, const Colors&, DPIRatio); + const ElementState&, const Colors&, DPIRatio); template void PaintRadioCheckmark(PaintBackendData&, const LayoutDeviceRect&, - const EventStates&, DPIRatio); + const ElementState&, DPIRatio); template void PaintTextField(PaintBackendData&, const LayoutDeviceRect&, - const EventStates&, const Colors&, DPIRatio); + const ElementState&, const Colors&, DPIRatio); template void PaintListbox(PaintBackendData&, const LayoutDeviceRect&, - const EventStates&, const Colors&, DPIRatio); + const ElementState&, const Colors&, DPIRatio); template void PaintMenulist(PaintBackendData&, const LayoutDeviceRect&, - const EventStates&, const Colors&, DPIRatio); + const ElementState&, const Colors&, DPIRatio); void PaintMenulistArrowButton(nsIFrame*, DrawTarget&, const LayoutDeviceRect&, - const EventStates&); + const ElementState&); void PaintSpinnerButton(nsIFrame*, DrawTarget&, const LayoutDeviceRect&, - const EventStates&, StyleAppearance, const Colors&, + const ElementState&, StyleAppearance, const Colors&, DPIRatio); template void PaintRange(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&, - const EventStates&, const Colors&, DPIRatio, + const ElementState&, const Colors&, DPIRatio, bool aHorizontal); template void PaintProgress(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&, - const EventStates&, const Colors&, DPIRatio, + const ElementState&, const Colors&, DPIRatio, bool aIsMeter); template void PaintButton(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&, - const EventStates&, const Colors&, DPIRatio); + const ElementState&, const Colors&, DPIRatio); static void PrefChangedCallback(const char*, void*) { LookAndFeel::NotifyChangedAllWindows(ThemeChangeKind::Layout); diff --git a/widget/ThemeColors.cpp b/widget/ThemeColors.cpp index 8f449a23e053..06f1aaffc38c 100644 --- a/widget/ThemeColors.cpp +++ b/widget/ThemeColors.cpp @@ -238,7 +238,7 @@ nscolor ThemeColors::ComputeCustomAccentForeground(nscolor aColor) { } nscolor ThemeColors::AdjustUnthemedScrollbarThumbColor(nscolor aFaceColor, - EventStates aStates) { + ElementState aStates) { // In Windows 10, scrollbar thumb has the following colors: // // State | Color | Luminance @@ -248,8 +248,8 @@ nscolor ThemeColors::AdjustUnthemedScrollbarThumbColor(nscolor aFaceColor, // Active | Gray 96 | 11.7% // // This function is written based on the ratios between the values. - bool isActive = aStates.HasState(NS_EVENT_STATE_ACTIVE); - bool isHover = aStates.HasState(NS_EVENT_STATE_HOVER); + bool isActive = aStates.HasState(ElementState::ACTIVE); + bool isHover = aStates.HasState(ElementState::HOVER); if (!isActive && !isHover) { return aFaceColor; } diff --git a/widget/ThemeColors.h b/widget/ThemeColors.h index 2e8335525413..3c324f0453d4 100644 --- a/widget/ThemeColors.h +++ b/widget/ThemeColors.h @@ -103,7 +103,7 @@ class ThemeColors { static nscolor ComputeCustomAccentForeground(nscolor aColor); static nscolor AdjustUnthemedScrollbarThumbColor(nscolor aFaceColor, - EventStates aStates); + dom::ElementState aStates); }; } // namespace mozilla::widget diff --git a/widget/cocoa/nsNativeThemeCocoa.h b/widget/cocoa/nsNativeThemeCocoa.h index 2e08a572f027..993df5b763ea 100644 --- a/widget/cocoa/nsNativeThemeCocoa.h +++ b/widget/cocoa/nsNativeThemeCocoa.h @@ -13,6 +13,7 @@ #include "nsITheme.h" #include "ThemeCocoa.h" +#include "mozilla/dom/RustTypes.h" @class MOZCellDrawWindow; @class MOZCellDrawView; @@ -22,7 +23,6 @@ class nsDeviceContext; struct SegmentedControlRenderSettings; namespace mozilla { -class EventStates; namespace gfx { class DrawTarget; } // namespace gfx @@ -341,21 +341,21 @@ class nsNativeThemeCocoa : public mozilla::widget::ThemeCocoa { LayoutDeviceIntMargin DirectionAwareMargin(const LayoutDeviceIntMargin& aMargin, nsIFrame* aFrame); nsIFrame* SeparatorResponsibility(nsIFrame* aBefore, nsIFrame* aAfter); - ControlParams ComputeControlParams(nsIFrame* aFrame, mozilla::EventStates aEventState); - MenuIconParams ComputeMenuIconParams(nsIFrame* aParams, mozilla::EventStates aEventState, + ControlParams ComputeControlParams(nsIFrame* aFrame, mozilla::dom::ElementState aEventState); + MenuIconParams ComputeMenuIconParams(nsIFrame* aParams, mozilla::dom::ElementState aEventState, MenuIcon aIcon); - MenuItemParams ComputeMenuItemParams(nsIFrame* aFrame, mozilla::EventStates aEventState, + MenuItemParams ComputeMenuItemParams(nsIFrame* aFrame, mozilla::dom::ElementState aEventState, bool aIsChecked); - SegmentParams ComputeSegmentParams(nsIFrame* aFrame, mozilla::EventStates aEventState, + SegmentParams ComputeSegmentParams(nsIFrame* aFrame, mozilla::dom::ElementState aEventState, SegmentType aSegmentType); - TextFieldParams ComputeTextFieldParams(nsIFrame* aFrame, mozilla::EventStates aEventState); - ProgressParams ComputeProgressParams(nsIFrame* aFrame, mozilla::EventStates aEventState, + TextFieldParams ComputeTextFieldParams(nsIFrame* aFrame, mozilla::dom::ElementState aEventState); + ProgressParams ComputeProgressParams(nsIFrame* aFrame, mozilla::dom::ElementState aEventState, bool aIsHorizontal); MeterParams ComputeMeterParams(nsIFrame* aFrame); TreeHeaderCellParams ComputeTreeHeaderCellParams(nsIFrame* aFrame, - mozilla::EventStates aEventState); + mozilla::dom::ElementState aEventState); mozilla::Maybe ComputeHTMLScaleParams(nsIFrame* aFrame, - mozilla::EventStates aEventState); + mozilla::dom::ElementState aEventState); // HITheme drawing routines void DrawMeter(CGContextRef context, const HIRect& inBoxRect, const MeterParams& aParams); diff --git a/widget/cocoa/nsNativeThemeCocoa.mm b/widget/cocoa/nsNativeThemeCocoa.mm index 00512c4c328e..20068b6c8742 100644 --- a/widget/cocoa/nsNativeThemeCocoa.mm +++ b/widget/cocoa/nsNativeThemeCocoa.mm @@ -31,7 +31,6 @@ #include "nsNativeThemeColors.h" #include "nsIScrollableFrame.h" #include "mozilla/ClearOnShutdown.h" -#include "mozilla/EventStates.h" #include "mozilla/Range.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/HTMLMeterElement.h" @@ -982,13 +981,13 @@ static bool IsInsideToolbar(nsIFrame* aFrame) { } nsNativeThemeCocoa::TextFieldParams nsNativeThemeCocoa::ComputeTextFieldParams( - nsIFrame* aFrame, EventStates aEventState) { + nsIFrame* aFrame, ElementState aEventState) { TextFieldParams params; params.insideToolbar = IsInsideToolbar(aFrame); - params.disabled = aEventState.HasState(NS_EVENT_STATE_DISABLED); + params.disabled = aEventState.HasState(ElementState::DISABLED); // See ShouldUnconditionallyDrawFocusRingIfFocused. - params.focused = aEventState.HasState(NS_EVENT_STATE_FOCUS); + params.focused = aEventState.HasState(ElementState::FOCUS); params.rtl = IsFrameRTL(aFrame); params.verticalAlignFactor = VerticalAlignFactor(aFrame); @@ -1066,8 +1065,8 @@ NSSize nsNativeThemeCocoa::GetMenuIconSize(MenuIcon aIcon) { } nsNativeThemeCocoa::MenuIconParams nsNativeThemeCocoa::ComputeMenuIconParams( - nsIFrame* aFrame, EventStates aEventState, MenuIcon aIcon) { - bool isDisabled = aEventState.HasState(NS_EVENT_STATE_DISABLED); + nsIFrame* aFrame, ElementState aEventState, MenuIcon aIcon) { + bool isDisabled = aEventState.HasState(ElementState::DISABLED); MenuIconParams params; params.icon = aIcon; @@ -1115,8 +1114,8 @@ void nsNativeThemeCocoa::DrawMenuIcon(CGContextRef cgContext, const CGRect& aRec } nsNativeThemeCocoa::MenuItemParams nsNativeThemeCocoa::ComputeMenuItemParams( - nsIFrame* aFrame, EventStates aEventState, bool aIsChecked) { - bool isDisabled = aEventState.HasState(NS_EVENT_STATE_DISABLED); + nsIFrame* aFrame, ElementState aEventState, bool aIsChecked) { + bool isDisabled = aEventState.HasState(ElementState::DISABLED); MenuItemParams params; params.checked = aIsChecked; @@ -1181,13 +1180,13 @@ static bool ShouldUnconditionallyDrawFocusRingIfFocused(nsIFrame* aFrame) { } nsNativeThemeCocoa::ControlParams nsNativeThemeCocoa::ComputeControlParams( - nsIFrame* aFrame, EventStates aEventState) { + nsIFrame* aFrame, ElementState aEventState) { ControlParams params; - params.disabled = aEventState.HasState(NS_EVENT_STATE_DISABLED); + params.disabled = aEventState.HasState(ElementState::DISABLED); params.insideActiveWindow = FrameIsInActiveWindow(aFrame); - params.pressed = aEventState.HasAllStates(NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER); - params.focused = aEventState.HasState(NS_EVENT_STATE_FOCUS) && - (aEventState.HasState(NS_EVENT_STATE_FOCUSRING) || + params.pressed = aEventState.HasAllStates(ElementState::ACTIVE | ElementState::HOVER); + params.focused = aEventState.HasState(ElementState::FOCUS) && + (aEventState.HasState(ElementState::FOCUSRING) || ShouldUnconditionallyDrawFocusRingIfFocused(aFrame)); params.rtl = IsFrameRTL(aFrame); return params; @@ -1459,7 +1458,7 @@ void nsNativeThemeCocoa::DrawButton(CGContextRef cgContext, const HIRect& inBoxR } nsNativeThemeCocoa::TreeHeaderCellParams nsNativeThemeCocoa::ComputeTreeHeaderCellParams( - nsIFrame* aFrame, EventStates aEventState) { + nsIFrame* aFrame, ElementState aEventState) { TreeHeaderCellParams params; params.controlParams = ComputeControlParams(aFrame, aEventState); params.sortDirection = GetTreeSortDirection(aFrame); @@ -1768,13 +1767,13 @@ static const CellRenderSettings progressSettings[2][2] = { }}}}}; nsNativeThemeCocoa::ProgressParams nsNativeThemeCocoa::ComputeProgressParams( - nsIFrame* aFrame, EventStates aEventState, bool aIsHorizontal) { + nsIFrame* aFrame, ElementState aEventState, bool aIsHorizontal) { ProgressParams params; params.value = GetProgressValue(aFrame); params.max = GetProgressMaxValue(aFrame); params.verticalAlignFactor = VerticalAlignFactor(aFrame); params.insideActiveWindow = FrameIsInActiveWindow(aFrame); - params.indeterminate = aEventState.HasState(NS_EVENT_STATE_INDETERMINATE); + params.indeterminate = aEventState.HasState(ElementState::INDETERMINATE); params.horizontal = aIsHorizontal; params.rtl = IsFrameRTL(aFrame); return params; @@ -1833,10 +1832,10 @@ nsNativeThemeCocoa::MeterParams nsNativeThemeCocoa::ComputeMeterParams(nsIFrame* params.value = meterElement->Value(); params.min = meterElement->Min(); params.max = meterElement->Max(); - EventStates states = meterElement->State(); - if (states.HasState(NS_EVENT_STATE_SUB_OPTIMUM)) { + ElementState states = meterElement->State(); + if (states.HasState(ElementState::SUB_OPTIMUM)) { params.optimumState = OptimumState::eSubOptimum; - } else if (states.HasState(NS_EVENT_STATE_SUB_SUB_OPTIMUM)) { + } else if (states.HasState(ElementState::SUB_SUB_OPTIMUM)) { params.optimumState = OptimumState::eSubSubOptimum; } params.horizontal = !IsVerticalMeter(aFrame); @@ -1934,7 +1933,7 @@ void nsNativeThemeCocoa::DrawTabPanel(CGContextRef cgContext, const HIRect& inBo } Maybe nsNativeThemeCocoa::ComputeHTMLScaleParams( - nsIFrame* aFrame, EventStates aEventState) { + nsIFrame* aFrame, ElementState aEventState) { nsRangeFrame* rangeFrame = do_QueryFrame(aFrame); if (!rangeFrame) { return Nothing(); @@ -1950,8 +1949,8 @@ Maybe nsNativeThemeCocoa::ComputeHTMLScaleParam params.max = 1000; params.reverse = !isHorizontal || rangeFrame->IsRightToLeft(); params.insideActiveWindow = FrameIsInActiveWindow(aFrame); - params.focused = aEventState.HasState(NS_EVENT_STATE_FOCUSRING); - params.disabled = aEventState.HasState(NS_EVENT_STATE_DISABLED); + params.focused = aEventState.HasState(ElementState::FOCUSRING); + params.disabled = aEventState.HasState(ElementState::DISABLED); params.horizontal = isHorizontal; return Some(params); } @@ -2043,13 +2042,13 @@ static const SegmentedControlRenderSettings toolbarButtonRenderSettings = { toolbarButtonHeights, @"kCUIWidgetButtonSegmentedSCurve"}; nsNativeThemeCocoa::SegmentParams nsNativeThemeCocoa::ComputeSegmentParams( - nsIFrame* aFrame, EventStates aEventState, SegmentType aSegmentType) { + nsIFrame* aFrame, ElementState aEventState, SegmentType aSegmentType) { SegmentParams params; params.segmentType = aSegmentType; params.insideActiveWindow = FrameIsInActiveWindow(aFrame); params.pressed = IsPressedButton(aFrame); params.selected = IsSelectedButton(aFrame); - params.focused = aEventState.HasState(NS_EVENT_STATE_FOCUSRING); + params.focused = aEventState.HasState(ElementState::FOCUSRING); bool isRTL = IsFrameRTL(aFrame); nsIFrame* left = GetAdjacentSiblingFrameWithSameAppearance(aFrame, isRTL); nsIFrame* right = GetAdjacentSiblingFrameWithSameAppearance(aFrame, !isRTL); @@ -2238,7 +2237,7 @@ Maybe nsNativeThemeCocoa::ComputeWidgetInfo( originalHeight *= 0.5f; } - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); switch (aAppearance) { case StyleAppearance::Menupopup: @@ -2273,9 +2272,9 @@ Maybe nsNativeThemeCocoa::ComputeWidgetInfo( CheckboxOrRadioParams params; params.state = CheckboxOrRadioState::eOff; - if (eventState.HasState(NS_EVENT_STATE_INDETERMINATE)) { + if (eventState.HasState(ElementState::INDETERMINATE)) { params.state = CheckboxOrRadioState::eIndeterminate; - } else if (eventState.HasState(NS_EVENT_STATE_CHECKED)) { + } else if (eventState.HasState(ElementState::CHECKED)) { params.state = CheckboxOrRadioState::eOn; } params.controlParams = ComputeControlParams(aFrame, eventState); @@ -2297,9 +2296,9 @@ Maybe nsNativeThemeCocoa::ComputeWidgetInfo( // default buttons in active windows have blue background and white // text, and default buttons in inactive windows have white background // and black text.) - EventStates docState = aFrame->GetContent()->OwnerDoc()->GetDocumentState(); + DocumentState docState = aFrame->GetContent()->OwnerDoc()->GetDocumentState(); ControlParams params = ComputeControlParams(aFrame, eventState); - params.insideActiveWindow = !docState.HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE); + params.insideActiveWindow = !docState.HasState(DocumentState::WINDOW_INACTIVE); return Some(WidgetInfo::Button(ButtonParams{params, ButtonType::eDefaultPushButton})); } if (IsButtonTypeMenu(aFrame)) { @@ -2359,7 +2358,7 @@ Maybe nsNativeThemeCocoa::ComputeWidgetInfo( params.pressedButton = Some(SpinButton::eDown); } } - params.disabled = eventState.HasState(NS_EVENT_STATE_DISABLED); + params.disabled = eventState.HasState(ElementState::DISABLED); params.insideActiveWindow = FrameIsInActiveWindow(aFrame); return Some(WidgetInfo::SpinButtons(params)); @@ -2376,7 +2375,7 @@ Maybe nsNativeThemeCocoa::ComputeWidgetInfo( } else if (numberControlFrame->SpinnerDownButtonIsDepressed()) { params.pressedButton = Some(SpinButton::eDown); } - params.disabled = eventState.HasState(NS_EVENT_STATE_DISABLED); + params.disabled = eventState.HasState(ElementState::DISABLED); params.insideActiveWindow = FrameIsInActiveWindow(aFrame); if (aAppearance == StyleAppearance::SpinnerUpbutton) { return Some(WidgetInfo::SpinButtonUp(params)); @@ -2439,7 +2438,7 @@ Maybe nsNativeThemeCocoa::ComputeWidgetInfo( return Some(WidgetInfo::SearchField(ComputeTextFieldParams(aFrame, eventState))); case StyleAppearance::ProgressBar: { - if (eventState.HasState(NS_EVENT_STATE_INDETERMINATE)) { + if (eventState.HasState(ElementState::INDETERMINATE)) { if (!QueueAnimatedContentForRefresh(aFrame->GetContent(), 30)) { NS_WARNING("Unable to animate progressbar!"); } @@ -2488,7 +2487,7 @@ Maybe nsNativeThemeCocoa::ComputeWidgetInfo( } case StyleAppearance::Textarea: - return Some(WidgetInfo::MultilineTextField(eventState.HasState(NS_EVENT_STATE_FOCUS))); + return Some(WidgetInfo::MultilineTextField(eventState.HasState(ElementState::FOCUS))); case StyleAppearance::Listbox: return Some(WidgetInfo::ListBox()); @@ -3461,8 +3460,8 @@ nsITheme::ThemeGeometryType nsNativeThemeCocoa::ThemeGeometryTypeForWidget( return eThemeGeometryTypeMenu; case StyleAppearance::Menuitem: case StyleAppearance::Checkmenuitem: { - EventStates eventState = GetContentState(aFrame, aAppearance); - bool isDisabled = eventState.HasState(NS_EVENT_STATE_DISABLED); + ElementState eventState = GetContentState(aFrame, aAppearance); + bool isDisabled = eventState.HasState(ElementState::DISABLED); bool isSelected = !isDisabled && CheckBooleanAttr(aFrame, nsGkAtoms::menuactive); return isSelected ? eThemeGeometryTypeHighlightedMenuItem : eThemeGeometryTypeMenu; } diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp index 5f3e7689dc1a..3728c818d180 100644 --- a/widget/gtk/nsLookAndFeel.cpp +++ b/widget/gtk/nsLookAndFeel.cpp @@ -1731,10 +1731,10 @@ void nsLookAndFeel::PerThemeData::Init() { } mThemedScrollbarThumbHover = ThemeColors::AdjustUnthemedScrollbarThumbColor( - mThemedScrollbarThumb, NS_EVENT_STATE_HOVER); + mThemedScrollbarThumb, dom::ElementState::HOVER); mThemedScrollbarThumbActive = - ThemeColors::AdjustUnthemedScrollbarThumbColor(mThemedScrollbarThumb, - NS_EVENT_STATE_ACTIVE); + ThemeColors::AdjustUnthemedScrollbarThumbColor( + mThemedScrollbarThumb, dom::ElementState::ACTIVE); } // The label is not added to a parent widget, but shared for constructing diff --git a/widget/gtk/nsNativeThemeGTK.cpp b/widget/gtk/nsNativeThemeGTK.cpp index 9072e95dcf05..48583b5073ee 100644 --- a/widget/gtk/nsNativeThemeGTK.cpp +++ b/widget/gtk/nsNativeThemeGTK.cpp @@ -25,7 +25,6 @@ #include "mozilla/dom/HTMLInputElement.h" #include "mozilla/ClearOnShutdown.h" -#include "mozilla/EventStates.h" #include "mozilla/Services.h" #include @@ -191,26 +190,26 @@ bool nsNativeThemeGTK::GetGtkWidgetAndState(StyleAppearance aAppearance, *aWidgetFlags = 0; } - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); if (aState) { memset(aState, 0, sizeof(GtkWidgetState)); // For XUL checkboxes and radio buttons, the state of the parent // determines our state. if (aWidgetFlags) { - if (eventState.HasState(NS_EVENT_STATE_CHECKED)) { + if (eventState.HasState(ElementState::CHECKED)) { *aWidgetFlags |= MOZ_GTK_WIDGET_CHECKED; } - if (eventState.HasState(NS_EVENT_STATE_INDETERMINATE)) { + if (eventState.HasState(ElementState::INDETERMINATE)) { *aWidgetFlags |= MOZ_GTK_WIDGET_INCONSISTENT; } } aState->disabled = - eventState.HasState(NS_EVENT_STATE_DISABLED) || IsReadOnly(aFrame); - aState->active = eventState.HasState(NS_EVENT_STATE_ACTIVE); - aState->focused = eventState.HasState(NS_EVENT_STATE_FOCUS); - aState->inHover = eventState.HasState(NS_EVENT_STATE_HOVER); + eventState.HasState(ElementState::DISABLED) || IsReadOnly(aFrame); + aState->active = eventState.HasState(ElementState::ACTIVE); + aState->focused = eventState.HasState(ElementState::FOCUS); + aState->inHover = eventState.HasState(ElementState::HOVER); aState->isDefault = IsDefaultButton(aFrame); aState->canDefault = FALSE; // XXX fix me @@ -246,7 +245,7 @@ bool nsNativeThemeGTK::GetGtkWidgetAndState(StyleAppearance aAppearance, // For these widget types, some element (either a child or parent) // actually has element focus, so we check the focused attribute // to see whether to draw in the focused state. - aState->focused = eventState.HasState(NS_EVENT_STATE_FOCUSRING); + aState->focused = eventState.HasState(ElementState::FOCUSRING); if (aAppearance == StyleAppearance::Radio || aAppearance == StyleAppearance::Checkbox) { // In XUL, checkboxes and radios shouldn't have focus rings, their @@ -490,9 +489,9 @@ bool nsNativeThemeGTK::GetGtkWidgetAndState(StyleAppearance aAppearance, break; case StyleAppearance::Progresschunk: { nsIFrame* stateFrame = aFrame->GetParent(); - EventStates eventStates = GetContentState(stateFrame, aAppearance); + ElementState eventStates = GetContentState(stateFrame, aAppearance); - aGtkWidgetType = eventStates.HasState(NS_EVENT_STATE_INDETERMINATE) + aGtkWidgetType = eventStates.HasState(ElementState::INDETERMINATE) ? IsVerticalProgress(stateFrame) ? MOZ_GTK_PROGRESS_CHUNK_VERTICAL_INDETERMINATE : MOZ_GTK_PROGRESS_CHUNK_INDETERMINATE diff --git a/widget/nsNativeTheme.cpp b/widget/nsNativeTheme.cpp index 1217277e72df..f3443e19df4a 100644 --- a/widget/nsNativeTheme.cpp +++ b/widget/nsNativeTheme.cpp @@ -23,7 +23,6 @@ #include "nsCSSRendering.h" #include "ImageContainer.h" #include "mozilla/ComputedStyle.h" -#include "mozilla/EventStates.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/HTMLBodyElement.h" #include "mozilla/dom/HTMLInputElement.h" @@ -40,15 +39,15 @@ nsNativeTheme::nsNativeTheme() : mAnimatedContentTimeout(UINT32_MAX) {} NS_IMPL_ISUPPORTS(nsNativeTheme, nsITimerCallback, nsINamed) -/* static */ EventStates nsNativeTheme::GetContentState( +/* static */ ElementState nsNativeTheme::GetContentState( nsIFrame* aFrame, StyleAppearance aAppearance) { if (!aFrame) { - return EventStates(); + return ElementState(); } nsIContent* frameContent = aFrame->GetContent(); if (!frameContent || !frameContent->IsElement()) { - return EventStates(); + return ElementState(); } const bool isXULElement = frameContent->IsXULElement(); @@ -71,13 +70,13 @@ NS_IMPL_ISUPPORTS(nsNativeTheme, nsITimerCallback, nsINamed) MOZ_ASSERT(frameContent && frameContent->IsElement()); } - EventStates flags = frameContent->AsElement()->StyleState(); + ElementState flags = frameContent->AsElement()->StyleState(); nsNumberControlFrame* numberControlFrame = nsNumberControlFrame::GetNumberControlFrameForSpinButton(aFrame); if (numberControlFrame && numberControlFrame->GetContent()->AsElement()->StyleState().HasState( - NS_EVENT_STATE_DISABLED)) { - flags |= NS_EVENT_STATE_DISABLED; + ElementState::DISABLED)) { + flags |= ElementState::DISABLED; } if (!isXULElement) { @@ -85,31 +84,31 @@ NS_IMPL_ISUPPORTS(nsNativeTheme, nsITimerCallback, nsINamed) } if (CheckBooleanAttr(aFrame, nsGkAtoms::disabled)) { - flags |= NS_EVENT_STATE_DISABLED; + flags |= ElementState::DISABLED; } switch (aAppearance) { case StyleAppearance::RadioLabel: case StyleAppearance::Radio: { if (CheckBooleanAttr(aFrame, nsGkAtoms::focused)) { - flags |= NS_EVENT_STATE_FOCUS; + flags |= ElementState::FOCUS; nsPIDOMWindowOuter* window = aFrame->GetContent()->OwnerDoc()->GetWindow(); if (window && window->ShouldShowFocusRing()) { - flags |= NS_EVENT_STATE_FOCUSRING; + flags |= ElementState::FOCUSRING; } } if (CheckBooleanAttr(aFrame, nsGkAtoms::selected)) { - flags |= NS_EVENT_STATE_CHECKED; + flags |= ElementState::CHECKED; } break; } case StyleAppearance::CheckboxLabel: case StyleAppearance::Checkbox: { if (CheckBooleanAttr(aFrame, nsGkAtoms::checked)) { - flags |= NS_EVENT_STATE_CHECKED; + flags |= ElementState::CHECKED; } else if (CheckBooleanAttr(aFrame, nsGkAtoms::indeterminate)) { - flags |= NS_EVENT_STATE_INDETERMINATE; + flags |= ElementState::INDETERMINATE; } break; } @@ -120,7 +119,7 @@ NS_IMPL_ISUPPORTS(nsNativeTheme, nsITimerCallback, nsINamed) case StyleAppearance::Searchfield: case StyleAppearance::Textarea: { if (CheckBooleanAttr(aFrame, nsGkAtoms::focused)) { - flags |= NS_EVENT_STATE_FOCUS | NS_EVENT_STATE_FOCUSRING; + flags |= ElementState::FOCUS | ElementState::FOCUSRING; } break; } @@ -193,12 +192,12 @@ bool nsNativeTheme::IsButtonTypeMenu(nsIFrame* aFrame) { } bool nsNativeTheme::IsPressedButton(nsIFrame* aFrame) { - EventStates eventState = + ElementState eventState = GetContentState(aFrame, StyleAppearance::Toolbarbutton); - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) return false; + if (eventState.HasState(ElementState::DISABLED)) return false; return IsOpenButton(aFrame) || - eventState.HasAllStates(NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER); + eventState.HasAllStates(ElementState::ACTIVE | ElementState::HOVER); } bool nsNativeTheme::IsWidgetStyled(nsPresContext* aPresContext, diff --git a/widget/nsNativeTheme.h b/widget/nsNativeTheme.h index 9088e07da893..54f3db2ca00e 100644 --- a/widget/nsNativeTheme.h +++ b/widget/nsNativeTheme.h @@ -20,6 +20,7 @@ #include "nsINamed.h" #include "nsITimer.h" #include "nsIContent.h" +#include "mozilla/dom/RustTypes.h" class nsIFrame; class nsPresContext; @@ -27,7 +28,6 @@ class nsPresContext; namespace mozilla { class ComputedStyle; enum class StyleAppearance : uint8_t; -class EventStates; } // namespace mozilla class nsNativeTheme : public nsITimerCallback, public nsINamed { @@ -53,7 +53,7 @@ class nsNativeTheme : public nsITimerCallback, public nsINamed { eTreeSortDirection_Ascending }; // Returns the content state (hover, focus, etc), see EventStateManager.h - static mozilla::EventStates GetContentState( + static mozilla::dom::ElementState GetContentState( nsIFrame* aFrame, mozilla::StyleAppearance aAppearance); // Returns whether the widget is already styled by content diff --git a/widget/windows/nsNativeThemeWin.cpp b/widget/windows/nsNativeThemeWin.cpp index 41b416e6402e..a948118fc9f7 100644 --- a/widget/windows/nsNativeThemeWin.cpp +++ b/widget/windows/nsNativeThemeWin.cpp @@ -14,7 +14,6 @@ #include "gfxWindowsPlatform.h" #include "gfxWindowsSurface.h" #include "mozilla/ClearOnShutdown.h" -#include "mozilla/EventStates.h" #include "mozilla/gfx/Types.h" // for Color::FromABGR #include "mozilla/Logging.h" #include "mozilla/RelativeLuminanceUtils.h" @@ -46,6 +45,8 @@ using namespace mozilla; using namespace mozilla::gfx; using namespace mozilla::widget; +using ElementState = dom::ElementState; + extern mozilla::LazyLogModule gWindowsLog; namespace mozilla::widget { @@ -107,25 +108,25 @@ static int32_t GetTopLevelWindowActiveState(nsIFrame* aFrame) { } static int32_t GetWindowFrameButtonState(nsIFrame* aFrame, - EventStates eventState) { + ElementState eventState) { if (GetTopLevelWindowActiveState(aFrame) == mozilla::widget::themeconst::FS_INACTIVE) { - if (eventState.HasState(NS_EVENT_STATE_HOVER)) + if (eventState.HasState(ElementState::HOVER)) return mozilla::widget::themeconst::BS_HOT; return mozilla::widget::themeconst::BS_INACTIVE; } - if (eventState.HasState(NS_EVENT_STATE_HOVER)) { - if (eventState.HasState(NS_EVENT_STATE_ACTIVE)) + if (eventState.HasState(ElementState::HOVER)) { + if (eventState.HasState(ElementState::ACTIVE)) return mozilla::widget::themeconst::BS_PUSHED; return mozilla::widget::themeconst::BS_HOT; } return mozilla::widget::themeconst::BS_NORMAL; } -static int32_t GetClassicWindowFrameButtonState(EventStates eventState) { - if (eventState.HasState(NS_EVENT_STATE_ACTIVE) && - eventState.HasState(NS_EVENT_STATE_HOVER)) +static int32_t GetClassicWindowFrameButtonState(ElementState eventState) { + if (eventState.HasState(ElementState::ACTIVE) && + eventState.HasState(ElementState::HOVER)) return DFCS_BUTTONPUSH | DFCS_PUSHED; return DFCS_BUTTONPUSH; } @@ -559,9 +560,9 @@ void nsNativeThemeWin::DrawThemedProgressMeter( return; } - EventStates eventStates = GetContentState(parentFrame, aAppearance); + ElementState eventStates = GetContentState(parentFrame, aAppearance); bool vertical = IsVerticalProgress(parentFrame); - bool indeterminate = eventStates.HasState(NS_EVENT_STATE_INDETERMINATE); + bool indeterminate = eventStates.HasState(ElementState::INDETERMINATE); bool animate = indeterminate; // Vista and up progress meter is fill style, rendered here. We render @@ -787,22 +788,22 @@ nsNativeThemeWin::GetTheme(StyleAppearance aAppearance) { int32_t nsNativeThemeWin::StandardGetState(nsIFrame* aFrame, StyleAppearance aAppearance, bool wantFocused) { - EventStates eventState = GetContentState(aFrame, aAppearance); - if (eventState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE)) { + ElementState eventState = GetContentState(aFrame, aAppearance); + if (eventState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE)) { return TS_ACTIVE; } - if (eventState.HasState(NS_EVENT_STATE_HOVER)) { + if (eventState.HasState(ElementState::HOVER)) { return TS_HOVER; } if (wantFocused) { - if (eventState.HasState(NS_EVENT_STATE_FOCUSRING)) { + if (eventState.HasState(ElementState::FOCUSRING)) { return TS_FOCUSED; } // On Windows, focused buttons are always drawn as such by the native - // theme, that's why we check NS_EVENT_STATE_FOCUS instead of - // NS_EVENT_STATE_FOCUSRING. + // theme, that's why we check ElementState::FOCUS instead of + // ElementState::FOCUSRING. if (aAppearance == StyleAppearance::Button && - eventState.HasState(NS_EVENT_STATE_FOCUS)) { + eventState.HasState(ElementState::FOCUS)) { return TS_FOCUSED; } } @@ -839,8 +840,8 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, return NS_OK; } - EventStates eventState = GetContentState(aFrame, aAppearance); - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + ElementState eventState = GetContentState(aFrame, aAppearance); + if (eventState.HasState(ElementState::DISABLED)) { aState = TS_DISABLED; return NS_OK; } @@ -867,15 +868,15 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, if (!aFrame) { aState = TS_NORMAL; } else { - EventStates eventState = GetContentState(aFrame, aAppearance); - if (eventState.HasState(NS_EVENT_STATE_CHECKED)) { + ElementState eventState = GetContentState(aFrame, aAppearance); + if (eventState.HasState(ElementState::CHECKED)) { inputState = CHECKED; } - if (isCheckbox && eventState.HasState(NS_EVENT_STATE_INDETERMINATE)) { + if (isCheckbox && eventState.HasState(ElementState::INDETERMINATE)) { inputState = INDETERMINATE; } - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + if (eventState.HasState(ElementState::DISABLED)) { aState = TS_DISABLED; } else { aState = StandardGetState(aFrame, aAppearance, false); @@ -896,7 +897,7 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, case StyleAppearance::NumberInput: case StyleAppearance::Textfield: case StyleAppearance::Textarea: { - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); /* Note: the NOSCROLL type has a rounded corner in each corner. The more * specific HSCROLL, VSCROLL, HVSCROLL types have side and/or top/bottom @@ -908,15 +909,15 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, if (!aFrame) { aState = TFS_EDITBORDER_NORMAL; - } else if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + } else if (eventState.HasState(ElementState::DISABLED)) { aState = TFS_EDITBORDER_DISABLED; } else if (IsReadOnly(aFrame)) { /* no special read-only state */ aState = TFS_EDITBORDER_NORMAL; - } else if (eventState.HasAtLeastOneOfStates(NS_EVENT_STATE_ACTIVE | - NS_EVENT_STATE_FOCUSRING)) { + } else if (eventState.HasAtLeastOneOfStates(ElementState::ACTIVE | + ElementState::FOCUSRING)) { aState = TFS_EDITBORDER_FOCUSED; - } else if (eventState.HasState(NS_EVENT_STATE_HOVER)) { + } else if (eventState.HasState(ElementState::HOVER)) { aState = TFS_EDITBORDER_HOVER; } else { aState = TFS_EDITBORDER_NORMAL; @@ -954,8 +955,8 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, return NS_OK; } - EventStates eventState = GetContentState(aFrame, aAppearance); - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + ElementState eventState = GetContentState(aFrame, aAppearance); + if (eventState.HasState(ElementState::DISABLED)) { aState = TS_DISABLED; return NS_OK; } @@ -964,9 +965,9 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, return NS_OK; } - if (eventState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE)) + if (eventState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE)) aState = TS_ACTIVE; - else if (eventState.HasState(NS_EVENT_STATE_HOVER)) { + else if (eventState.HasState(ElementState::HOVER)) { if (IsCheckedButton(aFrame)) aState = TB_HOVER_CHECKED; else @@ -1001,21 +1002,21 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, } else { aPart = IsFrameRTL(aFrame) ? TKP_THUMBLEFT : TKP_THUMBRIGHT; } - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); if (!aFrame) { aState = TS_NORMAL; - } else if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + } else if (eventState.HasState(ElementState::DISABLED)) { aState = TKP_DISABLED; } else { if (eventState.HasState( - NS_EVENT_STATE_ACTIVE)) // Hover is not also a requirement for - // the thumb, since the drag is not - // canceled when you move outside the - // thumb. + ElementState::ACTIVE)) // Hover is not also a requirement for + // the thumb, since the drag is not + // canceled when you move outside the + // thumb. aState = TS_ACTIVE; - else if (eventState.HasState(NS_EVENT_STATE_FOCUSRING)) + else if (eventState.HasState(ElementState::FOCUSRING)) aState = TKP_FOCUSED; - else if (eventState.HasState(NS_EVENT_STATE_HOVER)) + else if (eventState.HasState(ElementState::HOVER)) aState = TS_HOVER; else aState = TS_NORMAL; @@ -1026,10 +1027,10 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, case StyleAppearance::SpinnerDownbutton: { aPart = (aAppearance == StyleAppearance::SpinnerUpbutton) ? SPNP_UP : SPNP_DOWN; - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); if (!aFrame) { aState = TS_NORMAL; - } else if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + } else if (eventState.HasState(ElementState::DISABLED)) { aState = TS_DISABLED; } else { aState = StandardGetState(aFrame, aAppearance, false); @@ -1104,8 +1105,8 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, return NS_OK; } - EventStates eventState = GetContentState(aFrame, aAppearance); - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + ElementState eventState = GetContentState(aFrame, aAppearance); + if (eventState.HasState(ElementState::DISABLED)) { aState = TS_DISABLED; return NS_OK; } @@ -1139,7 +1140,7 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, case StyleAppearance::Menulist: { nsIContent* content = aFrame->GetContent(); bool useDropBorder = content && content->IsHTMLElement(); - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); /* On Vista/Win7, we use CBP_DROPBORDER instead of DROPFRAME for HTML * content or for editable menulists; this gives us the thin outline, @@ -1149,19 +1150,19 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, else aPart = CBP_DROPFRAME; - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + if (eventState.HasState(ElementState::DISABLED)) { aState = TS_DISABLED; } else if (IsReadOnly(aFrame)) { aState = TS_NORMAL; } else if (IsOpenButton(aFrame)) { aState = TS_ACTIVE; } else if (useDropBorder && - eventState.HasState(NS_EVENT_STATE_FOCUSRING)) { + eventState.HasState(ElementState::FOCUSRING)) { aState = TS_ACTIVE; - } else if (eventState.HasAllStates(NS_EVENT_STATE_HOVER | - NS_EVENT_STATE_ACTIVE)) { + } else if (eventState.HasAllStates(ElementState::HOVER | + ElementState::ACTIVE)) { aState = TS_ACTIVE; - } else if (eventState.HasState(NS_EVENT_STATE_HOVER)) { + } else if (eventState.HasState(ElementState::HOVER)) { aState = TS_HOVER; } else { aState = TS_NORMAL; @@ -1179,7 +1180,7 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, // parent. if (isHTML || isMenulist) aFrame = parentFrame; - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); aPart = CBP_DROPMARKER_VISTA; // For HTML controls with author styling, we should fall @@ -1189,7 +1190,7 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, StyleAppearance::Menulist)) aPart = CBP_DROPMARKER; - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + if (eventState.HasState(ElementState::DISABLED)) { aState = TS_DISABLED; return NS_OK; } @@ -1224,14 +1225,14 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, aState = TS_NORMAL; // Dropdown button active state doesn't need :hover. - if (eventState.HasState(NS_EVENT_STATE_ACTIVE)) { + if (eventState.HasState(ElementState::ACTIVE)) { if (isOpen && (isHTML || isMenulist)) { // XXX Button should look active until the mouse is released, but // without making it look active when the popup is clicked. return NS_OK; } aState = TS_ACTIVE; - } else if (eventState.HasState(NS_EVENT_STATE_HOVER)) { + } else if (eventState.HasState(ElementState::HOVER)) { // No hover effect for XUL menulists and autocomplete dropdown buttons // while the dropdown menu is open. if (isOpen) { @@ -1255,7 +1256,7 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, bool isOpen = false; bool isHover = false; nsMenuFrame* menuFrame = do_QueryFrame(aFrame); - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); isTopLevel = IsTopLevelMenu(aFrame); @@ -1274,7 +1275,7 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, aState = MBI_NORMAL; // the disabled states are offset by 3 - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + if (eventState.HasState(ElementState::DISABLED)) { aState += 3; } } else { @@ -1286,7 +1287,7 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, aState = MPI_NORMAL; // the disabled states are offset by 2 - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + if (eventState.HasState(ElementState::DISABLED)) { aState += 2; } } @@ -1299,14 +1300,14 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, return NS_OK; case StyleAppearance::Menuarrow: { aPart = MENU_POPUPSUBMENU; - EventStates eventState = GetContentState(aFrame, aAppearance); - aState = eventState.HasState(NS_EVENT_STATE_DISABLED) ? MSM_DISABLED - : MSM_NORMAL; + ElementState eventState = GetContentState(aFrame, aAppearance); + aState = eventState.HasState(ElementState::DISABLED) ? MSM_DISABLED + : MSM_NORMAL; return NS_OK; } case StyleAppearance::Menucheckbox: case StyleAppearance::Menuradio: { - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); aPart = MENU_POPUPCHECK; aState = MC_CHECKMARKNORMAL; @@ -1315,7 +1316,7 @@ nsresult nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, if (aAppearance == StyleAppearance::Menuradio) aState += 2; // the disabled states are offset by 1 - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + if (eventState.HasState(ElementState::DISABLED)) { aState += 1; } @@ -1586,10 +1587,10 @@ RENDER_AGAIN: if (isChecked) { int bgState = MCB_NORMAL; - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); // the disabled states are offset by 1 - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + if (eventState.HasState(ElementState::DISABLED)) { bgState += 1; } @@ -1745,9 +1746,9 @@ RENDER_AGAIN: // Draw focus rectangles for range elements // XXX it'd be nice to draw these outside of the frame if (aAppearance == StyleAppearance::Range) { - EventStates contentState = GetContentState(aFrame, aAppearance); + ElementState contentState = GetContentState(aFrame, aAppearance); - if (contentState.HasState(NS_EVENT_STATE_FOCUSRING)) { + if (contentState.HasState(ElementState::FOCUSRING)) { POINT vpOrg; HPEN hPen = nullptr; @@ -2801,16 +2802,16 @@ nsresult nsNativeThemeWin::ClassicGetThemePartAndState( aState = DFCS_BUTTONPUSH; aFocused = false; - EventStates contentState = GetContentState(aFrame, aAppearance); - if (contentState.HasState(NS_EVENT_STATE_DISABLED)) { + ElementState contentState = GetContentState(aFrame, aAppearance); + if (contentState.HasState(ElementState::DISABLED)) { aState |= DFCS_INACTIVE; } else if (IsOpenButton(aFrame)) { aState |= DFCS_PUSHED; } else if (IsCheckedButton(aFrame)) { aState |= DFCS_CHECKED; } else { - if (contentState.HasAllStates(NS_EVENT_STATE_ACTIVE | - NS_EVENT_STATE_HOVER)) { + if (contentState.HasAllStates(ElementState::ACTIVE | + ElementState::HOVER)) { aState |= DFCS_PUSHED; // The down state is flat if the button is focusable if (aFrame->StyleUI()->UserFocus() == StyleUserFocus::Normal) { @@ -2820,9 +2821,9 @@ nsresult nsNativeThemeWin::ClassicGetThemePartAndState( } } // On Windows, focused buttons are always drawn as such by the native - // theme, that's why we check NS_EVENT_STATE_FOCUS instead of - // NS_EVENT_STATE_FOCUSRING. - if (contentState.HasState(NS_EVENT_STATE_FOCUS) || + // theme, that's why we check ElementState::FOCUS instead of + // ElementState::FOCUSRING. + if (contentState.HasState(ElementState::FOCUS) || (aState == DFCS_BUTTONPUSH && IsDefaultButton(aFrame))) { aFocused = true; } @@ -2832,16 +2833,15 @@ nsresult nsNativeThemeWin::ClassicGetThemePartAndState( } case StyleAppearance::Checkbox: case StyleAppearance::Radio: { - EventStates contentState = GetContentState(aFrame, aAppearance); + ElementState contentState = GetContentState(aFrame, aAppearance); aFocused = false; aPart = DFC_BUTTON; aState = 0; nsIContent* content = aFrame->GetContent(); bool isCheckbox = (aAppearance == StyleAppearance::Checkbox); - bool isChecked = contentState.HasState(NS_EVENT_STATE_CHECKED); - bool isIndeterminate = - contentState.HasState(NS_EVENT_STATE_INDETERMINATE); + bool isChecked = contentState.HasState(ElementState::CHECKED); + bool isIndeterminate = contentState.HasState(ElementState::INDETERMINATE); if (isCheckbox) { // indeterminate state takes precedence over checkedness. @@ -2858,14 +2858,14 @@ nsresult nsNativeThemeWin::ClassicGetThemePartAndState( } if (!content->IsXULElement() && - contentState.HasState(NS_EVENT_STATE_FOCUSRING)) { + contentState.HasState(ElementState::FOCUSRING)) { aFocused = true; } - if (contentState.HasState(NS_EVENT_STATE_DISABLED)) { + if (contentState.HasState(ElementState::DISABLED)) { aState |= DFCS_INACTIVE; - } else if (contentState.HasAllStates(NS_EVENT_STATE_ACTIVE | - NS_EVENT_STATE_HOVER)) { + } else if (contentState.HasAllStates(ElementState::ACTIVE | + ElementState::HOVER)) { aState |= DFCS_PUSHED; } @@ -2877,7 +2877,7 @@ nsresult nsNativeThemeWin::ClassicGetThemePartAndState( bool isTopLevel = false; bool isOpen = false; nsMenuFrame* menuFrame = do_QueryFrame(aFrame); - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); // We indicate top-level-ness using aPart. 0 is a normal menu item, // 1 is a top-level menu item. The state of the item is composed of @@ -2893,7 +2893,7 @@ nsresult nsNativeThemeWin::ClassicGetThemePartAndState( isOpen = menuFrame->IsOpen(); } - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + if (eventState.HasState(ElementState::DISABLED)) { aState |= DFCS_INACTIVE; } @@ -2910,9 +2910,9 @@ nsresult nsNativeThemeWin::ClassicGetThemePartAndState( case StyleAppearance::Menuradio: case StyleAppearance::Menuarrow: { aState = 0; - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + if (eventState.HasState(ElementState::DISABLED)) { aState |= DFCS_INACTIVE; } if (IsMenuActive(aFrame, aAppearance)) aState |= DFCS_HOT; @@ -2961,9 +2961,9 @@ nsresult nsNativeThemeWin::ClassicGetThemePartAndState( // parent. if (isHTML || isMenulist) aFrame = parentFrame; - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + if (eventState.HasState(ElementState::DISABLED)) { aState |= DFCS_INACTIVE; return NS_OK; } @@ -2979,14 +2979,14 @@ nsresult nsNativeThemeWin::ClassicGetThemePartAndState( if (isOpen && (isHTML || isMenulist)) return NS_OK; // Dropdown button active state doesn't need :hover. - if (eventState.HasState(NS_EVENT_STATE_ACTIVE)) + if (eventState.HasState(ElementState::ACTIVE)) aState |= DFCS_PUSHED | DFCS_FLAT; return NS_OK; } case StyleAppearance::SpinnerUpbutton: case StyleAppearance::SpinnerDownbutton: { - EventStates contentState = GetContentState(aFrame, aAppearance); + ElementState contentState = GetContentState(aFrame, aAppearance); aPart = DFC_SCROLL; switch (aAppearance) { @@ -3000,11 +3000,11 @@ nsresult nsNativeThemeWin::ClassicGetThemePartAndState( break; } - if (contentState.HasState(NS_EVENT_STATE_DISABLED)) { + if (contentState.HasState(ElementState::DISABLED)) { aState |= DFCS_INACTIVE; } else { - if (contentState.HasAllStates(NS_EVENT_STATE_HOVER | - NS_EVENT_STATE_ACTIVE)) + if (contentState.HasAllStates(ElementState::HOVER | + ElementState::ACTIVE)) aState |= DFCS_PUSHED; } @@ -3302,11 +3302,11 @@ RENDER_AGAIN: // Draw inset edge ::DrawEdge(hdc, &widgetRect, EDGE_SUNKEN, BF_RECT | BF_ADJUST); - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); // Fill in background - if (eventState.HasState(NS_EVENT_STATE_DISABLED) || + if (eventState.HasState(ElementState::DISABLED) || (aFrame->GetContent()->IsXULElement() && IsReadOnly(aFrame))) ::FillRect(hdc, &widgetRect, (HBRUSH)(COLOR_BTNFACE + 1)); else @@ -3350,11 +3350,11 @@ RENDER_AGAIN: break; } case StyleAppearance::RangeThumb: { - EventStates eventState = GetContentState(aFrame, aAppearance); + ElementState eventState = GetContentState(aFrame, aAppearance); ::DrawEdge(hdc, &widgetRect, EDGE_RAISED, BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST); - if (eventState.HasState(NS_EVENT_STATE_DISABLED)) { + if (eventState.HasState(ElementState::DISABLED)) { DrawCheckedRect(hdc, widgetRect, COLOR_3DFACE, COLOR_3DHILIGHT, (HBRUSH)COLOR_3DHILIGHT); } @@ -3388,10 +3388,10 @@ RENDER_AGAIN: } case StyleAppearance::Progresschunk: { nsIFrame* stateFrame = aFrame->GetParent(); - EventStates eventStates = GetContentState(stateFrame, aAppearance); + ElementState eventStates = GetContentState(stateFrame, aAppearance); const bool indeterminate = - eventStates.HasState(NS_EVENT_STATE_INDETERMINATE); + eventStates.HasState(ElementState::INDETERMINATE); bool vertical = IsVerticalProgress(stateFrame); nsIContent* content = aFrame->GetContent();