Bug 347792 - expose accessible relations in DOM inspector, r=sdwilsh, ajvincent, evan.yan, sr=neil, a=dsicore

This commit is contained in:
surkov.alexander%gmail.com 2007-10-11 02:02:11 +00:00
Родитель e1cc3e061a
Коммит d1f2927376
11 изменённых файлов: 529 добавлений и 24 удалений

Просмотреть файл

@ -56,7 +56,7 @@ interface nsIDOMDOMStringList;
*
* @status UNDER_REVIEW
*/
[scriptable, uuid(56c34b1a-d390-44f4-89c3-6935c0e4e3fa)]
[scriptable, uuid(244e4c67-a1d3-44f2-9cab-cdaa31b68046)]
interface nsIAccessibleRetrieval : nsISupports
{
/**
@ -165,6 +165,14 @@ interface nsIAccessibleRetrieval : nsISupports
* @return - accessible event type presented as human readable string
*/
AString getStringEventType(in unsigned long aEventType);
/**
* Get the type of accessible relation as a string.
*
* @param aRelationType - the accessible relation type constant
* @return - accessible relation type presented as human readable string
*/
AString getStringRelationType(in unsigned long aRelationType);
};

Просмотреть файл

@ -1056,6 +1056,21 @@ nsAccessibilityService::GetStringEventType(PRUint32 aEventType,
return NS_OK;
}
// nsIAccessibleRetrieval::getStringRelationType()
NS_IMETHODIMP
nsAccessibilityService::GetStringRelationType(PRUint32 aRelationType,
nsAString& aString)
{
if (aRelationType >= NS_ARRAY_LENGTH(kRelationTypeNames)) {
aString.AssignLiteral("unknown");
return NS_OK;
}
CopyUTF8toUTF16(kRelationTypeNames[aRelationType], aString);
return NS_OK;
}
/**
* GetAccessibleFor - get an nsIAccessible from a DOM node
*/

Просмотреть файл

@ -355,4 +355,29 @@ static const char kEventTypeNames[][40] = {
"reorder" // EVENT_REORDER
};
/**
* Map nsIAccessibleRelation constants to strings. Used by
* nsIAccessibleRetrieval::getStringRelationType() method.
*/
static const char kRelationTypeNames[][20] = {
"unknown", // RELATION_NUL
"controlled by", // RELATION_CONTROLLED_BY
"controller for", // RELATION_CONTROLLER_FOR
"label for", // RELATION_LABEL_FOR
"labelled by", // RELATION_LABELLED_BY
"member of", // RELATION_MEMBER_OF
"node child of", // RELATION_NODE_CHILD_OF
"flows to", // RELATION_FLOWS_TO
"flows from", // RELATION_FLOWS_FROM
"subwindow of", // RELATION_SUBWINDOW_OF
"embeds", // RELATION_EMBEDS
"embedded by", // RELATION_EMBEDDED_BY
"popup for", // RELATION_POPUP_FOR
"parent window of", // RELATION_PARENT_WINDOW_OF
"described by", // RELATION_DESCRIBED_BY
"description for", // RELATION_DESCRIPTION_FOR
"default button" // RELATION_DEFAULT_BUTTON
};
#endif /* __nsIAccessibilityService_h__ */

Просмотреть файл

@ -70,6 +70,8 @@ inspector.jar:
content/inspector/viewers/accessibleObject/accessibleObject.xul (resources/content/viewers/accessibleObject/accessibleObject.xul)
content/inspector/viewers/accessibleProps/accessibleProps.js (resources/content/viewers/accessibleProps/accessibleProps.js)
content/inspector/viewers/accessibleProps/accessibleProps.xul (resources/content/viewers/accessibleProps/accessibleProps.xul)
content/inspector/viewers/accessibleRelations/accessibleRelations.js (resources/content/viewers/accessibleRelations/accessibleRelations.js)
content/inspector/viewers/accessibleRelations/accessibleRelations.xul (resources/content/viewers/accessibleRelations/accessibleRelations.xul)
content/inspector/viewers/accessibleTree/accessibleTree.js (resources/content/viewers/accessibleTree/accessibleTree.js)
content/inspector/viewers/accessibleTree/accessibleTree.xul (resources/content/viewers/accessibleTree/accessibleTree.xul)
content/inspector/viewers/computedStyle/computedStyle.js (resources/content/viewers/computedStyle/computedStyle.js)

Просмотреть файл

@ -46,11 +46,6 @@ include $(DEPTH)/config/autoconf.mk
ALL_LOCALES = \
en-US \
pl \
fr \
nb-NO \
ru \
sv-SE \
$(NULL)
include $(topsrcdir)/config/config.mk

Просмотреть файл

@ -145,6 +145,33 @@
</rdf:Description>
</rdf:li>
<rdf:li>
<rdf:Description ins:uid="accessibleRelations"
ins:panels="bxObjectPanel bxObjPanel"
ins:description="Accessible Relations">
<ins:filter><![CDATA[
if (!linkedViewer ||
!(object instanceof Components.interfaces.nsIDOMNode))
return false;
if (linkedViewer.uid != "accessibleEvents" &&
linkedViewer.uid != "accessibleTree" &&
(linkedViewer.uid != "dom" || !linkedViewer.getAccessibleNodes()))
return false;
try {
var accService =
Components.classes["@mozilla.org/accessibleRetrieval;1"]
.getService(Components.interfaces.nsIAccessibleRetrieval);
return accService.getAttachedAccessibleFor(object);
} catch(e) {
return false;
}
]]></ins:filter>
</rdf:Description>
</rdf:li>
<rdf:li>
<rdf:Description ins:uid="accessibleEvents"
ins:panels="bxDocPanel"

Просмотреть файл

@ -223,7 +223,10 @@ function clear()
AccessibleEventsView.prototype.getDOMNode =
function getDOMNode(aRow)
{
return this.mEvents[aRow].node;
var DOMNode = this.mEvents[aRow].node;
var accessNode = this.mEvents[aRow].accessnode;
DOMNode.setUserData("accessible", accessNode, null);
return DOMNode;
}
AccessibleEventsView.prototype.getCellText =

Просмотреть файл

@ -0,0 +1,270 @@
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Alexander Surkov <surkov.alexander@gmail.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
/***************************************************************
* AccessibleRelationsViewer --------------------------------------------
* The viewer for the accessible relations for the inspected accessible.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* REQUIRED IMPORTS:
* chrome://inspector/content/jsutil/xpcom/XPCU.js
****************************************************************/
///////////////////////////////////////////////////////////////////////////////
//// Global Variables
var viewer;
var gAccService = null;
///////////////////////////////////////////////////////////////////////////////
//// Global Constants
const kAccessibleRetrievalCID = "@mozilla.org/accessibleRetrieval;1";
const nsIAccessibleRetrieval = Components.interfaces.nsIAccessibleRetrieval;
const nsIAccessibleRelation = Components.interfaces.nsIAccessibleRelation;
const nsIAccessNode = Components.interfaces.nsIAccessNode;
const nsIAccessible = Components.interfaces.nsIAccessible;
///////////////////////////////////////////////////////////////////////////////
//// Initialization
window.addEventListener("load", AccessibleRelationsViewer_initialize, false);
function AccessibleRelationsViewer_initialize()
{
gAccService = XPCU.getService(kAccessibleRetrievalCID,
nsIAccessibleRetrieval);
viewer = new AccessibleRelationsViewer();
viewer.initialize(parent.FrameExchange.receiveData(window));
}
///////////////////////////////////////////////////////////////////////////////
//// class AccessibleRelationsViewer
function AccessibleRelationsViewer()
{
this.mURL = window.location;
this.mObsMan = new ObserverManager(this);
this.mTree = document.getElementById("olAccessibleRelations");
this.mTreeBox = this.mTree.treeBoxObject;
this.mTargetsTree = document.getElementById("olAccessibleTargets");
this.mTargetsTreeBox = this.mTargetsTree.treeBoxObject;
}
AccessibleRelationsViewer.prototype =
{
/////////////////////////
//// initialization
mSubject: null,
mPane: null,
mView: null,
mTargetsView: null,
/////////////////////////
//// interface inIViewer
get uid() { return "accessibleRelations"; },
get pane() { return this.mPane; },
get selection() { return this.mSelection; },
get subject() { return this.mSubject; },
set subject(aObject)
{
this.mView = new AccessibleRelationsView(aObject);
this.mTreeBox.view = this.mView;
this.mObsMan.dispatchEvent("subjectChange", { subject: aObject });
},
initialize: function initialize(aPane)
{
this.mPane = aPane;
aPane.notifyViewerReady(this);
},
destroy: function destroy()
{
this.mTreeBox.view = null;
this.mTargetsTreeBox.view = null;
},
isCommandEnabled: function isCommandEnabled(aCommand)
{
return false;
},
getCommand: function getCommand(aCommand)
{
return null;
},
/////////////////////////
//// event dispatching
addObserver: function addObserver(aEvent, aObserver)
{
this.mObsMan.addObserver(aEvent, aObserver);
},
removeObserver: function removeObserver(aEvent, aObserver)
{
this.mObsMan.removeObserver(aEvent, aObserver);
},
/////////////////////////
//// utils
onItemSelected: function onItemSelected()
{
var idx = this.mTree.currentIndex;
var relation = this.mView.getRelationObject(idx);
this.mTargetsView = new AccessibleTargetsView(relation);
this.mTargetsTreeBox.view = this.mTargetsView;
},
cmdInspectInNewView: function cmdInspectInNewView()
{
var idx = this.mTargetsTree.currentIndex;
if (idx >= 0) {
var node = this.mTargetsView.getDOMNode(idx);
if (node)
inspectObject(node);
}
}
};
///////////////////////////////////////////////////////////////////////////////
//// AccessibleRelationsView
function AccessibleRelationsView(aNode)
{
this.mNode = aNode;
this.mAccessible = aNode.getUserData("accessible");
if (this.mAccessible)
XPCU.QI(this.mAccessible, nsIAccessible);
else
this.mAccessible = gAccService.getAccessibleFor(aNode);
this.mRelations = this.mAccessible.getRelations();
}
AccessibleRelationsView.prototype = new inBaseTreeView();
AccessibleRelationsView.prototype.__defineGetter__("rowCount",
function rowCount()
{
return this.mRelations.length;
});
AccessibleRelationsView.prototype.getRelationObject =
function getRelationObject(aRow)
{
return this.mRelations.queryElementAt(aRow, nsIAccessibleRelation);
}
AccessibleRelationsView.prototype.getCellText =
function getCellText(aRow, aCol)
{
if (aCol.id == "olcRelationType") {
var relation = this.getRelationObject(aRow);
if (relation)
return gAccService.getStringRelationType(relation.relationType);
}
return "";
}
///////////////////////////////////////////////////////////////////////////////
//// AccessibleTargetsView
function AccessibleTargetsView(aRelation)
{
this.mRelation = aRelation;
this.mTargets = this.mRelation.getTargets();
}
///////////////////////////////////////////////////////////////////////////////
//// AccessibleTargetsView. nsITreeView
AccessibleTargetsView.prototype = new inBaseTreeView();
AccessibleTargetsView.prototype.__defineGetter__("rowCount",
function rowCount()
{
return this.mTargets.length;
});
AccessibleTargetsView.prototype.getCellText =
function getCellText(aRow, aCol)
{
if (aCol.id == "olcRole") {
var accessible = this.getAccessible(aRow);
if (accessible)
return gAccService.getStringRole(accessible.finalRole);
} else if (aCol.id == "olcNodeName") {
var node = this.getDOMNode(aRow);
if (node)
return node.nodeName;
}
return "";
}
///////////////////////////////////////////////////////////////////////////////
//// AccessibleTargetsView. Utils
AccessibleTargetsView.prototype.getAccessible =
function getAccessible(aRow)
{
return this.mTargets.queryElementAt(aRow, nsIAccessible);
}
AccessibleTargetsView.prototype.getDOMNode =
function getDOMNode(aRow)
{
var accessNode = this.mTargets.queryElementAt(aRow, nsIAccessNode);
if (!accessNode)
return null;
var DOMNode = accessNode.DOMNode;
DOMNode.setUserData("accessible", accessNode, null);
return DOMNode;
}

Просмотреть файл

@ -0,0 +1,116 @@
<?xml version="1.0"?>
<!-- ***** 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 DOM Inspector.
-
- The Initial Developer of the Original Code is
- Mozilla Foundation.
- Portions created by the Initial Developer are Copyright (C) 2007
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Alexander Surkov <surkov.alexander@gmail.com> (original author)
-
- Alternatively, the contents of this file may be used under the terms of
- either 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 ***** -->
<!DOCTYPE page [
<!ENTITY % dtd1 SYSTEM "chrome://inspector/locale/inspector.dtd"> %dtd1;
<!ENTITY % dtd2 SYSTEM "chrome://inspector/content/util.dtd"> %dtd2;
<!ENTITY % dtd3 SYSTEM "chrome://inspector/locale/viewers/accessibleRelations.dtd"> %dtd3;
]>
<?xml-stylesheet href="chrome://inspector/skin/"?>
<page id="winAccessibleEvents"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://inspector/content/jsutil/xul/inBaseTreeView.js"/>
<script type="application/javascript"
src="chrome://inspector/content/jsutil/xpcom/XPCU.js"/>
<script type="application/javascript"
src="chrome://inspector/content/jsutil/events/ObserverManager.js"/>
<script type="application/javascript"
src="chrome://inspector/content/hooks.js"/>
<script type="application/javascript"
src="chrome://inspector/content/viewers/accessibleRelations/accessibleRelations.js"/>
<commandset id="cmdsJSObjectViewer">
<command id="cmdInspectInNewView"
oncommand="viewer.cmdInspectInNewView();"/>
</commandset>
<menupopup id="popupContext">
<menuitem label="&inspectNewWindow.label;"
observes="cmdInspectInNewView"/>
</menupopup>
<label control="olAccessibleRelations"
value="&relations.label;"/>
<tree id="olAccessibleRelations"
class="plain"
flex="1"
onselect="viewer.onItemSelected()">
<treecols>
<treecol id="olcRelationType"
label="&relationType.label;"
primary="true"
flex="1"
persist="width,hidden,ordinal"/>
</treecols>
<treechildren id="olbAccessibleRelations"
alternatingbackground="true"/>
</tree>
<label control="olAccessibleTargets"
value="&relationTargets.label;"/>
<tree id="olAccessibleTargets"
class="plain"
flex="1"
context="popupContext">
<treecols>
<treecol id="olcRole"
primary="true"
label="&role.label;"
persist="width,hidden,ordinal"
flex="1"/>
<splitter class="tree-splitter"/>
<treecol id="olcNodeName"
label="&nodeName.label;"
persist="width,hidden,ordinal"
flex="1"/>
</treecols>
<treechildren id="olbAccessibleTargets"
alternatingbackground="true"/>
</tree>
</page>

Просмотреть файл

@ -0,0 +1,43 @@
<!-- ***** 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 DOM Inspector.
-
- The Initial Developer of the Original Code is
- Mozilla Foundation.
- Portions created by the Initial Developer are Copyright (C) 2007
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Alexander Surkov <surkov.alexander@gmail.com>
-
- Alternatively, the contents of this file may be used under the terms of
- either 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 LGPL or the GPL. 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 ***** -->
<!ENTITY relationType.label "Relation Type">
<!ENTITY role.label "Role">
<!ENTITY nodeName.label "Node Name">
<!ENTITY relations.label "Relations: ">
<!ENTITY relationTargets.label "Relation Targets: ">

Просмотреть файл

@ -2,20 +2,21 @@
inspector.jar:
% locale inspector @AB_CD@ %locale/@AB_CD@/inspector/
* locale/@AB_CD@/inspector/contents.rdf (contents.rdf)
locale/@AB_CD@/inspector/inspector.dtd (@AB_CD@/inspector.dtd)
locale/@AB_CD@/inspector/prefs.dtd (@AB_CD@/prefs.dtd)
locale/@AB_CD@/inspector/editing.dtd (@AB_CD@/editing.dtd)
locale/@AB_CD@/inspector/tasksOverlay.dtd (@AB_CD@/tasksOverlay.dtd)
* locale/@AB_CD@/inspector/viewers/accessibleEvents.dtd (@AB_CD@/viewers/accessibleEvents.dtd)
* locale/@AB_CD@/inspector/viewers/accessibleProps.dtd (@AB_CD@/viewers/accessibleProps.dtd)
* locale/@AB_CD@/inspector/viewers/accessibleTree.dtd (@AB_CD@/viewers/accessibleTree.dtd)
* locale/@AB_CD@/inspector/viewers/dom.dtd (@AB_CD@/viewers/dom.dtd)
* locale/@AB_CD@/inspector/viewers/domNode.dtd (@AB_CD@/viewers/domNode.dtd)
* locale/@AB_CD@/inspector/viewers/styleRules.dtd (@AB_CD@/viewers/styleRules.dtd)
* locale/@AB_CD@/inspector/viewers/stylesheets.dtd (@AB_CD@/viewers/stylesheets.dtd)
* locale/@AB_CD@/inspector/viewers/xblBindings.dtd (@AB_CD@/viewers/xblBindings.dtd)
* locale/@AB_CD@/inspector/viewers/boxModel.dtd (@AB_CD@/viewers/boxModel.dtd)
* locale/@AB_CD@/inspector/viewers/computedStyle.dtd (@AB_CD@/viewers/computedStyle.dtd)
* locale/@AB_CD@/inspector/viewers/jsObject.dtd (@AB_CD@/viewers/jsObject.dtd)
* locale/@AB_CD@/inspector/inspector.properties (@AB_CD@/inspector.properties)
* locale/@AB_CD@/inspector/contents.rdf (contents.rdf)
locale/@AB_CD@/inspector/inspector.dtd (@AB_CD@/inspector.dtd)
locale/@AB_CD@/inspector/prefs.dtd (@AB_CD@/prefs.dtd)
locale/@AB_CD@/inspector/editing.dtd (@AB_CD@/editing.dtd)
locale/@AB_CD@/inspector/tasksOverlay.dtd (@AB_CD@/tasksOverlay.dtd)
* locale/@AB_CD@/inspector/viewers/accessibleEvents.dtd (@AB_CD@/viewers/accessibleEvents.dtd)
* locale/@AB_CD@/inspector/viewers/accessibleProps.dtd (@AB_CD@/viewers/accessibleProps.dtd)
* locale/@AB_CD@/inspector/viewers/accessibleRelations.dtd (@AB_CD@/viewers/accessibleRelations.dtd)
* locale/@AB_CD@/inspector/viewers/accessibleTree.dtd (@AB_CD@/viewers/accessibleTree.dtd)
* locale/@AB_CD@/inspector/viewers/dom.dtd (@AB_CD@/viewers/dom.dtd)
* locale/@AB_CD@/inspector/viewers/domNode.dtd (@AB_CD@/viewers/domNode.dtd)
* locale/@AB_CD@/inspector/viewers/styleRules.dtd (@AB_CD@/viewers/styleRules.dtd)
* locale/@AB_CD@/inspector/viewers/stylesheets.dtd (@AB_CD@/viewers/stylesheets.dtd)
* locale/@AB_CD@/inspector/viewers/xblBindings.dtd (@AB_CD@/viewers/xblBindings.dtd)
* locale/@AB_CD@/inspector/viewers/boxModel.dtd (@AB_CD@/viewers/boxModel.dtd)
* locale/@AB_CD@/inspector/viewers/computedStyle.dtd (@AB_CD@/viewers/computedStyle.dtd)
* locale/@AB_CD@/inspector/viewers/jsObject.dtd (@AB_CD@/viewers/jsObject.dtd)
* locale/@AB_CD@/inspector/inspector.properties (@AB_CD@/inspector.properties)