2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
2006-03-30 12:03:04 +04: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.
|
|
|
|
*/
|
|
|
|
|
2004-07-15 02:19:22 +04:00
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsXMLElement.h"
|
|
|
|
#include "nsImageLoadingContent.h"
|
|
|
|
#include "imgIRequest.h"
|
2013-09-25 15:21:22 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2004-07-15 02:19:22 +04:00
|
|
|
|
2014-03-18 08:48:19 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsGenConImageContent final : public nsXMLElement,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsImageLoadingContent
|
2004-07-15 02:19:22 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit nsGenConImageContent(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2004-07-15 02:19:22 +04:00
|
|
|
: nsXMLElement(aNodeInfo)
|
|
|
|
{
|
2011-06-01 05:46:57 +04:00
|
|
|
// nsImageLoadingContent starts out broken, so we start out
|
|
|
|
// suppressed to match it.
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_SUPPRESSED);
|
2004-07-15 02:19:22 +04:00
|
|
|
}
|
|
|
|
|
2012-10-12 16:43:01 +04:00
|
|
|
nsresult Init(imgRequestProxy* aImageRequest)
|
2004-07-15 02:19:22 +04:00
|
|
|
{
|
2005-09-20 06:05:48 +04:00
|
|
|
// No need to notify, since we have no frame.
|
2014-08-20 01:49:38 +04:00
|
|
|
return UseAsPrimaryRequest(aImageRequest, false, eImageLoadType_Normal);
|
2004-07-15 02:19:22 +04:00
|
|
|
}
|
2005-09-18 22:05:40 +04:00
|
|
|
|
|
|
|
// nsIContent overrides
|
2012-08-14 02:11:50 +04:00
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aCompileEventHandlers) override;
|
|
|
|
virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
|
|
|
|
virtual EventStates IntrinsicState() const override;
|
2012-11-06 22:54:02 +04:00
|
|
|
|
2016-10-21 05:11:07 +03:00
|
|
|
virtual nsresult GetEventTargetParent(EventChainPreVisitor& aVisitor) override
|
2012-11-06 22:54:02 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInNativeAnonymousSubtree());
|
2015-09-02 09:07:59 +03:00
|
|
|
if (aVisitor.mEvent->mMessage == eLoad ||
|
2015-09-02 09:07:59 +03:00
|
|
|
aVisitor.mEvent->mMessage == eLoadError) {
|
2012-11-06 22:54:02 +04:00
|
|
|
// Don't propagate the events to the parent.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-10-21 05:11:07 +03:00
|
|
|
return nsXMLElement::GetEventTargetParent(aVisitor);
|
2012-11-06 22:54:02 +04:00
|
|
|
}
|
2005-09-18 22:05:40 +04:00
|
|
|
|
2004-07-15 02:19:22 +04:00
|
|
|
private:
|
2006-06-01 22:35:21 +04:00
|
|
|
virtual ~nsGenConImageContent();
|
2004-07-15 02:19:22 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsGenConImageContent,
|
|
|
|
nsXMLElement,
|
|
|
|
nsIImageLoadingContent,
|
|
|
|
imgINotificationObserver,
|
|
|
|
imgIOnloadBlocker)
|
2004-07-15 02:19:22 +04:00
|
|
|
|
|
|
|
nsresult
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_NewGenConImageContent(nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2012-10-12 16:43:01 +04:00
|
|
|
imgRequestProxy* aImageRequest)
|
2004-07-15 02:19:22 +04:00
|
|
|
{
|
2005-09-20 06:05:48 +04:00
|
|
|
NS_PRECONDITION(aImageRequest, "Must have request!");
|
2008-02-03 02:41:24 +03:00
|
|
|
nsGenConImageContent *it = new nsGenConImageContent(aNodeInfo);
|
2004-07-15 02:19:22 +04:00
|
|
|
NS_ADDREF(*aResult = it);
|
|
|
|
nsresult rv = it->Init(aImageRequest);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
NS_RELEASE(*aResult);
|
|
|
|
return rv;
|
|
|
|
}
|
2005-09-18 22:05:40 +04:00
|
|
|
|
2006-06-01 22:35:21 +04:00
|
|
|
nsGenConImageContent::~nsGenConImageContent()
|
|
|
|
{
|
|
|
|
DestroyImageLoadingContent();
|
|
|
|
}
|
|
|
|
|
2012-08-14 02:11:50 +04: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-03 08:18:36 +04:00
|
|
|
EventStates
|
2005-09-18 22:05:40 +04:00
|
|
|
nsGenConImageContent::IntrinsicState() const
|
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsXMLElement::IntrinsicState();
|
2005-09-18 22:05:40 +04:00
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates imageState = nsImageLoadingContent::ImageState();
|
2010-10-20 15:26:32 +04:00
|
|
|
if (imageState.HasAtLeastOneOfStates(NS_EVENT_STATE_BROKEN | NS_EVENT_STATE_USERDISABLED)) {
|
2005-09-18 22:05:40 +04: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;
|
|
|
|
}
|
2005-11-02 03:00:20 +03:00
|
|
|
imageState &= ~NS_EVENT_STATE_LOADING;
|
2005-09-18 22:05:40 +04:00
|
|
|
return state | imageState;
|
|
|
|
}
|