From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- layout/style/MediaList.cpp | 176 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 layout/style/MediaList.cpp (limited to 'layout/style/MediaList.cpp') diff --git a/layout/style/MediaList.cpp b/layout/style/MediaList.cpp new file mode 100644 index 0000000000..b4e477c901 --- /dev/null +++ b/layout/style/MediaList.cpp @@ -0,0 +1,176 @@ +/* -*- 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/. */ + +/* base class for representation of media lists */ + +#include "mozilla/dom/MediaList.h" + +#include "mozAutoDocUpdate.h" +#include "mozilla/dom/Document.h" +#include "mozilla/dom/MediaListBinding.h" +#include "mozilla/ServoBindings.h" +#include "mozilla/ServoStyleSet.h" +#include "mozilla/StyleSheetInlines.h" + +namespace mozilla::dom { + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaList) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaList) +NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaList) + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(MediaList) + +JSObject* MediaList::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) { + return MediaList_Binding::Wrap(aCx, this, aGivenProto); +} + +void MediaList::SetStyleSheet(StyleSheet* aSheet) { + MOZ_ASSERT(aSheet == mStyleSheet || !aSheet || !mStyleSheet, + "Multiple style sheets competing for one media list"); + mStyleSheet = aSheet; +} + +nsISupports* MediaList::GetParentObject() const { return mStyleSheet; } + +template +void MediaList::DoMediaChange(Func aCallback, ErrorResult& aRv) { + if (IsReadOnly()) { + return; + } + + if (mStyleSheet) { + mStyleSheet->WillDirty(); + } + + aCallback(aRv); + if (aRv.Failed()) { + return; + } + + if (mStyleSheet) { + // FIXME(emilio): We should discern between "owned by a rule" (as in @media) + // and "owned by a sheet" (as in