bug 779520 - merge Accessible::Init() into constructors patch=fxa90id r=surkov, tbsaunde

This commit is contained in:
Trevor Saunders 2012-10-14 17:28:32 -04:00
parent 6a32724136
commit 96d247ef37
16 changed files with 148 additions and 226 deletions

View File

@ -511,12 +511,54 @@ add_listener (GSignalEmissionHook listener,
static nsresult LoadGtkModule(GnomeAccessibilityModule& aModule);
static gboolean toplevel_event_watcher(GSignalInvocationHint*, guint,
const GValue*, gpointer);
// ApplicationAccessibleWrap
ApplicationAccessibleWrap::ApplicationAccessibleWrap():
ApplicationAccessible()
{
MAI_LOG_DEBUG(("======Create AppRootAcc=%p\n", (void*)this));
if (ShouldA11yBeEnabled()) {
// Load and initialize gail library.
nsresult rv = LoadGtkModule(sGail);
if (NS_SUCCEEDED(rv)) {
(*sGail.init)();
} else {
MAI_LOG_DEBUG(("Fail to load lib: %s\n", sGail.libName));
}
MAI_LOG_DEBUG(("Mozilla Atk Implementation initializing\n"));
// Initialize the MAI Utility class, it will overwrite gail_util.
g_type_class_unref(g_type_class_ref(MAI_TYPE_UTIL));
// Init atk-bridge now
PR_SetEnv("NO_AT_BRIDGE=0");
// load and initialize atk-bridge library
rv = LoadGtkModule(sAtkBridge);
if (NS_SUCCEEDED(rv)) {
(*sAtkBridge.init)();
} else {
MAI_LOG_DEBUG(("Fail to load lib: %s\n", sAtkBridge.libName));
}
if (!sToplevel_event_hook_added) {
sToplevel_event_hook_added = true;
sToplevel_show_hook =
g_signal_add_emission_hook(g_signal_lookup("show", GTK_TYPE_WINDOW),
0, toplevel_event_watcher,
reinterpret_cast<gpointer>(nsIAccessibleEvent::EVENT_SHOW), NULL);
sToplevel_hide_hook =
g_signal_add_emission_hook(g_signal_lookup("hide", GTK_TYPE_WINDOW),
0, toplevel_event_watcher,
reinterpret_cast<gpointer>(nsIAccessibleEvent::EVENT_HIDE), NULL);
}
}
}
ApplicationAccessibleWrap::~ApplicationAccessibleWrap()
@ -573,52 +615,6 @@ toplevel_event_watcher(GSignalInvocationHint* ihint,
return TRUE;
}
void
ApplicationAccessibleWrap::Init()
{
if (ShouldA11yBeEnabled()) {
// load and initialize gail library
nsresult rv = LoadGtkModule(sGail);
if (NS_SUCCEEDED(rv)) {
(*sGail.init)();
}
else {
MAI_LOG_DEBUG(("Fail to load lib: %s\n", sGail.libName));
}
MAI_LOG_DEBUG(("Mozilla Atk Implementation initializing\n"));
// Initialize the MAI Utility class
// it will overwrite gail_util
g_type_class_unref(g_type_class_ref(MAI_TYPE_UTIL));
// Init atk-bridge now
PR_SetEnv("NO_AT_BRIDGE=0");
// load and initialize atk-bridge library
rv = LoadGtkModule(sAtkBridge);
if (NS_SUCCEEDED(rv)) {
// init atk-bridge
(*sAtkBridge.init)();
} else {
MAI_LOG_DEBUG(("Fail to load lib: %s\n", sAtkBridge.libName));
}
if (!sToplevel_event_hook_added) {
sToplevel_event_hook_added = true;
sToplevel_show_hook =
g_signal_add_emission_hook(g_signal_lookup("show", GTK_TYPE_WINDOW),
0, toplevel_event_watcher,
reinterpret_cast<gpointer>(nsIAccessibleEvent::EVENT_SHOW), NULL);
sToplevel_hide_hook =
g_signal_add_emission_hook(g_signal_lookup("hide", GTK_TYPE_WINDOW),
0, toplevel_event_watcher,
reinterpret_cast<gpointer>(nsIAccessibleEvent::EVENT_HIDE), NULL);
}
}
ApplicationAccessible::Init();
}
void
ApplicationAccessibleWrap::Unload()
{

View File

@ -22,9 +22,6 @@ public:
ApplicationAccessibleWrap();
virtual ~ApplicationAccessibleWrap();
// nsAccessNode
virtual void Init();
// Accessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual bool AppendChild(Accessible* aChild);

View File

@ -383,8 +383,7 @@ nsAccDocManager::CreateDocOrRootAccessible(nsIDocument* aDocument)
// Cache the document accessible into document cache.
mDocAccessibleCache.Put(aDocument, docAcc);
// Initialize the document accessible.
docAcc->Init();
// Set role map entry of document accessible.
docAcc->SetRoleMapEntry(aria::GetRoleMap(aDocument));
// Bind the document to the tree.

View File

@ -997,7 +997,6 @@ nsAccessibilityService::Init()
ApplicationAccessibleWrap::PreCreate();
gApplicationAccessible = new ApplicationAccessibleWrap();
NS_ADDREF(gApplicationAccessible); // will release in Shutdown()
gApplicationAccessible->Init();
// Initialize accessibility.
nsAccessNodeWrap::InitAccessibility();

View File

@ -190,11 +190,6 @@ Accessible::~Accessible()
{
}
void
Accessible::Init()
{
}
NS_IMETHODIMP
Accessible::GetDocument(nsIAccessibleDocument** aDocument)
{

View File

@ -126,11 +126,6 @@ public:
//////////////////////////////////////////////////////////////////////////////
// Public methods
/**
* Initialize the accessible.
*/
virtual void Init();
/**
* Get the description of this accessible.
*/

View File

@ -27,6 +27,7 @@ ApplicationAccessible::ApplicationAccessible() :
AccessibleWrap(nullptr, nullptr)
{
mFlags |= eApplicationAccessible;
mAppInfo = do_GetService("@mozilla.org/xre/app-info;1");
}
////////////////////////////////////////////////////////////////////////////////
@ -266,12 +267,6 @@ ApplicationAccessible::GetPlatformVersion(nsAString& aVersion)
////////////////////////////////////////////////////////////////////////////////
// nsAccessNode public methods
void
ApplicationAccessible::Init()
{
mAppInfo = do_GetService("@mozilla.org/xre/app-info;1");
}
void
ApplicationAccessible::Shutdown()
{

View File

@ -58,7 +58,6 @@ public:
NS_DECL_NSIACCESSIBLEAPPLICATION
// nsAccessNode
virtual void Init();
virtual void Shutdown();
// Accessible

View File

@ -107,6 +107,49 @@ DocAccessible::
// We provide a virtual cursor if this is a root doc or if it's a tab doc.
mIsCursorable = (!(mDocument->GetParentDocument()) ||
nsCoreUtils::IsTabDocument(mDocument));
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eDocCreate))
logging::DocCreate("document initialize", mDocument, this);
#endif
// Initialize notification controller.
mNotificationController = new NotificationController(this, mPresShell);
// Mark the document accessible as loaded if its DOM document was loaded at
// this point (this can happen because a11y is started late or DOM document
// having no container was loaded.
if (mDocument->GetReadyStateEnum() == nsIDocument::READYSTATE_COMPLETE)
mLoadState |= eDOMLoaded;
nsCOMPtr<nsISupports> container = mDocument->GetContainer();
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(container));
// We only want to be a command observer for content docshells with an
// editor.
int32_t itemType;
docShellTreeItem->GetItemType(&itemType);
bool isContent = (itemType == nsIDocShellTreeItem::typeContent);
if (isContent) {
nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShellTreeItem);
if (commandManager)
commandManager->AddCommandObserver(this, "obs_documentCreated");
}
a11y::RootAccessible* rootAccessible = RootAccessible();
// XXX we might be the root accessible in which case eRootAccessible hasn't
// been added to mFlags yet, so the downcast failed, and RootAccessible()
// returned NULL. Bug 678477 should
// remove this hack.
if (rootAccessible) {
nsRefPtr<nsCaretAccessible> caretAccessible = rootAccessible->GetCaretAccessible();
if (caretAccessible)
caretAccessible->AddDocSelectionListener(mPresShell);
}
// Add document observer.
mDocument->AddObserver(this);
}
DocAccessible::~DocAccessible()
@ -582,26 +625,6 @@ DocAccessible::GetAccessible(nsINode* aNode) const
////////////////////////////////////////////////////////////////////////////////
// nsAccessNode
void
DocAccessible::Init()
{
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eDocCreate))
logging::DocCreate("document initialize", mDocument, this);
#endif
// Initialize notification controller.
mNotificationController = new NotificationController(this, mPresShell);
// Mark the document accessible as loaded if its DOM document was loaded at
// this point (this can happen because a11y is started late or DOM document
// having no container was loaded.
if (mDocument->GetReadyStateEnum() == nsIDocument::READYSTATE_COMPLETE)
mLoadState |= eDOMLoaded;
AddEventListeners();
}
void
DocAccessible::Shutdown()
{
@ -713,50 +736,6 @@ DocAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame** aRelativeFrame)
}
}
// DocAccessible protected member
nsresult
DocAccessible::AddEventListeners()
{
// 1) Set up scroll position listener
// 2) Check for editor and listen for changes to editor
NS_ENSURE_TRUE(mPresShell, NS_ERROR_FAILURE);
nsCOMPtr<nsISupports> container = mDocument->GetContainer();
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(container));
NS_ENSURE_TRUE(docShellTreeItem, NS_ERROR_FAILURE);
// Make sure we're a content docshell
// We don't want to listen to chrome progress
int32_t itemType;
docShellTreeItem->GetItemType(&itemType);
bool isContent = (itemType == nsIDocShellTreeItem::typeContent);
if (isContent) {
// We're not an editor yet, but we might become one
nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShellTreeItem);
if (commandManager) {
commandManager->AddCommandObserver(this, "obs_documentCreated");
}
}
nsCOMPtr<nsIDocShellTreeItem> rootTreeItem;
docShellTreeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem));
if (rootTreeItem) {
a11y::RootAccessible* rootAccessible = RootAccessible();
NS_ENSURE_TRUE(rootAccessible, NS_ERROR_FAILURE);
nsRefPtr<nsCaretAccessible> caretAccessible = rootAccessible->GetCaretAccessible();
if (caretAccessible) {
caretAccessible->AddDocSelectionListener(mPresShell);
}
}
// add document observer
mDocument->AddObserver(this);
return NS_OK;
}
// DocAccessible protected member
nsresult
DocAccessible::RemoveEventListeners()
@ -1388,9 +1367,6 @@ DocAccessible::BindToDocument(Accessible* aAccessible,
// Put into unique ID cache.
mAccessibleCache.Put(aAccessible->UniqueID(), aAccessible);
// Initialize the accessible.
aAccessible->Init();
aAccessible->SetRoleMapEntry(aRoleMapEntry);
if (aAccessible->IsElement())
AddDependentIDsFor(aAccessible);

View File

@ -76,7 +76,6 @@ public:
NS_DECL_NSIDOCUMENTOBSERVER
// nsAccessNode
virtual void Init();
virtual void Shutdown();
virtual nsIFrame* GetFrame() const;
virtual nsINode* GetNode() const { return mDocument; }
@ -322,7 +321,6 @@ protected:
virtual void CacheChildren();
// DocAccessible
virtual nsresult AddEventListeners();
virtual nsresult RemoveEventListeners();
/**

View File

@ -48,6 +48,35 @@
using namespace mozilla;
using namespace mozilla::a11y;
const char* const kEventTypes[] = {
#ifdef DEBUG_DRAGDROPSTART
// Capture mouse over events and fire fake DRAGDROPSTART event to simplify
// debugging a11y objects with event viewers.
"mouseover",
#endif
// Fired whenever list or tree control selection is changed.
"select",
// Fired whenever value changes, immediately after, whether focus moves or
// not.
"ValueChange",
"AlertActive",
"TreeRowCountChanged",
"TreeInvalidated",
// add ourself as a OpenStateChange listener (custom event fired in tree.xml)
"OpenStateChange",
// add ourself as a CheckboxStateChange listener (custom event fired in nsHTMLInputElement.cpp)
"CheckboxStateChange",
// add ourself as a RadioStateChange Listener ( custom event fired in in nsHTMLInputElement.cpp & radio.xml)
"RadioStateChange",
"popupshown",
"popuphiding",
"DOMMenuInactive",
"DOMMenuItemActive",
"DOMMenuItemInactive",
"DOMMenuBarActive",
"DOMMenuBarInactive"
};
////////////////////////////////////////////////////////////////////////////////
// nsISupports
@ -62,6 +91,25 @@ RootAccessible::
DocAccessibleWrap(aDocument, aRootContent, aPresShell)
{
mFlags |= eRootAccessible;
// nsIDOMEventTarget interface allows to register event listeners to
// receive untrusted events (synthetic events generated by untrusted code).
// For example, XBL bindings implementations for elements that are hosted in
// non chrome document fire untrusted events.
nsCOMPtr<nsIDOMEventTarget> nstarget(do_QueryInterface(mDocument));
if (nstarget) {
for (const char* const* e = kEventTypes,
* const* e_end = ArrayEnd(kEventTypes);
e < e_end; ++e) {
nstarget->AddEventListener(NS_ConvertASCIItoUTF16(*e),
this, true, true, 2);
}
}
// XXX DocAccessible constructor can't tell if its creating a RootAccessible
// so we need to construct the caret accessible here.
mCaretAccessible = new nsCaretAccessible(this);
mCaretAccessible->AddDocSelectionListener(aPresShell);
}
RootAccessible::~RootAccessible()
@ -151,68 +199,13 @@ RootAccessible::NativeState()
return state;
}
const char* const docEvents[] = {
#ifdef DEBUG_DRAGDROPSTART
// Capture mouse over events and fire fake DRAGDROPSTART event to simplify
// debugging a11y objects with event viewers
"mouseover",
#endif
// capture Form change events
"select",
// capture ValueChange events (fired whenever value changes, immediately after, whether focus moves or not)
"ValueChange",
// capture AlertActive events (fired whenever alert pops up)
"AlertActive",
"TreeRowCountChanged",
"TreeInvalidated",
// add ourself as a OpenStateChange listener (custom event fired in tree.xml)
"OpenStateChange",
// add ourself as a CheckboxStateChange listener (custom event fired in nsHTMLInputElement.cpp)
"CheckboxStateChange",
// add ourself as a RadioStateChange Listener ( custom event fired in in nsHTMLInputElement.cpp & radio.xml)
"RadioStateChange",
"popupshown",
"popuphiding",
"DOMMenuInactive",
"DOMMenuItemActive",
"DOMMenuItemInactive",
"DOMMenuBarActive",
"DOMMenuBarInactive"
};
nsresult
RootAccessible::AddEventListeners()
{
// nsIDOMEventTarget interface allows to register event listeners to
// receive untrusted events (synthetic events generated by untrusted code).
// For example, XBL bindings implementations for elements that are hosted in
// non chrome document fire untrusted events.
nsCOMPtr<nsIDOMEventTarget> nstarget(do_QueryInterface(mDocument));
if (nstarget) {
for (const char* const* e = docEvents,
* const* e_end = ArrayEnd(docEvents);
e < e_end; ++e) {
nsresult rv = nstarget->AddEventListener(NS_ConvertASCIItoUTF16(*e),
this, true, true, 2);
NS_ENSURE_SUCCESS(rv, rv);
}
}
if (!mCaretAccessible) {
mCaretAccessible = new nsCaretAccessible(this);
}
return DocAccessible::AddEventListeners();
}
nsresult
RootAccessible::RemoveEventListeners()
{
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mDocument));
if (target) {
for (const char* const* e = docEvents,
* const* e_end = ArrayEnd(docEvents);
for (const char* const* e = kEventTypes,
* const* e_end = ArrayEnd(kEventTypes);
e < e_end; ++e) {
nsresult rv = target->RemoveEventListener(NS_ConvertASCIItoUTF16(*e), this, true);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -50,9 +50,8 @@ public:
protected:
/**
* Add/remove DOM event listeners.
* Remove DOM event listeners.
*/
virtual nsresult AddEventListeners();
virtual nsresult RemoveEventListeners();
/**

View File

@ -1099,6 +1099,7 @@ XULTreeItemAccessible::
XULTreeItemAccessibleBase(aContent, aDoc, aParent, aTree, aTreeView, aRow)
{
mColumn = nsCoreUtils::GetFirstSensibleColumn(mTree);
GetCellName(mColumn, mCachedName);
}
////////////////////////////////////////////////////////////////////////////////
@ -1136,13 +1137,6 @@ XULTreeItemAccessible::Name(nsString& aName)
////////////////////////////////////////////////////////////////////////////////
// XULTreeItemAccessible: nsAccessNode implementation
void
XULTreeItemAccessible::Init()
{
XULTreeItemAccessibleBase::Init();
Name(mCachedName);
}
void
XULTreeItemAccessible::Shutdown()
{

View File

@ -233,7 +233,6 @@ public:
XULTreeItemAccessibleBase)
// nsAccessNode
virtual void Init();
virtual void Shutdown();
// Accessible

View File

@ -469,6 +469,15 @@ XULTreeGridCellAccessible::
{
mParent = aRowAcc;
mFlags |= eSharedNode;
NS_ASSERTION(mTreeView, "mTreeView is null");
int16_t type = -1;
mColumn->GetType(&type);
if (type == nsITreeColumn::TYPE_CHECKBOX)
mTreeView->GetCellValue(mRow, mColumn, mCachedTextEquiv);
else
mTreeView->GetCellText(mRow, mColumn, mCachedTextEquiv);
}
////////////////////////////////////////////////////////////////////////////////
@ -705,24 +714,6 @@ XULTreeGridCellAccessible::Selected()
return selected;
}
////////////////////////////////////////////////////////////////////////////////
// XULTreeGridCellAccessible: nsAccessNode implementation
void
XULTreeGridCellAccessible::Init()
{
LeafAccessible::Init();
NS_ASSERTION(mTreeView, "mTreeView is null");
int16_t type;
mColumn->GetType(&type);
if (type == nsITreeColumn::TYPE_CHECKBOX)
mTreeView->GetCellValue(mRow, mColumn, mCachedTextEquiv);
else
mTreeView->GetCellText(mRow, mColumn, mCachedTextEquiv);
}
////////////////////////////////////////////////////////////////////////////////
// XULTreeGridCellAccessible: Accessible public implementation

View File

@ -150,9 +150,6 @@ public:
// nsIAccessibleTableCell
NS_FORWARD_NSIACCESSIBLETABLECELL(xpcAccessibleTableCell::)
// nsAccessNode
virtual void Init();
// Accessible
virtual TableCellAccessible* AsTableCell() { return this; }
virtual void Shutdown();