summaryrefslogtreecommitdiffstats
path: root/toolkit/components/sessionstore/SessionStoreScrollData.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/sessionstore/SessionStoreScrollData.cpp
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/sessionstore/SessionStoreScrollData.cpp')
-rw-r--r--toolkit/components/sessionstore/SessionStoreScrollData.cpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/toolkit/components/sessionstore/SessionStoreScrollData.cpp b/toolkit/components/sessionstore/SessionStoreScrollData.cpp
new file mode 100644
index 0000000000..29d58befaa
--- /dev/null
+++ b/toolkit/components/sessionstore/SessionStoreScrollData.cpp
@@ -0,0 +1,123 @@
+/* -*- 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/. */
+
+#include "mozilla/dom/SessionStoreScrollData.h"
+#include <utility>
+
+#include "js/PropertyAndElement.h"
+#include "js/TypeDecls.h"
+#include "mozilla/Assertions.h"
+#include "mozilla/RefPtr.h"
+#include "mozilla/dom/BindingUtils.h"
+#include "mozilla/dom/BrowserSessionStoreBinding.h"
+#include "mozilla/dom/BrowsingContext.h"
+
+#include "nsPresContext.h"
+
+#include "mozilla/dom/WebIDLGlobalNameHash.h"
+#include "js/PropertyDescriptor.h"
+
+#include "mozilla/dom/ToJSValue.h"
+#include "mozilla/dom/GeneratedAtomList.h"
+#include "js/StructuredClone.h"
+#include "mozilla/dom/DOMJSClass.h"
+#include "mozilla/dom/StructuredCloneHolder.h"
+#include "nsContentUtils.h"
+#include "js/Array.h"
+#include "js/JSON.h"
+
+using namespace mozilla::dom;
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(SessionStoreScrollData)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(SessionStoreScrollData)
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WEAK_PTR(SessionStoreScrollData,
+ mChildren)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SessionStoreScrollData)
+ NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
+ NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END
+
+nsISupports* SessionStoreScrollData::GetParentObject() const {
+ return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
+ ;
+}
+
+JSObject* SessionStoreScrollData::WrapObject(
+ JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
+ return SessionStoreScrollData_Binding::Wrap(aCx, this, aGivenProto);
+}
+
+void SessionStoreScrollData::GetScroll(nsACString& aScroll) const {
+ int scrollX = nsPresContext::AppUnitsToIntCSSPixels(mScroll.x);
+ int scrollY = nsPresContext::AppUnitsToIntCSSPixels(mScroll.y);
+
+ if ((scrollX != 0) || (scrollY != 0)) {
+ aScroll = nsPrintfCString("%d,%d", scrollX, scrollY);
+ } else {
+ aScroll.SetIsVoid(true);
+ }
+}
+
+SessionStoreScrollData::ChildrenArray& SessionStoreScrollData::Children() {
+ return mChildren;
+}
+
+void SessionStoreScrollData::GetChildren(
+ Nullable<ChildrenArray>& aChildren) const {
+ if (!mChildren.IsEmpty()) {
+ aChildren.SetValue() = mChildren.Clone();
+ } else {
+ aChildren.SetNull();
+ }
+}
+
+void SessionStoreScrollData::ToJSON(JSContext* aCx,
+ JS::MutableHandle<JSObject*> aRetval) {
+ JS::Rooted<JSObject*> self(aCx);
+ {
+ JS::Rooted<JS::Value> value(aCx);
+ if (!GetOrCreateDOMReflector(aCx, this, &value)) {
+ return;
+ }
+
+ self.set(value.toObjectOrNull());
+ }
+
+ JS::Rooted<JSObject*> result(aCx, JS_NewPlainObject(aCx));
+
+ if (!IsEmpty()) {
+ if (HasData(mScroll)) {
+ if (!SessionStoreUtils::CopyProperty(aCx, result, self, u"scroll"_ns)) {
+ return;
+ }
+ }
+
+ SessionStoreUtils::CopyChildren(aCx, result, mChildren);
+ }
+
+ aRetval.set(result);
+}
+
+void SessionStoreScrollData::Update(const CollectedType& aUpdate) {
+ SessionStoreScrollData_Binding::ClearCachedScrollValue(this);
+ mScroll = aUpdate;
+}
+
+void SessionStoreScrollData::ClearCachedChildren() {
+ SessionStoreScrollData_Binding::ClearCachedChildrenValue(this);
+}
+
+/* static */
+bool SessionStoreScrollData::HasData(const CollectedType& aPoint) {
+ int scrollX = nsPresContext::AppUnitsToIntCSSPixels(aPoint.x);
+ int scrollY = nsPresContext::AppUnitsToIntCSSPixels(aPoint.y);
+ return scrollX != 0 || scrollY != 0;
+}
+
+bool SessionStoreScrollData::IsEmpty() const {
+ return !HasData(mScroll) && mChildren.IsEmpty();
+}