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"
|
2015-05-19 11:15:34 -07:00
|
|
|
#include "mozilla/Logging.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsCRT.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2012-07-20 09:42:08 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2013-09-25 04:21:22 -07:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2014-03-17 21:48:21 -07:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2013-07-23 16:39:17 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-01 20:46:04 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2013-11-27 15:13:11 -08:00
|
|
|
static PRLogModuleInfo* gCommandLog;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsXULCommandDispatcher::nsXULCommandDispatcher(nsIDocument* aDocument)
|
2012-07-30 07:20:58 -07:00
|
|
|
: mDocument(aDocument), mUpdaters(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
|
2013-11-27 15:13:11 -08:00
|
|
|
if (! gCommandLog)
|
|
|
|
gCommandLog = PR_NewLogModule("nsXULCommandDispatcher");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXULCommandDispatcher::~nsXULCommandDispatcher()
|
|
|
|
{
|
2007-03-24 03:53:07 -07:00
|
|
|
Disconnect();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsXULCommandDispatcher
|
2010-01-12 05:08:43 -08:00
|
|
|
|
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
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULCommandDispatcher)
|
|
|
|
|
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)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocument)
|
2007-03-24 03:53:07 -07:00
|
|
|
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;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocument = nullptr;
|
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) {
|
2013-06-21 07:25:20 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window(mDocument->GetWindow());
|
2010-02-20 08:07:03 -08:00
|
|
|
if (window) {
|
|
|
|
return window->GetTopWindowRoot();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-03-24 03:53:07 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
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)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aWindow = nullptr;
|
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 (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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
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
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::GetFocusedElement(nsIDOMElement** aElement)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aElement = nullptr;
|
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> 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)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aWindow = nullptr;
|
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;
|
|
|
|
|
2015-03-12 10:20:29 -07:00
|
|
|
window.forget(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.
|
2013-07-23 16:39:17 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> frameElement =
|
|
|
|
do_QueryInterface(window->GetFrameElementInternal());
|
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 (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()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return AdvanceFocusIntoSubtree(nullptr);
|
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)
|
2012-07-30 07:20:58 -07:00
|
|
|
return fm->MoveFocus(win, nullptr, nsIFocusManager::MOVEFOCUS_BACKWARD,
|
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
|
|
|
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)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(aElement != nullptr, "null ptr");
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
2015-06-02 04:05:56 -07:00
|
|
|
if (PR_LOG_TEST(gCommandLog, PR_LOG_NOTICE)) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString eventsC, targetsC, aeventsC, atargetsC;
|
2007-03-22 10:30:00 -07:00
|
|
|
eventsC.AssignWithConversion(updater->mEvents);
|
|
|
|
targetsC.AssignWithConversion(updater->mTargets);
|
|
|
|
CopyUTF16toUTF8(aEvents, aeventsC);
|
|
|
|
CopyUTF16toUTF8(aTargets, atargetsC);
|
2015-06-02 04:05:56 -07:00
|
|
|
MOZ_LOG(gCommandLog, PR_LOG_NOTICE,
|
2007-03-22 10:30:00 -07:00
|
|
|
("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
|
2015-06-02 04:05:56 -07:00
|
|
|
if (PR_LOG_TEST(gCommandLog, PR_LOG_NOTICE)) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString aeventsC, atargetsC;
|
2007-03-22 10:30:00 -07:00
|
|
|
CopyUTF16toUTF8(aEvents, aeventsC);
|
|
|
|
CopyUTF16toUTF8(aTargets, atargetsC);
|
|
|
|
|
2015-06-02 04:05:56 -07:00
|
|
|
MOZ_LOG(gCommandLog, PR_LOG_NOTICE,
|
2007-03-22 10:30:00 -07:00
|
|
|
("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)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(aElement != nullptr, "null ptr");
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
2015-06-02 04:05:56 -07:00
|
|
|
if (PR_LOG_TEST(gCommandLog, PR_LOG_NOTICE)) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString eventsC, targetsC;
|
2007-03-22 10:30:00 -07:00
|
|
|
eventsC.AssignWithConversion(updater->mEvents);
|
|
|
|
targetsC.AssignWithConversion(updater->mTargets);
|
2015-06-02 04:05:56 -07:00
|
|
|
MOZ_LOG(gCommandLog, PR_LOG_NOTICE,
|
2007-03-22 10:30:00 -07:00
|
|
|
("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;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
for (Updater* updater = mUpdaters; updater != nullptr; updater = updater->mNext) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(content != nullptr, "not an nsIContent");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (! content)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2010-10-25 07:06:26 -07:00
|
|
|
updaters.AppendObject(content);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t u = 0; u < updaters.Count(); u++) {
|
2010-10-25 07:06:26 -07:00
|
|
|
nsIContent* content = updaters[u];
|
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2015-06-02 04:05:56 -07:00
|
|
|
if (PR_LOG_TEST(gCommandLog, PR_LOG_NOTICE)) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString aeventnameC;
|
2007-03-22 10:30:00 -07:00
|
|
|
CopyUTF16toUTF8(aEventName, aeventnameC);
|
2015-06-02 04:05:56 -07:00
|
|
|
MOZ_LOG(gCommandLog, PR_LOG_NOTICE,
|
2007-03-22 10:30:00 -07:00
|
|
|
("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
|
|
|
|
|
2014-08-22 13:11:27 -07:00
|
|
|
WidgetEvent event(true, NS_XUL_COMMAND_UPDATE);
|
|
|
|
EventDispatcher::Dispatch(content, nullptr, &event);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t indx = aList.Find(PromiseFlatString(aElement));
|
2007-03-22 10:30:00 -07:00
|
|
|
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) {
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t ch = aList[indx - 1];
|
|
|
|
if (! nsCRT::IsAsciiSpace(ch) && ch != char16_t(','))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (indx + aElement.Length() < aList.Length()) {
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t ch = aList[indx + aElement.Length()];
|
|
|
|
if (! nsCRT::IsAsciiSpace(ch) && ch != char16_t(','))
|
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
|
|
|
}
|
|
|
|
|