layout/xul/tree/nsTreeImageListener.cpp

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial