Bug 1404222 Part 2: Extend ImageLoader to associate flags with each request-frame relationship. r=dbaron

This commit is contained in:
Brad Werth 2018-03-16 11:01:57 -07:00
Родитель 8efec59d87
Коммит 311eb01351
2 изменённых файлов: 39 добавлений и 7 удалений

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

@ -77,9 +77,10 @@ ImageLoader::AssociateRequestToFrame(imgIRequest* aRequest,
});
// Add these to the sets, but only if they're not already there.
uint32_t i = frameSet->IndexOfFirstElementGt(aFrame);
if (i == 0 || aFrame != frameSet->ElementAt(i-1)) {
frameSet->InsertElementAt(i, aFrame);
FrameWithFlags fwf(aFrame);
uint32_t i = frameSet->IndexOfFirstElementGt(fwf, FrameOnlyComparator());
if (i == 0 || aFrame != frameSet->ElementAt(i-1).mFrame) {
frameSet->InsertElementAt(i, fwf);
}
i = requestSet->IndexOfFirstElementGt(aRequest);
if (i == 0 || aRequest != requestSet->ElementAt(i-1)) {
@ -139,7 +140,8 @@ ImageLoader::RemoveRequestToFrameMapping(imgIRequest* aRequest,
if (auto entry = mRequestToFrameMap.Lookup(aRequest)) {
FrameSet* frameSet = entry.Data();
MOZ_ASSERT(frameSet, "This should never be null");
frameSet->RemoveElementSorted(aFrame);
frameSet->RemoveElementSorted(FrameWithFlags(aFrame),
FrameOnlyComparator());
if (frameSet->IsEmpty()) {
nsPresContext* presContext = GetPresContext();
if (presContext) {
@ -362,7 +364,8 @@ ImageLoader::DoRedraw(FrameSet* aFrameSet, bool aForcePaint)
NS_ASSERTION(aFrameSet, "Must have a frame set");
NS_ASSERTION(mDocument, "Should have returned earlier!");
for (nsIFrame* frame : *aFrameSet) {
for (FrameWithFlags& fwf : *aFrameSet) {
nsIFrame* frame = fwf.mFrame;
if (frame->StyleVisibility()->IsVisible()) {
if (frame->IsFrameOfType(nsIFrame::eTablePart)) {
// Tables don't necessarily build border/background display items
@ -454,7 +457,8 @@ ImageLoader::OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage)
return NS_OK;
}
for (nsIFrame* frame : *frameSet) {
for (FrameWithFlags& fwf : *frameSet) {
nsIFrame* frame = fwf.mFrame;
if (frame->StyleVisibility()->IsVisible()) {
frame->MarkNeedsDisplayItemRebuild();
}

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

@ -80,7 +80,35 @@ private:
// the frame goes away). Thus we maintain hashtables going both ways. These
// should always be in sync.
typedef nsTArray<nsIFrame*> FrameSet;
// We also associate flags alongside frames in the request-to-frames hashmap.
// These are used for special handling of events for requests.
typedef uint32_t FrameFlags;
struct FrameWithFlags {
FrameWithFlags(nsIFrame* aFrame)
: mFrame(aFrame),
mFlags(0)
{
MOZ_ASSERT(mFrame);
}
nsIFrame* const mFrame;
FrameFlags mFlags;
};
// A helper class to compare FrameWithFlags by comparing mFrame and
// ignoring mFlags.
class FrameOnlyComparator {
public:
bool Equals(const FrameWithFlags& aElem1,
const FrameWithFlags& aElem2) const
{ return aElem1.mFrame == aElem2.mFrame; }
bool LessThan(const FrameWithFlags& aElem1,
const FrameWithFlags& aElem2) const
{ return aElem1.mFrame < aElem2.mFrame; }
};
typedef nsTArray<FrameWithFlags> FrameSet;
typedef nsTArray<nsCOMPtr<imgIRequest> > RequestSet;
typedef nsTHashtable<nsPtrHashKey<Image> > ImageHashSet;
typedef nsClassHashtable<nsISupportsHashKey,