зеркало из https://github.com/mozilla/pjs.git
Bug 381174. Locale not exposed for ATK document interface. r=surkov
This commit is contained in:
Родитель
9ec97fb1f5
Коммит
57c1be6eb2
|
@ -56,7 +56,7 @@ interface nsIDOMCSSPrimitiveValue;
|
|||
*
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
[scriptable, uuid(0120eb06-3df3-49bf-95b1-2e2593a59265)]
|
||||
[scriptable, uuid(71a3b4e7-e83d-45cf-a20e-9ce292bcf19f)]
|
||||
interface nsIAccessNode : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -166,5 +166,10 @@ interface nsIAccessNode : nsISupports
|
|||
*/
|
||||
nsIDOMCSSPrimitiveValue getComputedStyleCSSValue(in DOMString pseudoElt,
|
||||
in DOMString propertyName);
|
||||
|
||||
/**
|
||||
* The language for the current DOM node, e.g. en, de, etc.
|
||||
*/
|
||||
readonly attribute DOMString language;
|
||||
};
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
|
||||
#include "nsAccessibleWrap.h"
|
||||
#include "nsMaiInterfaceDocument.h"
|
||||
#include "nsAccessibilityAtoms.h"
|
||||
|
||||
const char *const kDocTypeName = "W3C-doctype";
|
||||
const char *const kDocUrlName = "DocURL";
|
||||
|
@ -53,12 +54,32 @@ documentInterfaceInitCB(AtkDocumentIface *aIface)
|
|||
return;
|
||||
|
||||
/*
|
||||
* We don't support get_document, get_locale and set_attribute right now.
|
||||
* We don't support get_document or set_attribute right now.
|
||||
* get_document_type is deprecated, we return DocType in
|
||||
* get_document_attribute_value and get_document_attributes instead.
|
||||
*/
|
||||
aIface->get_document_attributes = getDocumentAttributesCB;
|
||||
aIface->get_document_attribute_value = getDocumentAttributeValueCB;
|
||||
aIface->get_document_locale = getDocumentLocaleCB;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
getDocumentLocaleCB(AtkDocument *aDocument)
|
||||
{
|
||||
nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
|
||||
NS_ENSURE_TRUE(accWrap, nsnull);
|
||||
|
||||
nsCOMPtr<nsIAccessNode> docAccessNode;
|
||||
accWrap->QueryInterface(NS_GET_IID(nsIAccessNode),
|
||||
getter_AddRefs(docAccessNode));
|
||||
NS_ENSURE_TRUE(accDocument, nsnull);
|
||||
|
||||
nsAutoString locale;
|
||||
docAccessNode->GetLanguage(getter_AddRefs(locale));
|
||||
if (locale.IsEmpty()) {
|
||||
return nsnull;
|
||||
}
|
||||
return nsAccessibleWrap::ReturnString(locale);
|
||||
}
|
||||
|
||||
const gchar *
|
||||
|
@ -72,10 +93,10 @@ getDocumentTypeCB(AtkDocument *aDocument)
|
|||
getter_AddRefs(accDocument));
|
||||
NS_ENSURE_TRUE(accDocument, nsnull);
|
||||
|
||||
nsAutoString aMimeType;
|
||||
nsresult rv = accDocument->GetMimeType(aMimeType);
|
||||
nsAutoString mimeType;
|
||||
nsresult rv = accDocument->GetMimeType(mimeType);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
return nsAccessibleWrap::ReturnString(aMimeType);
|
||||
return nsAccessibleWrap::ReturnString(mimeType);
|
||||
}
|
||||
|
||||
static inline GSList *
|
||||
|
|
|
@ -49,6 +49,7 @@ G_BEGIN_DECLS
|
|||
/* document interface callbacks */
|
||||
void documentInterfaceInitCB(AtkDocumentIface *aIface);
|
||||
AtkAttributeSet* getDocumentAttributesCB(AtkDocument *aDocument);
|
||||
const gchar* getDocumentLocaleCB(AtkDocument *aDocument);
|
||||
const gchar* getDocumentAttributeValueCB(AtkDocument *aDocument,
|
||||
const gchar *aAttrName);
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
#include "nsIDOMCSSPrimitiveValue.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsIDOMHTMLElement.h"
|
||||
#include "nsIDOMNSHTMLElement.h"
|
||||
#include "nsIDOMViewCSS.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
|
@ -792,3 +794,47 @@ already_AddRefed<nsIDOMNode> nsAccessNode::GetCurrentFocus()
|
|||
|
||||
return focusedNode;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAccessNode::GetLanguage(nsAString& aLanguage)
|
||||
{
|
||||
aLanguage.Truncate();
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
||||
if (!content) {
|
||||
// For documents make sure we look for lang attribute on
|
||||
// document element
|
||||
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mDOMNode));
|
||||
if (domDoc) {
|
||||
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(mDOMNode));
|
||||
if (htmlDoc) {
|
||||
// Make sure we look for lang attribute on HTML <body>
|
||||
nsCOMPtr<nsIDOMHTMLElement> bodyElement;
|
||||
htmlDoc->GetBody(getter_AddRefs(bodyElement));
|
||||
content = do_QueryInterface(bodyElement);
|
||||
}
|
||||
if (!content) {
|
||||
nsCOMPtr<nsIDOMElement> docElement;
|
||||
domDoc->GetDocumentElement(getter_AddRefs(docElement));
|
||||
content = do_QueryInterface(docElement);
|
||||
}
|
||||
}
|
||||
if (!content) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
nsIContent *walkUp = content;
|
||||
while (walkUp && !walkUp->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::lang, aLanguage)) {
|
||||
walkUp = walkUp->GetParent();
|
||||
}
|
||||
|
||||
if (aLanguage.IsEmpty()) { // Nothing found, so use document's language
|
||||
nsIDocument *doc = content->GetOwnerDoc();
|
||||
if (doc) {
|
||||
doc->GetHeaderData(nsAccessibilityAtoms::headerContentLanguage, aLanguage);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
#include "nsIPresShell.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsAttrName.h"
|
||||
|
||||
/// the accessible library and cached methods
|
||||
|
@ -481,26 +480,10 @@ nsAccessNodeWrap::get_innerHTML(BSTR __RPC_FAR *aInnerHTML)
|
|||
STDMETHODIMP
|
||||
nsAccessNodeWrap::get_language(BSTR __RPC_FAR *aLanguage)
|
||||
{
|
||||
*aLanguage = nsnull;
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
||||
if (!content) {
|
||||
nsAutoString language;
|
||||
if (NS_FAILED(GetLanguage(language))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
nsAutoString language;
|
||||
for (nsIContent *walkUp = content; walkUp = walkUp->GetParent(); walkUp) {
|
||||
if (walkUp->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::lang, language)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (language.IsEmpty()) { // Nothing found, so use document's language
|
||||
nsIDocument *doc = content->GetOwnerDoc();
|
||||
if (doc) {
|
||||
doc->GetHeaderData(nsAccessibilityAtoms::headerContentLanguage, language);
|
||||
}
|
||||
}
|
||||
|
||||
*aLanguage = ::SysAllocString(language.get());
|
||||
return S_OK;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче