Bug 1298243 part 5. Notify the DataTransfer whenever its types list changes. r=mystor

This commit is contained in:
Boris Zbarsky 2016-10-10 21:07:47 -04:00
Родитель ee441d05fb
Коммит 241a4d12eb
4 изменённых файлов: 29 добавлений и 5 удалений

Просмотреть файл

@ -692,6 +692,13 @@ DataTransfer::PrincipalMaySetData(const nsAString& aType,
return true;
}
void
DataTransfer::TypesListMayHaveChanged()
{
// For now do nothing; we'll want to clear our cached types list once we start
// caching it.
}
nsresult
DataTransfer::SetDataAtInternal(const nsAString& aFormat, nsIVariant* aData,
uint32_t aIndex,

Просмотреть файл

@ -289,6 +289,11 @@ public:
nsIVariant* aData,
nsIPrincipal* aPrincipal);
// Notify the DataTransfer that the list returned from GetTypes may have
// changed. This can happen due to items we care about for purposes of
// GetTypes being added or removed or changing item kinds.
void TypesListMayHaveChanged();
protected:
// caches text and uri-list data formats that exist in the drag service or

Просмотреть файл

@ -224,11 +224,10 @@ DataTransferItem::FillInExternalData()
SetData(variant);
#ifdef DEBUG
if (oldKind != Kind()) {
NS_WARNING("Clipboard data provided by the OS does not match predicted kind");
mDataTransfer->TypesListMayHaveChanged();
}
#endif
}
already_AddRefed<File>

Просмотреть файл

@ -370,6 +370,10 @@ DataTransferItemList::SetDataWithPrincipal(const nsAString& aType,
DataTransferItem::eKind oldKind = item->Kind();
item->SetData(aData);
if (oldKind != item->Kind()) {
// Types list may have changed, even if aIndex == 0.
mDataTransfer->TypesListMayHaveChanged();
}
if (aIndex != 0) {
// If the item changes from being a file to not a file or vice-versa,
@ -433,9 +437,15 @@ DataTransferItemList::AppendNewItem(uint32_t aIndex,
// adding to is 0, or the item we are adding is a file. If we add an item
// which is not a file to a non-zero index, invariants could be broken.
// (namely the invariant that there are not 2 non-file entries in the items
// array with the same type)
if (!aHidden && (item->Kind() == DataTransferItem::KIND_FILE || aIndex == 0)) {
mItems.AppendElement(item);
// array with the same type).
//
// We also want to update our DataTransfer's type list any time we're adding a
// KIND_FILE item, or an item at index 0.
if (item->Kind() == DataTransferItem::KIND_FILE || aIndex == 0) {
if (!aHidden) {
mItems.AppendElement(item);
}
mDataTransfer->TypesListMayHaveChanged();
}
return item;
@ -475,6 +485,7 @@ DataTransferItemList::ClearAllItems()
mItems.Clear();
mIndexedItems.Clear();
mIndexedItems.SetLength(1);
mDataTransfer->TypesListMayHaveChanged();
// Re-generate files (into an empty list)
RegenerateFiles();
@ -517,6 +528,8 @@ DataTransferItemList::ClearDataHelper(DataTransferItem* aItem,
items.RemoveElement(aItem);
}
mDataTransfer->TypesListMayHaveChanged();
// Check if we should remove the index. We never remove index 0.
if (items.Length() == 0 && aItem->Index() != 0) {
mIndexedItems.RemoveElementAt(aItem->Index());