Bug 1609603 - Optimize the callers of DataTransfer::GetTypes() r=smaug

In C++ code, `DataTransfer::GetTypes()` are used for checking whether the
`DataTransfer` instance has specific type `DataTransferItem` or not.  Therefore,
it does not make sense to retrieve all item types nor compare some types
looking for with the retrieved item types.

This patch adds `DataTransfer::HasType()` and `DataTransfer::HasFile()` for
the current C++ users.  They don't take `CallerType` since all C++ users use
`GetTypes()` as `CallertType::System`.  And they just call a corresponding
method of `DataTransferItemList`.

Then, `DataTransferItemList` methods compares given type with every items
simply.

Note that this patch moves `DataTransfer::GetTypes()` to `DataTransferItemList`
too because new methods and `GetTypes()` should be maintained at every logic
changes.

The reason why there is no `DataTransfer::HasAnyOfTypes()` method is,
`DataTransfer.h` cannot include `DataTransferItemList.h` due to their
dependency but parameter pack requires inline methods.

Differential Revision: https://phabricator.services.mozilla.com/D60387
This commit is contained in:
Masayuki Nakano
2020-01-20 09:46:48 +00:00
parent 4d22b7eed8
commit 76f439a6ab
7 changed files with 73 additions and 48 deletions

View File

@@ -487,10 +487,7 @@ bool nsFileControlFrame::DnDListener::IsValidDropData(
}
// We only support dropping files onto a file upload control
nsTArray<nsString> types;
aDataTransfer->GetTypes(types, CallerType::System);
return types.Contains(NS_LITERAL_STRING("Files"));
return aDataTransfer->HasFile();
}
bool nsFileControlFrame::DnDListener::CanDropTheseFiles(