2013-02-07 19:38:26 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/HTMLSourceElement.h"
|
2013-02-07 19:39:10 +04:00
|
|
|
#include "mozilla/dom/HTMLSourceElementBinding.h"
|
2013-02-07 19:38:26 +04:00
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
#include "mozilla/dom/HTMLImageElement.h"
|
|
|
|
#include "mozilla/dom/ResponsiveImageSelector.h"
|
|
|
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
|
2014-04-18 01:38:18 +04:00
|
|
|
#include "nsIMediaList.h"
|
|
|
|
#include "nsCSSParser.h"
|
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2013-02-07 19:38:26 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Source)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLSourceElement::HTMLSourceElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-02-07 19:38:26 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLSourceElement::~HTMLSourceElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLSourceElement, nsGenericHTMLElement,
|
|
|
|
nsIDOMHTMLSourceElement)
|
2013-02-07 19:38:26 +04:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLSourceElement)
|
|
|
|
|
|
|
|
NS_IMPL_URI_ATTR(HTMLSourceElement, Src, src)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLSourceElement, Type, type)
|
2014-04-24 00:55:05 +04:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLSourceElement, Srcset, srcset)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLSourceElement, Sizes, sizes)
|
2013-02-07 19:38:26 +04:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLSourceElement, Media, media)
|
|
|
|
|
2014-04-18 01:38:18 +04:00
|
|
|
bool
|
|
|
|
HTMLSourceElement::MatchesCurrentMedia()
|
|
|
|
{
|
|
|
|
if (mMediaList) {
|
|
|
|
nsIPresShell* presShell = OwnerDoc()->GetShell();
|
|
|
|
nsPresContext* pctx = presShell ? presShell->GetPresContext() : nullptr;
|
|
|
|
return pctx && mMediaList->Matches(pctx, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// No media specified
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-11 02:53:00 +03:00
|
|
|
/* static */ bool
|
|
|
|
HTMLSourceElement::WouldMatchMediaForDocument(const nsAString& aMedia,
|
|
|
|
const nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
if (aMedia.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* presShell = aDocument->GetShell();
|
|
|
|
nsPresContext* pctx = presShell ? presShell->GetPresContext() : nullptr;
|
|
|
|
MOZ_ASSERT(pctx, "Called for document with no prescontext");
|
|
|
|
|
|
|
|
nsCSSParser cssParser;
|
|
|
|
nsRefPtr<nsMediaList> mediaList = new nsMediaList();
|
|
|
|
cssParser.ParseMediaList(aMedia, nullptr, 0, mediaList, false);
|
|
|
|
|
|
|
|
return pctx && mediaList->Matches(pctx, nullptr);
|
|
|
|
}
|
|
|
|
|
2014-04-18 01:38:18 +04:00
|
|
|
nsresult
|
|
|
|
HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
|
|
|
{
|
2014-05-03 01:32:20 +04:00
|
|
|
// If we are associated with a <picture> with a valid <img>, notify it of
|
|
|
|
// responsive parameter changes
|
|
|
|
nsINode *parent = nsINode::GetParentNode();
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
2014-10-02 07:30:49 +04:00
|
|
|
(aName == nsGkAtoms::srcset ||
|
|
|
|
aName == nsGkAtoms::sizes ||
|
2014-10-09 01:01:19 +04:00
|
|
|
aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type) &&
|
2014-10-02 07:30:49 +04:00
|
|
|
parent && parent->Tag() == nsGkAtoms::picture) {
|
2014-05-03 01:32:20 +04:00
|
|
|
nsString strVal = aValue ? aValue->GetStringValue() : EmptyString();
|
|
|
|
// Find all img siblings after this <source> and notify them of the change
|
|
|
|
nsCOMPtr<nsINode> sibling = AsContent();
|
|
|
|
while ( (sibling = sibling->GetNextSibling()) ) {
|
|
|
|
if (sibling->Tag() == nsGkAtoms::img) {
|
|
|
|
HTMLImageElement *img = static_cast<HTMLImageElement*>(sibling.get());
|
|
|
|
if (aName == nsGkAtoms::srcset) {
|
|
|
|
img->PictureSourceSrcsetChanged(AsContent(), strVal, aNotify);
|
|
|
|
} else if (aName == nsGkAtoms::sizes) {
|
|
|
|
img->PictureSourceSizesChanged(AsContent(), strVal, aNotify);
|
2014-10-09 01:01:19 +04:00
|
|
|
} else if (aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type) {
|
|
|
|
img->PictureSourceMediaOrTypeChanged(AsContent(), aNotify);
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::media) {
|
2014-04-18 01:38:18 +04:00
|
|
|
mMediaList = nullptr;
|
|
|
|
if (aValue) {
|
|
|
|
nsString mediaStr = aValue->GetStringValue();
|
|
|
|
if (!mediaStr.IsEmpty()) {
|
|
|
|
nsCSSParser cssParser;
|
|
|
|
mMediaList = new nsMediaList();
|
|
|
|
cssParser.ParseMediaList(mediaStr, nullptr, 0, mMediaList, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
|
|
|
|
aValue, aNotify);
|
|
|
|
}
|
|
|
|
|
2013-02-07 19:38:26 +04:00
|
|
|
void
|
2015-02-13 04:27:39 +03:00
|
|
|
HTMLSourceElement::GetItemValueText(DOMString& aValue)
|
2013-02-07 19:38:26 +04:00
|
|
|
{
|
|
|
|
GetSrc(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLSourceElement::SetItemValueText(const nsAString& aValue)
|
|
|
|
{
|
|
|
|
SetSrc(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLSourceElement::BindToTree(nsIDocument *aDocument,
|
|
|
|
nsIContent *aParent,
|
|
|
|
nsIContent *aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument,
|
|
|
|
aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
if (aParent && aParent->IsNodeOfType(nsINode::eMEDIA)) {
|
|
|
|
HTMLMediaElement* media = static_cast<HTMLMediaElement*>(aParent);
|
|
|
|
media->NotifyAddedSource();
|
|
|
|
} else if (aParent && aParent->Tag() == nsGkAtoms::picture) {
|
|
|
|
// Find any img siblings after this <source> and notify them
|
|
|
|
nsCOMPtr<nsINode> sibling = AsContent();
|
|
|
|
while ( (sibling = sibling->GetNextSibling()) ) {
|
|
|
|
if (sibling->Tag() == nsGkAtoms::img) {
|
|
|
|
HTMLImageElement *img = static_cast<HTMLImageElement*>(sibling.get());
|
|
|
|
img->PictureSourceAdded(AsContent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-07 19:38:26 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-07 19:39:10 +04:00
|
|
|
JSObject*
|
2014-04-09 02:27:17 +04:00
|
|
|
HTMLSourceElement::WrapNode(JSContext* aCx)
|
2013-02-07 19:39:10 +04:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-09 02:27:17 +04:00
|
|
|
return HTMLSourceElementBinding::Wrap(aCx, this);
|
2013-02-07 19:39:10 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 19:38:26 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|