Files
palemoon27/layout/base/FramePropertyTable.cpp
T
roytam1 f197afa7c1 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1230034 part 1 - Remove NS_PROPERTY_DESCRIPTOR_CONST macro. r=dbaron (7251a79067)
- Bug 1230034 part 2 - Constify aFrame parameters of frame property functions. r=dbaron (da8f373594)
- Bug 1230034 part 3 - Move some frame property declaration around. r=dbaron (d081d6b103)
- Bug 1235467. If the root reference frame is transformed don't use an ancestor of the root reference frame as the local reference frame. r=mattwoodrow (05fd8ae29c)
- Bug 1163583 - Crashtest. (cc20379288)
- Bug 1235489 - Remove assertion which is breakable when reflow is interrupted. r=jfkthame (f6a4001b55)
- Bug 1224669 - Reftest with extreme negative letter-spacing affecting intrinsic width. r=dholbert (b7dc81eb9a)
- Bug 1224669 - Clamp width to be non-negative during intrinsic width calculation. r=dholbert (9fa8d6cab7)
- Bug 1239251 - Initialize mCommonAncestorWithLastFrame with nullptr in constructor BuildTextRunsScanner. r=roc (2178f72ee3)
- Bug 1231175 - Reftest for failure to recognize mixed directionality in RTL para beginning with number within embed/isolate controls. r=smontagu (f3b0755b4c)
- Bug 1231175 - Missed change from Unicode 6.3 bidi algorithm update (ported from ICU's ubidi): include new ENL and ENR bidi pseudo-types in MASK_LTR. r=smontagu (f9c2cb657c)
- Bug 1233135 - Do not touch display value of anonymous box for ruby. r=dbaron (efe08e7e4a)
- Bug 1228716 - Give different frame keys for nsDisplayBlendContainer. r=roc (d7dfe4af0f)
- Bug 1235696. The animated geometry root of a transfromed and sticky pos frame should be the frame itself. r=mattwoodrow (d94a1284c5)
- Bug 1240073 - Use the transformed frame as the AGR for active transform so that FrameLayerBuilder knows that they can move independently. r=tnikkel (67b1ea8173)
- Bug 1237982 - Force perspective layers to always be active. r=thinker (591f169a91)
- Bug 1230774 - Use correct Z order to sort perspective items. r=roc (1be759c298)
- Bug 1230693 - Rebase transforms to the origin for callers than don't want them offset. r=mstange (cabb21c6e7)
- Bug 1230780 - Propagate preserve-3d handling through nsDisplayPerspective. r=thinker (8f82183587)
- Bug 1237457 - Partially Moz2Dify nsDisplayGeneric. r=roc. (e2221425d5)
- Bug 1226796 - Remove redundant preprocessor flags in nsContainerFrame.cpp. r=jfkthame (1853453cd4)
- Bug 1211635 - Popups should be treated as top-level windows, allowing XUL alerts translucency. r=MattN r=roc (07bd00b85a)
2023-08-22 11:29:19 +08:00

237 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(const 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 = 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(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 = 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(const 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(const 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