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-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"
|
2017-01-27 03:51:01 +03:00
|
|
|
#include "mozilla/GenericSpecifiedValuesInlines.h"
|
2016-05-11 04:38:05 +03:00
|
|
|
#include "mozilla/net/ReferrerPolicy.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"
|
|
|
|
|
2016-05-11 04:38:05 +03:00
|
|
|
using namespace mozilla::net;
|
|
|
|
|
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
|
2016-04-26 03:23:21 +03:00
|
|
|
class ImageLoadTask : public Runnable
|
2014-10-02 07:30:49 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-04-25 04:17:38 +03:00
|
|
|
ImageLoadTask(HTMLImageElement *aElement, bool aAlwaysLoad,
|
|
|
|
bool aUseUrgentStartForChannel)
|
2015-08-31 22:29:40 +03:00
|
|
|
: mElement(aElement)
|
|
|
|
, mAlwaysLoad(aAlwaysLoad)
|
2017-04-25 04:17:38 +03:00
|
|
|
, mUseUrgentStartForChannel(aUseUrgentStartForChannel)
|
2015-06-06 16:21:56 +03:00
|
|
|
{
|
|
|
|
mDocument = aElement->OwnerDoc();
|
|
|
|
mDocument->BlockOnload();
|
|
|
|
}
|
2014-10-02 07:30:49 +04:00
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override
|
2014-10-02 07:30:49 +04:00
|
|
|
{
|
|
|
|
if (mElement->mPendingImageLoadTask == this) {
|
|
|
|
mElement->mPendingImageLoadTask = nullptr;
|
2017-04-25 04:17:38 +03:00
|
|
|
mElement->mUseUrgentStartForChannel = mUseUrgentStartForChannel;
|
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;
|
2017-04-25 04:17:38 +03:00
|
|
|
|
|
|
|
// True if we want to set nsIClassOfService::UrgentStart to the channel to
|
|
|
|
// get the response ASAP for better user responsiveness.
|
|
|
|
bool mUseUrgentStartForChannel;
|
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)
|
2016-09-26 21:17:38 +03:00
|
|
|
, mCurrentDensity(1.0)
|
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)
|
2016-05-05 21:29:54 +03:00
|
|
|
NS_IMPL_URI_ATTR(HTMLImageElement, Lowsrc, lowsrc)
|
2012-12-31 21:25:46 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-10-06 07:30:35 +03:00
|
|
|
void
|
|
|
|
HTMLImageElement::AsyncEventRunning(AsyncEventDispatcher* aEvent)
|
|
|
|
{
|
|
|
|
nsImageLoadingContent::AsyncEventRunning(aEvent);
|
|
|
|
}
|
|
|
|
|
2014-05-14 01:21:15 +04:00
|
|
|
nsresult
|
|
|
|
HTMLImageElement::GetCurrentSrc(nsAString& aValue)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
|
|
|
GetCurrentURI(getter_AddRefs(currentURI));
|
|
|
|
if (currentURI) {
|
|
|
|
nsAutoCString spec;
|
|
|
|
currentURI->GetSpec(spec);
|
|
|
|
CopyUTF8toUTF16(spec, aValue);
|
|
|
|
} else {
|
|
|
|
SetDOMStringToNull(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-01-05 10:31:56 +03:00
|
|
|
nsIFrame* frame = GetPrimaryFrame(FlushType::Layout);
|
2012-04-24 23:04:37 +04:00
|
|
|
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,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapImageBorderAttributeInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
|
|
|
|
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) {
|
2016-07-06 08:06:14 +03:00
|
|
|
retval |= nsChangeHint_ReconstructFrame;
|
2013-08-21 16:44:14 +04:00
|
|
|
} else if (aAttribute == nsGkAtoms::alt) {
|
|
|
|
if (aModType == nsIDOMMutationEvent::ADDITION ||
|
|
|
|
aModType == nsIDOMMutationEvent::REMOVAL) {
|
2016-07-06 08:06:14 +03:00
|
|
|
retval |= nsChangeHint_ReconstructFrame;
|
2013-08-21 16:44:14 +04:00
|
|
|
}
|
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,
|
2017-03-16 21:50:41 +03:00
|
|
|
const 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()) {
|
2016-11-21 20:34:02 +03:00
|
|
|
mForm->RemoveImageElementFromTable(this, tmp);
|
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()));
|
|
|
|
}
|
|
|
|
|
2016-04-15 01:53:44 +03:00
|
|
|
// Handle src/srcset 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) {
|
2017-04-25 04:17:38 +03:00
|
|
|
// Mark channel as urgent-start before load image if the image load is
|
|
|
|
// initaiated by a user interaction.
|
|
|
|
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
// 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 &&
|
2016-04-17 01:07:56 +03:00
|
|
|
aNameSpaceID == kNameSpaceID_None) {
|
2017-04-25 04:17:38 +03:00
|
|
|
// Mark channel as urgent-start before load image if the image load is
|
|
|
|
// initaiated by a user interaction.
|
|
|
|
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
|
|
|
|
|
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 &&
|
2016-04-17 01:07:56 +03:00
|
|
|
aNameSpaceID == kNameSpaceID_None) {
|
2017-04-25 04:17:38 +03:00
|
|
|
// Mark channel as urgent-start before load image if the image load is
|
|
|
|
// initaiated by a user interaction.
|
|
|
|
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
PictureSourceSizesChanged(this, attrVal.String(), aNotify);
|
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
|
2016-10-21 05:11:07 +03:00
|
|
|
HTMLImageElement::GetEventTargetParent(EventChainPreVisitor& aVisitor)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2016-05-16 10:45:43 +03:00
|
|
|
// We handle image element with attribute ismap in its corresponding frame
|
|
|
|
// element. Set mMultipleActionsPrevented here to prevent the click event
|
|
|
|
// trigger the behaviors in Element::PostHandleEventForLinks
|
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()) {
|
2016-05-16 10:45:43 +03:00
|
|
|
mouseEvent->mFlags.mMultipleActionsPrevented = true;
|
2000-06-14 19:02:18 +04:00
|
|
|
}
|
2016-10-21 05:11:07 +03:00
|
|
|
return nsGenericHTMLElement::GetEventTargetParent(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
|
|
|
{
|
2016-05-11 04:38:05 +03:00
|
|
|
bool forceReload = false;
|
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) {
|
|
|
|
|
2017-04-25 04:17:38 +03:00
|
|
|
// Mark channel as urgent-start before load image if the image load is
|
|
|
|
// initaiated by a user interaction.
|
|
|
|
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
|
|
|
|
|
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;
|
|
|
|
}
|
2016-04-15 01:53:44 +03:00
|
|
|
} else if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
aName == nsGkAtoms::crossorigin &&
|
|
|
|
aNotify) {
|
|
|
|
nsAttrValue attrValue;
|
|
|
|
ParseCORSValue(aValue, attrValue);
|
|
|
|
if (GetCORSMode() != AttrValueToCORSMode(&attrValue)) {
|
|
|
|
// Force a new load of the image with the new cross origin policy.
|
2016-05-11 04:38:05 +03:00
|
|
|
forceReload = true;
|
|
|
|
}
|
|
|
|
} else if (aName == nsGkAtoms::referrerpolicy &&
|
|
|
|
aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
aNotify) {
|
2016-05-30 10:17:45 +03:00
|
|
|
ReferrerPolicy referrerPolicy = AttributeReferrerPolicyFromString(aValue);
|
|
|
|
if (!InResponsiveMode() &&
|
|
|
|
referrerPolicy != RP_Unset &&
|
|
|
|
referrerPolicy != GetImageReferrerPolicy()) {
|
2016-05-11 04:38:05 +03:00
|
|
|
// XXX: Bug 1076583 - We still use the older synchronous algorithm
|
|
|
|
// Because referrerPolicy is not treated as relevant mutations, setting
|
|
|
|
// the attribute will neither trigger a reload nor update the referrer
|
|
|
|
// policy of the loading channel (whether it has previously completed or
|
|
|
|
// not). Force a new load of the image with the new referrerpolicy.
|
|
|
|
forceReload = true;
|
2016-04-15 01:53:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
|
|
|
|
aValue, aNotify);
|
|
|
|
|
|
|
|
// Because we load image synchronously in non-responsive-mode, we need to do
|
|
|
|
// reload after the attribute has been set if the reload is triggerred by
|
|
|
|
// cross origin changing.
|
2016-05-11 04:38:05 +03:00
|
|
|
if (forceReload) {
|
2017-04-25 04:17:38 +03:00
|
|
|
// Mark channel as urgent-start before load image if the image load is
|
|
|
|
// initaiated by a user interaction.
|
|
|
|
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
|
|
|
|
|
2016-04-15 01:53:44 +03:00
|
|
|
if (InResponsiveMode()) {
|
|
|
|
// per spec, full selection runs when this changes, even though
|
|
|
|
// it doesn't directly affect the source selection
|
|
|
|
QueueImageLoadTask(true);
|
|
|
|
} else {
|
|
|
|
// Bug 1076583 - We still use the older synchronous algorithm in
|
|
|
|
// non-responsive mode. Force a new load of the image with the
|
|
|
|
// new cross origin policy
|
|
|
|
ForceReload(aNotify);
|
|
|
|
}
|
2014-03-11 01:38:02 +04:00
|
|
|
}
|
|
|
|
|
2016-04-15 01:53:44 +03:00
|
|
|
return rv;
|
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
|
|
|
|
2017-04-25 04:17:38 +03:00
|
|
|
// Mark channel as urgent-start before load image if the image load is
|
|
|
|
// initaiated by a user interaction.
|
|
|
|
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
|
|
|
|
|
2016-05-04 05:21:45 +03:00
|
|
|
// Run selection algorithm when an img element is inserted into a document
|
|
|
|
// in order to react to changes in the environment. See note of
|
|
|
|
// https://html.spec.whatwg.org/multipage/embedded-content.html#img-environment-changes
|
|
|
|
QueueImageLoadTask(false);
|
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.
|
|
|
|
|
2017-04-25 04:17:38 +03:00
|
|
|
// Mark channel as urgent-start before load image if the image load is
|
|
|
|
// initaiated by a user interaction.
|
|
|
|
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
|
|
|
|
|
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(
|
2016-05-05 11:45:00 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-10-04 20:50:33 +03:00
|
|
|
mLastSelectedSource = nullptr;
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-11-18 10:54:21 +03:00
|
|
|
void
|
2017-02-23 04:19:04 +03:00
|
|
|
HTMLImageElement::NodeInfoChanged(nsIDocument* aOldDoc)
|
2016-11-18 10:54:21 +03:00
|
|
|
{
|
2017-03-25 01:28:19 +03:00
|
|
|
nsGenericHTMLElement::NodeInfoChanged(aOldDoc);
|
2016-11-18 10:54:21 +03:00
|
|
|
// Resetting the last selected source if adoption steps are run.
|
|
|
|
mLastSelectedSource = nullptr;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
2017-04-20 22:57:48 +03:00
|
|
|
HTMLImageElement::CopyInnerTo(Element* aDest, bool aPreallocateChildren)
|
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
|
|
|
|
2017-04-20 22:57:48 +03:00
|
|
|
nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest, aPreallocateChildren);
|
2015-07-22 20:21:25 +03:00
|
|
|
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)) {
|
2017-04-25 04:17:38 +03:00
|
|
|
// Mark channel as urgent-start before load image if the image load is
|
|
|
|
// initaiated by a user interaction.
|
|
|
|
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
|
|
|
|
|
2015-07-22 20:21:25 +03:00
|
|
|
nsContentUtils::AddScriptRunner(
|
2016-05-05 11:45:00 +03:00
|
|
|
NewRunnableMethod(dest, &HTMLImageElement::MaybeLoadImage));
|
2015-07-22 20:21:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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()) {
|
2016-11-21 20:34:02 +03:00
|
|
|
mForm->RemoveImageElementFromTable(this, nameVal);
|
2013-06-18 16:53:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!idVal.IsEmpty()) {
|
2016-11-21 20:34:02 +03:00
|
|
|
mForm->RemoveImageElementFromTable(this, idVal);
|
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();
|
|
|
|
}
|
2017-04-25 04:17:38 +03:00
|
|
|
RefPtr<ImageLoadTask> task = new ImageLoadTask(this,
|
|
|
|
alwaysLoad,
|
|
|
|
mUseUrgentStartForChannel);
|
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()
|
|
|
|
{
|
2016-04-17 01:07:56 +03:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::srcset)) {
|
2014-10-02 07:59:56 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-09-26 21:17:38 +03:00
|
|
|
bool
|
|
|
|
HTMLImageElement::SelectedSourceMatchesLast(nsIURI* aSelectedSource, double aSelectedDensity)
|
|
|
|
{
|
|
|
|
// If there was no selected source previously, we don't want to short-circuit the load.
|
|
|
|
// Similarly for if there is no newly selected source.
|
|
|
|
if (!mLastSelectedSource || !aSelectedSource) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool equal = false;
|
|
|
|
return NS_SUCCEEDED(mLastSelectedSource->Equals(aSelectedSource, &equal)) && equal &&
|
|
|
|
aSelectedDensity == mCurrentDensity;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-09-26 21:17:38 +03:00
|
|
|
nsCOMPtr<nsIURI> selectedSource;
|
|
|
|
double currentDensity = 1.0; // default to 1.0 for the src attribute case
|
2014-05-03 03:26:22 +04:00
|
|
|
if (mResponsiveSelector) {
|
|
|
|
nsCOMPtr<nsIURI> url = mResponsiveSelector->GetSelectedImageURL();
|
2016-09-26 21:17:38 +03:00
|
|
|
selectedSource = url;
|
|
|
|
currentDensity = mResponsiveSelector->GetSelectedImageDensity();
|
|
|
|
if (!aAlwaysLoad && SelectedSourceMatchesLast(selectedSource, currentDensity)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
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 {
|
2016-09-26 21:17:38 +03:00
|
|
|
nsIDocument* doc = GetOurOwnerDoc();
|
|
|
|
if (doc) {
|
|
|
|
StringToURI(src, doc, getter_AddRefs(selectedSource));
|
|
|
|
if (!aAlwaysLoad && SelectedSourceMatchesLast(selectedSource, currentDensity)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2016-09-26 21:17:38 +03:00
|
|
|
mLastSelectedSource = selectedSource;
|
|
|
|
mCurrentDensity = currentDensity;
|
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
|
|
|
{
|
2016-04-17 01:07:56 +03:00
|
|
|
MOZ_ASSERT(aSourceNode == this ||
|
|
|
|
IsPreviousSibling(aSourceNode, this),
|
2014-10-02 07:30:49 +04:00
|
|
|
"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-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
|
|
|
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
|
|
|
{
|
2016-05-04 05:21:45 +03:00
|
|
|
MOZ_ASSERT(aSourceNode == this ||
|
|
|
|
IsPreviousSibling(aSourceNode, this),
|
|
|
|
"Should not be getting notifications for non-previous-siblings");
|
|
|
|
|
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
|
|
|
{
|
2016-04-22 17:36:54 +03:00
|
|
|
MOZ_ASSERT(aSourceNode == this ||
|
|
|
|
IsPreviousSibling(aSourceNode, this),
|
|
|
|
"Should not be getting notifications for non-previous-siblings");
|
|
|
|
|
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-10-02 07:30:49 +04:00
|
|
|
nsIContent *currentSource =
|
|
|
|
mResponsiveSelector ? mResponsiveSelector->Content() : nullptr;
|
2016-04-17 01:07:56 +03:00
|
|
|
Element *parent = nsINode::GetParentElement();
|
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
|
|
|
|
2016-01-06 23:40:09 +03:00
|
|
|
// If we reach this point, either:
|
|
|
|
// - there was no selector originally, and there is not one now
|
|
|
|
// - there was no selector originally, and there is one now
|
|
|
|
// - there was a selector, and there is a different one now
|
|
|
|
// - there was a selector, and there is not one now
|
|
|
|
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)
|
|
|
|
{
|
2016-03-18 17:16:00 +03:00
|
|
|
nsAutoString type;
|
|
|
|
nsAutoString params;
|
|
|
|
|
|
|
|
nsContentUtils::SplitMimeType(aType, type, params);
|
|
|
|
if (type.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-11 02:53:00 +03:00
|
|
|
return
|
2016-03-18 17:16:00 +03:00
|
|
|
imgLoader::SupportImageWithMimeType(NS_ConvertUTF16toUTF8(type).get(),
|
2014-12-11 02:53:00 +03:00
|
|
|
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));
|
|
|
|
|
|
|
|
// 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
|
2016-04-16 23:50:02 +03:00
|
|
|
HTMLImageElement::TryCreateResponsiveSelector(nsIContent *aSourceNode)
|
2014-05-03 01:32:20 +04:00
|
|
|
{
|
|
|
|
// 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;
|
2016-04-16 23:50:02 +03:00
|
|
|
if (!aSourceNode->GetAttr(kNameSpaceID_None, nsGkAtoms::srcset, srcset)) {
|
2014-05-03 01:32:20 +04:00
|
|
|
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
|
|
|
|
2016-04-16 23:50:02 +03:00
|
|
|
nsAutoString sizes;
|
|
|
|
aSourceNode->GetAttr(kNameSpaceID_None, nsGkAtoms::sizes, sizes);
|
|
|
|
sel->SetSizesFromDescriptor(sizes);
|
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");
|
|
|
|
|
2016-04-17 01:07:56 +03:00
|
|
|
if (aSrcsetAttr.IsEmpty()) {
|
2014-12-11 02:53:00 +03:00
|
|
|
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);
|
2016-04-17 01:07:56 +03:00
|
|
|
if (!aSizesAttr.IsEmpty()) {
|
2014-12-11 02:53:00 +03:00
|
|
|
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
|
|
|
|