mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 666446, Part 8/18 - Change xul tree implementation to utilize refresh driver based animations for performance improvements with animated images. [r=roc]
This commit is contained in:
parent
91dcb84e48
commit
8828abe2a6
64
layout/xul/base/src/tree/src/nsITreeImageListener.h
Normal file
64
layout/xul/base/src/tree/src/nsITreeImageListener.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dave Hyatt <hyatt@mozilla.org> (Original Author)
|
||||
* Jan Varga <varga@ku.sk>
|
||||
* Scott Johnson <sjohnson@mozilla.com>, Mozilla Corporation
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsITreeImageListener_h__
|
||||
#define nsITreeImageListener_h__
|
||||
|
||||
// The interface for our image listener.
|
||||
// {90586540-2D50-403e-8DCE-981CAA778444}
|
||||
#define NS_ITREEIMAGELISTENER_IID \
|
||||
{ 0x90586540, 0x2d50, 0x403e, { 0x8d, 0xce, 0x98, 0x1c, 0xaa, 0x77, 0x84, 0x44 } }
|
||||
|
||||
class nsITreeImageListener : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITREEIMAGELISTENER_IID)
|
||||
|
||||
NS_IMETHOD AddCell(PRInt32 aIndex, nsITreeColumn* aCol) = 0;
|
||||
|
||||
/**
|
||||
* Clear the internal frame pointer to prevent dereferencing an object
|
||||
* that no longer exists.
|
||||
*/
|
||||
NS_IMETHOD ClearFrame() = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsITreeImageListener, NS_ITREEIMAGELISTENER_IID)
|
||||
|
||||
#endif
|
@ -54,6 +54,7 @@
|
||||
|
||||
#include "nsTreeBodyFrame.h"
|
||||
#include "nsTreeSelection.h"
|
||||
#include "nsTreeImageListener.h"
|
||||
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsCSSAnonBoxes.h"
|
||||
@ -114,6 +115,14 @@ static PLDHashOperator
|
||||
CancelImageRequest(const nsAString& aKey,
|
||||
nsTreeImageCacheEntry aEntry, void* aData)
|
||||
{
|
||||
|
||||
// If our imgIRequest object was registered with the refresh driver,
|
||||
// then we need to deregister it.
|
||||
nsTreeBodyFrame* frame = static_cast<nsTreeBodyFrame*>(aData);
|
||||
|
||||
nsLayoutUtils::DeregisterImageRequest(frame->PresContext(), aEntry.request,
|
||||
nsnull);
|
||||
|
||||
aEntry.request->CancelAndForgetObserver(NS_BINDING_ABORTED);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
@ -164,7 +173,8 @@ nsTreeBodyFrame::nsTreeBodyFrame(nsIPresShell* aPresShell, nsStyleContext* aCont
|
||||
// Destructor
|
||||
nsTreeBodyFrame::~nsTreeBodyFrame()
|
||||
{
|
||||
mImageCache.EnumerateRead(CancelImageRequest, nsnull);
|
||||
mImageCache.EnumerateRead(CancelImageRequest, this);
|
||||
DetachImageListeners();
|
||||
delete mSlots;
|
||||
}
|
||||
|
||||
@ -197,8 +207,11 @@ nsTreeBodyFrame::Init(nsIContent* aContent,
|
||||
mIndentation = GetIndentation();
|
||||
mRowHeight = GetRowHeight();
|
||||
|
||||
NS_ENSURE_TRUE(mCreatedListeners.Init(), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ENSURE_TRUE(mImageCache.Init(16), NS_ERROR_OUT_OF_MEMORY);
|
||||
EnsureBoxObject();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -2154,10 +2167,14 @@ nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, nsTreeColumn* aCol, bool aUseContex
|
||||
if (!*aResult) {
|
||||
// Create a new nsTreeImageListener object and pass it our row and column
|
||||
// information.
|
||||
nsTreeImageListener* listener = new nsTreeImageListener(mTreeBoxObject);
|
||||
nsTreeImageListener* listener = new nsTreeImageListener(this);
|
||||
if (!listener)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (!mCreatedListeners.PutEntry(listener)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
listener->AddCell(aRowIndex, aCol);
|
||||
nsCOMPtr<imgIDecoderObserver> imgDecoderObserver = listener;
|
||||
|
||||
@ -4236,7 +4253,7 @@ nsresult
|
||||
nsTreeBodyFrame::ClearStyleAndImageCaches()
|
||||
{
|
||||
mStyleCache.Clear();
|
||||
mImageCache.EnumerateRead(CancelImageRequest, nsnull);
|
||||
mImageCache.EnumerateRead(CancelImageRequest, this);
|
||||
mImageCache.Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
@ -4468,6 +4485,20 @@ nsTreeBodyFrame::PostScrollEvent()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsTreeBodyFrame::DetachImageListeners()
|
||||
{
|
||||
mCreatedListeners.Clear();
|
||||
}
|
||||
|
||||
void
|
||||
nsTreeBodyFrame::RemoveTreeImageListener(nsTreeImageListener* aListener)
|
||||
{
|
||||
if (aListener) {
|
||||
mCreatedListeners.RemoveEntry(aListener);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ACCESSIBILITY
|
||||
void
|
||||
nsTreeBodyFrame::FireRowCountChangedEvent(PRInt32 aIndex, PRInt32 aCount)
|
||||
@ -4641,3 +4672,19 @@ nsTreeBodyFrame::FullScrollbarsUpdate(bool aNeedsFullInvalidation)
|
||||
nsContentUtils::AddScriptRunner(new nsOverflowChecker(this));
|
||||
return weakFrame.IsAlive();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTreeBodyFrame::OnStartDecode(imgIRequest* aRequest)
|
||||
{
|
||||
nsLayoutUtils::RegisterImageRequest(PresContext(), aRequest, nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTreeBodyFrame::OnStopDecode(imgIRequest* aRequest, nsresult aStatus,
|
||||
const PRUnichar* aStatusArg)
|
||||
{
|
||||
nsLayoutUtils::DeregisterImageRequestIfNotAnimated(PresContext(), aRequest,
|
||||
nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -54,7 +54,6 @@
|
||||
#include "nsTArray.h"
|
||||
#include "nsTreeStyleCache.h"
|
||||
#include "nsTreeColumns.h"
|
||||
#include "nsTreeImageListener.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsDataHashtable.h"
|
||||
#include "imgIRequest.h"
|
||||
@ -62,8 +61,10 @@
|
||||
#include "nsScrollbarFrame.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/LookAndFeel.h"
|
||||
#include "nsITreeImageListener.h"
|
||||
|
||||
class nsOverflowChecker;
|
||||
class nsTreeImageListener;
|
||||
|
||||
// An entry in the tree's image cache
|
||||
struct nsTreeImageCacheEntry
|
||||
@ -91,6 +92,13 @@ public:
|
||||
NS_DECL_QUERYFRAME
|
||||
NS_DECL_FRAMEARENA_HELPERS
|
||||
|
||||
// Callback handler methods for refresh driver based animations.
|
||||
// Calls to these functions are forwarded from nsTreeImageListener. These
|
||||
// mirror how nsImageFrame works.
|
||||
nsresult OnStartDecode(imgIRequest* aRequest);
|
||||
nsresult OnStopDecode(imgIRequest* aRequest, nsresult aStatus,
|
||||
const PRUnichar* aStatusArg);
|
||||
|
||||
// non-virtual signatures like nsITreeBodyFrame
|
||||
nsresult GetColumns(nsITreeColumns **aColumns);
|
||||
nsresult GetView(nsITreeView **aView);
|
||||
@ -435,6 +443,15 @@ public:
|
||||
return col;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an nsITreeImageListener from being tracked by this frame. Only tree
|
||||
* image listeners that are created by this frame are tracked.
|
||||
*
|
||||
* @param aListener A pointer to an nsTreeImageListener to no longer
|
||||
* track.
|
||||
*/
|
||||
void RemoveTreeImageListener(nsTreeImageListener* aListener);
|
||||
|
||||
protected:
|
||||
|
||||
// Create a new timer. This method is used to delay various actions like
|
||||
@ -465,6 +482,12 @@ protected:
|
||||
void PostScrollEvent();
|
||||
void FireScrollEvent();
|
||||
|
||||
/**
|
||||
* Clear the pointer to this frame for all nsTreeImageListeners that were
|
||||
* created by this frame.
|
||||
*/
|
||||
void DetachImageListeners();
|
||||
|
||||
#ifdef ACCESSIBILITY
|
||||
/**
|
||||
* Fires 'treeRowCountChanged' event asynchronously. The event supports
|
||||
@ -602,6 +625,11 @@ protected: // Data Members
|
||||
bool mHorizontalOverflow;
|
||||
|
||||
bool mReflowCallbackPosted;
|
||||
|
||||
// Hash table to keep track of which listeners we created and thus
|
||||
// have pointers to us.
|
||||
nsTHashtable<nsPtrHashKey<nsTreeImageListener> > mCreatedListeners;
|
||||
|
||||
}; // class nsTreeBodyFrame
|
||||
|
||||
#endif
|
||||
|
@ -44,8 +44,8 @@
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsTreeImageListener, imgIDecoderObserver, imgIContainerObserver, nsITreeImageListener)
|
||||
|
||||
nsTreeImageListener::nsTreeImageListener(nsITreeBoxObject* aTree)
|
||||
: mTree(aTree),
|
||||
nsTreeImageListener::nsTreeImageListener(nsTreeBodyFrame* aTreeFrame)
|
||||
: mTreeFrame(aTreeFrame),
|
||||
mInvalidationSuppressed(PR_TRUE),
|
||||
mInvalidationArea(nsnull)
|
||||
{
|
||||
@ -56,6 +56,29 @@ nsTreeImageListener::~nsTreeImageListener()
|
||||
delete mInvalidationArea;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTreeImageListener::OnStartDecode(imgIRequest *aRequest)
|
||||
{
|
||||
if (!mTreeFrame) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// grab the frame we want to use
|
||||
return mTreeFrame->OnStartDecode(aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTreeImageListener::OnStopDecode(imgIRequest *aRequest,
|
||||
nsresult aStatus,
|
||||
const PRUnichar *aStatusArg)
|
||||
{
|
||||
if (!mTreeFrame) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return mTreeFrame->OnStopDecode(aRequest, aStatus, aStatusArg);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTreeImageListener::OnStartContainer(imgIRequest *aRequest,
|
||||
imgIContainer *aImage)
|
||||
{
|
||||
@ -113,10 +136,16 @@ void
|
||||
nsTreeImageListener::Invalidate()
|
||||
{
|
||||
if (!mInvalidationSuppressed) {
|
||||
for (InvalidationArea* currArea = mInvalidationArea; currArea; currArea = currArea->GetNext()) {
|
||||
for (InvalidationArea* currArea = mInvalidationArea; currArea;
|
||||
currArea = currArea->GetNext()) {
|
||||
// Loop from min to max, invalidating each cell that was listening for this image.
|
||||
for (PRInt32 i = currArea->GetMin(); i <= currArea->GetMax(); ++i) {
|
||||
mTree->InvalidateCell(i, currArea->GetCol());
|
||||
if (mTreeFrame) {
|
||||
nsITreeBoxObject* tree = mTreeFrame->GetTreeBoxObject();
|
||||
if (tree) {
|
||||
tree->InvalidateCell(i, currArea->GetCol());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -140,3 +169,10 @@ nsTreeImageListener::InvalidationArea::AddRow(PRInt32 aIndex)
|
||||
else if (aIndex > mMax)
|
||||
mMax = aIndex;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTreeImageListener::ClearFrame()
|
||||
{
|
||||
mTreeFrame = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -44,33 +44,21 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsITreeColumns.h"
|
||||
#include "nsStubImageDecoderObserver.h"
|
||||
|
||||
class nsITreeBoxObject;
|
||||
|
||||
// The interface for our image listener.
|
||||
// {90586540-2D50-403e-8DCE-981CAA778444}
|
||||
#define NS_ITREEIMAGELISTENER_IID \
|
||||
{ 0x90586540, 0x2d50, 0x403e, { 0x8d, 0xce, 0x98, 0x1c, 0xaa, 0x77, 0x84, 0x44 } }
|
||||
|
||||
class nsITreeImageListener : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITREEIMAGELISTENER_IID)
|
||||
|
||||
NS_IMETHOD AddCell(PRInt32 aIndex, nsITreeColumn* aCol) = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsITreeImageListener, NS_ITREEIMAGELISTENER_IID)
|
||||
#include "nsTreeBodyFrame.h"
|
||||
#include "nsITreeImageListener.h"
|
||||
|
||||
// This class handles image load observation.
|
||||
class nsTreeImageListener : public nsStubImageDecoderObserver, public nsITreeImageListener
|
||||
{
|
||||
public:
|
||||
nsTreeImageListener(nsITreeBoxObject* aTree);
|
||||
nsTreeImageListener(nsTreeBodyFrame *aTreeFrame);
|
||||
~nsTreeImageListener();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
// imgIDecoderObserver (override nsStubImageDecoderObserver)
|
||||
NS_IMETHOD OnStartDecode(imgIRequest *aRequest);
|
||||
NS_IMETHOD OnStopDecode(imgIRequest *aRequest,
|
||||
nsresult aStatus, const PRUnichar *aStatusArg);
|
||||
NS_IMETHOD OnStartContainer(imgIRequest *aRequest, imgIContainer *aImage);
|
||||
NS_IMETHOD OnDataAvailable(imgIRequest *aRequest, bool aCurrentFrame,
|
||||
const nsIntRect *aRect);
|
||||
@ -79,6 +67,8 @@ public:
|
||||
const nsIntRect *aDirtyRect);
|
||||
|
||||
NS_IMETHOD AddCell(PRInt32 aIndex, nsITreeColumn* aCol);
|
||||
|
||||
NS_IMETHOD ClearFrame();
|
||||
|
||||
friend class nsTreeBodyFrame;
|
||||
|
||||
@ -87,7 +77,7 @@ protected:
|
||||
void Invalidate();
|
||||
|
||||
private:
|
||||
nsITreeBoxObject* mTree;
|
||||
nsTreeBodyFrame* mTreeFrame;
|
||||
|
||||
// A guard that prevents us from recursive painting.
|
||||
bool mInvalidationSuppressed;
|
||||
|
Loading…
Reference in New Issue
Block a user