Bug 1857513 - Clean up document state setup. r=smaug

Now that we have a DocumentState type we can be a bit less explicit
(before this used EventStates, so the extra Document in the names was
useful).

Differential Revision: https://phabricator.services.mozilla.com/D190602
This commit is contained in:
Emilio Cobos Álvarez 2023-10-11 08:24:14 +00:00
parent a3e8abd326
commit 84a3ba3580
9 changed files with 24 additions and 33 deletions

View file

@ -7659,14 +7659,6 @@ void Document::NotifyActivityChanged() {
EnumerateActivityObservers(NotifyActivityChangedCallback);
}
bool Document::IsTopLevelWindowInactive() const {
if (BrowsingContext* bc = GetBrowsingContext()) {
return !bc->GetIsActiveBrowserWindow();
}
return false;
}
void Document::SetContainer(nsDocShell* aContainer) {
if (aContainer) {
mDocumentContainer = aContainer;
@ -12506,34 +12498,35 @@ void Document::ForgetImagePreload(nsIURI* aURI) {
void Document::UpdateDocumentStates(DocumentState aMaybeChangedStates,
bool aNotify) {
const DocumentState oldStates = mDocumentState;
const DocumentState oldStates = mState;
if (aMaybeChangedStates.HasAtLeastOneOfStates(
DocumentState::ALL_LOCALEDIR_BITS)) {
mDocumentState &= ~DocumentState::ALL_LOCALEDIR_BITS;
mState &= ~DocumentState::ALL_LOCALEDIR_BITS;
if (IsDocumentRightToLeft()) {
mDocumentState |= DocumentState::RTL_LOCALE;
mState |= DocumentState::RTL_LOCALE;
} else {
mDocumentState |= DocumentState::LTR_LOCALE;
mState |= DocumentState::LTR_LOCALE;
}
}
if (aMaybeChangedStates.HasAtLeastOneOfStates(DocumentState::LWTHEME)) {
if (ComputeDocumentLWTheme()) {
mDocumentState |= DocumentState::LWTHEME;
mState |= DocumentState::LWTHEME;
} else {
mDocumentState &= ~DocumentState::LWTHEME;
mState &= ~DocumentState::LWTHEME;
}
}
if (aMaybeChangedStates.HasState(DocumentState::WINDOW_INACTIVE)) {
if (IsTopLevelWindowInactive()) {
mDocumentState |= DocumentState::WINDOW_INACTIVE;
BrowsingContext* bc = GetBrowsingContext();
if (!bc || !bc->GetIsActiveBrowserWindow()) {
mState |= DocumentState::WINDOW_INACTIVE;
} else {
mDocumentState &= ~DocumentState::WINDOW_INACTIVE;
mState &= ~DocumentState::WINDOW_INACTIVE;
}
}
const DocumentState changedStates = oldStates ^ mDocumentState;
const DocumentState changedStates = oldStates ^ mState;
if (aNotify && !changedStates.IsEmpty()) {
if (PresShell* ps = GetObservingPresShell()) {
ps->DocumentStatesChanged(changedStates);

View file

@ -1764,7 +1764,9 @@ class Document : public nsINode,
return GetInnerWindow() ? GetInnerWindow()->GetWindowContext() : nullptr;
}
bool IsTopLevelWindowInactive() const;
bool IsTopLevelWindowInactive() const {
return mState.HasState(DocumentState::WINDOW_INACTIVE);
}
/**
* Get the script loader for this document
@ -1997,7 +1999,7 @@ class Document : public nsINode,
// 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.
// implementation of Document::State.
//
// aNotify controls whether we notify our DocumentStatesChanged observers.
void UpdateDocumentStates(DocumentState aMaybeChangedStates, bool aNotify);
@ -3004,7 +3006,7 @@ class Document : public nsINode,
return MediaDocumentKind::NotMedia;
}
DocumentState GetDocumentState() const { return mDocumentState; }
DocumentState State() const { return mState; }
nsISupports* GetCurrentContentSink();
@ -4524,7 +4526,7 @@ class Document : public nsINode,
// Last time we found any scroll linked effect in this document.
TimeStamp mLastScrollLinkedEffectDetectionTime;
DocumentState mDocumentState{DocumentState::LTR_LOCALE};
DocumentState mState{DocumentState::LTR_LOCALE};
RefPtr<Promise> mReadyForIdle;

View file

@ -3746,8 +3746,7 @@ bool nsDisplayThemedBackground::CreateWebRenderCommands(
}
bool nsDisplayThemedBackground::IsWindowActive() const {
DocumentState docState = mFrame->GetContent()->OwnerDoc()->GetDocumentState();
return !docState.HasState(DocumentState::WINDOW_INACTIVE);
return !mFrame->PresContext()->Document()->IsTopLevelWindowInactive();
}
void nsDisplayThemedBackground::ComputeInvalidationRegion(

View file

@ -374,7 +374,7 @@ nsresult nsXULTooltipListener::ShowTooltip() {
// Make sure the document still has focus.
auto* doc = tooltipNode->GetComposedDoc();
if (!doc || !nsContentUtils::IsChromeDoc(doc) ||
doc->GetDocumentState().HasState(DocumentState::WINDOW_INACTIVE)) {
doc->IsTopLevelWindowInactive()) {
return NS_OK;
}

View file

@ -2485,9 +2485,7 @@ class nsDisplayTreeBody final : public nsPaintedDisplayItem {
}
bool IsWindowActive() const {
DocumentState docState =
mFrame->PresContext()->Document()->GetDocumentState();
return !docState.HasState(DocumentState::WINDOW_INACTIVE);
return !mFrame->PresContext()->Document()->IsTopLevelWindowInactive();
}
void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,

View file

@ -714,7 +714,7 @@ impl<'le> GeckoElement<'le> {
#[inline]
fn document_state(&self) -> DocumentState {
DocumentState::from_bits_retain(self.as_node().owner_doc().0.mDocumentState.bits)
DocumentState::from_bits_retain(self.as_node().owner_doc().0.mState.bits)
}
#[inline]

View file

@ -122,7 +122,7 @@ LayoutDeviceIntCoord ScrollbarDrawing::GetScrollbarSize(
bool ScrollbarDrawing::IsScrollbarTrackOpaque(nsIFrame* aFrame) {
auto trackColor = ComputeScrollbarTrackColor(
aFrame, *nsLayoutUtils::StyleForScrollbar(aFrame),
aFrame->PresContext()->Document()->GetDocumentState(),
aFrame->PresContext()->Document()->State(),
Colors(aFrame, StyleAppearance::ScrollbartrackVertical));
return trackColor.a == 1.0f;
}

View file

@ -1172,7 +1172,7 @@ bool Theme::DoDrawWidgetBackground(PaintBackendData& aPaintData,
const nscoord twipsPerPixel = pc->AppUnitsPerDevPixel();
const auto devPxRect = ToSnappedRect(aRect, twipsPerPixel, aPaintData);
const DocumentState docState = pc->Document()->GetDocumentState();
const DocumentState docState = pc->Document()->State();
ElementState elementState = GetContentState(aFrame, aAppearance);
// Paint the outline iff we're asked to draw overflow and we have
// outline-style: auto.

View file

@ -2406,8 +2406,7 @@ Maybe<nsNativeThemeCocoa::WidgetInfo> 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.)
DocumentState docState =
aFrame->GetContent()->OwnerDoc()->GetDocumentState();
DocumentState docState = aFrame->PresContext()->Document()->State();
ControlParams params = ComputeControlParams(aFrame, elementState);
params.insideActiveWindow =
!docState.HasState(DocumentState::WINDOW_INACTIVE);