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/. */
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2012-12-31 21:25:46 +04:00
|
|
|
#include "mozilla/dom/HTMLImageElement.h"
|
2012-12-31 22:48:55 +04:00
|
|
|
#include "mozilla/dom/HTMLImageElementBinding.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-03 05:03:33 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2004-01-26 22:22:05 +03:00
|
|
|
#include "nsMappedAttributes.h"
|
1999-05-07 04:08:21 +04:00
|
|
|
#include "nsSize.h"
|
2015-03-17 22:25:35 +03:00
|
|
|
#include "nsDocument.h"
|
1999-05-07 04:08:21 +04:00
|
|
|
#include "nsIDocument.h"
|
2013-08-21 16:44:14 +04:00
|
|
|
#include "nsIDOMMutationEvent.h"
|
1999-05-07 04:08:21 +04:00
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIURL.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2001-02-19 15:55:42 +03:00
|
|
|
#include "nsContentUtils.h"
|
2014-05-25 02:20:39 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2000-05-10 17:13:39 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2001-05-22 02:40:10 +04:00
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2010-08-09 20:15:47 +04:00
|
|
|
#include "nsFocusManager.h"
|
2013-06-19 18:24:37 +04:00
|
|
|
#include "mozilla/dom/HTMLFormElement.h"
|
2014-07-02 00:36:06 +04:00
|
|
|
#include "nsAttrValueOrString.h"
|
2014-10-09 00:53:24 +04:00
|
|
|
#include "imgLoader.h"
|
2015-03-17 22:25:35 +03:00
|
|
|
#include "Image.h"
|
1999-12-18 23:29:29 +03:00
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
// Responsive images!
|
|
|
|
#include "mozilla/dom/HTMLSourceElement.h"
|
|
|
|
#include "mozilla/dom/ResponsiveImageSelector.h"
|
|
|
|
|
2001-03-22 04:42:01 +03:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgILoader.h"
|
2012-10-12 20:11:22 +04:00
|
|
|
#include "imgINotificationObserver.h"
|
2012-10-12 16:43:01 +04:00
|
|
|
#include "imgRequestProxy.h"
|
2001-03-22 04:42:01 +03:00
|
|
|
|
|
|
|
#include "nsILoadGroup.h"
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2004-07-20 10:11:27 +04:00
|
|
|
#include "nsRuleData.h"
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2004-07-25 01:12:43 +04:00
|
|
|
#include "nsIDOMHTMLMapElement.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"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2007-02-18 13:43:12 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
|
2014-05-03 03:26:22 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
static const char *kPrefSrcsetEnabled = "dom.image.srcset.enabled";
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Image)
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2014-10-02 07:59:56 +04:00
|
|
|
#ifdef DEBUG
|
2014-05-03 01:32:20 +04:00
|
|
|
// Is aSubject a previous sibling of aNode.
|
|
|
|
static bool IsPreviousSibling(nsINode *aSubject, nsINode *aNode)
|
|
|
|
{
|
|
|
|
if (aSubject == aNode) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINode *parent = aSubject->GetParentNode();
|
|
|
|
if (parent && parent == aNode->GetParentNode()) {
|
|
|
|
return parent->IndexOf(aSubject) < parent->IndexOf(aNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-02 07:59:56 +04:00
|
|
|
#endif
|
2014-05-03 01:32:20 +04:00
|
|
|
|
2012-12-31 21:25:46 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
// Calls LoadSelectedImage on host element unless it has been superseded or
|
|
|
|
// canceled -- this is the synchronous section of "update the image data".
|
|
|
|
// https://html.spec.whatwg.org/multipage/embedded-content.html#update-the-image-data
|
|
|
|
class ImageLoadTask : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2015-08-31 22:29:40 +03:00
|
|
|
ImageLoadTask(HTMLImageElement *aElement, bool aAlwaysLoad)
|
|
|
|
: mElement(aElement)
|
|
|
|
, mAlwaysLoad(aAlwaysLoad)
|
2015-06-06 16:21:56 +03:00
|
|
|
{
|
|
|
|
mDocument = aElement->OwnerDoc();
|
|
|
|
mDocument->BlockOnload();
|
|
|
|
}
|
2014-10-02 07:30:49 +04:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
if (mElement->mPendingImageLoadTask == this) {
|
|
|
|
mElement->mPendingImageLoadTask = nullptr;
|
2015-08-31 22:29:40 +03:00
|
|
|
mElement->LoadSelectedImage(true, true, mAlwaysLoad);
|
2014-10-02 07:30:49 +04:00
|
|
|
}
|
2015-06-06 16:21:56 +03:00
|
|
|
mDocument->UnblockOnload(false);
|
2014-10-02 07:30:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-30 19:39:59 +03:00
|
|
|
bool AlwaysLoad() {
|
|
|
|
return mAlwaysLoad;
|
|
|
|
}
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
private:
|
|
|
|
~ImageLoadTask() {}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLImageElement> mElement;
|
2015-06-06 16:21:56 +03:00
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
2015-08-31 22:29:40 +03:00
|
|
|
bool mAlwaysLoad;
|
2014-10-02 07:30:49 +04:00
|
|
|
};
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLImageElement::HTMLImageElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2004-05-19 00:58:12 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
2013-06-18 16:53:23 +04:00
|
|
|
, mForm(nullptr)
|
2015-08-31 22:29:40 +03:00
|
|
|
, mInDocResponsiveContent(false)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2011-06-01 05:46:57 +04:00
|
|
|
// We start out broken
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_BROKEN);
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
|
|
|
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::~HTMLImageElement()
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2006-06-01 22:35:21 +04:00
|
|
|
DestroyImageLoadingContent();
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-31 21:25:46 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLImageElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLImageElement, Element)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2014-10-14 00:36:01 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLImageElement,
|
|
|
|
nsGenericHTMLElement,
|
|
|
|
mResponsiveSelector)
|
2010-01-12 16:08:43 +03:00
|
|
|
|
2012-12-31 21:25:46 +04:00
|
|
|
// QueryInterface implementation for HTMLImageElement
|
2013-06-18 16:53:23 +04:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLImageElement)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(HTMLImageElement,
|
|
|
|
nsIDOMHTMLImageElement,
|
|
|
|
nsIImageLoadingContent,
|
|
|
|
imgIOnloadBlocker,
|
|
|
|
imgINotificationObserver)
|
2013-08-08 00:23:08 +04:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
|
|
|
|
2012-12-31 21:25:46 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLImageElement)
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-31 21:25:46 +04:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLImageElement, Name, name)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLImageElement, Align, align)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLImageElement, Alt, alt)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLImageElement, Border, border)
|
|
|
|
NS_IMPL_INT_ATTR(HTMLImageElement, Hspace, hspace)
|
|
|
|
NS_IMPL_BOOL_ATTR(HTMLImageElement, IsMap, ismap)
|
|
|
|
NS_IMPL_URI_ATTR(HTMLImageElement, LongDesc, longdesc)
|
2014-03-20 01:18:57 +04:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLImageElement, Sizes, sizes)
|
2012-12-31 21:25:46 +04:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLImageElement, Lowsrc, lowsrc)
|
|
|
|
NS_IMPL_URI_ATTR(HTMLImageElement, Src, src)
|
2014-03-20 01:18:24 +04:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLImageElement, Srcset, srcset)
|
2012-12-31 21:25:46 +04:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLImageElement, UseMap, usemap)
|
|
|
|
NS_IMPL_INT_ATTR(HTMLImageElement, Vspace, vspace)
|
2000-01-04 06:06:13 +03:00
|
|
|
|
2015-01-20 23:39:28 +03:00
|
|
|
bool
|
2015-03-17 23:42:14 +03:00
|
|
|
HTMLImageElement::IsInteractiveHTMLContent(bool aIgnoreTabindex) const
|
2015-01-20 23:39:28 +03:00
|
|
|
{
|
2015-03-23 12:02:33 +03:00
|
|
|
return HasAttr(kNameSpaceID_None, nsGkAtoms::usemap) ||
|
|
|
|
nsGenericHTMLElement::IsInteractiveHTMLContent(aIgnoreTabindex);
|
2015-01-20 23:39:28 +03:00
|
|
|
}
|
|
|
|
|
2014-05-03 03:26:22 +04:00
|
|
|
bool
|
|
|
|
HTMLImageElement::IsSrcsetEnabled()
|
|
|
|
{
|
|
|
|
return Preferences::GetBool(kPrefSrcsetEnabled, false);
|
|
|
|
}
|
|
|
|
|
2014-05-14 01:21:15 +04:00
|
|
|
nsresult
|
|
|
|
HTMLImageElement::GetCurrentSrc(nsAString& aValue)
|
|
|
|
{
|
|
|
|
if (!IsSrcsetEnabled()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
|
|
|
GetCurrentURI(getter_AddRefs(currentURI));
|
|
|
|
if (currentURI) {
|
|
|
|
nsAutoCString spec;
|
|
|
|
currentURI->GetSpec(spec);
|
|
|
|
CopyUTF8toUTF16(spec, aValue);
|
|
|
|
} else {
|
|
|
|
SetDOMStringToNull(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-05 03:49:57 +04:00
|
|
|
void
|
2015-02-13 04:27:39 +03:00
|
|
|
HTMLImageElement::GetItemValueText(DOMString& aValue)
|
2012-06-05 03:49:57 +04:00
|
|
|
{
|
|
|
|
GetSrc(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::SetItemValueText(const nsAString& aValue)
|
2012-06-05 03:49:57 +04:00
|
|
|
{
|
|
|
|
SetSrc(aValue);
|
|
|
|
}
|
|
|
|
|
2012-10-06 11:19:52 +04:00
|
|
|
bool
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::Draggable() const
|
2008-08-27 16:07:27 +04:00
|
|
|
{
|
|
|
|
// images may be dragged unless the draggable attribute is false
|
2012-10-06 11:19:52 +04:00
|
|
|
return !AttrValueIs(kNameSpaceID_None, nsGkAtoms::draggable,
|
|
|
|
nsGkAtoms::_false, eIgnoreCase);
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
|
|
|
|
2012-12-31 22:48:55 +04:00
|
|
|
bool
|
|
|
|
HTMLImageElement::Complete()
|
2000-01-07 02:41:14 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
if (!mCurrentRequest) {
|
2012-12-31 22:48:55 +04:00
|
|
|
return true;
|
2000-01-07 02:41:14 +03:00
|
|
|
}
|
|
|
|
|
2015-02-05 05:05:17 +03:00
|
|
|
if (mPendingRequest) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t status;
|
2003-03-19 06:47:09 +03:00
|
|
|
mCurrentRequest->GetImageStatus(&status);
|
2012-12-31 22:48:55 +04:00
|
|
|
return
|
2003-05-03 06:32:43 +04:00
|
|
|
(status &
|
|
|
|
(imgIRequest::STATUS_LOAD_COMPLETE | imgIRequest::STATUS_ERROR)) != 0;
|
2012-12-31 22:48:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLImageElement::GetComplete(bool* aComplete)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aComplete, "Null out param!");
|
|
|
|
|
|
|
|
*aComplete = Complete();
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2000-07-12 07:35:13 +04:00
|
|
|
return NS_OK;
|
2000-01-07 02:41:14 +03:00
|
|
|
}
|
|
|
|
|
2013-06-12 11:00:08 +04:00
|
|
|
CSSIntPoint
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::GetXY()
|
2012-04-24 23:04:37 +04:00
|
|
|
{
|
|
|
|
nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
|
|
|
|
if (!frame) {
|
2013-06-12 11:00:08 +04:00
|
|
|
return CSSIntPoint(0, 0);
|
2012-04-24 23:04:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* layer = nsLayoutUtils::GetClosestLayer(frame->GetParent());
|
2013-06-12 11:00:08 +04:00
|
|
|
return CSSIntPoint::FromAppUnitsRounded(frame->GetOffsetTo(layer));
|
2012-04-24 23:04:37 +04:00
|
|
|
}
|
|
|
|
|
2013-06-02 19:38:25 +04:00
|
|
|
int32_t
|
|
|
|
HTMLImageElement::X()
|
|
|
|
{
|
|
|
|
return GetXY().x;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
HTMLImageElement::Y()
|
|
|
|
{
|
|
|
|
return GetXY().y;
|
|
|
|
}
|
|
|
|
|
2012-04-24 23:04:37 +04:00
|
|
|
NS_IMETHODIMP
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::GetX(int32_t* aX)
|
2012-04-24 23:04:37 +04:00
|
|
|
{
|
2013-06-02 19:38:25 +04:00
|
|
|
*aX = X();
|
2012-04-24 23:04:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::GetY(int32_t* aY)
|
2012-04-24 23:04:37 +04:00
|
|
|
{
|
2013-06-02 19:38:25 +04:00
|
|
|
*aY = Y();
|
2012-04-24 23:04:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-03 09:05:32 +03:00
|
|
|
NS_IMETHODIMP
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::GetHeight(uint32_t* aHeight)
|
2002-01-03 09:05:32 +03:00
|
|
|
{
|
2012-12-31 22:48:55 +04:00
|
|
|
*aHeight = Height();
|
2004-01-10 02:54:21 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2002-01-03 09:05:32 +03:00
|
|
|
}
|
|
|
|
|
2000-06-07 05:23:55 +04:00
|
|
|
NS_IMETHODIMP
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::SetHeight(uint32_t aHeight)
|
2000-06-07 05:23:55 +04:00
|
|
|
{
|
2013-04-04 11:03:50 +04:00
|
|
|
ErrorResult rv;
|
|
|
|
SetHeight(aHeight, rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2000-01-04 06:06:13 +03:00
|
|
|
}
|
|
|
|
|
2000-06-07 05:23:55 +04:00
|
|
|
NS_IMETHODIMP
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::GetWidth(uint32_t* aWidth)
|
2000-06-07 05:23:55 +04:00
|
|
|
{
|
2012-12-31 22:48:55 +04:00
|
|
|
*aWidth = Width();
|
2004-01-10 02:54:21 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-06-07 05:23:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::SetWidth(uint32_t aWidth)
|
2000-06-07 05:23:55 +04:00
|
|
|
{
|
2013-04-04 11:03:50 +04:00
|
|
|
ErrorResult rv;
|
|
|
|
SetWidth(aWidth, rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2000-06-07 05:23:55 +04:00
|
|
|
}
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2005-11-29 19:37:15 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
2005-11-29 19:37:15 +03:00
|
|
|
return ParseAlignValue(aValue, aResult);
|
|
|
|
}
|
2011-07-17 21:40:22 +04:00
|
|
|
if (aAttribute == nsGkAtoms::crossorigin) {
|
2012-03-10 20:13:51 +04:00
|
|
|
ParseCORSValue(aValue, aResult);
|
|
|
|
return true;
|
2011-07-14 22:47:35 +04:00
|
|
|
}
|
2005-11-29 19:37:15 +03:00
|
|
|
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2005-11-29 19:37:15 +03:00
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult);
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
|
|
|
|
2013-11-19 23:21:29 +04:00
|
|
|
void
|
|
|
|
HTMLImageElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
|
|
|
nsRuleData* aData)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2003-07-12 01:16:12 +04:00
|
|
|
nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aData);
|
2001-06-01 02:19:43 +04:00
|
|
|
nsGenericHTMLElement::MapImageBorderAttributeInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData);
|
2003-07-12 01:16:12 +04:00
|
|
|
nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
|
2001-06-01 02:19:43 +04:00
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
1998-09-05 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2004-10-24 21:10:32 +04:00
|
|
|
nsChangeHint
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) const
|
1999-07-07 05:24:40 +04:00
|
|
|
{
|
2004-10-24 21:10:32 +04:00
|
|
|
nsChangeHint retval =
|
|
|
|
nsGenericHTMLElement::GetAttributeChangeHint(aAttribute, aModType);
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::usemap ||
|
|
|
|
aAttribute == nsGkAtoms::ismap) {
|
2004-10-24 21:10:32 +04:00
|
|
|
NS_UpdateHint(retval, NS_STYLE_HINT_FRAMECHANGE);
|
2013-08-21 16:44:14 +04:00
|
|
|
} else if (aAttribute == nsGkAtoms::alt) {
|
|
|
|
if (aModType == nsIDOMMutationEvent::ADDITION ||
|
|
|
|
aModType == nsIDOMMutationEvent::REMOVAL) {
|
|
|
|
NS_UpdateHint(retval, NS_STYLE_HINT_FRAMECHANGE);
|
|
|
|
}
|
2003-07-12 01:16:12 +04:00
|
|
|
}
|
2004-10-24 21:10:32 +04:00
|
|
|
return retval;
|
2003-07-12 01:16:12 +04:00
|
|
|
}
|
2003-04-17 00:54:20 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
2003-07-12 01:16:12 +04:00
|
|
|
{
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2003-04-17 00:54:20 +04:00
|
|
|
sCommonAttributeMap,
|
2003-07-12 01:16:12 +04:00
|
|
|
sImageMarginSizeAttributeMap,
|
|
|
|
sImageBorderAttributeMap,
|
|
|
|
sImageAlignAttributeMap
|
2003-04-17 00:54:20 +04:00
|
|
|
};
|
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
1999-07-07 05:24:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
nsMapRuleToAttributesFunc
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::GetAttributeMappingFunction() const
|
1998-09-05 08:00:06 +04:00
|
|
|
{
|
2005-01-12 22:45:38 +03:00
|
|
|
return &MapAttributesIntoRule;
|
1998-09-03 05:03:33 +04:00
|
|
|
}
|
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
nsresult
|
|
|
|
HTMLImageElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2015-08-01 08:14:06 +03:00
|
|
|
nsAttrValueOrString* aValue,
|
2013-06-18 16:53:23 +04:00
|
|
|
bool aNotify)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None && mForm &&
|
|
|
|
(aName == nsGkAtoms::name || aName == nsGkAtoms::id)) {
|
|
|
|
// remove the image from the hashtable as needed
|
|
|
|
nsAutoString tmp;
|
|
|
|
GetAttr(kNameSpaceID_None, aName, tmp);
|
|
|
|
|
|
|
|
if (!tmp.IsEmpty()) {
|
2013-06-18 16:54:27 +04:00
|
|
|
mForm->RemoveImageElementFromTable(this, tmp,
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::AttributeUpdated);
|
2013-06-18 16:53:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::BeforeSetAttr(aNameSpaceID, aName,
|
|
|
|
aValue, aNotify);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None && mForm &&
|
|
|
|
(aName == nsGkAtoms::name || aName == nsGkAtoms::id) &&
|
|
|
|
aValue && !aValue->IsEmptyString()) {
|
|
|
|
// add the image to the hashtable as needed
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aValue->Type() == nsAttrValue::eAtom,
|
|
|
|
"Expected atom value for name/id");
|
2013-06-18 16:53:23 +04:00
|
|
|
mForm->AddImageElementToTable(this,
|
|
|
|
nsDependentAtomString(aValue->GetAtomValue()));
|
|
|
|
}
|
|
|
|
|
2014-05-03 03:26:22 +04:00
|
|
|
// Handle src/srcset/crossorigin updates. If aNotify is false, we are coming
|
|
|
|
// from the parser or some such place; we'll get bound after all the
|
|
|
|
// attributes have been set, so we'll do the image load from BindToTree.
|
2014-05-03 01:32:20 +04:00
|
|
|
|
2014-07-02 00:36:06 +04:00
|
|
|
nsAttrValueOrString attrVal(aValue);
|
|
|
|
|
2014-05-03 03:26:22 +04:00
|
|
|
if (aName == nsGkAtoms::src &&
|
2014-10-02 07:30:49 +04:00
|
|
|
aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
!aValue) {
|
|
|
|
// SetAttr handles setting src since it needs to catch img.src =
|
|
|
|
// img.src, so we only need to handle the unset case
|
2014-10-02 07:59:56 +04:00
|
|
|
if (InResponsiveMode()) {
|
2015-03-11 00:38:30 +03:00
|
|
|
if (mResponsiveSelector &&
|
|
|
|
mResponsiveSelector->Content() == this) {
|
2014-12-11 02:53:00 +03:00
|
|
|
mResponsiveSelector->SetDefaultSource(NullString());
|
2014-10-02 07:30:49 +04:00
|
|
|
}
|
2015-08-31 22:29:40 +03:00
|
|
|
QueueImageLoadTask(true);
|
2014-10-02 07:30:49 +04:00
|
|
|
} else {
|
|
|
|
// Bug 1076583 - We still behave synchronously in the non-responsive case
|
2014-05-03 03:26:22 +04:00
|
|
|
CancelImageRequests(aNotify);
|
|
|
|
}
|
|
|
|
} else if (aName == nsGkAtoms::srcset &&
|
|
|
|
aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
IsSrcsetEnabled()) {
|
2014-10-02 07:30:49 +04:00
|
|
|
PictureSourceSrcsetChanged(this, attrVal.String(), aNotify);
|
2014-05-03 01:32:20 +04:00
|
|
|
} else if (aName == nsGkAtoms::sizes &&
|
|
|
|
aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
HTMLPictureElement::IsPictureEnabled()) {
|
2014-10-02 07:30:49 +04:00
|
|
|
PictureSourceSizesChanged(this, attrVal.String(), aNotify);
|
2014-05-03 03:26:22 +04:00
|
|
|
} else if (aName == nsGkAtoms::crossorigin &&
|
|
|
|
aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
aNotify) {
|
2014-10-02 07:30:49 +04:00
|
|
|
// Force a new load of the image with the new cross origin policy.
|
2014-10-02 07:59:56 +04:00
|
|
|
if (InResponsiveMode()) {
|
2014-10-02 07:30:49 +04:00
|
|
|
// per spec, full selection runs when this changes, even though
|
|
|
|
// it doesn't directly affect the source selection
|
2015-08-31 22:29:40 +03:00
|
|
|
QueueImageLoadTask(true);
|
2014-10-02 07:30:49 +04:00
|
|
|
} else {
|
|
|
|
// Bug 1076583 - We still use the older synchronous algorithm in
|
2014-08-20 01:49:38 +04:00
|
|
|
// non-responsive mode. Force a new load of the image with the
|
|
|
|
// new cross origin policy.
|
|
|
|
ForceReload(aNotify);
|
2014-05-03 03:26:22 +04:00
|
|
|
}
|
2013-10-10 18:54:02 +04:00
|
|
|
}
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
|
|
|
|
aValue, aNotify);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult
|
2014-03-18 08:48:19 +04:00
|
|
|
HTMLImageElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2000-12-23 13:56:31 +03:00
|
|
|
// If we are a map and get a mouse click, don't let it be handled by
|
|
|
|
// the Generic Element as this could cause a click event to fire
|
|
|
|
// twice, once by the image frame for the map and once by the Anchor
|
|
|
|
// element. (bug 39723)
|
2013-10-28 13:03:19 +04:00
|
|
|
WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
|
2015-09-10 14:49:19 +03:00
|
|
|
if (mouseEvent && mouseEvent->IsLeftClickEvent() && IsMap()) {
|
|
|
|
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
|
2000-06-14 19:02:18 +04:00
|
|
|
}
|
2006-03-07 20:08:51 +03:00
|
|
|
return nsGenericHTMLElement::PreHandleEvent(aVisitor);
|
1998-09-15 03:02:32 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::IsHTMLFocusable(bool aWithMouse,
|
|
|
|
bool *aIsFocusable, int32_t *aTabIndex)
|
2004-07-25 01:12:43 +04:00
|
|
|
{
|
2012-10-06 11:19:51 +04:00
|
|
|
int32_t tabIndex = TabIndex();
|
2004-07-25 01:12:43 +04:00
|
|
|
|
2016-03-31 13:58:25 +03:00
|
|
|
if (IsInUncomposedDoc()) {
|
2004-07-25 01:12:43 +04:00
|
|
|
nsAutoString usemap;
|
|
|
|
GetUseMap(usemap);
|
2004-10-11 20:14:27 +04:00
|
|
|
// XXXbz which document should this be using? sXBL/XBL2 issue! I
|
2011-10-18 14:53:36 +04:00
|
|
|
// think that OwnerDoc() is right, since we don't want to
|
2004-10-11 20:14:27 +04:00
|
|
|
// assume stuff about the document we're bound to.
|
2011-10-18 15:19:44 +04:00
|
|
|
if (OwnerDoc()->FindImageMap(usemap)) {
|
2004-07-25 01:12:43 +04:00
|
|
|
if (aTabIndex) {
|
|
|
|
// Use tab index on individual map areas
|
|
|
|
*aTabIndex = (sTabFocusModel & eTabFocus_linksMask)? 0 : -1;
|
|
|
|
}
|
2004-07-30 17:02:31 +04:00
|
|
|
// Image map is not focusable itself, but flag as tabbable
|
|
|
|
// so that image map areas get walked into.
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsFocusable = false;
|
2008-04-30 04:11:04 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2004-07-25 01:12:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTabIndex) {
|
|
|
|
// Can be in tab order if tabindex >=0 and form controls are tabbable.
|
|
|
|
*aTabIndex = (sTabFocusModel & eTabFocus_formElementsMask)? tabIndex : -1;
|
|
|
|
}
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
*aIsFocusable =
|
2010-06-21 16:37:34 +04:00
|
|
|
#ifdef XP_MACOSX
|
2010-08-09 20:15:47 +04:00
|
|
|
(!aWithMouse || nsFocusManager::sMouseFocusesFormControl) &&
|
2010-06-21 16:37:34 +04:00
|
|
|
#endif
|
|
|
|
(tabIndex >= 0 || HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex));
|
2008-04-15 22:40:38 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2004-07-25 01:12:43 +04:00
|
|
|
}
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
|
|
|
bool aNotify)
|
2003-03-19 06:47:09 +03:00
|
|
|
{
|
2014-03-11 01:38:02 +04:00
|
|
|
// We need to force our image to reload. This must be done here, not in
|
|
|
|
// AfterSetAttr or BeforeSetAttr, because we want to do it even if the attr is
|
|
|
|
// being set to its existing value, which is normally optimized away as a
|
|
|
|
// no-op.
|
|
|
|
//
|
2014-10-02 07:30:49 +04:00
|
|
|
// If we are in responsive mode, we drop the forced reload behavior,
|
|
|
|
// but still trigger a image load task for img.src = img.src per
|
|
|
|
// spec.
|
2014-05-03 03:26:22 +04:00
|
|
|
//
|
2014-10-02 07:30:49 +04:00
|
|
|
// Both cases handle unsetting src in AfterSetAttr
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
2014-03-11 01:38:02 +04:00
|
|
|
aName == nsGkAtoms::src) {
|
|
|
|
|
2014-10-02 07:59:56 +04:00
|
|
|
if (InResponsiveMode()) {
|
2014-10-02 07:30:49 +04:00
|
|
|
if (mResponsiveSelector &&
|
|
|
|
mResponsiveSelector->Content() == this) {
|
|
|
|
mResponsiveSelector->SetDefaultSource(aValue);
|
|
|
|
}
|
2015-08-31 22:29:40 +03:00
|
|
|
QueueImageLoadTask(true);
|
2014-10-02 07:30:49 +04:00
|
|
|
} else if (aNotify) {
|
|
|
|
// If aNotify is false, we are coming from the parser or some such place;
|
|
|
|
// we'll get bound after all the attributes have been set, so we'll do the
|
|
|
|
// sync image load from BindToTree. Skip the LoadImage call in that case.
|
|
|
|
|
|
|
|
// Note that this sync behavior is partially removed from the spec, bug 1076583
|
2014-03-11 01:38:02 +04:00
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
// A hack to get animations to reset. See bug 594771.
|
|
|
|
mNewRequestsWillNeedAnimationReset = true;
|
2014-03-11 01:38:02 +04:00
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
// Force image loading here, so that we'll try to load the image from
|
|
|
|
// network if it's set to be not cacheable... If we change things so that
|
|
|
|
// the state gets in Element's attr-setting happen around this
|
|
|
|
// LoadImage call, we could start passing false instead of aNotify
|
|
|
|
// here.
|
2014-08-20 01:49:38 +04:00
|
|
|
LoadImage(aValue, true, aNotify, eImageLoadType_Normal);
|
2014-10-02 07:30:49 +04:00
|
|
|
|
|
|
|
mNewRequestsWillNeedAnimationReset = false;
|
|
|
|
}
|
2014-03-11 01:38:02 +04:00
|
|
|
}
|
|
|
|
|
2004-02-10 22:36:43 +03:00
|
|
|
return nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, aValue,
|
|
|
|
aNotify);
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
|
|
|
|
2005-04-06 03:54:35 +04:00
|
|
|
nsresult
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2003-07-13 02:32:20 +04:00
|
|
|
{
|
2005-04-06 03:54:35 +04:00
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
nsImageLoadingContent::BindToTree(aDocument, aParent, aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
if (aParent) {
|
|
|
|
UpdateFormOwner();
|
|
|
|
}
|
|
|
|
|
2015-08-31 22:29:40 +03:00
|
|
|
if (HaveSrcsetOrInPicture()) {
|
|
|
|
if (aDocument && !mInDocResponsiveContent) {
|
2015-05-12 01:07:49 +03:00
|
|
|
aDocument->AddResponsiveContent(this);
|
2015-08-31 22:29:40 +03:00
|
|
|
mInDocResponsiveContent = true;
|
2015-05-12 01:07:49 +03:00
|
|
|
}
|
2015-08-31 22:29:40 +03:00
|
|
|
|
|
|
|
bool forceLoadEvent = HTMLPictureElement::IsPictureEnabled() &&
|
|
|
|
aParent && aParent->IsHTMLElement(nsGkAtoms::picture);
|
|
|
|
QueueImageLoadTask(forceLoadEvent);
|
2014-10-02 07:59:56 +04:00
|
|
|
} else if (!InResponsiveMode() &&
|
2014-10-02 07:30:49 +04:00
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::src)) {
|
|
|
|
// We skip loading when our attributes were set from parser land,
|
|
|
|
// so trigger a aForce=false load now to check if things changed.
|
|
|
|
// This isn't necessary for responsive mode, since creating the
|
|
|
|
// image load task is asynchronous we don't need to take special
|
|
|
|
// care to avoid doing so when being filled by the parser.
|
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
// FIXME: Bug 660963 it would be nice if we could just have
|
|
|
|
// ClearBrokenState update our state and do it fast...
|
2009-05-20 12:00:04 +04:00
|
|
|
ClearBrokenState();
|
2011-06-01 05:46:57 +04:00
|
|
|
RemoveStatesSilently(NS_EVENT_STATE_BROKEN);
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
// We still act synchronously for the non-responsive case (Bug
|
|
|
|
// 1076583), but still need to delay if it is unsafe to run
|
|
|
|
// script.
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2009-11-20 07:39:11 +03:00
|
|
|
// If loading is temporarily disabled, don't even launch MaybeLoadImage.
|
|
|
|
// Otherwise MaybeLoadImage may run later when someone has reenabled
|
|
|
|
// loading.
|
|
|
|
if (LoadingEnabled()) {
|
|
|
|
nsContentUtils::AddScriptRunner(
|
2014-10-02 07:30:49 +04:00
|
|
|
NS_NewRunnableMethod(this, &HTMLImageElement::MaybeLoadImage));
|
2009-11-20 07:39:11 +03:00
|
|
|
}
|
2009-05-20 12:00:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
void
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2012-08-14 02:11:50 +04:00
|
|
|
{
|
2013-06-18 16:53:23 +04:00
|
|
|
if (mForm) {
|
|
|
|
if (aNullParent || !FindAncestorForm(mForm)) {
|
|
|
|
ClearForm(true);
|
|
|
|
} else {
|
|
|
|
UnsetFlags(MAYBE_ORPHAN_FORM_ELEMENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-31 22:29:40 +03:00
|
|
|
if (mInDocResponsiveContent) {
|
2015-05-12 01:07:49 +03:00
|
|
|
nsIDocument* doc = GetOurOwnerDoc();
|
2015-08-31 22:29:40 +03:00
|
|
|
MOZ_ASSERT(doc);
|
2015-05-12 01:07:49 +03:00
|
|
|
if (doc) {
|
|
|
|
doc->RemoveResponsiveContent(this);
|
2015-08-31 22:29:40 +03:00
|
|
|
mInDocResponsiveContent = false;
|
2015-05-12 01:07:49 +03:00
|
|
|
}
|
2015-08-31 22:29:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GetParent() &&
|
|
|
|
GetParent()->IsHTMLElement(nsGkAtoms::picture) &&
|
|
|
|
HTMLPictureElement::IsPictureEnabled()) {
|
2014-10-02 07:30:49 +04:00
|
|
|
// Being removed from picture re-triggers selection, even if we
|
|
|
|
// weren't using a <source> peer
|
2015-05-12 01:07:49 +03:00
|
|
|
if (aNullParent) {
|
2015-08-31 22:29:40 +03:00
|
|
|
QueueImageLoadTask(true);
|
2015-05-12 01:07:49 +03:00
|
|
|
}
|
2014-10-02 07:30:49 +04:00
|
|
|
}
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
nsImageLoadingContent::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
void
|
|
|
|
HTMLImageElement::UpdateFormOwner()
|
|
|
|
{
|
|
|
|
if (!mForm) {
|
|
|
|
mForm = FindAncestorForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mForm && !HasFlag(ADDED_TO_FORM)) {
|
|
|
|
// Now we need to add ourselves to the form
|
|
|
|
nsAutoString nameVal, idVal;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::name, nameVal);
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::id, idVal);
|
|
|
|
|
|
|
|
SetFlags(ADDED_TO_FORM);
|
|
|
|
|
|
|
|
mForm->AddImageElement(this);
|
|
|
|
|
|
|
|
if (!nameVal.IsEmpty()) {
|
|
|
|
mForm->AddImageElementToTable(this, nameVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!idVal.IsEmpty()) {
|
|
|
|
mForm->AddImageElementToTable(this, idVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-20 12:00:04 +04:00
|
|
|
void
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::MaybeLoadImage()
|
2009-05-20 12:00:04 +04:00
|
|
|
{
|
2014-05-03 03:26:22 +04:00
|
|
|
// Our base URI may have changed, or we may have had responsive parameters
|
|
|
|
// change while not bound to the tree. Re-parse src/srcset and call LoadImage,
|
|
|
|
// which is a no-op if it resolves to the same effective URI without aForce.
|
|
|
|
|
2009-05-20 12:00:04 +04:00
|
|
|
// Note, check LoadingEnabled() after LoadImage call.
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2015-08-31 22:29:40 +03:00
|
|
|
LoadSelectedImage(false, true, false);
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
if (!LoadingEnabled()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
CancelImageRequests(true);
|
2003-07-13 02:32:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::IntrinsicState() const
|
2005-09-18 22:05:40 +04:00
|
|
|
{
|
|
|
|
return nsGenericHTMLElement::IntrinsicState() |
|
|
|
|
nsImageLoadingContent::ImageState();
|
|
|
|
}
|
|
|
|
|
2013-01-22 14:53:13 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<HTMLImageElement>
|
|
|
|
HTMLImageElement::Image(const GlobalObject& aGlobal,
|
|
|
|
const Optional<uint32_t>& aWidth,
|
2013-08-23 09:17:08 +04:00
|
|
|
const Optional<uint32_t>& aHeight,
|
|
|
|
ErrorResult& aError)
|
1999-05-07 04:08:21 +04:00
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(aGlobal.GetAsSupports());
|
2013-01-22 14:53:13 +04:00
|
|
|
nsIDocument* doc;
|
|
|
|
if (!win || !(doc = win->GetExtantDoc())) {
|
|
|
|
aError.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
1999-05-07 04:08:21 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo> nodeInfo =
|
2013-01-22 14:53:13 +04:00
|
|
|
doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::img, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLImageElement> img = new HTMLImageElement(nodeInfo);
|
2001-09-07 08:00:37 +04:00
|
|
|
|
2013-01-22 14:53:13 +04:00
|
|
|
if (aWidth.WasPassed()) {
|
2013-04-04 11:03:50 +04:00
|
|
|
img->SetWidth(aWidth.Value(), aError);
|
2013-01-22 14:53:13 +04:00
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-01-22 14:53:13 +04:00
|
|
|
if (aHeight.WasPassed()) {
|
2013-04-04 11:03:50 +04:00
|
|
|
img->SetHeight(aHeight.Value(), aError);
|
2013-01-22 14:53:13 +04:00
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
1999-05-07 04:08:21 +04:00
|
|
|
}
|
|
|
|
|
2013-01-22 14:53:13 +04:00
|
|
|
return img.forget();
|
1999-05-07 04:08:21 +04:00
|
|
|
}
|
|
|
|
|
2012-12-31 22:48:55 +04:00
|
|
|
uint32_t
|
|
|
|
HTMLImageElement::NaturalHeight()
|
2000-09-08 06:06:56 +04:00
|
|
|
{
|
2014-05-03 04:05:19 +04:00
|
|
|
uint32_t height;
|
|
|
|
nsresult rv = nsImageLoadingContent::GetNaturalHeight(&height);
|
2012-12-31 22:48:55 +04:00
|
|
|
|
2014-05-03 04:05:19 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_ASSERT(false, "GetNaturalHeight should not fail");
|
2012-12-31 22:48:55 +04:00
|
|
|
return 0;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2014-05-03 04:06:45 +04:00
|
|
|
if (mResponsiveSelector) {
|
|
|
|
double density = mResponsiveSelector->GetSelectedImageDensity();
|
2015-07-06 04:03:00 +03:00
|
|
|
MOZ_ASSERT(density >= 0.0);
|
2014-05-03 04:06:45 +04:00
|
|
|
height = NSToIntRound(double(height) / density);
|
|
|
|
height = std::max(height, 0u);
|
|
|
|
}
|
|
|
|
|
2014-05-03 04:05:19 +04:00
|
|
|
return height;
|
2000-09-08 06:06:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-31 22:48:55 +04:00
|
|
|
HTMLImageElement::GetNaturalHeight(uint32_t* aNaturalHeight)
|
2000-09-08 06:06:56 +04:00
|
|
|
{
|
2012-12-31 22:48:55 +04:00
|
|
|
*aNaturalHeight = NaturalHeight();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
HTMLImageElement::NaturalWidth()
|
|
|
|
{
|
2014-05-03 04:05:19 +04:00
|
|
|
uint32_t width;
|
|
|
|
nsresult rv = nsImageLoadingContent::GetNaturalWidth(&width);
|
2012-12-31 22:48:55 +04:00
|
|
|
|
2014-05-03 04:05:19 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_ASSERT(false, "GetNaturalWidth should not fail");
|
2012-12-31 22:48:55 +04:00
|
|
|
return 0;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2014-05-03 04:06:45 +04:00
|
|
|
if (mResponsiveSelector) {
|
|
|
|
double density = mResponsiveSelector->GetSelectedImageDensity();
|
2015-07-06 04:03:00 +03:00
|
|
|
MOZ_ASSERT(density >= 0.0);
|
2014-05-03 04:06:45 +04:00
|
|
|
width = NSToIntRound(double(width) / density);
|
|
|
|
width = std::max(width, 0u);
|
|
|
|
}
|
|
|
|
|
2014-05-03 04:05:19 +04:00
|
|
|
return width;
|
2012-12-31 22:48:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLImageElement::GetNaturalWidth(uint32_t* aNaturalWidth)
|
|
|
|
{
|
|
|
|
*aNaturalWidth = NaturalWidth();
|
2001-09-07 08:00:37 +04:00
|
|
|
return NS_OK;
|
2000-09-08 06:06:56 +04:00
|
|
|
}
|
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
nsresult
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::CopyInnerTo(Element* aDest)
|
2009-12-11 07:02:13 +03:00
|
|
|
{
|
2015-07-22 20:21:25 +03:00
|
|
|
bool destIsStatic = aDest->OwnerDoc()->IsStaticDocument();
|
|
|
|
auto dest = static_cast<HTMLImageElement*>(aDest);
|
|
|
|
if (destIsStatic) {
|
|
|
|
CreateStaticImageClone(dest);
|
2009-12-11 07:02:13 +03:00
|
|
|
}
|
2015-07-22 20:21:25 +03:00
|
|
|
|
|
|
|
nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!destIsStatic) {
|
|
|
|
// In SetAttr (called from nsGenericHTMLElement::CopyInnerTo), dest skipped
|
|
|
|
// doing the image load because we passed in false for aNotify. But we
|
|
|
|
// really do want it to do the load, so set it up to happen once the cloning
|
|
|
|
// reaches a stable state.
|
|
|
|
if (!dest->InResponsiveMode() &&
|
|
|
|
dest->HasAttr(kNameSpaceID_None, nsGkAtoms::src)) {
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
NS_NewRunnableMethod(dest, &HTMLImageElement::MaybeLoadImage));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2009-12-11 07:02:13 +03:00
|
|
|
}
|
2011-07-14 22:47:35 +04:00
|
|
|
|
2012-03-10 20:13:51 +04:00
|
|
|
CORSMode
|
2012-12-31 21:25:46 +04:00
|
|
|
HTMLImageElement::GetCORSMode()
|
2011-07-14 22:47:35 +04:00
|
|
|
{
|
2012-03-10 20:13:52 +04:00
|
|
|
return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
|
2011-07-14 22:47:35 +04:00
|
|
|
}
|
2012-12-31 21:25:46 +04:00
|
|
|
|
2012-12-31 22:48:55 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
HTMLImageElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-31 22:48:55 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return HTMLImageElementBinding::Wrap(aCx, this, aGivenProto);
|
2012-12-31 22:48:55 +04:00
|
|
|
}
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsIDOMHTMLFormElement*
|
|
|
|
HTMLImageElement::GetForm() const
|
|
|
|
{
|
|
|
|
return mForm;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLImageElement::SetForm(nsIDOMHTMLFormElement* aForm)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aForm, "Don't pass null here");
|
|
|
|
NS_ASSERTION(!mForm,
|
|
|
|
"We don't support switching from one non-null form to another.");
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
mForm = static_cast<HTMLFormElement*>(aForm);
|
2013-06-18 16:53:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLImageElement::ClearForm(bool aRemoveFromForm)
|
|
|
|
{
|
|
|
|
NS_ASSERTION((mForm != nullptr) == HasFlag(ADDED_TO_FORM),
|
|
|
|
"Form control should have had flag set correctly");
|
|
|
|
|
|
|
|
if (!mForm) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRemoveFromForm) {
|
|
|
|
nsAutoString nameVal, idVal;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::name, nameVal);
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::id, idVal);
|
|
|
|
|
|
|
|
mForm->RemoveImageElement(this);
|
|
|
|
|
|
|
|
if (!nameVal.IsEmpty()) {
|
2013-06-18 16:54:27 +04:00
|
|
|
mForm->RemoveImageElementFromTable(this, nameVal,
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::ElementRemoved);
|
2013-06-18 16:53:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!idVal.IsEmpty()) {
|
2013-06-18 16:54:27 +04:00
|
|
|
mForm->RemoveImageElementFromTable(this, idVal,
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement::ElementRemoved);
|
2013-06-18 16:53:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UnsetFlags(ADDED_TO_FORM);
|
|
|
|
mForm = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
void
|
2015-08-31 22:29:40 +03:00
|
|
|
HTMLImageElement::QueueImageLoadTask(bool aAlwaysLoad)
|
2014-10-02 07:30:49 +04:00
|
|
|
{
|
|
|
|
// If loading is temporarily disabled, we don't want to queue tasks
|
|
|
|
// that may then run when loading is re-enabled.
|
|
|
|
if (!LoadingEnabled() || !this->OwnerDoc()->IsCurrentActiveDocument()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-30 19:39:59 +03:00
|
|
|
// Ensure that we don't overwrite a previous load request that requires
|
|
|
|
// a complete load to occur.
|
|
|
|
bool alwaysLoad = aAlwaysLoad;
|
|
|
|
if (mPendingImageLoadTask) {
|
|
|
|
alwaysLoad = alwaysLoad || mPendingImageLoadTask->AlwaysLoad();
|
|
|
|
}
|
|
|
|
RefPtr<ImageLoadTask> task = new ImageLoadTask(this, alwaysLoad);
|
2015-06-11 05:36:12 +03:00
|
|
|
// The task checks this to determine if it was the last
|
|
|
|
// queued event, and so earlier tasks are implicitly canceled.
|
|
|
|
mPendingImageLoadTask = task;
|
|
|
|
nsContentUtils::RunInStableState(task.forget());
|
2014-10-02 07:30:49 +04:00
|
|
|
}
|
|
|
|
|
2014-10-02 07:59:56 +04:00
|
|
|
bool
|
|
|
|
HTMLImageElement::HaveSrcsetOrInPicture()
|
|
|
|
{
|
|
|
|
if (IsSrcsetEnabled() && HasAttr(kNameSpaceID_None, nsGkAtoms::srcset)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HTMLPictureElement::IsPictureEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-19 14:43:42 +03:00
|
|
|
Element *parent = nsINode::GetParentElement();
|
2015-03-03 14:08:59 +03:00
|
|
|
return (parent && parent->IsHTMLElement(nsGkAtoms::picture));
|
2014-10-02 07:59:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HTMLImageElement::InResponsiveMode()
|
|
|
|
{
|
|
|
|
// When we lose srcset or leave a <picture> element, the fallback to img.src
|
|
|
|
// will happen from the microtask, and we should behave responsively in the
|
|
|
|
// interim
|
|
|
|
return mResponsiveSelector ||
|
|
|
|
mPendingImageLoadTask ||
|
|
|
|
HaveSrcsetOrInPicture();
|
|
|
|
}
|
|
|
|
|
2014-05-03 03:26:22 +04:00
|
|
|
nsresult
|
2015-08-31 22:29:40 +03:00
|
|
|
HTMLImageElement::LoadSelectedImage(bool aForce, bool aNotify, bool aAlwaysLoad)
|
2014-05-03 03:26:22 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
if (aForce) {
|
|
|
|
// In responsive mode we generally want to re-run the full
|
|
|
|
// selection algorithm whenever starting a new load, per
|
|
|
|
// spec. This also causes us to re-resolve the URI as appropriate.
|
2015-08-31 22:29:40 +03:00
|
|
|
if (!UpdateResponsiveSource() && !aAlwaysLoad) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-10-02 07:30:49 +04:00
|
|
|
}
|
|
|
|
|
2014-05-03 03:26:22 +04:00
|
|
|
if (mResponsiveSelector) {
|
|
|
|
nsCOMPtr<nsIURI> url = mResponsiveSelector->GetSelectedImageURL();
|
2014-12-11 02:53:00 +03:00
|
|
|
if (url) {
|
|
|
|
rv = LoadImage(url, aForce, aNotify, eImageLoadType_Imageset);
|
|
|
|
}
|
2014-05-03 03:26:22 +04:00
|
|
|
} else {
|
|
|
|
nsAutoString src;
|
|
|
|
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
|
|
|
|
CancelImageRequests(aNotify);
|
|
|
|
rv = NS_OK;
|
|
|
|
} else {
|
2014-08-20 01:49:38 +04:00
|
|
|
// If we have a srcset attribute or are in a <picture> element,
|
|
|
|
// we always use the Imageset load type, even if we parsed no
|
|
|
|
// valid responsive sources from either, per spec.
|
|
|
|
rv = LoadImage(src, aForce, aNotify,
|
|
|
|
HaveSrcsetOrInPicture() ? eImageLoadType_Imageset
|
|
|
|
: eImageLoadType_Normal);
|
2014-05-03 03:26:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
CancelImageRequests(aNotify);
|
|
|
|
}
|
2014-05-03 03:26:22 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-05-03 01:32:20 +04:00
|
|
|
HTMLImageElement::PictureSourceSrcsetChanged(nsIContent *aSourceNode,
|
|
|
|
const nsAString& aNewValue,
|
|
|
|
bool aNotify)
|
2014-05-03 03:26:22 +04:00
|
|
|
{
|
2014-10-02 07:30:49 +04:00
|
|
|
bool isSelf = aSourceNode == this;
|
|
|
|
|
|
|
|
if (!IsSrcsetEnabled() ||
|
|
|
|
(!isSelf && !HTMLPictureElement::IsPictureEnabled())) {
|
2014-05-03 01:32:20 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
MOZ_ASSERT(isSelf || IsPreviousSibling(aSourceNode, this),
|
|
|
|
"Should not be getting notifications for non-previous-siblings");
|
|
|
|
|
|
|
|
nsIContent *currentSrc =
|
|
|
|
mResponsiveSelector ? mResponsiveSelector->Content() : nullptr;
|
2014-05-03 01:32:20 +04:00
|
|
|
|
|
|
|
if (aSourceNode == currentSrc) {
|
2014-10-02 07:30:49 +04:00
|
|
|
// We're currently using this node as our responsive selector
|
|
|
|
// source.
|
2014-05-03 01:32:20 +04:00
|
|
|
mResponsiveSelector->SetCandidatesFromSourceSet(aNewValue);
|
|
|
|
}
|
2014-10-02 07:30:49 +04:00
|
|
|
|
2015-12-18 04:48:47 +03:00
|
|
|
if (!mInDocResponsiveContent && IsInComposedDoc()) {
|
2015-08-31 22:29:40 +03:00
|
|
|
nsIDocument* doc = GetOurOwnerDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->AddResponsiveContent(this);
|
|
|
|
mInDocResponsiveContent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
// This always triggers the image update steps per the spec, even if
|
|
|
|
// we are not using this source.
|
2015-08-31 22:29:40 +03:00
|
|
|
QueueImageLoadTask(true);
|
2014-05-03 03:26:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-05-03 01:32:20 +04:00
|
|
|
HTMLImageElement::PictureSourceSizesChanged(nsIContent *aSourceNode,
|
|
|
|
const nsAString& aNewValue,
|
|
|
|
bool aNotify)
|
2014-05-03 03:26:22 +04:00
|
|
|
{
|
2014-05-03 01:32:20 +04:00
|
|
|
if (!HTMLPictureElement::IsPictureEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
MOZ_ASSERT(aSourceNode == this ||
|
|
|
|
IsPreviousSibling(aSourceNode, this),
|
|
|
|
"Should not be getting notifications for non-previous-siblings");
|
|
|
|
|
|
|
|
nsIContent *currentSrc =
|
|
|
|
mResponsiveSelector ? mResponsiveSelector->Content() : nullptr;
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
if (aSourceNode == currentSrc) {
|
2014-10-02 07:30:49 +04:00
|
|
|
// We're currently using this node as our responsive selector
|
|
|
|
// source.
|
2014-05-03 01:32:20 +04:00
|
|
|
mResponsiveSelector->SetSizesFromDescriptor(aNewValue);
|
|
|
|
}
|
2014-10-02 07:30:49 +04:00
|
|
|
|
|
|
|
// This always triggers the image update steps per the spec, even if
|
|
|
|
// we are not using this source.
|
2015-08-31 22:29:40 +03:00
|
|
|
QueueImageLoadTask(true);
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
void
|
2014-10-09 01:01:19 +04:00
|
|
|
HTMLImageElement::PictureSourceMediaOrTypeChanged(nsIContent *aSourceNode,
|
|
|
|
bool aNotify)
|
2014-05-03 01:32:20 +04:00
|
|
|
{
|
2014-10-02 07:30:49 +04:00
|
|
|
if (!HTMLPictureElement::IsPictureEnabled()) {
|
|
|
|
return;
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
2014-10-02 07:30:49 +04:00
|
|
|
|
|
|
|
MOZ_ASSERT(IsPreviousSibling(aSourceNode, this),
|
|
|
|
"Should not be getting notifications for non-previous-siblings");
|
|
|
|
|
|
|
|
// This always triggers the image update steps per the spec, even if
|
|
|
|
// we are not switching to/from this source
|
2015-08-31 22:29:40 +03:00
|
|
|
QueueImageLoadTask(true);
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-02 07:30:49 +04:00
|
|
|
HTMLImageElement::PictureSourceAdded(nsIContent *aSourceNode)
|
2014-05-03 01:32:20 +04:00
|
|
|
{
|
2014-10-02 07:30:49 +04:00
|
|
|
if (!HTMLPictureElement::IsPictureEnabled()) {
|
|
|
|
return;
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
2014-10-02 07:30:49 +04:00
|
|
|
|
2015-08-31 22:29:40 +03:00
|
|
|
QueueImageLoadTask(true);
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
void
|
|
|
|
HTMLImageElement::PictureSourceRemoved(nsIContent *aSourceNode)
|
2014-05-03 01:32:20 +04:00
|
|
|
{
|
2014-10-02 07:30:49 +04:00
|
|
|
if (!HTMLPictureElement::IsPictureEnabled()) {
|
|
|
|
return;
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
|
|
|
|
2015-08-31 22:29:40 +03:00
|
|
|
QueueImageLoadTask(true);
|
2014-10-02 07:30:49 +04:00
|
|
|
}
|
2014-05-03 01:32:20 +04:00
|
|
|
|
2015-08-31 22:29:40 +03:00
|
|
|
bool
|
2014-10-02 07:30:49 +04:00
|
|
|
HTMLImageElement::UpdateResponsiveSource()
|
|
|
|
{
|
2015-08-31 22:29:40 +03:00
|
|
|
bool hadSelector = !!mResponsiveSelector;
|
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
if (!IsSrcsetEnabled()) {
|
2014-10-02 07:30:49 +04:00
|
|
|
mResponsiveSelector = nullptr;
|
2015-08-31 22:29:40 +03:00
|
|
|
return hadSelector;
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
nsIContent *currentSource =
|
|
|
|
mResponsiveSelector ? mResponsiveSelector->Content() : nullptr;
|
2014-05-03 01:32:20 +04:00
|
|
|
bool pictureEnabled = HTMLPictureElement::IsPictureEnabled();
|
2015-02-19 14:43:42 +03:00
|
|
|
Element *parent = pictureEnabled ? nsINode::GetParentElement() : nullptr;
|
2014-10-02 07:30:49 +04:00
|
|
|
|
|
|
|
nsINode *candidateSource = nullptr;
|
2015-03-03 14:08:59 +03:00
|
|
|
if (parent && parent->IsHTMLElement(nsGkAtoms::picture)) {
|
2014-10-02 07:30:49 +04:00
|
|
|
// Walk source nodes previous to ourselves
|
|
|
|
candidateSource = parent->GetFirstChild();
|
|
|
|
} else {
|
|
|
|
candidateSource = this;
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
while (candidateSource) {
|
|
|
|
if (candidateSource == currentSource) {
|
|
|
|
// found no better source before current, re-run selection on
|
|
|
|
// that and keep it if it's still usable.
|
2015-08-31 22:29:40 +03:00
|
|
|
bool changed = mResponsiveSelector->SelectImage(true);
|
2014-10-02 07:30:49 +04:00
|
|
|
if (mResponsiveSelector->NumCandidates()) {
|
2015-05-12 01:07:49 +03:00
|
|
|
bool isUsableCandidate = true;
|
|
|
|
|
|
|
|
// an otherwise-usable source element may still have a media query that may not
|
|
|
|
// match any more.
|
|
|
|
if (candidateSource->IsHTMLElement(nsGkAtoms::source) &&
|
|
|
|
!SourceElementMatches(candidateSource->AsContent())) {
|
|
|
|
isUsableCandidate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isUsableCandidate) {
|
2015-08-31 22:29:40 +03:00
|
|
|
return changed;
|
2015-05-12 01:07:49 +03:00
|
|
|
}
|
2014-10-02 07:30:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// no longer valid
|
|
|
|
mResponsiveSelector = nullptr;
|
|
|
|
if (candidateSource == this) {
|
|
|
|
// No further possibilities
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (candidateSource == this) {
|
|
|
|
// We are the last possible source
|
|
|
|
if (!TryCreateResponsiveSelector(candidateSource->AsContent())) {
|
|
|
|
// Failed to find any source
|
|
|
|
mResponsiveSelector = nullptr;
|
|
|
|
}
|
2014-05-03 01:32:20 +04:00
|
|
|
break;
|
2015-03-03 14:08:59 +03:00
|
|
|
} else if (candidateSource->IsHTMLElement(nsGkAtoms::source) &&
|
2014-10-02 07:30:49 +04:00
|
|
|
TryCreateResponsiveSelector(candidateSource->AsContent())) {
|
|
|
|
// This led to a valid source, stop
|
2014-05-03 01:32:20 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-10-02 07:30:49 +04:00
|
|
|
candidateSource = candidateSource->GetNextSibling();
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
if (!candidateSource) {
|
|
|
|
// Ran out of siblings without finding ourself, e.g. XBL magic.
|
|
|
|
mResponsiveSelector = nullptr;
|
|
|
|
}
|
2015-08-31 22:29:40 +03:00
|
|
|
|
|
|
|
return !hadSelector || mResponsiveSelector;
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
|
|
|
|
2014-12-11 02:53:00 +03:00
|
|
|
/*static */ bool
|
|
|
|
HTMLImageElement::SupportedPictureSourceType(const nsAString& aType)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
imgLoader::SupportImageWithMimeType(NS_ConvertUTF16toUTF8(aType).get(),
|
|
|
|
AcceptedMimeTypes::IMAGES_AND_DOCUMENTS);
|
|
|
|
}
|
|
|
|
|
2015-05-12 01:07:49 +03:00
|
|
|
bool
|
|
|
|
HTMLImageElement::SourceElementMatches(nsIContent* aSourceNode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aSourceNode->IsHTMLElement(nsGkAtoms::source));
|
|
|
|
|
|
|
|
DebugOnly<Element *> parent(nsINode::GetParentElement());
|
|
|
|
MOZ_ASSERT(parent && parent->IsHTMLElement(nsGkAtoms::picture));
|
|
|
|
MOZ_ASSERT(IsPreviousSibling(aSourceNode, this));
|
|
|
|
MOZ_ASSERT(HTMLPictureElement::IsPictureEnabled());
|
|
|
|
|
|
|
|
// Check media and type
|
|
|
|
HTMLSourceElement *src = static_cast<HTMLSourceElement*>(aSourceNode);
|
|
|
|
if (!src->MatchesCurrentMedia()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString type;
|
|
|
|
if (aSourceNode->GetAttr(kNameSpaceID_None, nsGkAtoms::type, type) &&
|
|
|
|
!SupportedPictureSourceType(type)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
bool
|
|
|
|
HTMLImageElement::TryCreateResponsiveSelector(nsIContent *aSourceNode,
|
|
|
|
const nsAString *aSrcset,
|
|
|
|
const nsAString *aSizes)
|
|
|
|
{
|
|
|
|
if (!IsSrcsetEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool pictureEnabled = HTMLPictureElement::IsPictureEnabled();
|
|
|
|
// Skip if this is not a <source> with matching media query
|
2015-03-03 14:08:59 +03:00
|
|
|
bool isSourceTag = aSourceNode->IsHTMLElement(nsGkAtoms::source);
|
2014-05-03 01:32:20 +04:00
|
|
|
if (isSourceTag) {
|
2015-05-12 01:07:49 +03:00
|
|
|
if (!SourceElementMatches(aSourceNode)) {
|
2014-10-09 00:53:24 +04:00
|
|
|
return false;
|
|
|
|
}
|
2015-03-03 14:08:59 +03:00
|
|
|
} else if (aSourceNode->IsHTMLElement(nsGkAtoms::img)) {
|
2014-05-03 01:32:20 +04:00
|
|
|
// Otherwise this is the <img> tag itself
|
2014-10-02 07:30:49 +04:00
|
|
|
MOZ_ASSERT(aSourceNode == this);
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Skip if has no srcset or an empty srcset
|
|
|
|
nsString srcset;
|
|
|
|
if (aSrcset) {
|
|
|
|
srcset = *aSrcset;
|
|
|
|
} else if (!aSourceNode->GetAttr(kNameSpaceID_None, nsGkAtoms::srcset,
|
|
|
|
srcset)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srcset.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Try to parse
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ResponsiveImageSelector> sel = new ResponsiveImageSelector(aSourceNode);
|
2014-05-03 01:32:20 +04:00
|
|
|
if (!sel->SetCandidatesFromSourceSet(srcset)) {
|
|
|
|
// No possible candidates, don't need to bother parsing sizes
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
if (pictureEnabled && aSizes) {
|
|
|
|
sel->SetSizesFromDescriptor(*aSizes);
|
|
|
|
} else if (pictureEnabled) {
|
|
|
|
nsAutoString sizes;
|
|
|
|
aSourceNode->GetAttr(kNameSpaceID_None, nsGkAtoms::sizes, sizes);
|
|
|
|
sel->SetSizesFromDescriptor(sizes);
|
2014-05-03 03:26:22 +04:00
|
|
|
}
|
2014-05-03 01:32:20 +04:00
|
|
|
|
|
|
|
// If this is the <img> tag, also pull in src as the default source
|
|
|
|
if (!isSourceTag) {
|
2014-10-02 07:30:49 +04:00
|
|
|
MOZ_ASSERT(aSourceNode == this);
|
2014-05-03 01:32:20 +04:00
|
|
|
nsAutoString src;
|
|
|
|
if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src) && !src.IsEmpty()) {
|
|
|
|
sel->SetDefaultSource(src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mResponsiveSelector = sel;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-11 02:53:00 +03:00
|
|
|
/* static */ bool
|
|
|
|
HTMLImageElement::SelectSourceForTagWithAttrs(nsIDocument *aDocument,
|
|
|
|
bool aIsSourceTag,
|
|
|
|
const nsAString& aSrcAttr,
|
|
|
|
const nsAString& aSrcsetAttr,
|
|
|
|
const nsAString& aSizesAttr,
|
|
|
|
const nsAString& aTypeAttr,
|
|
|
|
const nsAString& aMediaAttr,
|
|
|
|
nsAString& aResult)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aIsSourceTag || (aTypeAttr.IsEmpty() && aMediaAttr.IsEmpty()),
|
|
|
|
"Passing type or media attrs makes no sense without aIsSourceTag");
|
|
|
|
MOZ_ASSERT(!aIsSourceTag || aSrcAttr.IsEmpty(),
|
|
|
|
"Passing aSrcAttr makes no sense with aIsSourceTag set");
|
|
|
|
|
|
|
|
bool pictureEnabled = HTMLPictureElement::IsPictureEnabled();
|
|
|
|
if (aIsSourceTag && !pictureEnabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsSrcsetEnabled() || aSrcsetAttr.IsEmpty()) {
|
|
|
|
if (!aIsSourceTag) {
|
|
|
|
// For an <img> with no srcset, we would always select the src attr.
|
|
|
|
aResult.Assign(aSrcAttr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Otherwise, a <source> without srcset is never selected
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Would not consider source tags with unsupported media or type
|
|
|
|
if (aIsSourceTag &&
|
|
|
|
((!aMediaAttr.IsVoid() &&
|
|
|
|
!HTMLSourceElement::WouldMatchMediaForDocument(aMediaAttr, aDocument)) ||
|
|
|
|
(!aTypeAttr.IsVoid() &&
|
|
|
|
!SupportedPictureSourceType(aTypeAttr)))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Using srcset or picture <source>, build a responsive selector for this tag.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ResponsiveImageSelector> sel =
|
2014-12-11 02:53:00 +03:00
|
|
|
new ResponsiveImageSelector(aDocument);
|
|
|
|
|
|
|
|
sel->SetCandidatesFromSourceSet(aSrcsetAttr);
|
|
|
|
if (pictureEnabled && !aSizesAttr.IsEmpty()) {
|
|
|
|
sel->SetSizesFromDescriptor(aSizesAttr);
|
|
|
|
}
|
|
|
|
if (!aIsSourceTag) {
|
|
|
|
sel->SetDefaultSource(aSrcAttr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sel->GetSelectedImageURLSpec(aResult)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aIsSourceTag) {
|
|
|
|
// <img> tag with no match would definitively load nothing.
|
|
|
|
aResult.Truncate();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// <source> tags with no match would leave source yet-undetermined.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
void
|
|
|
|
HTMLImageElement::DestroyContent()
|
|
|
|
{
|
|
|
|
mResponsiveSelector = nullptr;
|
2015-12-04 01:03:12 +03:00
|
|
|
|
|
|
|
nsGenericHTMLElement::DestroyContent();
|
2014-05-03 03:26:22 +04:00
|
|
|
}
|
|
|
|
|
2015-05-12 01:07:49 +03:00
|
|
|
void
|
|
|
|
HTMLImageElement::MediaFeatureValuesChanged()
|
|
|
|
{
|
2015-08-31 22:29:40 +03:00
|
|
|
QueueImageLoadTask(false);
|
2015-05-12 01:07:49 +03:00
|
|
|
}
|
|
|
|
|
2015-03-17 22:25:35 +03:00
|
|
|
void
|
|
|
|
HTMLImageElement::FlushUseCounters()
|
|
|
|
{
|
|
|
|
nsCOMPtr<imgIRequest> request;
|
|
|
|
GetRequest(CURRENT_REQUEST, getter_AddRefs(request));
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> container;
|
|
|
|
request->GetImage(getter_AddRefs(container));
|
|
|
|
|
|
|
|
static_cast<image::Image*>(container.get())->ReportUseCounters();
|
|
|
|
}
|
|
|
|
|
2012-12-31 21:25:46 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2014-05-03 03:26:22 +04:00
|
|
|
|