2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This file provides the implementation for the XUL Command Dispatcher.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsIContent.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
#include "nsFocusManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIControllers.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
2011-07-15 03:31:34 -07:00
|
|
|
#include "nsIDOMWindow.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2010-02-20 08:07:03 -08:00
|
|
|
#include "nsPIWindowRoot.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsRDFCID.h"
|
|
|
|
#include "nsXULCommandDispatcher.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsDOMError.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo* gLog;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsXULCommandDispatcher::nsXULCommandDispatcher(nsIDocument* aDocument)
|
2007-03-24 03:53:07 -07:00
|
|
|
: mDocument(aDocument), mUpdaters(nsnull)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (! gLog)
|
|
|
|
gLog = PR_NewLogModule("nsXULCommandDispatcher");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXULCommandDispatcher::~nsXULCommandDispatcher()
|
|
|
|
{
|
2007-03-24 03:53:07 -07:00
|
|
|
Disconnect();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-03-24 03:53:07 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULCommandDispatcher)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// QueryInterface implementation for nsXULCommandDispatcher
|
2010-01-12 05:08:43 -08:00
|
|
|
|
|
|
|
DOMCI_DATA(XULCommandDispatcher, nsXULCommandDispatcher)
|
|
|
|
|
2007-04-25 09:35:27 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULCommandDispatcher)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMXULCommandDispatcher)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXULCommandDispatcher)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(XULCommandDispatcher)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2007-03-24 03:53:07 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULCommandDispatcher)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULCommandDispatcher)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-03-24 03:53:07 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULCommandDispatcher)
|
|
|
|
tmp->Disconnect();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-03-24 03:53:07 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULCommandDispatcher)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument)
|
|
|
|
Updater* updater = tmp->mUpdaters;
|
|
|
|
while (updater) {
|
|
|
|
cb.NoteXPCOMChild(updater->mElement);
|
|
|
|
updater = updater->mNext;
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-03-24 03:53:07 -07:00
|
|
|
void
|
|
|
|
nsXULCommandDispatcher::Disconnect()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-24 03:53:07 -07:00
|
|
|
while (mUpdaters) {
|
|
|
|
Updater* doomed = mUpdaters;
|
|
|
|
mUpdaters = mUpdaters->mNext;
|
|
|
|
delete doomed;
|
|
|
|
}
|
|
|
|
mDocument = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-20 08:07:03 -08:00
|
|
|
already_AddRefed<nsPIWindowRoot>
|
|
|
|
nsXULCommandDispatcher::GetWindowRoot()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-02-20 08:07:03 -08:00
|
|
|
if (mDocument) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(mDocument->GetScriptGlobalObject()));
|
|
|
|
if (window) {
|
|
|
|
return window->GetTopWindowRoot();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-03-24 03:53:07 -07:00
|
|
|
|
2010-02-20 08:07:03 -08:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIContent*
|
|
|
|
nsXULCommandDispatcher::GetRootFocusedContentAndWindow(nsPIDOMWindow** aWindow)
|
|
|
|
{
|
|
|
|
*aWindow = nsnull;
|
|
|
|
|
|
|
|
if (mDocument) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = mDocument->GetWindow();
|
|
|
|
if (win) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> rootWindow = win->GetPrivateRoot();
|
|
|
|
if (rootWindow) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return nsFocusManager::GetFocusedDescendant(rootWindow, true, aWindow);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::GetFocusedElement(nsIDOMElement** aElement)
|
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
*aElement = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> focusedWindow;
|
|
|
|
nsIContent* focusedContent =
|
|
|
|
GetRootFocusedContentAndWindow(getter_AddRefs(focusedWindow));
|
|
|
|
if (focusedContent) {
|
|
|
|
CallQueryInterface(focusedContent, aElement);
|
|
|
|
|
|
|
|
// Make sure the caller can access the focused element.
|
|
|
|
if (!nsContentUtils::CanCallerAccess(*aElement)) {
|
|
|
|
// XXX This might want to return null, but we use that return value
|
|
|
|
// to mean "there is no focused element," so to be clear, throw an
|
|
|
|
// exception.
|
|
|
|
NS_RELEASE(*aElement);
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::GetFocusedWindow(nsIDOMWindow** aWindow)
|
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
*aWindow = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window;
|
|
|
|
GetRootFocusedContentAndWindow(getter_AddRefs(window));
|
|
|
|
if (!window)
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Make sure the caller can access this window. The caller can access this
|
|
|
|
// window iff it can access the document.
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsresult rv = window->GetDocument(getter_AddRefs(domdoc));
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Note: If there is no document, then this window has been cleared and
|
|
|
|
// there's nothing left to protect, so let the window pass through.
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (domdoc && !nsContentUtils::CanCallerAccess(domdoc))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
CallQueryInterface(window, aWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::SetFocusedElement(nsIDOMElement* aElement)
|
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
NS_ENSURE_TRUE(fm, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (aElement)
|
|
|
|
return fm->SetFocus(aElement, 0);
|
|
|
|
|
|
|
|
// if aElement is null, clear the focus in the currently focused child window
|
|
|
|
nsCOMPtr<nsPIDOMWindow> focusedWindow;
|
|
|
|
GetRootFocusedContentAndWindow(getter_AddRefs(focusedWindow));
|
|
|
|
return fm->ClearFocus(focusedWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::SetFocusedWindow(nsIDOMWindow* aWindow)
|
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
NS_ENSURE_TRUE(aWindow, NS_OK); // do nothing if set to null
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(aWindow));
|
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
NS_ENSURE_TRUE(fm, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
// get the containing frame for the window, and set it as focused. This will
|
|
|
|
// end up focusing whatever is currently focused inside the frame. Since
|
|
|
|
// setting the command dispatcher's focused window doesn't raise the window,
|
|
|
|
// setting it to a top-level window doesn't need to do anything.
|
|
|
|
nsCOMPtr<nsIDOMElement> frameElement = window->GetFrameElementInternal();
|
|
|
|
if (frameElement)
|
|
|
|
return fm->SetFocus(frameElement, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::AdvanceFocus()
|
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
return AdvanceFocusIntoSubtree(nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::RewindFocus()
|
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win;
|
|
|
|
GetRootFocusedContentAndWindow(getter_AddRefs(win));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> result;
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm)
|
|
|
|
return fm->MoveFocus(win, nsnull, nsIFocusManager::MOVEFOCUS_BACKWARD,
|
|
|
|
0, getter_AddRefs(result));
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::AdvanceFocusIntoSubtree(nsIDOMElement* aElt)
|
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win;
|
|
|
|
GetRootFocusedContentAndWindow(getter_AddRefs(win));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> result;
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm)
|
|
|
|
return fm->MoveFocus(win, aElt, nsIFocusManager::MOVEFOCUS_FORWARD,
|
|
|
|
0, getter_AddRefs(result));
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::AddCommandUpdater(nsIDOMElement* aElement,
|
|
|
|
const nsAString& aEvents,
|
|
|
|
const nsAString& aTargets)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
|
|
|
if (! aElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2012-04-03 00:25:38 -07:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2010-01-12 05:08:44 -08:00
|
|
|
nsresult rv = nsContentUtils::CheckSameOrigin(mDocument, aElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
Updater* updater = mUpdaters;
|
|
|
|
Updater** link = &mUpdaters;
|
|
|
|
|
|
|
|
while (updater) {
|
|
|
|
if (updater->mElement == aElement) {
|
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PR_LOG_TEST(gLog, PR_LOG_NOTICE)) {
|
|
|
|
nsCAutoString eventsC, targetsC, aeventsC, atargetsC;
|
|
|
|
eventsC.AssignWithConversion(updater->mEvents);
|
|
|
|
targetsC.AssignWithConversion(updater->mTargets);
|
|
|
|
CopyUTF16toUTF8(aEvents, aeventsC);
|
|
|
|
CopyUTF16toUTF8(aTargets, atargetsC);
|
|
|
|
PR_LOG(gLog, PR_LOG_NOTICE,
|
|
|
|
("xulcmd[%p] replace %p(events=%s targets=%s) with (events=%s targets=%s)",
|
|
|
|
this, aElement,
|
|
|
|
eventsC.get(),
|
|
|
|
targetsC.get(),
|
|
|
|
aeventsC.get(),
|
|
|
|
atargetsC.get()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// If the updater was already in the list, then replace
|
|
|
|
// (?) the 'events' and 'targets' filters with the new
|
|
|
|
// specification.
|
|
|
|
updater->mEvents = aEvents;
|
|
|
|
updater->mTargets = aTargets;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
link = &(updater->mNext);
|
|
|
|
updater = updater->mNext;
|
|
|
|
}
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PR_LOG_TEST(gLog, PR_LOG_NOTICE)) {
|
|
|
|
nsCAutoString aeventsC, atargetsC;
|
|
|
|
CopyUTF16toUTF8(aEvents, aeventsC);
|
|
|
|
CopyUTF16toUTF8(aTargets, atargetsC);
|
|
|
|
|
|
|
|
PR_LOG(gLog, PR_LOG_NOTICE,
|
|
|
|
("xulcmd[%p] add %p(events=%s targets=%s)",
|
|
|
|
this, aElement,
|
|
|
|
aeventsC.get(),
|
|
|
|
atargetsC.get()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// If we get here, this is a new updater. Append it to the list.
|
|
|
|
updater = new Updater(aElement, aEvents, aTargets);
|
|
|
|
if (! updater)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*link = updater;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::RemoveCommandUpdater(nsIDOMElement* aElement)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
|
|
|
if (! aElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
Updater* updater = mUpdaters;
|
|
|
|
Updater** link = &mUpdaters;
|
|
|
|
|
|
|
|
while (updater) {
|
|
|
|
if (updater->mElement == aElement) {
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PR_LOG_TEST(gLog, PR_LOG_NOTICE)) {
|
|
|
|
nsCAutoString eventsC, targetsC;
|
|
|
|
eventsC.AssignWithConversion(updater->mEvents);
|
|
|
|
targetsC.AssignWithConversion(updater->mTargets);
|
|
|
|
PR_LOG(gLog, PR_LOG_NOTICE,
|
|
|
|
("xulcmd[%p] remove %p(events=%s targets=%s)",
|
|
|
|
this, aElement,
|
|
|
|
eventsC.get(),
|
|
|
|
targetsC.get()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*link = updater->mNext;
|
|
|
|
delete updater;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
link = &(updater->mNext);
|
|
|
|
updater = updater->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hmm. Not found. Oh well.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::UpdateCommands(const nsAString& aEventName)
|
|
|
|
{
|
|
|
|
nsAutoString id;
|
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
GetFocusedElement(getter_AddRefs(element));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (element) {
|
|
|
|
nsresult rv = element->GetAttribute(NS_LITERAL_STRING("id"), id);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element's id");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2010-10-25 07:06:26 -07:00
|
|
|
nsCOMArray<nsIContent> updaters;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
for (Updater* updater = mUpdaters; updater != nsnull; updater = updater->mNext) {
|
|
|
|
// Skip any nodes that don't match our 'events' or 'targets'
|
|
|
|
// filters.
|
|
|
|
if (! Matches(updater->mEvents, aEventName))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (! Matches(updater->mTargets, id))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(updater->mElement);
|
|
|
|
NS_ASSERTION(content != nsnull, "not an nsIContent");
|
|
|
|
if (! content)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2010-10-25 07:06:26 -07:00
|
|
|
updaters.AppendObject(content);
|
|
|
|
}
|
|
|
|
|
2011-03-28 14:26:33 -07:00
|
|
|
for (PRInt32 u = 0; u < updaters.Count(); u++) {
|
2010-10-25 07:06:26 -07:00
|
|
|
nsIContent* content = updaters[u];
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDocument> document = content->GetDocument();
|
|
|
|
|
|
|
|
NS_ASSERTION(document != nsnull, "element has no document");
|
|
|
|
if (! document)
|
|
|
|
continue;
|
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PR_LOG_TEST(gLog, PR_LOG_NOTICE)) {
|
|
|
|
nsCAutoString aeventnameC;
|
|
|
|
CopyUTF16toUTF8(aEventName, aeventnameC);
|
|
|
|
PR_LOG(gLog, PR_LOG_NOTICE,
|
|
|
|
("xulcmd[%p] update %p event=%s",
|
2010-10-25 07:06:26 -07:00
|
|
|
this, content,
|
2007-03-22 10:30:00 -07:00
|
|
|
aeventnameC.get()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-25 06:59:57 -07:00
|
|
|
nsCOMPtr<nsIPresShell> shell = document->GetShell();
|
2010-01-07 02:36:11 -08:00
|
|
|
if (shell) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Retrieve the context in which our DOM event will fire.
|
2010-03-25 06:17:11 -07:00
|
|
|
nsRefPtr<nsPresContext> context = shell->GetPresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Handle the DOM event
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsEvent event(true, NS_XUL_COMMAND_UPDATE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsEventDispatcher::Dispatch(content, context, &event, nsnull, &status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXULCommandDispatcher::Matches(const nsString& aList,
|
|
|
|
const nsAString& aElement)
|
|
|
|
{
|
|
|
|
if (aList.EqualsLiteral("*"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return true; // match _everything_!
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRInt32 indx = aList.Find(PromiseFlatString(aElement));
|
|
|
|
if (indx == -1)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false; // not in the list at all
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// okay, now make sure it's not a substring snafu; e.g., 'ur'
|
|
|
|
// found inside of 'blur'.
|
|
|
|
if (indx > 0) {
|
|
|
|
PRUnichar ch = aList[indx - 1];
|
|
|
|
if (! nsCRT::IsAsciiSpace(ch) && ch != PRUnichar(','))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (indx + aElement.Length() < aList.Length()) {
|
|
|
|
PRUnichar ch = aList[indx + aElement.Length()];
|
|
|
|
if (! nsCRT::IsAsciiSpace(ch) && ch != PRUnichar(','))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::GetControllers(nsIControllers** aResult)
|
|
|
|
{
|
2010-02-20 08:07:03 -08:00
|
|
|
nsCOMPtr<nsPIWindowRoot> root = GetWindowRoot();
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-20 08:07:03 -08:00
|
|
|
return root->GetControllers(aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::GetControllerForCommand(const char *aCommand, nsIController** _retval)
|
|
|
|
{
|
2010-02-20 08:07:03 -08:00
|
|
|
nsCOMPtr<nsPIWindowRoot> root = GetWindowRoot();
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-20 08:07:03 -08:00
|
|
|
return root->GetControllerForCommand(aCommand, _retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULCommandDispatcher::GetSuppressFocusScroll(bool* aSuppressFocusScroll)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aSuppressFocusScroll = false;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULCommandDispatcher::SetSuppressFocusScroll(bool aSuppressFocusScroll)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|