Bug 666446, Part 3/10 - Create hook functions in nsLayoutUtils to coalesce some of the new code for frame-like objects and avoid code duplication. [r=roc]

This commit is contained in:
Scott Johnson 2011-11-09 13:39:16 -08:00
parent 7f71c7c437
commit 47400a66c0
2 changed files with 154 additions and 0 deletions

View File

@ -4327,6 +4327,102 @@ nsLayoutUtils::Shutdown()
}
}
/* static */
void
nsLayoutUtils::RegisterImageRequest(nsPresContext* aPresContext,
imgIRequest* aRequest,
bool* aRequestRegistered)
{
if (!aPresContext) {
return;
}
if (aRequestRegistered && *aRequestRegistered) {
// Our request is already registered with the refresh driver, so
// no need to register it again.
return;
}
if (aRequest) {
if (!aPresContext->RefreshDriver()->AddImageRequest(aRequest)) {
NS_WARNING("Unable to add image request");
return;
}
if (aRequestRegistered) {
*aRequestRegistered = true;
}
}
}
/* static */
void
nsLayoutUtils::RegisterImageRequestIfAnimated(nsPresContext* aPresContext,
imgIRequest* aRequest,
bool* aRequestRegistered)
{
if (!aPresContext) {
return;
}
if (aRequestRegistered && *aRequestRegistered) {
// Our request is already registered with the refresh driver, so
// no need to register it again.
return;
}
if (aRequest) {
nsCOMPtr<imgIContainer> image;
aRequest->GetImage(getter_AddRefs(image));
if (image) {
// Check to verify that the image is animated. If so, then add it to the
// list of images tracked by the refresh driver.
bool isAnimated = false;
nsresult rv = image->GetAnimated(&isAnimated);
if (NS_SUCCEEDED(rv) && isAnimated) {
if (!aPresContext->RefreshDriver()->AddImageRequest(aRequest)) {
NS_WARNING("Unable to add image request");
return;
}
if (aRequestRegistered) {
*aRequestRegistered = true;
}
}
}
}
}
/* static */
void
nsLayoutUtils::DeregisterImageRequest(nsPresContext* aPresContext,
imgIRequest* aRequest,
bool* aRequestRegistered)
{
if (!aPresContext) {
return;
}
// Deregister our imgIRequest with the refresh driver to
// complete tear-down, but only if it has been registered
if (aRequestRegistered && !*aRequestRegistered) {
return;
}
if (aRequest) {
nsCOMPtr<imgIContainer> image;
aRequest->GetImage(getter_AddRefs(image));
if (image) {
aPresContext->RefreshDriver()->RemoveImageRequest(aRequest);
if (aRequestRegistered) {
*aRequestRegistered = false;
}
}
}
}
nsSetAttrRunnable::nsSetAttrRunnable(nsIContent* aContent, nsIAtom* aAttrName,
const nsAString& aValue)
: mContent(aContent),

View File

@ -1454,6 +1454,64 @@ public:
static void Shutdown();
/**
* Register an imgIRequest object with a refresh driver.
*
* @param aPresContext The nsPresContext whose refresh driver we want to
* register with.
* @param aRequest A pointer to the imgIRequest object which the client wants
* to register with the refresh driver.
* @param aRequestRegistered A pointer to a boolean value which indicates
* whether the given image request is registered. If
* *aRequestRegistered is true, then this request will not be
* registered again. If the request is registered by this function,
* then *aRequestRegistered will be set to true upon the completion of
* this function.
*
*/
static void RegisterImageRequest(nsPresContext* aPresContext,
imgIRequest* aRequest,
bool* aRequestRegistered);
/**
* Register an imgIRequest object with a refresh driver, but only if the
* request is for an image that is animated.
*
* @param aPresContext The nsPresContext whose refresh driver we want to
* register with.
* @param aRequest A pointer to the imgIRequest object which the client wants
* to register with the refresh driver.
* @param aRequestRegistered A pointer to a boolean value which indicates
* whether the given image request is registered. If
* *aRequestRegistered is true, then this request will not be
* registered again. If the request is registered by this function,
* then *aRequestRegistered will be set to true upon the completion of
* this function.
*
*/
static void RegisterImageRequestIfAnimated(nsPresContext* aPresContext,
imgIRequest* aRequest,
bool* aRequestRegistered);
/**
* Deregister an imgIRequest object from a refresh driver.
*
* @param aPresContext The nsPresContext whose refresh driver we want to
* deregister from.
* @param aRequest A pointer to the imgIRequest object with which the client
* previously registered and now wants to deregister from the refresh
* driver.
* @param aRequestRegistered A pointer to a boolean value which indicates
* whether the given image request is registered. If
* *aRequestRegistered is false, then this request will not be
* deregistered. If the request is deregistered by this function,
* then *aRequestRegistered will be set to false upon the completion of
* this function.
*/
static void DeregisterImageRequest(nsPresContext* aPresContext,
imgIRequest* aRequest,
bool* aRequestRegistered);
#ifdef DEBUG
/**
* Assert that there are no duplicate continuations of the same frame