Title: [287498] trunk/Source/WebCore
- Revision
- 287498
- Author
- [email protected]
- Date
- 2021-12-31 22:03:35 -0800 (Fri, 31 Dec 2021)
Log Message
Reduce repetition in Internals "set page activity state" methods
https://bugs.webkit.org/show_bug.cgi?id=234768
Reviewed by Darin Adler.
`setPageVisibility`, `setPageIsFocusedAndActive`, and
`setPageIsInWindow` all modify page activity state, and repeat a lot
of the same logic to do so. This patch refactors this into a common
`updatePageActivityState` method.
* testing/Internals.cpp:
(WebCore::Internals::setPageVisibility):
(WebCore::Internals::setPageIsFocusedAndActive):
(WebCore::Internals::setPageIsInWindow):
Refactor to use the new updatePageActivityState method.
(WebCore::Internals::updatePageActivityState):
Added.
* testing/Internals.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (287497 => 287498)
--- trunk/Source/WebCore/ChangeLog 2022-01-01 00:22:38 UTC (rev 287497)
+++ trunk/Source/WebCore/ChangeLog 2022-01-01 06:03:35 UTC (rev 287498)
@@ -1,3 +1,24 @@
+2021-12-31 Tyler Wilcock <[email protected]>
+
+ Reduce repetition in Internals "set page activity state" methods
+ https://bugs.webkit.org/show_bug.cgi?id=234768
+
+ Reviewed by Darin Adler.
+
+ `setPageVisibility`, `setPageIsFocusedAndActive`, and
+ `setPageIsInWindow` all modify page activity state, and repeat a lot
+ of the same logic to do so. This patch refactors this into a common
+ `updatePageActivityState` method.
+
+ * testing/Internals.cpp:
+ (WebCore::Internals::setPageVisibility):
+ (WebCore::Internals::setPageIsFocusedAndActive):
+ (WebCore::Internals::setPageIsInWindow):
+ Refactor to use the new updatePageActivityState method.
+ (WebCore::Internals::updatePageActivityState):
+ Added.
+ * testing/Internals.h:
+
2021-12-31 Wenson Hsieh <[email protected]>
Include a few more tag names to search when running modal container detection
Modified: trunk/Source/WebCore/testing/Internals.cpp (287497 => 287498)
--- trunk/Source/WebCore/testing/Internals.cpp 2022-01-01 00:22:38 UTC (rev 287497)
+++ trunk/Source/WebCore/testing/Internals.cpp 2022-01-01 06:03:35 UTC (rev 287498)
@@ -28,7 +28,6 @@
#include "Internals.h"
#include "AXObjectCache.h"
-#include "ActivityState.h"
#include "AddEventListenerOptions.h"
#include "AnimationTimeline.h"
#include "ApplicationCacheStorage.h"
@@ -5348,50 +5347,32 @@
void Internals::setPageVisibility(bool isVisible)
{
- auto* document = contextDocument();
- if (!document || !document->page())
- return;
- auto& page = *document->page();
- auto state = page.activityState();
-
- if (!isVisible)
- state.remove(ActivityState::IsVisible);
- else
- state.add(ActivityState::IsVisible);
-
- page.setActivityState(state);
+ updatePageActivityState(ActivityState::IsVisible, isVisible);
}
void Internals::setPageIsFocusedAndActive(bool isFocusedAndActive)
{
- auto* document = contextDocument();
- if (!document || !document->page())
- return;
- auto& page = *document->page();
- auto state = page.activityState();
-
- if (!isFocusedAndActive)
- state.remove({ ActivityState::IsFocused, ActivityState::WindowIsActive });
- else
- state.add({ ActivityState::IsFocused, ActivityState::WindowIsActive });
-
- page.setActivityState(state);
+ updatePageActivityState({ ActivityState::IsFocused, ActivityState::WindowIsActive }, isFocusedAndActive);
}
void Internals::setPageIsInWindow(bool isInWindow)
{
- auto* document = contextDocument();
- if (!document || !document->page())
+ updatePageActivityState(ActivityState::IsInWindow, isInWindow);
+}
+
+void Internals::updatePageActivityState(OptionSet<ActivityState::Flag> statesToChange, bool newValue)
+{
+ auto* page = contextDocument() ? contextDocument()->page() : nullptr;
+ if (!page)
return;
- auto& page = *document->page();
- auto state = page.activityState();
+ auto state = page->activityState();
- if (!isInWindow)
- state.remove({ ActivityState::IsInWindow });
+ if (!newValue)
+ state.remove(statesToChange);
else
- state.add({ ActivityState::IsInWindow });
+ state.add(statesToChange);
- page.setActivityState(state);
+ page->setActivityState(state);
}
bool Internals::isPageActive() const
Modified: trunk/Source/WebCore/testing/Internals.h (287497 => 287498)
--- trunk/Source/WebCore/testing/Internals.h 2022-01-01 00:22:38 UTC (rev 287497)
+++ trunk/Source/WebCore/testing/Internals.h 2022-01-01 06:03:35 UTC (rev 287498)
@@ -26,6 +26,7 @@
#pragma once
+#include "ActivityState.h"
#include "CSSComputedStyleDeclaration.h"
#include "ContextDestructionObserver.h"
#include "Cookie.h"
@@ -1235,6 +1236,8 @@
Document* contextDocument() const;
Frame* frame() const;
+ void updatePageActivityState(OptionSet<ActivityState::Flag> statesToChange, bool newValue);
+
ExceptionOr<RenderedDocumentMarker*> markerAt(Node&, const String& markerType, unsigned index);
ExceptionOr<ScrollableArea*> scrollableAreaForNode(Node*) const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes