Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsTreeImageListener.h" |
michael@0 | 7 | #include "nsITreeBoxObject.h" |
michael@0 | 8 | #include "imgIRequest.h" |
michael@0 | 9 | #include "imgIContainer.h" |
michael@0 | 10 | |
michael@0 | 11 | NS_IMPL_ISUPPORTS(nsTreeImageListener, imgINotificationObserver) |
michael@0 | 12 | |
michael@0 | 13 | nsTreeImageListener::nsTreeImageListener(nsTreeBodyFrame* aTreeFrame) |
michael@0 | 14 | : mTreeFrame(aTreeFrame), |
michael@0 | 15 | mInvalidationSuppressed(true), |
michael@0 | 16 | mInvalidationArea(nullptr) |
michael@0 | 17 | { |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | nsTreeImageListener::~nsTreeImageListener() |
michael@0 | 21 | { |
michael@0 | 22 | delete mInvalidationArea; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | NS_IMETHODIMP |
michael@0 | 26 | nsTreeImageListener::Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData) |
michael@0 | 27 | { |
michael@0 | 28 | if (aType == imgINotificationObserver::IS_ANIMATED) { |
michael@0 | 29 | return mTreeFrame ? mTreeFrame->OnImageIsAnimated(aRequest) : NS_OK; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | if (aType == imgINotificationObserver::SIZE_AVAILABLE) { |
michael@0 | 33 | // Ensure the animation (if any) is started. Note: There is no |
michael@0 | 34 | // corresponding call to Decrement for this. This Increment will be |
michael@0 | 35 | // 'cleaned up' by the Request when it is destroyed, but only then. |
michael@0 | 36 | aRequest->IncrementAnimationConsumers(); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | if (aType == imgINotificationObserver::FRAME_UPDATE) { |
michael@0 | 40 | Invalidate(); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | return NS_OK; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | void |
michael@0 | 47 | nsTreeImageListener::AddCell(int32_t aIndex, nsITreeColumn* aCol) |
michael@0 | 48 | { |
michael@0 | 49 | if (!mInvalidationArea) { |
michael@0 | 50 | mInvalidationArea = new InvalidationArea(aCol); |
michael@0 | 51 | mInvalidationArea->AddRow(aIndex); |
michael@0 | 52 | } |
michael@0 | 53 | else { |
michael@0 | 54 | InvalidationArea* currArea; |
michael@0 | 55 | for (currArea = mInvalidationArea; currArea; currArea = currArea->GetNext()) { |
michael@0 | 56 | if (currArea->GetCol() == aCol) { |
michael@0 | 57 | currArea->AddRow(aIndex); |
michael@0 | 58 | break; |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | if (!currArea) { |
michael@0 | 62 | currArea = new InvalidationArea(aCol); |
michael@0 | 63 | currArea->SetNext(mInvalidationArea); |
michael@0 | 64 | mInvalidationArea = currArea; |
michael@0 | 65 | mInvalidationArea->AddRow(aIndex); |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | |
michael@0 | 71 | void |
michael@0 | 72 | nsTreeImageListener::Invalidate() |
michael@0 | 73 | { |
michael@0 | 74 | if (!mInvalidationSuppressed) { |
michael@0 | 75 | for (InvalidationArea* currArea = mInvalidationArea; currArea; |
michael@0 | 76 | currArea = currArea->GetNext()) { |
michael@0 | 77 | // Loop from min to max, invalidating each cell that was listening for this image. |
michael@0 | 78 | for (int32_t i = currArea->GetMin(); i <= currArea->GetMax(); ++i) { |
michael@0 | 79 | if (mTreeFrame) { |
michael@0 | 80 | nsITreeBoxObject* tree = mTreeFrame->GetTreeBoxObject(); |
michael@0 | 81 | if (tree) { |
michael@0 | 82 | tree->InvalidateCell(i, currArea->GetCol()); |
michael@0 | 83 | } |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | nsTreeImageListener::InvalidationArea::InvalidationArea(nsITreeColumn* aCol) |
michael@0 | 91 | : mCol(aCol), |
michael@0 | 92 | mMin(-1), // min should start out "undefined" |
michael@0 | 93 | mMax(0), |
michael@0 | 94 | mNext(nullptr) |
michael@0 | 95 | { |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | void |
michael@0 | 99 | nsTreeImageListener::InvalidationArea::AddRow(int32_t aIndex) |
michael@0 | 100 | { |
michael@0 | 101 | if (mMin == -1) |
michael@0 | 102 | mMin = mMax = aIndex; |
michael@0 | 103 | else if (aIndex < mMin) |
michael@0 | 104 | mMin = aIndex; |
michael@0 | 105 | else if (aIndex > mMax) |
michael@0 | 106 | mMax = aIndex; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | NS_IMETHODIMP |
michael@0 | 110 | nsTreeImageListener::ClearFrame() |
michael@0 | 111 | { |
michael@0 | 112 | mTreeFrame = nullptr; |
michael@0 | 113 | return NS_OK; |
michael@0 | 114 | } |