2010-07-16 18:15:07 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-11-20 18:15:32 +04:00
|
|
|
#include "DocManager.h"
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-04-25 15:29:40 +04:00
|
|
|
#include "ApplicationAccessible.h"
|
2013-04-25 07:48:26 +04:00
|
|
|
#include "ARIAMap.h"
|
2012-06-01 22:39:47 +04:00
|
|
|
#include "DocAccessible-inl.h"
|
2010-06-08 20:39:58 +04:00
|
|
|
#include "nsAccessibilityService.h"
|
2012-05-04 10:09:22 +04:00
|
|
|
#include "RootAccessibleWrap.h"
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
#include "Logging.h"
|
|
|
|
#endif
|
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2010-06-08 20:39:58 +04:00
|
|
|
#include "nsCURILoader.h"
|
|
|
|
#include "nsDocShellLoadTypes.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-09-11 02:18:59 +04:00
|
|
|
#include "nsIWebProgress.h"
|
|
|
|
#include "nsCoreUtils.h"
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-12-16 05:26:05 +04:00
|
|
|
using namespace mozilla;
|
2011-07-27 16:43:01 +04:00
|
|
|
using namespace mozilla::a11y;
|
2013-04-20 02:18:33 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-07-27 16:43:01 +04:00
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 18:15:32 +04:00
|
|
|
// DocManager
|
2010-06-08 20:39:58 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-02 12:41:57 +04:00
|
|
|
DocManager::DocManager()
|
2014-08-06 17:31:21 +04:00
|
|
|
: mDocAccessibleCache(2)
|
2013-09-02 12:41:57 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 18:15:32 +04:00
|
|
|
// DocManager public
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible*
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::GetDocAccessible(nsIDocument* aDocument)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
if (!aDocument)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2010-08-06 11:03:32 +04:00
|
|
|
// Ensure CacheChildren is called before we query cache.
|
2012-09-10 17:20:26 +04:00
|
|
|
ApplicationAcc()->EnsureChildren();
|
2010-08-06 11:03:32 +04:00
|
|
|
|
2012-11-03 03:57:58 +04:00
|
|
|
DocAccessible* docAcc = GetExistingDocAccessible(aDocument);
|
2010-06-08 20:39:58 +04:00
|
|
|
if (docAcc)
|
|
|
|
return docAcc;
|
|
|
|
|
|
|
|
return CreateDocOrRootAccessible(aDocument);
|
|
|
|
}
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible*
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::FindAccessibleInCache(nsINode* aNode) const
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
nsSearchAccessibleInCacheArg arg;
|
2010-10-21 08:16:10 +04:00
|
|
|
arg.mNode = aNode;
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
mDocAccessibleCache.EnumerateRead(SearchAccessibleInDocCache,
|
|
|
|
static_cast<void*>(&arg));
|
|
|
|
|
|
|
|
return arg.mAccessible;
|
|
|
|
}
|
|
|
|
|
2011-10-06 06:10:30 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::IsProcessingRefreshDriverNotification() const
|
2011-10-06 06:10:30 +04:00
|
|
|
{
|
|
|
|
bool isDocRefreshing = false;
|
|
|
|
mDocAccessibleCache.EnumerateRead(SearchIfDocIsRefreshing,
|
|
|
|
static_cast<void*>(&isDocRefreshing));
|
|
|
|
|
|
|
|
return isDocRefreshing;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-18 06:44:09 +04:00
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 18:15:32 +04:00
|
|
|
// DocManager protected
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::Init()
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebProgress> progress =
|
|
|
|
do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (!progress)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
progress->AddProgressListener(static_cast<nsIWebProgressListener*>(this),
|
|
|
|
nsIWebProgress::NOTIFY_STATE_DOCUMENT);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::Shutdown()
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebProgress> progress =
|
|
|
|
do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (progress)
|
|
|
|
progress->RemoveProgressListener(static_cast<nsIWebProgressListener*>(this));
|
|
|
|
|
|
|
|
ClearDocCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISupports
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(DocManager,
|
|
|
|
nsIWebProgressListener,
|
|
|
|
nsIDOMEventListener,
|
|
|
|
nsISupportsWeakReference)
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIWebProgressListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::OnStateChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, uint32_t aStateFlags,
|
|
|
|
nsresult aStatus)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aStateFlags & STATE_IS_DOCUMENT, "Other notifications excluded");
|
|
|
|
|
|
|
|
if (nsAccessibilityService::IsShutdown() || !aWebProgress ||
|
|
|
|
(aStateFlags & (STATE_START | STATE_STOP)) == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> DOMWindow;
|
|
|
|
aWebProgress->GetDOMWindow(getter_AddRefs(DOMWindow));
|
|
|
|
NS_ENSURE_STATE(DOMWindow);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> DOMDocument;
|
|
|
|
DOMWindow->GetDocument(getter_AddRefs(DOMDocument));
|
|
|
|
NS_ENSURE_STATE(DOMDocument);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> document(do_QueryInterface(DOMDocument));
|
|
|
|
|
|
|
|
// Document was loaded.
|
|
|
|
if (aStateFlags & STATE_STOP) {
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad))
|
|
|
|
logging::DocLoad("document loaded", aWebProgress, aRequest, aStateFlags);
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
// Figure out an event type to notify the document has been loaded.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t eventType = nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_STOPPED;
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
// Some XUL documents get start state and then stop state with failure
|
|
|
|
// status when everything is ok. Fire document load complete event in this
|
|
|
|
// case.
|
|
|
|
if (NS_SUCCEEDED(aStatus) || !nsCoreUtils::IsContentDocument(document))
|
|
|
|
eventType = nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE;
|
|
|
|
|
|
|
|
// If end consumer has been retargeted for loaded content then do not fire
|
|
|
|
// any event because it means no new document has been loaded, for example,
|
|
|
|
// it happens when user clicks on file link.
|
|
|
|
if (aRequest) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t loadFlags = 0;
|
2010-06-08 20:39:58 +04:00
|
|
|
aRequest->GetLoadFlags(&loadFlags);
|
|
|
|
if (loadFlags & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI)
|
|
|
|
eventType = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
HandleDOMDocumentLoad(document, eventType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Document loading was started.
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad))
|
|
|
|
logging::DocLoad("start document loading", aWebProgress, aRequest, aStateFlags);
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-11-03 03:57:58 +04:00
|
|
|
DocAccessible* docAcc = GetExistingDocAccessible(document);
|
2010-06-08 20:39:58 +04:00
|
|
|
if (!docAcc)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_GetInterface(DOMWindow));
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(webNav));
|
|
|
|
NS_ENSURE_STATE(docShell);
|
|
|
|
|
2011-08-08 11:55:36 +04:00
|
|
|
bool isReloading = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t loadType;
|
2010-06-08 20:39:58 +04:00
|
|
|
docShell->GetLoadType(&loadType);
|
|
|
|
if (loadType == LOAD_RELOAD_NORMAL ||
|
|
|
|
loadType == LOAD_RELOAD_BYPASS_CACHE ||
|
|
|
|
loadType == LOAD_RELOAD_BYPASS_PROXY ||
|
2013-01-30 12:04:34 +04:00
|
|
|
loadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE ||
|
|
|
|
loadType == LOAD_RELOAD_ALLOW_MIXED_CONTENT) {
|
2011-08-08 11:55:36 +04:00
|
|
|
isReloading = true;
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
2011-08-08 11:55:36 +04:00
|
|
|
docAcc->NotifyOfLoading(isReloading);
|
2010-06-08 20:39:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::OnProgressChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
int32_t aCurSelfProgress,
|
|
|
|
int32_t aMaxSelfProgress,
|
|
|
|
int32_t aCurTotalProgress,
|
|
|
|
int32_t aMaxTotalProgress)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::OnLocationChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, nsIURI* aLocation,
|
|
|
|
uint32_t aFlags)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::OnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, nsresult aStatus,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aMessage)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::OnSecurityChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
uint32_t aState)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMEventListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::HandleEvent(nsIDOMEvent* aEvent)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
nsAutoString type;
|
|
|
|
aEvent->GetType(type);
|
|
|
|
|
2013-04-20 02:18:32 +04:00
|
|
|
nsCOMPtr<nsIDocument> document =
|
|
|
|
do_QueryInterface(aEvent->InternalDOMEvent()->GetTarget());
|
2010-06-08 20:39:58 +04:00
|
|
|
NS_ASSERTION(document, "pagehide or DOMContentLoaded for non document!");
|
|
|
|
if (!document)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (type.EqualsLiteral("pagehide")) {
|
|
|
|
// 'pagehide' event is registered on every DOM document we create an
|
|
|
|
// accessible for, process the event for the target. This document
|
|
|
|
// accessible and all its sub document accessible are shutdown as result of
|
|
|
|
// processing.
|
|
|
|
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocDestroy))
|
|
|
|
logging::DocDestroy("received 'pagehide' event", document);
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
// Shutdown this one and sub document accessibles.
|
2010-10-28 13:34:26 +04:00
|
|
|
|
|
|
|
// We're allowed to not remove listeners when accessible document is
|
|
|
|
// shutdown since we don't keep strong reference on chrome event target and
|
|
|
|
// listeners are removed automatically when chrome event target goes away.
|
2012-11-03 03:57:58 +04:00
|
|
|
DocAccessible* docAccessible = GetExistingDocAccessible(document);
|
2010-10-28 13:34:26 +04:00
|
|
|
if (docAccessible)
|
|
|
|
docAccessible->Shutdown();
|
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: handle error pages loading separately since they get neither
|
|
|
|
// webprogress notifications nor 'pageshow' event.
|
|
|
|
if (type.EqualsLiteral("DOMContentLoaded") &&
|
|
|
|
nsCoreUtils::IsErrorPage(document)) {
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad))
|
|
|
|
logging::DocLoad("handled 'DOMContentLoaded' event", document);
|
|
|
|
#endif
|
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
HandleDOMDocumentLoad(document,
|
2010-11-22 11:22:04 +03:00
|
|
|
nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE);
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 18:15:32 +04:00
|
|
|
// DocManager private
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
void
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::HandleDOMDocumentLoad(nsIDocument* aDocument,
|
|
|
|
uint32_t aLoadEventType)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
// Document accessible can be created before we were notified the DOM document
|
|
|
|
// was loaded completely. However if it's not created yet then create it.
|
2012-11-03 03:57:58 +04:00
|
|
|
DocAccessible* docAcc = GetExistingDocAccessible(aDocument);
|
2010-06-08 20:39:58 +04:00
|
|
|
if (!docAcc) {
|
|
|
|
docAcc = CreateDocOrRootAccessible(aDocument);
|
|
|
|
if (!docAcc)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-08 11:55:36 +04:00
|
|
|
docAcc->NotifyOfLoad(aLoadEventType);
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::AddListeners(nsIDocument* aDocument,
|
|
|
|
bool aAddDOMContentLoadedListener)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
2013-04-20 02:18:33 +04:00
|
|
|
nsPIDOMWindow* window = aDocument->GetWindow();
|
|
|
|
EventTarget* target = window->GetChromeEventHandler();
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* elm = target->GetOrCreateListenerManager();
|
2010-06-08 20:39:58 +04:00
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtCapture());
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocCreate))
|
|
|
|
logging::Text("added 'pagehide' listener");
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
if (aAddDOMContentLoadedListener) {
|
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("DOMContentLoaded"),
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtCapture());
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocCreate))
|
|
|
|
logging::Text("added 'DOMContentLoaded' listener");
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:56:34 +04:00
|
|
|
void
|
|
|
|
DocManager::RemoveListeners(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
nsPIDOMWindow* window = aDocument->GetWindow();
|
2013-03-13 10:23:28 +04:00
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
2013-04-20 02:18:33 +04:00
|
|
|
EventTarget* target = window->GetChromeEventHandler();
|
2013-06-25 10:22:00 +04:00
|
|
|
if (!target)
|
|
|
|
return;
|
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* elm = target->GetOrCreateListenerManager();
|
2013-03-05 18:56:34 +04:00
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtCapture());
|
2013-03-05 18:56:34 +04:00
|
|
|
|
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("DOMContentLoaded"),
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtCapture());
|
2013-03-05 18:56:34 +04:00
|
|
|
}
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible*
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::CreateDocOrRootAccessible(nsIDocument* aDocument)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
2014-04-02 23:36:48 +04:00
|
|
|
// Ignore hiding, resource documents and documents without docshell.
|
|
|
|
if (!aDocument->IsVisibleConsideringAncestors() ||
|
2010-10-15 06:44:22 +04:00
|
|
|
aDocument->IsResourceDoc() || !aDocument->IsActive())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-02-27 15:33:55 +04:00
|
|
|
// Ignore documents without presshell and not having root frame.
|
|
|
|
nsIPresShell* presShell = aDocument->GetShell();
|
2012-12-27 08:25:27 +04:00
|
|
|
if (!presShell || presShell->IsDestroying())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isRootDoc = nsCoreUtils::IsRootDocument(aDocument);
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
DocAccessible* parentDocAcc = nullptr;
|
2011-01-26 09:35:51 +03:00
|
|
|
if (!isRootDoc) {
|
2010-06-08 20:39:58 +04:00
|
|
|
// XXXaaronl: ideally we would traverse the presshell chain. Since there's
|
|
|
|
// no easy way to do that, we cheat and use the document hierarchy.
|
2011-01-26 09:35:51 +03:00
|
|
|
parentDocAcc = GetDocAccessible(aDocument->GetParentDocument());
|
|
|
|
NS_ASSERTION(parentDocAcc,
|
|
|
|
"Can't create an accessible for the document!");
|
|
|
|
if (!parentDocAcc)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We only create root accessibles for the true root, otherwise create a
|
|
|
|
// doc accessible.
|
2012-10-31 06:25:17 +04:00
|
|
|
nsIContent *rootElm = nsCoreUtils::GetRoleContent(aDocument);
|
2012-05-27 13:01:40 +04:00
|
|
|
nsRefPtr<DocAccessible> docAcc = isRootDoc ?
|
2012-05-04 10:09:22 +04:00
|
|
|
new RootAccessibleWrap(aDocument, rootElm, presShell) :
|
2012-05-27 13:01:40 +04:00
|
|
|
new DocAccessibleWrap(aDocument, rootElm, presShell);
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2010-11-12 22:00:55 +03:00
|
|
|
// Cache the document accessible into document cache.
|
2012-05-18 21:30:49 +04:00
|
|
|
mDocAccessibleCache.Put(aDocument, docAcc);
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-11-20 07:54:41 +04:00
|
|
|
// Initialize the document accessible.
|
|
|
|
docAcc->Init();
|
2012-04-16 13:24:23 +04:00
|
|
|
docAcc->SetRoleMapEntry(aria::GetRoleMap(aDocument));
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2011-01-26 09:35:51 +03:00
|
|
|
// Bind the document to the tree.
|
|
|
|
if (isRootDoc) {
|
2012-09-10 17:20:26 +04:00
|
|
|
if (!ApplicationAcc()->AppendChild(docAcc)) {
|
2011-01-26 09:35:51 +03:00
|
|
|
docAcc->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-01-26 09:35:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fire reorder event to notify new accessible document has been attached to
|
2011-07-19 12:30:32 +04:00
|
|
|
// the tree. The reorder event is delivered after the document tree is
|
|
|
|
// constructed because event processing and tree construction are done by
|
|
|
|
// the same document.
|
2012-11-13 10:29:22 +04:00
|
|
|
// Note: don't use AccReorderEvent to avoid coalsecense and special reorder
|
|
|
|
// events processing.
|
2012-11-20 08:53:38 +04:00
|
|
|
docAcc->FireDelayedEvent(nsIAccessibleEvent::EVENT_REORDER,
|
|
|
|
ApplicationAcc());
|
2011-01-26 09:35:51 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
parentDocAcc->BindChildDocument(docAcc);
|
|
|
|
}
|
|
|
|
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocCreate)) {
|
|
|
|
logging::DocCreate("document creation finished", aDocument);
|
|
|
|
logging::Stack();
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
AddListeners(aDocument, isRootDoc);
|
|
|
|
return docAcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 18:15:32 +04:00
|
|
|
// DocManager static
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
PLDHashOperator
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::GetFirstEntryInDocCache(const nsIDocument* aKey,
|
|
|
|
DocAccessible* aDocAccessible,
|
|
|
|
void* aUserArg)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aDocAccessible,
|
2010-12-02 19:07:14 +03:00
|
|
|
"No doc accessible for the object in doc accessible cache!");
|
2012-05-27 13:01:40 +04:00
|
|
|
*reinterpret_cast<DocAccessible**>(aUserArg) = aDocAccessible;
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2010-12-02 19:07:14 +03:00
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2010-12-02 19:07:14 +03:00
|
|
|
void
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::ClearDocCache()
|
2010-12-02 19:07:14 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
DocAccessible* docAcc = nullptr;
|
2010-12-02 19:07:14 +03:00
|
|
|
while (mDocAccessibleCache.EnumerateRead(GetFirstEntryInDocCache, static_cast<void*>(&docAcc))) {
|
|
|
|
if (docAcc)
|
|
|
|
docAcc->Shutdown();
|
|
|
|
}
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::SearchAccessibleInDocCache(const nsIDocument* aKey,
|
|
|
|
DocAccessible* aDocAccessible,
|
|
|
|
void* aUserArg)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aDocAccessible,
|
|
|
|
"No doc accessible for the object in doc accessible cache!");
|
|
|
|
|
|
|
|
if (aDocAccessible) {
|
|
|
|
nsSearchAccessibleInCacheArg* arg =
|
|
|
|
static_cast<nsSearchAccessibleInCacheArg*>(aUserArg);
|
2011-01-28 07:37:08 +03:00
|
|
|
arg->mAccessible = aDocAccessible->GetAccessible(arg->mNode);
|
2010-06-12 08:04:35 +04:00
|
|
|
if (arg->mAccessible)
|
2010-06-08 20:39:58 +04:00
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2011-10-06 06:10:30 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PLDHashOperator
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::SearchIfDocIsRefreshing(const nsIDocument* aKey,
|
|
|
|
DocAccessible* aDocAccessible,
|
|
|
|
void* aUserArg)
|
2011-10-06 06:10:30 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aDocAccessible,
|
|
|
|
"No doc accessible for the object in doc accessible cache!");
|
|
|
|
|
|
|
|
if (aDocAccessible && aDocAccessible->mNotificationController &&
|
|
|
|
aDocAccessible->mNotificationController->IsUpdating()) {
|
|
|
|
*(static_cast<bool*>(aUserArg)) = true;
|
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
#endif
|