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-12-31 13:44:03 +04:00
|
|
|
|
2013-03-02 10:08:42 +04:00
|
|
|
#include "mozilla/dom/SVGTests.h"
|
2011-12-31 13:44:03 +04:00
|
|
|
#include "DOMSVGStringList.h"
|
|
|
|
#include "nsSVGFeatures.h"
|
2013-01-06 10:25:54 +04:00
|
|
|
#include "mozilla/dom/SVGSwitchElement.h"
|
2011-12-31 13:44:03 +04:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
|
|
|
#include "nsStyleUtil.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2013-03-02 10:08:42 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-12-31 13:44:03 +04:00
|
|
|
|
2017-10-27 02:31:13 +03:00
|
|
|
nsStaticAtom** SVGTests::sStringListNames[3] =
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2012-02-16 03:40:46 +04:00
|
|
|
&nsGkAtoms::requiredFeatures,
|
|
|
|
&nsGkAtoms::requiredExtensions,
|
|
|
|
&nsGkAtoms::systemLanguage,
|
2011-12-31 13:44:03 +04:00
|
|
|
};
|
|
|
|
|
2013-03-02 10:08:42 +04:00
|
|
|
SVGTests::SVGTests()
|
2012-09-05 01:53:04 +04:00
|
|
|
{
|
|
|
|
mStringListAttributes[LANGUAGE].SetIsCommaSeparated(true);
|
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
already_AddRefed<DOMSVGStringList>
|
2013-03-02 10:08:42 +04:00
|
|
|
SVGTests::RequiredFeatures()
|
2013-01-03 10:17:02 +04:00
|
|
|
{
|
|
|
|
return DOMSVGStringList::GetDOMWrapper(
|
2018-02-04 12:40:57 +03:00
|
|
|
&mStringListAttributes[FEATURES], AsSVGElement(), true, FEATURES);
|
2013-01-03 10:17:02 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
already_AddRefed<DOMSVGStringList>
|
2013-03-02 10:08:42 +04:00
|
|
|
SVGTests::RequiredExtensions()
|
2013-01-03 10:17:02 +04:00
|
|
|
{
|
|
|
|
return DOMSVGStringList::GetDOMWrapper(
|
2018-02-04 12:40:57 +03:00
|
|
|
&mStringListAttributes[EXTENSIONS], AsSVGElement(), true, EXTENSIONS);
|
2013-01-03 10:17:02 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
already_AddRefed<DOMSVGStringList>
|
2013-03-02 10:08:42 +04:00
|
|
|
SVGTests::SystemLanguage()
|
2013-01-03 10:17:02 +04:00
|
|
|
{
|
|
|
|
return DOMSVGStringList::GetDOMWrapper(
|
2018-02-04 12:40:57 +03:00
|
|
|
&mStringListAttributes[LANGUAGE], AsSVGElement(), true, LANGUAGE);
|
2013-01-03 10:17:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-03-02 10:08:42 +04:00
|
|
|
SVGTests::HasExtension(const nsAString& aExtension)
|
2013-01-03 10:17:02 +04:00
|
|
|
{
|
2018-03-07 17:18:52 +03:00
|
|
|
return nsSVGFeatures::HasExtension(aExtension,
|
|
|
|
AsSVGElement()->IsInChromeDocument());
|
2013-01-03 10:17:02 +04:00
|
|
|
}
|
|
|
|
|
2011-12-31 13:44:03 +04:00
|
|
|
bool
|
2017-10-03 01:05:19 +03:00
|
|
|
SVGTests::IsConditionalProcessingAttribute(const nsAtom* aAttribute) const
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(sStringListNames); i++) {
|
2012-02-16 03:40:46 +04:00
|
|
|
if (aAttribute == *sStringListNames[i]) {
|
2011-12-31 13:44:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2017-06-20 12:19:52 +03:00
|
|
|
SVGTests::GetBestLanguagePreferenceRank(const nsAString& aAcceptLangs) const
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
|
|
|
const nsDefaultStringComparator defaultComparator;
|
|
|
|
|
2014-09-09 16:00:03 +04:00
|
|
|
if (!mStringListAttributes[LANGUAGE].IsExplicitlySet()) {
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t lowestRank = -1;
|
2011-12-31 13:44:03 +04:00
|
|
|
|
2012-09-05 01:53:04 +04:00
|
|
|
for (uint32_t i = 0; i < mStringListAttributes[LANGUAGE].Length(); i++) {
|
2011-12-31 13:44:03 +04:00
|
|
|
nsCharSeparatedTokenizer languageTokenizer(aAcceptLangs, ',');
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = 0;
|
2011-12-31 13:44:03 +04:00
|
|
|
while (languageTokenizer.hasMoreTokens()) {
|
2017-06-20 12:19:52 +03:00
|
|
|
const nsAString& languageToken = languageTokenizer.nextToken();
|
2012-09-05 01:53:04 +04:00
|
|
|
bool exactMatch = (languageToken == mStringListAttributes[LANGUAGE][i]);
|
2011-12-31 13:44:03 +04:00
|
|
|
bool prefixOnlyMatch =
|
|
|
|
!exactMatch &&
|
2012-09-05 01:53:04 +04:00
|
|
|
nsStyleUtil::DashMatchCompare(mStringListAttributes[LANGUAGE][i],
|
2011-12-31 13:44:03 +04:00
|
|
|
languageTokenizer.nextToken(),
|
|
|
|
defaultComparator);
|
|
|
|
if (index == 0 && exactMatch) {
|
|
|
|
// best possible match
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((exactMatch || prefixOnlyMatch) &&
|
|
|
|
(lowestRank == -1 || 2 * index + prefixOnlyMatch < lowestRank)) {
|
|
|
|
lowestRank = 2 * index + prefixOnlyMatch;
|
|
|
|
}
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lowestRank;
|
|
|
|
}
|
|
|
|
|
2013-03-02 10:08:42 +04:00
|
|
|
const nsString * const SVGTests::kIgnoreSystemLanguage = (nsString *) 0x01;
|
2011-12-31 13:44:03 +04:00
|
|
|
|
|
|
|
bool
|
2013-03-02 10:08:42 +04:00
|
|
|
SVGTests::PassesConditionalProcessingTests(const nsString *aAcceptLangs) const
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
|
|
|
// Required Extensions
|
|
|
|
//
|
|
|
|
// The requiredExtensions attribute defines a list of required language
|
|
|
|
// extensions. Language extensions are capabilities within a user agent that
|
|
|
|
// go beyond the feature set defined in the SVG specification.
|
|
|
|
// Each extension is identified by a URI reference.
|
|
|
|
// For now, claim that mozilla's SVG implementation supports XHTML and MathML.
|
2012-09-05 01:53:04 +04:00
|
|
|
if (mStringListAttributes[EXTENSIONS].IsExplicitlySet()) {
|
|
|
|
if (mStringListAttributes[EXTENSIONS].IsEmpty()) {
|
2011-12-31 13:44:03 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-09-05 01:53:04 +04:00
|
|
|
for (uint32_t i = 0; i < mStringListAttributes[EXTENSIONS].Length(); i++) {
|
2018-03-07 17:18:52 +03:00
|
|
|
if (!nsSVGFeatures::HasExtension(mStringListAttributes[EXTENSIONS][i],
|
|
|
|
AsSVGElement()->IsInChromeDocument())) {
|
2011-12-31 13:44:03 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAcceptLangs == kIgnoreSystemLanguage) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// systemLanguage
|
|
|
|
//
|
|
|
|
// Evaluates to "true" if one of the languages indicated by user preferences
|
|
|
|
// exactly equals one of the languages given in the value of this parameter,
|
|
|
|
// or if one of the languages indicated by user preferences exactly equals a
|
|
|
|
// prefix of one of the languages given in the value of this parameter such
|
|
|
|
// that the first tag character following the prefix is "-".
|
2012-09-05 01:53:04 +04:00
|
|
|
if (mStringListAttributes[LANGUAGE].IsExplicitlySet()) {
|
|
|
|
if (mStringListAttributes[LANGUAGE].IsEmpty()) {
|
2011-12-31 13:44:03 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get our language preferences
|
2017-07-31 07:23:50 +03:00
|
|
|
nsAutoString acceptLangs;
|
|
|
|
if (aAcceptLangs) {
|
|
|
|
acceptLangs.Assign(*aAcceptLangs);
|
|
|
|
} else {
|
|
|
|
Preferences::GetLocalizedString("intl.accept_languages", acceptLangs);
|
|
|
|
}
|
2011-12-31 13:44:03 +04:00
|
|
|
|
|
|
|
if (acceptLangs.IsEmpty()) {
|
|
|
|
NS_WARNING("no default language specified for systemLanguage conditional test");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsDefaultStringComparator defaultComparator;
|
|
|
|
|
2012-09-05 01:53:04 +04:00
|
|
|
for (uint32_t i = 0; i < mStringListAttributes[LANGUAGE].Length(); i++) {
|
2011-12-31 13:44:03 +04:00
|
|
|
nsCharSeparatedTokenizer languageTokenizer(acceptLangs, ',');
|
|
|
|
while (languageTokenizer.hasMoreTokens()) {
|
2012-09-05 01:53:04 +04:00
|
|
|
if (nsStyleUtil::DashMatchCompare(mStringListAttributes[LANGUAGE][i],
|
2011-12-31 13:44:03 +04:00
|
|
|
languageTokenizer.nextToken(),
|
|
|
|
defaultComparator)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-10-03 01:05:19 +03:00
|
|
|
SVGTests::ParseConditionalProcessingAttribute(nsAtom* aAttribute,
|
2013-03-02 10:08:42 +04:00
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(sStringListNames); i++) {
|
2012-02-16 03:40:46 +04:00
|
|
|
if (aAttribute == *sStringListNames[i]) {
|
2012-09-05 01:53:04 +04:00
|
|
|
nsresult rv = mStringListAttributes[i].SetValue(aValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mStringListAttributes[i].Clear();
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
MaybeInvalidate();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-10-03 01:05:19 +03:00
|
|
|
SVGTests::UnsetAttr(const nsAtom* aAttribute)
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(sStringListNames); i++) {
|
2012-02-16 03:40:46 +04:00
|
|
|
if (aAttribute == *sStringListNames[i]) {
|
2012-09-05 01:53:04 +04:00
|
|
|
mStringListAttributes[i].Clear();
|
|
|
|
MaybeInvalidate();
|
2011-12-31 13:44:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom*
|
2013-03-02 10:08:42 +04:00
|
|
|
SVGTests::GetAttrName(uint8_t aAttrEnum) const
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2012-02-16 03:40:46 +04:00
|
|
|
return *sStringListNames[aAttrEnum];
|
|
|
|
}
|
2011-12-31 13:44:03 +04:00
|
|
|
|
2012-02-16 03:40:46 +04:00
|
|
|
void
|
2013-03-02 10:08:42 +04:00
|
|
|
SVGTests::GetAttrValue(uint8_t aAttrEnum, nsAttrValue& aValue) const
|
2012-02-16 03:40:46 +04:00
|
|
|
{
|
2012-03-30 01:12:55 +04:00
|
|
|
MOZ_ASSERT(aAttrEnum < ArrayLength(sStringListNames),
|
|
|
|
"aAttrEnum out of range");
|
2012-09-05 01:53:04 +04:00
|
|
|
aValue.SetTo(mStringListAttributes[aAttrEnum], nullptr);
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-02 10:08:42 +04:00
|
|
|
SVGTests::MaybeInvalidate()
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2018-02-04 12:40:57 +03:00
|
|
|
nsIContent* parent = AsSVGElement()->GetFlattenedTreeParent();
|
2012-02-16 03:40:46 +04:00
|
|
|
|
2011-12-31 13:44:03 +04:00
|
|
|
if (parent &&
|
|
|
|
parent->NodeInfo()->Equals(nsGkAtoms::svgSwitch, kNameSpaceID_SVG)) {
|
2013-01-06 10:25:54 +04:00
|
|
|
static_cast<dom::SVGSwitchElement*>(parent)->MaybeInvalidate();
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
}
|
2013-03-02 10:08:42 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|