mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 484176 - Support allowReorder for switch. r=jwatt,sr=roc
This commit is contained in:
parent
cb4004dfeb
commit
983f8abcf2
@ -153,7 +153,7 @@
|
||||
#include "nsICSSParser.h"
|
||||
|
||||
#ifdef MOZ_SVG
|
||||
PRBool NS_SVG_HaveFeature(const nsAString &aFeature);
|
||||
#include "nsSVGFeatures.h"
|
||||
#endif /* MOZ_SVG */
|
||||
|
||||
#ifdef DEBUG_waterson
|
||||
@ -1917,7 +1917,7 @@ nsGenericElement::InternalIsSupported(nsISupports* aObject,
|
||||
#ifdef MOZ_SVG
|
||||
else if (PL_strcasecmp(f, "SVGEvents") == 0 ||
|
||||
PL_strcasecmp(f, "SVGZoomEvents") == 0 ||
|
||||
NS_SVG_HaveFeature(aFeature)) {
|
||||
nsSVGFeatures::HaveFeature(aFeature)) {
|
||||
if (aVersion.IsEmpty() ||
|
||||
PL_strcmp(v, "1.0") == 0 ||
|
||||
PL_strcmp(v, "1.1") == 0) {
|
||||
|
@ -1006,6 +1006,7 @@ GK_ATOM(zeroDigit, "zero-digit")
|
||||
GK_ATOM(percentage, "%")
|
||||
GK_ATOM(A, "A")
|
||||
GK_ATOM(alignment_baseline, "alignment-baseline")
|
||||
GK_ATOM(allowReorder, "allowReorder")
|
||||
GK_ATOM(altGlyph, "altGlyph")
|
||||
GK_ATOM(altGlyphDef, "altGlyphDef")
|
||||
GK_ATOM(altGlyphItem, "altGlyphItem")
|
||||
|
@ -161,6 +161,7 @@ EXPORTS = \
|
||||
nsISVGValue.h \
|
||||
nsISVGValueObserver.h \
|
||||
nsISVGValueUtils.h \
|
||||
nsSVGFeatures.h \
|
||||
nsSVGNumber.h \
|
||||
nsSVGRect.h \
|
||||
nsSVGPoint.h \
|
||||
|
@ -46,7 +46,7 @@
|
||||
* http://www.w3.org/TR/SVG11/struct.html#ConditionalProcessing
|
||||
*/
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsSVGFeatures.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsContentUtils.h"
|
||||
@ -55,14 +55,8 @@
|
||||
#include "nsStyleUtil.h"
|
||||
#include "nsSVGUtils.h"
|
||||
|
||||
/**
|
||||
* Check whether we support the given feature string.
|
||||
*
|
||||
* @param aFeature one of the feature strings specified at
|
||||
* http://www.w3.org/TR/SVG11/feature.html
|
||||
*/
|
||||
PRBool
|
||||
NS_SVG_HaveFeature(const nsAString& aFeature)
|
||||
/*static*/ PRBool
|
||||
nsSVGFeatures::HaveFeature(const nsAString& aFeature)
|
||||
{
|
||||
if (!NS_SVGEnabled()) {
|
||||
return PR_FALSE;
|
||||
@ -76,32 +70,20 @@ NS_SVG_HaveFeature(const nsAString& aFeature)
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we support the given list of feature strings.
|
||||
*
|
||||
* @param aFeatures a whitespace separated list containing one or more of the
|
||||
* feature strings specified at http://www.w3.org/TR/SVG11/feature.html
|
||||
*/
|
||||
static PRBool
|
||||
HaveFeatures(const nsSubstring& aFeatures)
|
||||
/*static*/ PRBool
|
||||
nsSVGFeatures::HaveFeatures(const nsSubstring& aFeatures)
|
||||
{
|
||||
nsWhitespaceTokenizer tokenizer(aFeatures);
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
if (!NS_SVG_HaveFeature(tokenizer.nextToken())) {
|
||||
if (!HaveFeature(tokenizer.nextToken())) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we support the given extension string.
|
||||
*
|
||||
* @param aExtension the URI of an extension. Known extensions are
|
||||
* MathML and XHTML.
|
||||
*/
|
||||
static PRBool
|
||||
HaveExtension(const nsAString& aExtension)
|
||||
/*static*/ PRBool
|
||||
nsSVGFeatures::HaveExtension(const nsAString& aExtension)
|
||||
{
|
||||
#define SVG_SUPPORTED_EXTENSION(str) if (aExtension.Equals(NS_LITERAL_STRING(str).get())) return PR_TRUE;
|
||||
SVG_SUPPORTED_EXTENSION("http://www.w3.org/1999/xhtml")
|
||||
@ -113,14 +95,8 @@ HaveExtension(const nsAString& aExtension)
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we support the given list of extension strings.
|
||||
*
|
||||
* @param aExtension a whitespace separated list containing one or more
|
||||
* extension strings
|
||||
*/
|
||||
static PRBool
|
||||
HaveExtensions(const nsSubstring& aExtensions)
|
||||
/*static*/ PRBool
|
||||
nsSVGFeatures::HaveExtensions(const nsSubstring& aExtensions)
|
||||
{
|
||||
nsWhitespaceTokenizer tokenizer(aExtensions);
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
@ -131,17 +107,9 @@ HaveExtensions(const nsSubstring& aExtensions)
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the language name(s) in a systemLanguage attribute to the
|
||||
* user's language preferences, as defined in
|
||||
* http://www.w3.org/TR/SVG11/struct.html#SystemLanguageAttribute
|
||||
* We have a match if a language name in the users language preferences
|
||||
* exactly equals one of the language names or exactly equals a prefix of
|
||||
* one of the language names in the systemLanguage attribute.
|
||||
* XXX This algorithm is O(M*N).
|
||||
*/
|
||||
static PRBool
|
||||
MatchesLanguagePreferences(const nsSubstring& aAttribute, const nsSubstring& aLanguagePreferences)
|
||||
/*static*/ PRBool
|
||||
nsSVGFeatures::MatchesLanguagePreferences(const nsSubstring& aAttribute,
|
||||
const nsSubstring& aAcceptLangs)
|
||||
{
|
||||
const nsDefaultStringComparator defaultComparator;
|
||||
|
||||
@ -149,7 +117,7 @@ MatchesLanguagePreferences(const nsSubstring& aAttribute, const nsSubstring& aLa
|
||||
|
||||
while (attributeTokenizer.hasMoreTokens()) {
|
||||
const nsSubstring &attributeToken = attributeTokenizer.nextToken();
|
||||
nsCommaSeparatedTokenizer languageTokenizer(aLanguagePreferences);
|
||||
nsCommaSeparatedTokenizer languageTokenizer(aAcceptLangs);
|
||||
while (languageTokenizer.hasMoreTokens()) {
|
||||
if (nsStyleUtil::DashMatchCompare(attributeToken,
|
||||
languageTokenizer.nextToken(),
|
||||
@ -161,17 +129,43 @@ MatchesLanguagePreferences(const nsSubstring& aAttribute, const nsSubstring& aLa
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this element supports the specified attributes
|
||||
* (i.e. whether the SVG specification defines the attributes
|
||||
* for the specified element).
|
||||
*
|
||||
* @param aTagName the tag for the element
|
||||
* @param aAttr the conditional to test for, either
|
||||
* ATTRS_TEST or ATTRS_EXTERNAL
|
||||
*/
|
||||
static PRBool
|
||||
ElementSupportsAttributes(const nsIAtom *aTagName, PRUint16 aAttr)
|
||||
/*static*/ PRInt32
|
||||
nsSVGFeatures::GetBestLanguagePreferenceRank(const nsSubstring& aAttribute,
|
||||
const nsSubstring& aAcceptLangs)
|
||||
{
|
||||
const nsDefaultStringComparator defaultComparator;
|
||||
|
||||
nsCommaSeparatedTokenizer attributeTokenizer(aAttribute);
|
||||
PRInt32 lowestRank = -1;
|
||||
|
||||
while (attributeTokenizer.hasMoreTokens()) {
|
||||
const nsSubstring &attributeToken = attributeTokenizer.nextToken();
|
||||
nsCommaSeparatedTokenizer languageTokenizer(aAcceptLangs);
|
||||
PRInt32 index = 0;
|
||||
while (languageTokenizer.hasMoreTokens()) {
|
||||
const nsSubstring &languageToken = languageTokenizer.nextToken();
|
||||
PRBool exactMatch = (languageToken == attributeToken);
|
||||
PRBool prefixOnlyMatch =
|
||||
!exactMatch &&
|
||||
nsStyleUtil::DashMatchCompare(attributeToken,
|
||||
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;
|
||||
}
|
||||
|
||||
/*static*/ PRBool
|
||||
nsSVGFeatures::ElementSupportsAttributes(const nsIAtom *aTagName, PRUint16 aAttr)
|
||||
{
|
||||
#define SVG_ELEMENT(_atom, _supports) if (aTagName == nsGkAtoms::_atom) return (_supports & aAttr) != 0;
|
||||
#include "nsSVGElementList.h"
|
||||
@ -179,16 +173,11 @@ ElementSupportsAttributes(const nsIAtom *aTagName, PRUint16 aAttr)
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the conditional processing attributes requiredFeatures,
|
||||
* requiredExtensions and systemLanguage all "return true" if they apply to
|
||||
* and are specified on the given element. Returns true if this element
|
||||
* should be rendered, false if it should not.
|
||||
*
|
||||
* @param aContent the element to test
|
||||
*/
|
||||
PRBool
|
||||
NS_SVG_PassesConditionalProcessingTests(nsIContent *aContent)
|
||||
const nsAdoptingString * const nsSVGFeatures::kIgnoreSystemLanguage = (nsAdoptingString *) 0x01;
|
||||
|
||||
/*static*/ PRBool
|
||||
nsSVGFeatures::PassesConditionalProcessingTests(nsIContent *aContent,
|
||||
const nsAdoptingString *aAcceptLangs)
|
||||
{
|
||||
if (!aContent->IsNodeOfType(nsINode::eELEMENT)) {
|
||||
return PR_FALSE;
|
||||
@ -219,6 +208,13 @@ NS_SVG_PassesConditionalProcessingTests(nsIContent *aContent)
|
||||
}
|
||||
}
|
||||
|
||||
if (aAcceptLangs == kIgnoreSystemLanguage) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
const nsAdoptingString& acceptLangs = aAcceptLangs ? *aAcceptLangs :
|
||||
nsContentUtils::GetLocalizedStringPref("intl.accept_languages");
|
||||
|
||||
// systemLanguage
|
||||
//
|
||||
// Evaluates to "true" if one of the languages indicated by user preferences
|
||||
@ -229,11 +225,8 @@ NS_SVG_PassesConditionalProcessingTests(nsIContent *aContent)
|
||||
if (aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::systemLanguage,
|
||||
value)) {
|
||||
// Get our language preferences
|
||||
nsAutoString langPrefs(nsContentUtils::GetLocalizedStringPref("intl.accept_languages"));
|
||||
if (!langPrefs.IsEmpty()) {
|
||||
langPrefs.StripWhitespace();
|
||||
value.StripWhitespace();
|
||||
return MatchesLanguagePreferences(value, langPrefs);
|
||||
if (!acceptLangs.IsEmpty()) {
|
||||
return MatchesLanguagePreferences(value, acceptLangs);
|
||||
} else {
|
||||
// For now, evaluate to true.
|
||||
NS_WARNING("no default language specified for systemLanguage conditional test");
|
||||
|
150
content/svg/content/src/nsSVGFeatures.h
Normal file
150
content/svg/content/src/nsSVGFeatures.h
Normal file
@ -0,0 +1,150 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla SVG project.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Robert Longson.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Robert Longson <longsonr@gmail.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __NS_SVGFEATURES_H__
|
||||
#define __NS_SVGFEATURES_H__
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIContent;
|
||||
class nsIAtom;
|
||||
|
||||
class nsSVGFeatures
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Check whether we support the given feature string.
|
||||
*
|
||||
* @param aFeature one of the feature strings specified at
|
||||
* http://www.w3.org/TR/SVG11/feature.html
|
||||
*/
|
||||
static PRBool
|
||||
HaveFeature(const nsAString& aFeature);
|
||||
|
||||
/**
|
||||
* Compare the language name(s) in a systemLanguage attribute to the
|
||||
* user's language preferences, as defined in
|
||||
* http://www.w3.org/TR/SVG11/struct.html#SystemLanguageAttribute
|
||||
* We have a match if a language name in the users language preferences
|
||||
* exactly equals one of the language names or exactly equals a prefix of
|
||||
* one of the language names in the systemLanguage attribute.
|
||||
* @returns 2 * the lowest index in the aAcceptLangs that matches + 1
|
||||
* if only the prefix matches, or -1 if no indices match.
|
||||
* XXX This algorithm is O(M*N).
|
||||
*/
|
||||
static int
|
||||
GetBestLanguagePreferenceRank(const nsSubstring& aAttribute,
|
||||
const nsSubstring& aAcceptLangs);
|
||||
|
||||
/**
|
||||
* Special value to pass to PassesConditionalProcessingTests to ignore systemLanguage
|
||||
* attributes
|
||||
*/
|
||||
static const nsAdoptingString * const kIgnoreSystemLanguage;
|
||||
|
||||
/**
|
||||
* Check whether the conditional processing attributes requiredFeatures,
|
||||
* requiredExtensions and systemLanguage all "return true" if they apply to
|
||||
* and are specified on the given element. Returns true if this element
|
||||
* should be rendered, false if it should not.
|
||||
*
|
||||
* @param aContent the element to test
|
||||
* @param aAcceptLangs Optional parameter to pass in the value of the
|
||||
* intl.accept_languages preference if the caller has it cached.
|
||||
* Alternatively, pass in kIgnoreSystemLanguage to skip the systemLanguage
|
||||
* check if the caller is giving that special treatment.
|
||||
*/
|
||||
static PRBool
|
||||
PassesConditionalProcessingTests(nsIContent *aContent,
|
||||
const nsAdoptingString *aAcceptLangs = nsnull);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Check whether we support the given list of feature strings.
|
||||
*
|
||||
* @param aFeatures a whitespace separated list containing one or more of the
|
||||
* feature strings specified at http://www.w3.org/TR/SVG11/feature.html
|
||||
*/
|
||||
static PRBool
|
||||
HaveFeatures(const nsSubstring& aFeatures);
|
||||
|
||||
/**
|
||||
* Check whether we support the given extension string.
|
||||
*
|
||||
* @param aExtension the URI of an extension. Known extensions are
|
||||
* "http://www.w3.org/1999/xhtml" and "http://www.w3.org/1998/Math/MathML"
|
||||
*/
|
||||
static PRBool
|
||||
HaveExtension(const nsAString& aExtension);
|
||||
|
||||
/**
|
||||
* Check whether we support the given list of extension strings.
|
||||
*
|
||||
* @param aExtension a whitespace separated list containing one or more
|
||||
* extension strings
|
||||
*/
|
||||
static PRBool
|
||||
HaveExtensions(const nsSubstring& aExtensions);
|
||||
|
||||
/**
|
||||
* Compare the language name(s) in a systemLanguage attribute to the
|
||||
* user's language preferences, as defined in
|
||||
* http://www.w3.org/TR/SVG11/struct.html#SystemLanguageAttribute
|
||||
* We have a match if a language name in the users language preferences
|
||||
* exactly equals one of the language names or exactly equals a prefix of
|
||||
* one of the language names in the systemLanguage attribute.
|
||||
* XXX This algorithm is O(M*N).
|
||||
*/
|
||||
static PRBool
|
||||
MatchesLanguagePreferences(const nsSubstring& aAttribute,
|
||||
const nsSubstring& aAcceptLangs);
|
||||
|
||||
/**
|
||||
* Check whether this element supports the specified attributes
|
||||
* (i.e. whether the SVG specification defines the attributes
|
||||
* for the specified element).
|
||||
*
|
||||
* @param aTagName the tag for the element
|
||||
* @param aAttr the conditional to test for, either
|
||||
* ATTRS_TEST or ATTRS_EXTERNAL
|
||||
*/
|
||||
static PRBool
|
||||
ElementSupportsAttributes(const nsIAtom *aTagName, PRUint16 aAttr);
|
||||
};
|
||||
|
||||
#endif // __NS_SVGFEATURES_H__
|
@ -34,14 +34,12 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSVGFeatures.h"
|
||||
#include "nsSVGSwitchElement.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsISVGChildFrame.h"
|
||||
#include "nsSVGUtils.h"
|
||||
|
||||
PRBool
|
||||
NS_SVG_PassesConditionalProcessingTests(nsIContent *aContent);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// implementation
|
||||
|
||||
@ -86,41 +84,19 @@ nsSVGSwitchElement::MaybeInvalidate()
|
||||
// to determine if we should call nsSVGUtils::UpdateGraphic. If we did that,
|
||||
// nsSVGUtils::UpdateGraphic would not invalidate the old mActiveChild area!
|
||||
|
||||
PRUint32 count = GetChildCount();
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsIContent * child = GetChildAt(i);
|
||||
if (NS_SVG_PassesConditionalProcessingTests(child)) {
|
||||
if (FindActiveChild() == mActiveChild) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mActiveChild == child) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsIFrame *frame = GetPrimaryFrame();
|
||||
if (frame) {
|
||||
nsISVGChildFrame* svgFrame = do_QueryFrame(frame);
|
||||
if (svgFrame) {
|
||||
nsSVGUtils::UpdateGraphic(svgFrame);
|
||||
}
|
||||
}
|
||||
return;
|
||||
nsIFrame *frame = GetPrimaryFrame();
|
||||
if (frame) {
|
||||
nsISVGChildFrame* svgFrame = do_QueryFrame(frame);
|
||||
if (svgFrame) {
|
||||
nsSVGUtils::UpdateGraphic(svgFrame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsSVGSwitchElement::UpdateActiveChild()
|
||||
{
|
||||
PRUint32 count = GetChildCount();
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsIContent * child = GetChildAt(i);
|
||||
if (NS_SVG_PassesConditionalProcessingTests(child)) {
|
||||
mActiveChild = child;
|
||||
return;
|
||||
}
|
||||
}
|
||||
mActiveChild = nsnull;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsIDOMNode methods
|
||||
|
||||
@ -172,3 +148,62 @@ nsSVGSwitchElement::IsAttributeMapped(const nsIAtom* name) const
|
||||
return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
|
||||
nsSVGSwitchElementBase::IsAttributeMapped(name);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Implementation Helpers:
|
||||
|
||||
nsIContent *
|
||||
nsSVGSwitchElement::FindActiveChild() const
|
||||
{
|
||||
PRBool allowReorder = AttrValueIs(kNameSpaceID_None,
|
||||
nsGkAtoms::allowReorder,
|
||||
nsGkAtoms::yes, eCaseMatters);
|
||||
|
||||
const nsAdoptingString& acceptLangs =
|
||||
nsContentUtils::GetLocalizedStringPref("intl.accept_languages");
|
||||
|
||||
PRUint32 count = GetChildCount();
|
||||
|
||||
if (allowReorder && !acceptLangs.IsEmpty()) {
|
||||
PRInt32 bestLanguagePreferenceRank = -1;
|
||||
nsIContent *bestChild = nsnull;
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsIContent *child = GetChildAt(i);
|
||||
if (nsSVGFeatures::PassesConditionalProcessingTests(
|
||||
child, nsSVGFeatures::kIgnoreSystemLanguage)) {
|
||||
nsAutoString value;
|
||||
if (child->GetAttr(kNameSpaceID_None, nsGkAtoms::systemLanguage,
|
||||
value)) {
|
||||
PRInt32 languagePreferenceRank =
|
||||
nsSVGFeatures::GetBestLanguagePreferenceRank(value, acceptLangs);
|
||||
switch (languagePreferenceRank) {
|
||||
case 0:
|
||||
// best possible match
|
||||
return child;
|
||||
case -1:
|
||||
// not found
|
||||
break;
|
||||
default:
|
||||
if (bestLanguagePreferenceRank == -1 ||
|
||||
languagePreferenceRank < bestLanguagePreferenceRank) {
|
||||
bestLanguagePreferenceRank = languagePreferenceRank;
|
||||
bestChild = child;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (!bestChild) {
|
||||
bestChild = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
return bestChild;
|
||||
}
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsIContent *child = GetChildAt(i);
|
||||
if (nsSVGFeatures::PassesConditionalProcessingTests(child, &acceptLangs)) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
@ -36,6 +36,9 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __NS_SVGSWITCHELEMENT_H__
|
||||
#define __NS_SVGSWITCHELEMENT_H__
|
||||
|
||||
#include "nsSVGGraphicElement.h"
|
||||
#include "nsIDOMSVGSwitchElement.h"
|
||||
|
||||
@ -51,7 +54,7 @@ protected:
|
||||
nsSVGSwitchElement(nsINodeInfo *aNodeInfo);
|
||||
|
||||
public:
|
||||
nsIContent * GetActiveChild()
|
||||
nsIContent * GetActiveChild() const
|
||||
{ return mActiveChild; }
|
||||
void MaybeInvalidate();
|
||||
|
||||
@ -78,8 +81,12 @@ public:
|
||||
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
|
||||
|
||||
private:
|
||||
void UpdateActiveChild();
|
||||
void UpdateActiveChild()
|
||||
{ mActiveChild = FindActiveChild(); }
|
||||
nsIContent* FindActiveChild() const;
|
||||
|
||||
// only this child will be displayed
|
||||
nsCOMPtr<nsIContent> mActiveChild;
|
||||
};
|
||||
|
||||
#endif // __NS_SVGSWITCHELEMENT_H__
|
||||
|
@ -55,6 +55,8 @@ _TEST_FILES = \
|
||||
test_pathSeg.xhtml \
|
||||
test_scientific.html \
|
||||
scientific-helper.svg \
|
||||
test_switch.xhtml \
|
||||
switch-helper.svg \
|
||||
test_text.html \
|
||||
text-helper.svg \
|
||||
test_valueLeaks.xhtml \
|
||||
|
12
content/svg/content/test/switch-helper.svg
Normal file
12
content/svg/content/test/switch-helper.svg
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/licenses/publicdomain/
|
||||
-->
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||||
<switch id="s">
|
||||
<rect systemLanguage="fr" id="first" x="75" y="100" width="70" height="70" fill="yellow"/>
|
||||
<rect id="second" x="75" y="100" width="50" height="50" fill="lime"/>
|
||||
<rect x="75" y="100" width="80" height="80" fill="red"/>
|
||||
</switch>
|
||||
</svg>
|
After Width: | Height: | Size: 478 B |
108
content/svg/content/test/test_switch.xhtml
Normal file
108
content/svg/content/test/test_switch.xhtml
Normal file
@ -0,0 +1,108 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=484176
|
||||
-->
|
||||
<head>
|
||||
<title>Test SVG Switch</title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=484176">Mozilla Bug 484176</a>
|
||||
<p id="display"></p>
|
||||
<div id="content"></div>
|
||||
|
||||
<iframe id="svg" src="switch-helper.svg"></iframe>
|
||||
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
<![CDATA[
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var test = 1;
|
||||
|
||||
function checkBounds(element, x, y, w, h)
|
||||
{
|
||||
var bbox = element.getBBox();
|
||||
var name = element.nodeName;
|
||||
|
||||
is(bbox.x, x, test + " " + name + ".getBBox().x");
|
||||
is(bbox.y, y, test + " " + name + ".getBBox().y");
|
||||
is(bbox.width, w, test + " " + name + ".getBBox().width");
|
||||
is(bbox.height, h, test + " " + name + ".getBBox().height");
|
||||
++test;
|
||||
}
|
||||
|
||||
function checkWidth(element, x, y, w, h)
|
||||
{
|
||||
var bbox = element.getBBox();
|
||||
var name = element.nodeName;
|
||||
|
||||
is(bbox.width, w, test + " " + name + ".getBBox().width");
|
||||
++test;
|
||||
}
|
||||
|
||||
function run()
|
||||
{
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
// Set accept_languages to something we know
|
||||
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefService);
|
||||
var branch = prefService.getBranch("intl.");
|
||||
var oldAcceptLanguages = branch.getCharPref("accept_languages");
|
||||
branch.setCharPref("accept_languages", "en-gb,en,it");
|
||||
|
||||
try {
|
||||
var doc = $("svg").contentDocument;
|
||||
var s = doc.getElementById("s");
|
||||
var first = doc.getElementById("first");
|
||||
var second = doc.getElementById("second");
|
||||
|
||||
/* test for an exact match */
|
||||
second.setAttribute("systemLanguage", "en-gb");
|
||||
checkBounds(s, 75, 100, 50, 50);
|
||||
|
||||
/* test for a close match i.e. the same language prefix */
|
||||
second.setAttribute("systemLanguage", "en-us");
|
||||
checkWidth(s, 75, 100, 50, 50);
|
||||
|
||||
/* test that we pick the first match */
|
||||
first.setAttribute("systemLanguage", "it");
|
||||
checkWidth(s, 75, 100, 70, 70);
|
||||
|
||||
/* this time with reordering */
|
||||
first.setAttribute("systemLanguage", "fr");
|
||||
s.setAttribute("allowReorder", "yes");
|
||||
|
||||
/* test for an exact match */
|
||||
second.setAttribute("systemLanguage", "en-gb");
|
||||
checkWidth(s, 75, 100, 50, 50);
|
||||
|
||||
/* test for a close match i.e. the same language prefix */
|
||||
second.setAttribute("systemLanguage", "en-us");
|
||||
checkWidth(s, 75, 100, 50, 50);
|
||||
|
||||
/* test that we pick the best match */
|
||||
second.setAttribute("systemLanguage", "it");
|
||||
checkWidth(s, 75, 100, 50, 50);
|
||||
|
||||
/* test that we pick the best match */
|
||||
first.setAttribute("systemLanguage", "en");
|
||||
second.setAttribute("systemLanguage", "en-gb");
|
||||
checkWidth(s, 75, 100, 50, 50);
|
||||
|
||||
} finally {
|
||||
branch.setCharPref("accept_languages", oldAcceptLanguages);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("load", run, false);
|
||||
|
||||
]]>
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -148,6 +148,7 @@
|
||||
#include "nsMathMLParts.h"
|
||||
#endif
|
||||
#ifdef MOZ_SVG
|
||||
#include "nsSVGFeatures.h"
|
||||
#include "nsSVGEffects.h"
|
||||
#include "nsSVGUtils.h"
|
||||
#include "nsSVGOuterSVGFrame.h"
|
||||
@ -192,8 +193,6 @@ nsIFrame*
|
||||
NS_NewSVGContainerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
||||
nsIFrame*
|
||||
NS_NewSVGUseFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
||||
PRBool
|
||||
NS_SVG_PassesConditionalProcessingTests(nsIContent *aContent);
|
||||
extern nsIFrame*
|
||||
NS_NewSVGLinearGradientFrame(nsIPresShell *aPresShell, nsStyleContext* aContext);
|
||||
extern nsIFrame*
|
||||
@ -4939,7 +4938,7 @@ nsCSSFrameConstructor::FindSVGData(nsIContent* aContent,
|
||||
// Reduce the number of frames we create unnecessarily. Note that this is not
|
||||
// where we select which frame in a <switch> to render! That happens in
|
||||
// nsSVGSwitchFrame::PaintSVG.
|
||||
if (!NS_SVG_PassesConditionalProcessingTests(aContent)) {
|
||||
if (!nsSVGFeatures::PassesConditionalProcessingTests(aContent)) {
|
||||
// Note that just returning is probably not right. According
|
||||
// to the spec, <use> is allowed to use an element that fails its
|
||||
// conditional, but because we never actually create the frame when
|
||||
|
Loading…
Reference in New Issue
Block a user