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"
|
2018-12-22 02:29:24 +03:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIContentInlines.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
|
|
|
|
2019-06-26 21:51:12 +03:00
|
|
|
nsStaticAtom* const SVGTests::sStringListNames[2] = {
|
2018-03-29 12:45:31 +03:00
|
|
|
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> SVGTests::RequiredExtensions() {
|
2013-01-03 10:17:02 +04:00
|
|
|
return DOMSVGStringList::GetDOMWrapper(&mStringListAttributes[EXTENSIONS],
|
2018-02-04 12:40:57 +03:00
|
|
|
AsSVGElement(), true, EXTENSIONS);
|
2013-01-03 10:17:02 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
already_AddRefed<DOMSVGStringList> SVGTests::SystemLanguage() {
|
2013-01-03 10:17:02 +04:00
|
|
|
return DOMSVGStringList::GetDOMWrapper(&mStringListAttributes[LANGUAGE],
|
2018-02-04 12:40:57 +03:00
|
|
|
AsSVGElement(), true, LANGUAGE);
|
2013-01-03 10:17:02 +04:00
|
|
|
}
|
|
|
|
|
2018-12-31 18:10:00 +03:00
|
|
|
bool SVGTests::HasExtension(const nsAString& aExtension) const {
|
|
|
|
#define SVG_SUPPORTED_EXTENSION(str) \
|
|
|
|
if (aExtension.EqualsLiteral(str)) return true;
|
|
|
|
SVG_SUPPORTED_EXTENSION("http://www.w3.org/1999/xhtml")
|
|
|
|
nsNameSpaceManager* nameSpaceManager = nsNameSpaceManager::GetInstance();
|
|
|
|
if (AsSVGElement()->IsInChromeDocument() ||
|
|
|
|
!nameSpaceManager->mMathMLDisabled) {
|
|
|
|
SVG_SUPPORTED_EXTENSION("http://www.w3.org/1998/Math/MathML")
|
|
|
|
}
|
|
|
|
#undef SVG_SUPPORTED_EXTENSION
|
|
|
|
|
|
|
|
return false;
|
2013-01-03 10:17:02 +04:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
bool SVGTests::IsConditionalProcessingAttribute(
|
|
|
|
const nsAtom* aAttribute) const {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(sStringListNames); i++) {
|
2018-03-29 12:45:31 +03:00
|
|
|
if (aAttribute == sStringListNames[i]) {
|
2011-12-31 13:44:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-20 12:19:52 +03:00
|
|
|
int32_t SVGTests::GetBestLanguagePreferenceRank(
|
|
|
|
const nsAString& aAcceptLangs) const {
|
2018-08-06 23:47:20 +03:00
|
|
|
const nsCaseInsensitiveStringComparator caseInsensitiveComparator;
|
2011-12-31 13:44:03 +04:00
|
|
|
|
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();
|
2018-08-06 23:47:20 +03:00
|
|
|
bool exactMatch = languageToken.Equals(mStringListAttributes[LANGUAGE][i],
|
|
|
|
caseInsensitiveComparator);
|
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(),
|
2018-08-06 23:47:20 +03:00
|
|
|
caseInsensitiveComparator);
|
2011-12-31 13:44:03 +04:00
|
|
|
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
|
|
|
|
2013-03-02 10:08:42 +04:00
|
|
|
bool 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-12-31 18:10:00 +03:00
|
|
|
if (!HasExtension(mStringListAttributes[EXTENSIONS][i])) {
|
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;
|
|
|
|
}
|
|
|
|
|
2018-08-06 23:47:20 +03:00
|
|
|
const nsCaseInsensitiveStringComparator caseInsensitiveComparator;
|
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(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(),
|
2018-08-06 23:47:20 +03:00
|
|
|
caseInsensitiveComparator)) {
|
2011-12-31 13:44:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
bool SVGTests::ParseConditionalProcessingAttribute(nsAtom* aAttribute,
|
2013-03-02 10:08:42 +04:00
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(sStringListNames); i++) {
|
2018-03-29 12:45:31 +03: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;
|
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
void SVGTests::UnsetAttr(const nsAtom* aAttribute) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(sStringListNames); i++) {
|
2018-03-29 12:45:31 +03: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-02 10:08:42 +04:00
|
|
|
nsStaticAtom* SVGTests::GetAttrName(uint8_t aAttrEnum) const {
|
2018-03-29 12:45:31 +03:00
|
|
|
return sStringListNames[aAttrEnum];
|
2012-02-16 03:40:46 +04:00
|
|
|
}
|
2011-12-31 13:44:03 +04:00
|
|
|
|
2013-03-02 10:08:42 +04:00
|
|
|
void SVGTests::GetAttrValue(uint8_t aAttrEnum, nsAttrValue& aValue) const {
|
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
|
|
|
}
|
|
|
|
|
2013-03-02 10:08:42 +04:00
|
|
|
void SVGTests::MaybeInvalidate() {
|
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
|