1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2003
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Dave Hyatt <hyatt@mozilla.org> (Original Author)
24 : * Jan Varga <varga@ku.sk>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "nsTreeImageListener.h"
41 : #include "nsITreeBoxObject.h"
42 : #include "imgIRequest.h"
43 : #include "imgIContainer.h"
44 :
45 0 : NS_IMPL_ISUPPORTS2(nsTreeImageListener, imgIDecoderObserver, imgIContainerObserver)
46 :
47 0 : nsTreeImageListener::nsTreeImageListener(nsTreeBodyFrame* aTreeFrame)
48 : : mTreeFrame(aTreeFrame),
49 : mInvalidationSuppressed(true),
50 0 : mInvalidationArea(nsnull)
51 : {
52 0 : }
53 :
54 0 : nsTreeImageListener::~nsTreeImageListener()
55 : {
56 0 : delete mInvalidationArea;
57 0 : }
58 :
59 : NS_IMETHODIMP
60 0 : nsTreeImageListener::OnImageIsAnimated(imgIRequest *aRequest)
61 : {
62 0 : if (!mTreeFrame) {
63 0 : return NS_OK;
64 : }
65 :
66 0 : return mTreeFrame->OnImageIsAnimated(aRequest);
67 : }
68 :
69 0 : NS_IMETHODIMP nsTreeImageListener::OnStartContainer(imgIRequest *aRequest,
70 : imgIContainer *aImage)
71 : {
72 : // Ensure the animation (if any) is started. Note: There is no
73 : // corresponding call to Decrement for this. This Increment will be
74 : // 'cleaned up' by the Request when it is destroyed, but only then.
75 0 : aRequest->IncrementAnimationConsumers();
76 0 : return NS_OK;
77 : }
78 :
79 0 : NS_IMETHODIMP nsTreeImageListener::OnDataAvailable(imgIRequest *aRequest,
80 : bool aCurrentFrame,
81 : const nsIntRect *aRect)
82 : {
83 0 : Invalidate();
84 0 : return NS_OK;
85 : }
86 :
87 0 : NS_IMETHODIMP nsTreeImageListener::FrameChanged(imgIRequest *aRequest,
88 : imgIContainer *aContainer,
89 : const nsIntRect *aDirtyRect)
90 : {
91 0 : Invalidate();
92 0 : return NS_OK;
93 : }
94 :
95 :
96 : void
97 0 : nsTreeImageListener::AddCell(PRInt32 aIndex, nsITreeColumn* aCol)
98 : {
99 0 : if (!mInvalidationArea) {
100 0 : mInvalidationArea = new InvalidationArea(aCol);
101 0 : mInvalidationArea->AddRow(aIndex);
102 : }
103 : else {
104 : InvalidationArea* currArea;
105 0 : for (currArea = mInvalidationArea; currArea; currArea = currArea->GetNext()) {
106 0 : if (currArea->GetCol() == aCol) {
107 0 : currArea->AddRow(aIndex);
108 0 : break;
109 : }
110 : }
111 0 : if (!currArea) {
112 0 : currArea = new InvalidationArea(aCol);
113 0 : currArea->SetNext(mInvalidationArea);
114 0 : mInvalidationArea = currArea;
115 0 : mInvalidationArea->AddRow(aIndex);
116 : }
117 : }
118 0 : }
119 :
120 :
121 : void
122 0 : nsTreeImageListener::Invalidate()
123 : {
124 0 : if (!mInvalidationSuppressed) {
125 0 : for (InvalidationArea* currArea = mInvalidationArea; currArea;
126 : currArea = currArea->GetNext()) {
127 : // Loop from min to max, invalidating each cell that was listening for this image.
128 0 : for (PRInt32 i = currArea->GetMin(); i <= currArea->GetMax(); ++i) {
129 0 : if (mTreeFrame) {
130 0 : nsITreeBoxObject* tree = mTreeFrame->GetTreeBoxObject();
131 0 : if (tree) {
132 0 : tree->InvalidateCell(i, currArea->GetCol());
133 : }
134 : }
135 : }
136 : }
137 : }
138 0 : }
139 :
140 0 : nsTreeImageListener::InvalidationArea::InvalidationArea(nsITreeColumn* aCol)
141 : : mCol(aCol),
142 : mMin(-1), // min should start out "undefined"
143 : mMax(0),
144 0 : mNext(nsnull)
145 : {
146 0 : }
147 :
148 : void
149 0 : nsTreeImageListener::InvalidationArea::AddRow(PRInt32 aIndex)
150 : {
151 0 : if (mMin == -1)
152 0 : mMin = mMax = aIndex;
153 0 : else if (aIndex < mMin)
154 0 : mMin = aIndex;
155 0 : else if (aIndex > mMax)
156 0 : mMax = aIndex;
157 0 : }
158 :
159 : NS_IMETHODIMP
160 0 : nsTreeImageListener::ClearFrame()
161 : {
162 0 : mTreeFrame = nsnull;
163 0 : return NS_OK;
164 : }
|