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-31 22:16:48 +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/. */
|
|
|
|
|
2012-12-31 21:25:46 +04:00
|
|
|
#ifndef mozilla_dom_HTMLImageElement_h
|
|
|
|
#define mozilla_dom_HTMLImageElement_h
|
2012-05-31 22:16:48 +04:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-05-31 22:16:48 +04:00
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsImageLoadingContent.h"
|
2013-06-12 11:00:08 +04:00
|
|
|
#include "Units.h"
|
2014-10-14 00:36:01 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-05-03 01:32:20 +04:00
|
|
|
|
2012-12-31 21:25:46 +04:00
|
|
|
namespace mozilla {
|
2014-03-18 08:48:19 +04:00
|
|
|
class EventChainPreVisitor;
|
2012-12-31 21:25:46 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2016-03-30 19:39:59 +03:00
|
|
|
class ImageLoadTask;
|
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
class ResponsiveImageSelector;
|
2015-03-21 19:28:04 +03:00
|
|
|
class HTMLImageElement final : public nsGenericHTMLElement,
|
2017-10-06 23:27:23 +03:00
|
|
|
public nsImageLoadingContent {
|
2014-05-03 01:32:20 +04:00
|
|
|
friend class HTMLSourceElement;
|
2014-10-02 07:30:49 +04:00
|
|
|
friend class HTMLPictureElement;
|
|
|
|
friend class ImageLoadTask;
|
2012-05-31 22:16:48 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2018-09-21 23:45:49 +03:00
|
|
|
explicit HTMLImageElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-22 14:53:13 +04:00
|
|
|
static already_AddRefed<HTMLImageElement> Image(
|
2013-08-23 09:17:08 +04:00
|
|
|
const GlobalObject& aGlobal, const Optional<uint32_t>& aWidth,
|
|
|
|
const Optional<uint32_t>& aHeight, ErrorResult& aError);
|
2013-01-22 14:53:13 +04:00
|
|
|
|
2014-10-14 00:36:01 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLImageElement,
|
|
|
|
nsGenericHTMLElement)
|
|
|
|
|
2012-05-31 22:16:48 +04:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool Draggable() const override;
|
2012-05-31 22:16:48 +04:00
|
|
|
|
2018-05-16 20:39:16 +03:00
|
|
|
ResponsiveImageSelector* GetResponsiveImageSelector() {
|
|
|
|
return mResponsiveSelector.get();
|
|
|
|
}
|
|
|
|
|
2015-01-20 23:39:28 +03:00
|
|
|
// Element
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override;
|
2015-01-20 23:39:28 +03:00
|
|
|
|
2016-10-06 07:30:35 +03:00
|
|
|
// EventTarget
|
|
|
|
virtual void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
|
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLImageElement, img)
|
2014-10-02 07:30:49 +04:00
|
|
|
|
2012-05-31 22:16:48 +04:00
|
|
|
// override from nsImageLoadingContent
|
2015-03-21 19:28:04 +03:00
|
|
|
CORSMode GetCORSMode() override;
|
2012-05-31 22:16:48 +04:00
|
|
|
|
|
|
|
// nsIContent
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
2012-05-31 22:16:48 +04:00
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAttrValue& aResult) override;
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute,
|
2015-03-21 19:28:04 +03:00
|
|
|
int32_t aModType) const override;
|
2017-10-03 01:05:19 +03:00
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction()
|
|
|
|
const override;
|
2012-05-31 22:16:48 +04:00
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
2012-05-31 22:16:48 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
bool IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
|
|
|
|
int32_t* aTabIndex) override;
|
2012-05-31 22:16:48 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
virtual nsresult BindToTree(Document* aDocument, nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
|
2012-05-31 22:16:48 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual EventStates IntrinsicState() const override;
|
2018-08-09 02:58:44 +03:00
|
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
2012-05-31 22:16:48 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
virtual void NodeInfoChanged(Document* aOldDoc) override;
|
2016-11-18 10:54:21 +03:00
|
|
|
|
2018-08-09 02:58:44 +03:00
|
|
|
nsresult CopyInnerTo(HTMLImageElement* aDest);
|
2012-05-31 22:16:48 +04:00
|
|
|
|
2016-10-13 13:03:10 +03:00
|
|
|
void MaybeLoadImage(bool aAlwaysForceLoad);
|
2012-12-31 22:48:55 +04:00
|
|
|
|
|
|
|
bool IsMap() { return GetBoolAttr(nsGkAtoms::ismap); }
|
|
|
|
void SetIsMap(bool aIsMap, ErrorResult& aError) {
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::ismap, aIsMap, aError);
|
|
|
|
}
|
2019-03-13 03:30:11 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT uint32_t Width();
|
2012-12-31 22:48:55 +04:00
|
|
|
void SetWidth(uint32_t aWidth, ErrorResult& aError) {
|
2016-05-05 21:29:54 +03:00
|
|
|
SetUnsignedIntAttr(nsGkAtoms::width, aWidth, 0, aError);
|
2012-12-31 22:48:55 +04:00
|
|
|
}
|
2019-03-13 03:30:11 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT uint32_t Height();
|
2012-12-31 22:48:55 +04:00
|
|
|
void SetHeight(uint32_t aHeight, ErrorResult& aError) {
|
2016-05-05 21:29:54 +03:00
|
|
|
SetUnsignedIntAttr(nsGkAtoms::height, aHeight, 0, aError);
|
2012-12-31 22:48:55 +04:00
|
|
|
}
|
|
|
|
uint32_t NaturalWidth();
|
|
|
|
uint32_t NaturalHeight();
|
|
|
|
bool Complete();
|
2013-06-23 11:14:15 +04:00
|
|
|
uint32_t Hspace() { return GetUnsignedIntAttr(nsGkAtoms::hspace, 0); }
|
|
|
|
void SetHspace(uint32_t aHspace, ErrorResult& aError) {
|
2016-05-05 21:29:54 +03:00
|
|
|
SetUnsignedIntAttr(nsGkAtoms::hspace, aHspace, 0, aError);
|
2012-12-31 22:48:55 +04:00
|
|
|
}
|
2013-06-23 11:14:15 +04:00
|
|
|
uint32_t Vspace() { return GetUnsignedIntAttr(nsGkAtoms::vspace, 0); }
|
|
|
|
void SetVspace(uint32_t aVspace, ErrorResult& aError) {
|
2016-05-05 21:29:54 +03:00
|
|
|
SetUnsignedIntAttr(nsGkAtoms::vspace, aVspace, 0, aError);
|
2012-12-31 22:48:55 +04:00
|
|
|
}
|
|
|
|
|
2017-07-14 06:45:56 +03:00
|
|
|
void GetAlt(nsAString& aAlt) { GetHTMLAttr(nsGkAtoms::alt, aAlt); }
|
2012-12-31 22:48:55 +04:00
|
|
|
void SetAlt(const nsAString& aAlt, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::alt, aAlt, aError);
|
|
|
|
}
|
2017-07-14 06:45:56 +03:00
|
|
|
void GetSrc(nsAString& aSrc) { GetURIAttr(nsGkAtoms::src, nullptr, aSrc); }
|
2017-10-10 22:04:19 +03:00
|
|
|
void SetSrc(const nsAString& aSrc, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::src, aSrc, aError);
|
|
|
|
}
|
2017-12-21 01:43:18 +03:00
|
|
|
void SetSrc(const nsAString& aSrc, nsIPrincipal* aTriggeringPrincipal,
|
|
|
|
ErrorResult& aError) {
|
2017-10-03 06:28:32 +03:00
|
|
|
SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, aError);
|
2012-12-31 22:48:55 +04:00
|
|
|
}
|
2017-12-06 00:03:18 +03:00
|
|
|
void GetSrcset(nsAString& aSrcset) {
|
2017-07-14 06:45:56 +03:00
|
|
|
GetHTMLAttr(nsGkAtoms::srcset, aSrcset);
|
|
|
|
}
|
2017-12-21 01:43:18 +03:00
|
|
|
void SetSrcset(const nsAString& aSrcset, nsIPrincipal* aTriggeringPrincipal,
|
|
|
|
ErrorResult& aError) {
|
2017-10-03 07:30:34 +03:00
|
|
|
SetHTMLAttr(nsGkAtoms::srcset, aSrcset, aTriggeringPrincipal, aError);
|
2014-03-20 01:18:24 +04:00
|
|
|
}
|
2014-09-06 06:42:33 +04:00
|
|
|
void GetCrossOrigin(nsAString& aResult) {
|
|
|
|
// Null for both missing and invalid defaults is ok, since we
|
|
|
|
// always parse to an enum value, so we don't need an invalid
|
|
|
|
// default, and we _want_ the missing default to be null.
|
|
|
|
GetEnumAttr(nsGkAtoms::crossorigin, nullptr, aResult);
|
|
|
|
}
|
2012-12-31 22:48:55 +04:00
|
|
|
void SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& aError) {
|
2014-09-06 06:42:33 +04:00
|
|
|
SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin, aCrossOrigin, aError);
|
2012-12-31 22:48:55 +04:00
|
|
|
}
|
2017-07-14 06:45:56 +03:00
|
|
|
void GetUseMap(nsAString& aUseMap) {
|
|
|
|
GetHTMLAttr(nsGkAtoms::usemap, aUseMap);
|
|
|
|
}
|
2012-12-31 22:48:55 +04:00
|
|
|
void SetUseMap(const nsAString& aUseMap, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::usemap, aUseMap, aError);
|
|
|
|
}
|
2017-07-14 06:45:56 +03:00
|
|
|
void GetName(nsAString& aName) { GetHTMLAttr(nsGkAtoms::name, aName); }
|
2012-12-31 22:48:55 +04:00
|
|
|
void SetName(const nsAString& aName, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::name, aName, aError);
|
|
|
|
}
|
2017-07-14 06:45:56 +03:00
|
|
|
void GetAlign(nsAString& aAlign) { GetHTMLAttr(nsGkAtoms::align, aAlign); }
|
2012-12-31 22:48:55 +04:00
|
|
|
void SetAlign(const nsAString& aAlign, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
|
|
|
|
}
|
2017-07-14 06:45:56 +03:00
|
|
|
void GetLongDesc(nsAString& aLongDesc) {
|
|
|
|
GetURIAttr(nsGkAtoms::longdesc, nullptr, aLongDesc);
|
|
|
|
}
|
2012-12-31 22:48:55 +04:00
|
|
|
void SetLongDesc(const nsAString& aLongDesc, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::longdesc, aLongDesc, aError);
|
|
|
|
}
|
2017-07-14 06:45:56 +03:00
|
|
|
void GetSizes(nsAString& aSizes) { GetHTMLAttr(nsGkAtoms::sizes, aSizes); }
|
2014-03-20 01:18:57 +04:00
|
|
|
void SetSizes(const nsAString& aSizes, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::sizes, aSizes, aError);
|
|
|
|
}
|
2017-07-14 06:45:56 +03:00
|
|
|
void GetCurrentSrc(nsAString& aValue);
|
|
|
|
void GetBorder(nsAString& aBorder) {
|
|
|
|
GetHTMLAttr(nsGkAtoms::border, aBorder);
|
|
|
|
}
|
2012-12-31 22:48:55 +04:00
|
|
|
void SetBorder(const nsAString& aBorder, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::border, aBorder, aError);
|
|
|
|
}
|
2015-12-01 03:13:03 +03:00
|
|
|
void SetReferrerPolicy(const nsAString& aReferrer, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::referrerpolicy, aReferrer, aError);
|
2015-06-06 01:25:24 +03:00
|
|
|
}
|
2015-12-01 03:13:03 +03:00
|
|
|
void GetReferrerPolicy(nsAString& aReferrer) {
|
2016-04-18 13:35:47 +03:00
|
|
|
GetEnumAttr(nsGkAtoms::referrerpolicy, EmptyCString().get(), aReferrer);
|
2015-06-06 01:25:24 +03:00
|
|
|
}
|
2018-08-08 14:56:01 +03:00
|
|
|
void SetDecoding(const nsAString& aDecoding, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::decoding, aDecoding, aError);
|
|
|
|
}
|
|
|
|
void GetDecoding(nsAString& aValue);
|
2015-06-06 01:25:24 +03:00
|
|
|
|
2018-11-08 20:45:50 +03:00
|
|
|
already_AddRefed<Promise> Decode(ErrorResult& aRv);
|
|
|
|
|
2015-07-03 02:31:48 +03:00
|
|
|
net::ReferrerPolicy GetImageReferrerPolicy() override {
|
2015-12-01 03:13:03 +03:00
|
|
|
return GetReferrerPolicyAsEnum();
|
2015-06-06 01:25:24 +03:00
|
|
|
}
|
2012-12-31 22:48:55 +04:00
|
|
|
|
2017-12-05 19:18:16 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT int32_t X();
|
|
|
|
MOZ_CAN_RUN_SCRIPT int32_t Y();
|
2017-07-14 06:45:56 +03:00
|
|
|
void GetLowsrc(nsAString& aLowsrc) {
|
|
|
|
GetURIAttr(nsGkAtoms::lowsrc, nullptr, aLowsrc);
|
|
|
|
}
|
2013-06-02 19:38:25 +04:00
|
|
|
void SetLowsrc(const nsAString& aLowsrc, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::lowsrc, aLowsrc, aError);
|
|
|
|
}
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
#ifdef DEBUG
|
2018-03-14 23:42:25 +03:00
|
|
|
HTMLFormElement* GetForm() const;
|
2013-06-18 16:53:23 +04:00
|
|
|
#endif
|
2018-03-14 23:42:25 +03:00
|
|
|
void SetForm(HTMLFormElement* aForm);
|
2013-06-18 16:53:23 +04:00
|
|
|
void ClearForm(bool aRemoveFromForm);
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DestroyContent() override;
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2015-05-12 01:07:49 +03:00
|
|
|
void MediaFeatureValuesChanged();
|
|
|
|
|
2014-12-11 02:53:00 +03:00
|
|
|
/**
|
|
|
|
* Given a hypothetical <img> or <source> tag with the given parameters,
|
|
|
|
* return what URI we would attempt to use, if any. Used by the preloader to
|
|
|
|
* resolve sources prior to DOM creation.
|
|
|
|
*
|
|
|
|
* @param aDocument The document this image would be for, for referencing
|
|
|
|
* viewport width and DPI/zoom
|
|
|
|
* @param aIsSourceTag If these parameters are for a <source> tag (as in a
|
|
|
|
* <picture>) rather than an <img> tag. Note that some attrs are unused
|
|
|
|
* when this is true an vice versa
|
|
|
|
* @param aSrcAttr [ignored if aIsSourceTag] The src attr for this image.
|
|
|
|
* @param aSrcsetAttr The srcset attr for this image/source
|
|
|
|
* @param aSizesAttr The sizes attr for this image/source
|
|
|
|
* @param aTypeAttr [ignored if !aIsSourceTag] The type attr for this source.
|
|
|
|
* Should be a void string to differentiate no type attribute
|
|
|
|
* from an empty one.
|
|
|
|
* @param aMediaAttr [ignored if !aIsSourceTag] The media attr for this
|
|
|
|
* source. Should be a void string to differentiate no
|
|
|
|
* media attribute from an empty one.
|
|
|
|
* @param aResult A reference to store the resulting URL spec in if we
|
|
|
|
* selected a source. This value is not guaranteed to parse to
|
|
|
|
* a valid URL, merely the URL that the tag would attempt to
|
|
|
|
* resolve and load (which may be the empty string). This
|
|
|
|
* parameter is not modified if return value is false.
|
|
|
|
* @return True if we were able to select a final source, false if further
|
|
|
|
* sources would be considered. It follows that this always returns
|
|
|
|
* true if !aIsSourceTag.
|
|
|
|
*
|
|
|
|
* Note that the return value may be true with an empty string as the result,
|
|
|
|
* which implies that the parameters provided describe a tag that would select
|
|
|
|
* no source. This is distinct from a return of false which implies that
|
|
|
|
* further <source> or <img> tags would be considered.
|
|
|
|
*/
|
|
|
|
static bool SelectSourceForTagWithAttrs(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDocument, bool aIsSourceTag, const nsAString& aSrcAttr,
|
2014-12-11 02:53:00 +03:00
|
|
|
const nsAString& aSrcsetAttr, const nsAString& aSizesAttr,
|
|
|
|
const nsAString& aTypeAttr, const nsAString& aMediaAttr,
|
|
|
|
nsAString& aResult);
|
|
|
|
|
2015-03-17 22:25:35 +03:00
|
|
|
/**
|
|
|
|
* If this image's src pointers to an SVG document, flush the SVG document's
|
|
|
|
* use counters to telemetry. Only used for testing purposes.
|
|
|
|
*/
|
|
|
|
void FlushUseCounters();
|
|
|
|
|
2012-05-31 22:16:48 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~HTMLImageElement();
|
|
|
|
|
2014-10-02 07:59:56 +04:00
|
|
|
// Queues a task to run LoadSelectedImage pending stable state.
|
|
|
|
//
|
|
|
|
// Pending Bug 1076583 this is only used by the responsive image
|
|
|
|
// algorithm (InResponsiveMode()) -- synchronous actions when just
|
|
|
|
// using img.src will bypass this, and update source and kick off
|
|
|
|
// image load synchronously.
|
2015-08-31 22:29:40 +03:00
|
|
|
void QueueImageLoadTask(bool aAlwaysLoad);
|
2014-10-02 07:30:49 +04:00
|
|
|
|
2014-10-02 07:59:56 +04:00
|
|
|
// True if we have a srcset attribute or a <picture> parent, regardless of if
|
|
|
|
// any valid responsive sources were parsed from either.
|
|
|
|
bool HaveSrcsetOrInPicture();
|
|
|
|
|
|
|
|
// True if we are using the newer image loading algorithm. This will be the
|
|
|
|
// only mode after Bug 1076583
|
|
|
|
bool InResponsiveMode();
|
|
|
|
|
Bug 1149357: Properly update responsive images for density changes. r=dholbert
Before that we were not notifying the image frame in any way if we ended up not
doing a load, and we were instead relying on the reflow the viewport resize
caused to get the new density in ComputeSize from the content node (but nowhere
else, since that's the bug part 1 fixes).
This was generally unsound, since you can stash random media in a sizes=
attribute, which don't necessarily needs to cause a reflow.
Now we need to notify necessarily because nsImageFrame stores the adjusted
intrinsic size.
mCurrentDensity could also get out of sync as well, when the selected image
density changed, but we ended up returning early because our source hadn't
change in the first early exit.
This patch moves us to a model where we don't re-trigger loads for density
changes if the source doesn't change (unless we pass aAlwaysLoad when we need
to, per spec).
This matches our previous behavior (without the bugginess of not updating the
intrinsic size), and also Chromium, at least.
This changes behavior in one case, which is when we don't load the same source
node, but we have the same source URL, and the density does change. This could
happen with <picture> and two <source>s with same source and different media and
sizes. This makes our behavior consistent with the behavior we have when both
the source and the density doesn't change.
Blink and WebKit do trigger a second image load both when the source changes
without changing density and when density changes. I'll file a spec issue, since
per:
https://html.spec.whatwg.org/#reacting-to-environment-changes
We should be triggering the load when the density changes but the source
doesn't as well, but no UA does that.
I filed https://github.com/whatwg/html/issues/3709 with a little summary of the
situation and what I think the behavior should be (which is what this patch
implements). That being said, I'll update the impl if the spec people think
otherwise :).
MozReview-Commit-ID: Eqy16ygHRLo
2018-05-23 12:19:49 +03:00
|
|
|
// True if the given URL equals the last URL that was loaded by this element.
|
|
|
|
bool SelectedSourceMatchesLast(nsIURI* aSelectedSource);
|
2016-09-26 21:17:38 +03:00
|
|
|
|
2014-05-03 03:26:22 +04:00
|
|
|
// Resolve and load the current mResponsiveSelector (responsive mode) or src
|
|
|
|
// attr image.
|
2015-08-31 22:29:40 +03:00
|
|
|
nsresult LoadSelectedImage(bool aForce, bool aNotify, bool aAlwaysLoad);
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2014-12-11 02:53:00 +03:00
|
|
|
// True if this string represents a type we would support on <source type>
|
|
|
|
static bool SupportedPictureSourceType(const nsAString& aType);
|
|
|
|
|
2014-05-03 03:26:22 +04:00
|
|
|
// Update/create/destroy mResponsiveSelector
|
2014-05-03 01:32:20 +04:00
|
|
|
void PictureSourceSrcsetChanged(nsIContent* aSourceNode,
|
|
|
|
const nsAString& aNewValue, bool aNotify);
|
|
|
|
void PictureSourceSizesChanged(nsIContent* aSourceNode,
|
|
|
|
const nsAString& aNewValue, bool aNotify);
|
2014-10-09 01:01:19 +04:00
|
|
|
// As we re-run the source selection on these mutations regardless,
|
|
|
|
// we don't actually care which changed or to what
|
|
|
|
void PictureSourceMediaOrTypeChanged(nsIContent* aSourceNode, bool aNotify);
|
2014-05-03 01:32:20 +04:00
|
|
|
|
|
|
|
void PictureSourceAdded(nsIContent* aSourceNode);
|
|
|
|
// This should be called prior to the unbind, such that nextsibling works
|
|
|
|
void PictureSourceRemoved(nsIContent* aSourceNode);
|
|
|
|
|
2014-10-02 07:30:49 +04:00
|
|
|
// Re-evaluates all source nodes (picture <source>,<img>) and finds
|
|
|
|
// the best source set for mResponsiveSelector. If a better source
|
|
|
|
// is found, creates a new selector and feeds the source to it. If
|
|
|
|
// the current ResponsiveSelector is not changed, runs
|
|
|
|
// SelectImage(true) to re-evaluate its candidates.
|
|
|
|
//
|
|
|
|
// Because keeping the existing selector is the common case (and we
|
|
|
|
// often do no-op reselections), this does not re-parse values for
|
|
|
|
// the existing mResponsiveSelector, meaning you need to update its
|
|
|
|
// parameters as appropriate before calling (or null it out to force
|
|
|
|
// recreation)
|
2015-08-31 22:29:40 +03:00
|
|
|
//
|
|
|
|
// Returns true if the source has changed, and false otherwise.
|
|
|
|
bool UpdateResponsiveSource();
|
2014-05-03 01:32:20 +04:00
|
|
|
|
|
|
|
// Given a <source> node that is a previous sibling *or* ourselves, try to
|
|
|
|
// create a ResponsiveSelector.
|
|
|
|
|
|
|
|
// If the node's srcset/sizes make for an invalid selector, returns
|
|
|
|
// false. This does not guarantee the resulting selector matches an image,
|
|
|
|
// only that it is valid.
|
2017-12-07 21:13:50 +03:00
|
|
|
bool TryCreateResponsiveSelector(Element* aSourceElement);
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2017-12-05 19:18:16 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT CSSIntPoint GetXY();
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-06-18 16:53:23 +04:00
|
|
|
void UpdateFormOwner();
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult BeforeSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-03-16 21:50:41 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aNotify) override;
|
2013-06-18 16:53:23 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2017-05-19 00:09:01 +03:00
|
|
|
bool aNotify) override;
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName,
|
2017-06-02 01:38:45 +03:00
|
|
|
const nsAttrValueOrString& aValue,
|
|
|
|
bool aNotify) override;
|
2013-06-18 16:53:23 +04:00
|
|
|
|
2017-03-17 00:43:34 +03:00
|
|
|
// Override for nsImageLoadingContent.
|
|
|
|
nsIContent* AsContent() override { return this; }
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
// This is a weak reference that this element and the HTMLFormElement
|
|
|
|
// cooperate in maintaining.
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement* mForm;
|
2013-11-19 23:21:29 +04:00
|
|
|
|
2014-05-03 03:26:22 +04:00
|
|
|
// Created when we're tracking responsive image state
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ResponsiveImageSelector> mResponsiveSelector;
|
2014-05-03 03:26:22 +04:00
|
|
|
|
2013-11-19 23:21:29 +04:00
|
|
|
private:
|
2017-12-07 21:13:50 +03:00
|
|
|
bool SourceElementMatches(Element* aSourceElement);
|
2015-05-12 01:07:49 +03:00
|
|
|
|
2013-11-19 23:21:29 +04:00
|
|
|
static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
2018-06-22 19:48:42 +03:00
|
|
|
MappedDeclarations&);
|
2017-06-02 01:38:45 +03:00
|
|
|
/**
|
2017-06-09 19:46:54 +03:00
|
|
|
* This function is called by AfterSetAttr and OnAttrSetButNotChanged.
|
2017-06-02 01:38:45 +03:00
|
|
|
* It will not be called if the value is being unset.
|
|
|
|
*
|
|
|
|
* @param aNamespaceID the namespace of the attr being set
|
|
|
|
* @param aName the localname of the attribute being set
|
|
|
|
* @param aValue the value it's being set to represented as either a string or
|
|
|
|
* a parsed nsAttrValue.
|
2017-06-09 19:46:54 +03:00
|
|
|
* @param aOldValue the value previously set. Will be null if no value was
|
|
|
|
* previously set. This value should only be used when
|
|
|
|
* aValueMaybeChanged is true; when aValueMaybeChanged is false,
|
|
|
|
* aOldValue should be considered unreliable.
|
|
|
|
* @param aValueMaybeChanged will be false when this function is called from
|
|
|
|
* OnAttrSetButNotChanged to indicate that the value was not changed.
|
2017-06-02 01:38:45 +03:00
|
|
|
* @param aNotify Whether we plan to notify document observers.
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
void AfterMaybeChangeAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-06-09 19:46:54 +03:00
|
|
|
const nsAttrValueOrString& aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2017-06-09 19:46:54 +03:00
|
|
|
bool aValueMaybeChanged, bool aNotify);
|
2014-10-02 07:30:49 +04:00
|
|
|
|
2015-08-31 22:29:40 +03:00
|
|
|
bool mInDocResponsiveContent;
|
2016-03-30 19:39:59 +03:00
|
|
|
RefPtr<ImageLoadTask> mPendingImageLoadTask;
|
2017-10-03 06:28:32 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mSrcTriggeringPrincipal;
|
2017-10-03 07:30:34 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mSrcsetTriggeringPrincipal;
|
2016-09-26 21:17:38 +03:00
|
|
|
|
|
|
|
// Last URL that was attempted to load by this element.
|
|
|
|
nsCOMPtr<nsIURI> mLastSelectedSource;
|
|
|
|
// Last pixel density that was selected.
|
|
|
|
double mCurrentDensity;
|
2012-05-31 22:16:48 +04:00
|
|
|
};
|
|
|
|
|
2012-12-31 21:25:46 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_HTMLImageElement_h */
|