2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A fake content node class so that the image frame for
|
|
|
|
* content: url(foo);
|
|
|
|
* in CSS can have an nsIImageLoadingContent but use an
|
|
|
|
* imgIRequest that's already been loaded from the style system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsXMLElement.h"
|
|
|
|
#include "nsImageLoadingContent.h"
|
|
|
|
#include "imgIRequest.h"
|
2013-09-25 04:21:22 -07:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2014-03-17 21:48:21 -07:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-02 21:18:36 -07:00
|
|
|
#include "mozilla/EventStates.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-17 21:48:19 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2013-07-11 14:26:54 -07:00
|
|
|
class nsGenConImageContent MOZ_FINAL : public nsXMLElement,
|
|
|
|
public nsImageLoadingContent
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit nsGenConImageContent(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsXMLElement(aNodeInfo)
|
|
|
|
{
|
2011-05-31 18:46:57 -07:00
|
|
|
// nsImageLoadingContent starts out broken, so we start out
|
|
|
|
// suppressed to match it.
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_SUPPRESSED);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-12 05:43:01 -07:00
|
|
|
nsresult Init(imgRequestProxy* aImageRequest)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// No need to notify, since we have no frame.
|
2014-08-19 14:49:38 -07:00
|
|
|
return UseAsPrimaryRequest(aImageRequest, false, eImageLoadType_Normal);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIContent overrides
|
2012-08-13 15:11:50 -07:00
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2015-01-02 18:13:39 -08:00
|
|
|
bool aCompileEventHandlers) MOZ_OVERRIDE;
|
|
|
|
virtual void UnbindFromTree(bool aDeep, bool aNullParent) MOZ_OVERRIDE;
|
|
|
|
virtual EventStates IntrinsicState() const MOZ_OVERRIDE;
|
2012-11-06 10:54:02 -08:00
|
|
|
|
2015-01-02 18:13:39 -08:00
|
|
|
virtual nsresult PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE
|
2012-11-06 10:54:02 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInNativeAnonymousSubtree());
|
|
|
|
if (aVisitor.mEvent->message == NS_LOAD ||
|
|
|
|
aVisitor.mEvent->message == NS_LOAD_ERROR) {
|
|
|
|
// Don't propagate the events to the parent.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return nsXMLElement::PreHandleEvent(aVisitor);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~nsGenConImageContent();
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsGenConImageContent,
|
|
|
|
nsXMLElement,
|
|
|
|
nsIImageLoadingContent,
|
|
|
|
imgINotificationObserver,
|
|
|
|
imgIOnloadBlocker)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
2014-06-19 19:01:40 -07:00
|
|
|
NS_NewGenConImageContent(nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2012-10-12 05:43:01 -07:00
|
|
|
imgRequestProxy* aImageRequest)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aImageRequest, "Must have request!");
|
2008-02-02 15:41:24 -08:00
|
|
|
nsGenConImageContent *it = new nsGenConImageContent(aNodeInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!it)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*aResult = it);
|
|
|
|
nsresult rv = it->Init(aImageRequest);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
NS_RELEASE(*aResult);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGenConImageContent::~nsGenConImageContent()
|
|
|
|
{
|
|
|
|
DestroyImageLoadingContent();
|
|
|
|
}
|
|
|
|
|
2012-08-13 15:11:50 -07:00
|
|
|
nsresult
|
|
|
|
nsGenConImageContent::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = nsXMLElement::BindToTree(aDocument, aParent, aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsImageLoadingContent::BindToTree(aDocument, aParent, aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenConImageContent::UnbindFromTree(bool aDeep, bool aNullParent)
|
|
|
|
{
|
|
|
|
nsImageLoadingContent::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
nsXMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGenConImageContent::IntrinsicState() const
|
|
|
|
{
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates state = nsXMLElement::IntrinsicState();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates imageState = nsImageLoadingContent::ImageState();
|
2010-10-20 04:26:32 -07:00
|
|
|
if (imageState.HasAtLeastOneOfStates(NS_EVENT_STATE_BROKEN | NS_EVENT_STATE_USERDISABLED)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We should never be in an error state; if the image fails to load, we
|
|
|
|
// just go to the suppressed state.
|
|
|
|
imageState |= NS_EVENT_STATE_SUPPRESSED;
|
|
|
|
imageState &= ~NS_EVENT_STATE_BROKEN;
|
|
|
|
}
|
|
|
|
imageState &= ~NS_EVENT_STATE_LOADING;
|
|
|
|
return state | imageState;
|
|
|
|
}
|