Files
palemoon27/layout/base/FramePropertyTable.cpp
T
roytam1 fa6c289afc import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1148718 - init TextureSource for current TextureHost when attach. r=nical, r=sotaro (f1eb3995a)
- Bug 1022080 - Add surface dumping for X11 basic textures. r=nical (37e49a4ef)
- Bug 1022080 - Dump compositable textures as something that we can paste into the URL bar. r=nical (73a9f5756)
- Bug 1022080 - Split out the paint item dumping from the rest of the paint dumping. r=mattwoodrow (ee751065f)
- Bug 1103348 - Part 1: Correctly reset the direction of an ancestor that is still in the tree when a text node is removed; r=smontagu (20bb27d10)
- Bug 1103348 - Part 2: Test case; r=ehsan (b177d5e1e)
- Bug 1169267: treat an empty nsTextDirectionalityMap as missing when changing text content (fd61ffbce)
- Tests for bug 1169267 (3e316e9f5)
- Bug 1181443 (part 1) - Use nsTHashtable::Iterator in nsCheapSet. r=froydnj. (0375daaf7)
- Bug 1181443 (part 2) - Use nsTHashtable::Iterator in TestHashtables.cpp. r=froydnj. (65a6fd77c)
- Bug 1182962 (part 1) - Use nsTHashtable::Iterator in gfxUserFontSet. r=jfkthame. (c54843415)
- Bug 1182962 (part 2) - Use nsTHashtable::Iterator in gfxFont. r=jfkthame. (08323c06e)
- Bug 1182963 - Use nsTHashTable::Iterator in FramePropertyTable. r=njn (dc613f42a)
- Bug 1182958 - Use nsTHashTable::Iterator in image/. r=seth. (da247b700)
- Bug 1157086 - Fix order of test listing in dom/animation/test/mochitest.ini. r=birtles (abee03ed9)
- Bug 1157053 - Test restarting of finished transitions. r=birtles (6257c7854)
- Bug 1157074 - Fix Web Animations' Web Platform tests to make them use step_func when they should. r=birtles (a5ff7736b)
- Bug 1159743. Stop forcing the dom.animations-api.core.enabled preference on in the test harness. r=birtles (29a84181b)
- Bug 1166164 part 1 - Make setting the current time complete a pending pause, not abort it; r=jwatt (e952486dd)
- Bug 1166164 part 2 - Make UpdateFinishedState take a non-defaulted enum; r=jwatt (ad5a2db34)
- Bug 1166164 part 3 - Resolve start time on finish(); r=jwatt (1019f154d)
- Bug 1166164 part 4 - Make finished promise not resolve when paused; r=jwatt (f591576ed)
- Bug 1166164 part 5 - Make play() throw when it should seek to the end of an infinite effect; r=jwatt, r=smaug (0e18eb111)
- Bug 1134381 - Don't pause an AnimationPlayer if it is already paused; r=jwatt (0ae4d1f71)
- Bug 1166164 part 6 - Make pausing from idle set the current time; r=jwatt, r=smaug (bd97211ef)
- Bug 1166164 part 7 - Call pause directly when creating an initially-paused animation; r=jwatt (eefeca3fe)
- Bug 1166164 part 8 - Drop a few references to players; r=jwatt (e89f33188)
- Bug 1147940 - Remove the dom.webcrypto.enabled pref as it is no longer necessary. r=smaug,r=rbarnes (4a329477f)
- Bug 1178186 part 1 - Add CSSAnimation and CSSTransition interfaces; r=smaug (64b61a9d2)
- Bug 1178186 part 2 - Add tests for CSSAnimation and CSSTransition interfaces; r=jwatt (9157d7172)
- Bug 1159117 - Test emulation of formats removed in core profiles. r=jgilbert (9cbcbb325)
2021-03-22 09:16:23 +08:00

234 lines
6.0 KiB
C++

/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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 "FramePropertyTable.h"
#include "mozilla/MemoryReporting.h"
namespace mozilla {
void
FramePropertyTable::Set(nsIFrame* aFrame, const FramePropertyDescriptor* aProperty,
void* aValue)
{
NS_ASSERTION(aFrame, "Null frame?");
NS_ASSERTION(aProperty, "Null property?");
if (mLastFrame != aFrame || !mLastEntry) {
mLastFrame = aFrame;
mLastEntry = mEntries.PutEntry(aFrame);
}
Entry* entry = mLastEntry;
if (!entry->mProp.IsArray()) {
if (!entry->mProp.mProperty) {
// Empty entry, so we can just store our property in the empty slot
entry->mProp.mProperty = aProperty;
entry->mProp.mValue = aValue;
return;
}
if (entry->mProp.mProperty == aProperty) {
// Just overwrite the current value
entry->mProp.DestroyValueFor(aFrame);
entry->mProp.mValue = aValue;
return;
}
// We need to expand the single current entry to an array
PropertyValue current = entry->mProp;
entry->mProp.mProperty = nullptr;
static_assert(sizeof(nsTArray<PropertyValue>) <= sizeof(void *),
"Property array must fit entirely within entry->mProp.mValue");
new (&entry->mProp.mValue) nsTArray<PropertyValue>(4);
entry->mProp.ToArray()->AppendElement(current);
}
nsTArray<PropertyValue>* array = entry->mProp.ToArray();
nsTArray<PropertyValue>::index_type index =
array->IndexOf(aProperty, 0, PropertyComparator());
if (index != nsTArray<PropertyValue>::NoIndex) {
PropertyValue* pv = &array->ElementAt(index);
pv->DestroyValueFor(aFrame);
pv->mValue = aValue;
return;
}
array->AppendElement(PropertyValue(aProperty, aValue));
}
void*
FramePropertyTable::Get(const nsIFrame* aFrame,
const FramePropertyDescriptor* aProperty,
bool* aFoundResult)
{
NS_ASSERTION(aFrame, "Null frame?");
NS_ASSERTION(aProperty, "Null property?");
if (aFoundResult) {
*aFoundResult = false;
}
if (mLastFrame != aFrame) {
mLastFrame = const_cast<nsIFrame*>(aFrame);
mLastEntry = mEntries.GetEntry(mLastFrame);
}
Entry* entry = mLastEntry;
if (!entry)
return nullptr;
if (entry->mProp.mProperty == aProperty) {
if (aFoundResult) {
*aFoundResult = true;
}
return entry->mProp.mValue;
}
if (!entry->mProp.IsArray()) {
// There's just one property and it's not the one we want, bail
return nullptr;
}
nsTArray<PropertyValue>* array = entry->mProp.ToArray();
nsTArray<PropertyValue>::index_type index =
array->IndexOf(aProperty, 0, PropertyComparator());
if (index == nsTArray<PropertyValue>::NoIndex)
return nullptr;
if (aFoundResult) {
*aFoundResult = true;
}
return array->ElementAt(index).mValue;
}
void*
FramePropertyTable::Remove(nsIFrame* aFrame, const FramePropertyDescriptor* aProperty,
bool* aFoundResult)
{
NS_ASSERTION(aFrame, "Null frame?");
NS_ASSERTION(aProperty, "Null property?");
if (aFoundResult) {
*aFoundResult = false;
}
if (mLastFrame != aFrame) {
mLastFrame = aFrame;
mLastEntry = mEntries.GetEntry(aFrame);
}
Entry* entry = mLastEntry;
if (!entry)
return nullptr;
if (entry->mProp.mProperty == aProperty) {
// There's only one entry and it's the one we want
void* value = entry->mProp.mValue;
mEntries.RawRemoveEntry(entry);
mLastEntry = nullptr;
if (aFoundResult) {
*aFoundResult = true;
}
return value;
}
if (!entry->mProp.IsArray()) {
// There's just one property and it's not the one we want, bail
return nullptr;
}
nsTArray<PropertyValue>* array = entry->mProp.ToArray();
nsTArray<PropertyValue>::index_type index =
array->IndexOf(aProperty, 0, PropertyComparator());
if (index == nsTArray<PropertyValue>::NoIndex) {
// No such property, bail
return nullptr;
}
if (aFoundResult) {
*aFoundResult = true;
}
void* result = array->ElementAt(index).mValue;
uint32_t last = array->Length() - 1;
array->ElementAt(index) = array->ElementAt(last);
array->RemoveElementAt(last);
if (last == 1) {
PropertyValue pv = array->ElementAt(0);
array->~nsTArray<PropertyValue>();
entry->mProp = pv;
}
return result;
}
void
FramePropertyTable::Delete(nsIFrame* aFrame, const FramePropertyDescriptor* aProperty)
{
NS_ASSERTION(aFrame, "Null frame?");
NS_ASSERTION(aProperty, "Null property?");
bool found;
void* v = Remove(aFrame, aProperty, &found);
if (found) {
PropertyValue pv(aProperty, v);
pv.DestroyValueFor(aFrame);
}
}
/* static */ void
FramePropertyTable::DeleteAllForEntry(Entry* aEntry)
{
if (!aEntry->mProp.IsArray()) {
aEntry->mProp.DestroyValueFor(aEntry->GetKey());
return;
}
nsTArray<PropertyValue>* array = aEntry->mProp.ToArray();
for (uint32_t i = 0; i < array->Length(); ++i) {
array->ElementAt(i).DestroyValueFor(aEntry->GetKey());
}
array->~nsTArray<PropertyValue>();
}
void
FramePropertyTable::DeleteAllFor(nsIFrame* aFrame)
{
NS_ASSERTION(aFrame, "Null frame?");
Entry* entry = mEntries.GetEntry(aFrame);
if (!entry)
return;
if (mLastFrame == aFrame) {
// Flush cache. We assume DeleteAllForEntry will be called before
// a frame is destroyed.
mLastFrame = nullptr;
mLastEntry = nullptr;
}
DeleteAllForEntry(entry);
mEntries.RawRemoveEntry(entry);
}
void
FramePropertyTable::DeleteAll()
{
mLastFrame = nullptr;
mLastEntry = nullptr;
for (auto iter = mEntries.Iter(); !iter.Done(); iter.Next()) {
DeleteAllForEntry(iter.Get());
}
mEntries.Clear();
}
size_t
FramePropertyTable::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
return mEntries.SizeOfExcludingThis(aMallocSizeOf);
}
} // namespace mozilla