2002-07-16 17:09:15 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-10-25 05:34:16 +04:00
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
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/. */
|
1999-05-29 02:16:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
This file provides the implementation for the XUL Command Dispatcher.
|
1999-05-29 02:16:47 +04:00
|
|
|
|
1999-12-06 02:04:22 +03:00
|
|
|
*/
|
1999-05-29 02:16:47 +04:00
|
|
|
|
|
|
|
#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 22:00:39 +04:00
|
|
|
#include "nsFocusManager.h"
|
1999-12-06 02:04:22 +03:00
|
|
|
#include "nsIControllers.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
2011-07-15 14:31:34 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
1999-06-09 01:58:55 +04:00
|
|
|
#include "nsIDOMXULElement.h"
|
1999-12-06 02:04:22 +03:00
|
|
|
#include "nsIDocument.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1999-08-25 05:49:24 +04:00
|
|
|
#include "nsIPresShell.h"
|
1999-12-06 02:04:22 +03:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
1999-10-14 14:58:25 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2010-02-20 19:07:03 +03:00
|
|
|
#include "nsPIWindowRoot.h"
|
1999-12-06 02:04:22 +03:00
|
|
|
#include "nsRDFCID.h"
|
|
|
|
#include "nsXULCommandDispatcher.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
#include "nsContentUtils.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2012-07-20 20:42:08 +04:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2013-09-25 15:21:22 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2013-07-24 03:39:17 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
1999-10-13 04:43:46 +04:00
|
|
|
|
2013-10-02 07:46:04 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2013-11-28 03:13:11 +04:00
|
|
|
static PRLogModuleInfo* gCommandLog;
|
1999-10-13 04:43:46 +04:00
|
|
|
|
1999-05-29 02:16:47 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
nsXULCommandDispatcher::nsXULCommandDispatcher(nsIDocument* aDocument)
|
2012-07-30 18:20:58 +04:00
|
|
|
: mDocument(aDocument), mUpdaters(nullptr)
|
1999-05-29 02:16:47 +04:00
|
|
|
{
|
2000-10-29 02:17:53 +04:00
|
|
|
|
2013-11-28 03:13:11 +04:00
|
|
|
if (! gCommandLog)
|
|
|
|
gCommandLog = PR_NewLogModule("nsXULCommandDispatcher");
|
1999-05-29 02:16:47 +04:00
|
|
|
}
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
nsXULCommandDispatcher::~nsXULCommandDispatcher()
|
1999-05-29 02:16:47 +04:00
|
|
|
{
|
2007-03-24 13:53:07 +03:00
|
|
|
Disconnect();
|
1999-05-29 02:16:47 +04:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
// QueryInterface implementation for nsXULCommandDispatcher
|
2010-01-12 16:08:43 +03:00
|
|
|
|
2007-04-25 20:35:27 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULCommandDispatcher)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMXULCommandDispatcher)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXULCommandDispatcher)
|
2010-03-17 18:09:05 +03:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(XULCommandDispatcher)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
1999-05-29 02:16:47 +04:00
|
|
|
|
2007-03-24 13:53:07 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULCommandDispatcher)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULCommandDispatcher)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULCommandDispatcher)
|
|
|
|
|
2007-03-24 13:53:07 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULCommandDispatcher)
|
|
|
|
tmp->Disconnect();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
1999-12-06 02:04:22 +03:00
|
|
|
|
2007-03-24 13:53:07 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULCommandDispatcher)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocument)
|
2007-03-24 13:53:07 +03:00
|
|
|
Updater* updater = tmp->mUpdaters;
|
|
|
|
while (updater) {
|
|
|
|
cb.NoteXPCOMChild(updater->mElement);
|
|
|
|
updater = updater->mNext;
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
1999-12-06 02:04:22 +03:00
|
|
|
|
2007-03-24 13:53:07 +03:00
|
|
|
void
|
|
|
|
nsXULCommandDispatcher::Disconnect()
|
1999-12-06 02:04:22 +03:00
|
|
|
{
|
2007-03-24 13:53:07 +03:00
|
|
|
while (mUpdaters) {
|
|
|
|
Updater* doomed = mUpdaters;
|
|
|
|
mUpdaters = mUpdaters->mNext;
|
|
|
|
delete doomed;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocument = nullptr;
|
1999-05-29 02:16:47 +04:00
|
|
|
}
|
|
|
|
|
2010-02-20 19:07:03 +03:00
|
|
|
already_AddRefed<nsPIWindowRoot>
|
|
|
|
nsXULCommandDispatcher::GetWindowRoot()
|
2000-11-04 11:21:20 +03:00
|
|
|
{
|
2010-02-20 19:07:03 +03:00
|
|
|
if (mDocument) {
|
2013-06-21 18:25:20 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window(mDocument->GetWindow());
|
2010-02-20 19:07:03 +03:00
|
|
|
if (window) {
|
|
|
|
return window->GetTopWindowRoot();
|
|
|
|
}
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
2007-03-24 13:53:07 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
1999-05-29 02:16:47 +04: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 22:00:39 +04:00
|
|
|
nsIContent*
|
|
|
|
nsXULCommandDispatcher::GetRootFocusedContentAndWindow(nsPIDOMWindow** aWindow)
|
|
|
|
{
|
2012-07-30 18:20:58 +04: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 22:00:39 +04:00
|
|
|
|
|
|
|
if (mDocument) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = mDocument->GetWindow();
|
|
|
|
if (win) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> rootWindow = win->GetPrivateRoot();
|
|
|
|
if (rootWindow) {
|
2011-10-17 18:59:28 +04: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 22:00:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04: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 22:00:39 +04:00
|
|
|
}
|
1999-05-29 02:16:47 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-12-08 07:56:56 +03:00
|
|
|
nsXULCommandDispatcher::GetFocusedElement(nsIDOMElement** aElement)
|
|
|
|
{
|
2012-07-30 18:20:58 +04: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 22:00:39 +04: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;
|
|
|
|
}
|
2005-10-25 05:34:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-12-08 07:56:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
nsXULCommandDispatcher::GetFocusedWindow(nsIDOMWindow** aWindow)
|
1999-08-25 05:49:24 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aWindow = nullptr;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04: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 22:00:39 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window;
|
|
|
|
GetRootFocusedContentAndWindow(getter_AddRefs(window));
|
|
|
|
if (!window)
|
|
|
|
return NS_OK;
|
2005-10-25 05:34:16 +04: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 22:00:39 +04:00
|
|
|
nsresult rv = window->GetDocument(getter_AddRefs(domdoc));
|
2005-10-25 05:34:16 +04: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 22:00:39 +04:00
|
|
|
if (domdoc && !nsContentUtils::CanCallerAccess(domdoc))
|
2005-10-25 05:34:16 +04:00
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
|
2015-03-12 20:20:29 +03:00
|
|
|
window.forget(aWindow);
|
2005-10-25 05:34:16 +04:00
|
|
|
return NS_OK;
|
1999-08-25 05:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-12-08 07:56:56 +03:00
|
|
|
nsXULCommandDispatcher::SetFocusedElement(nsIDOMElement* aElement)
|
1999-08-25 05:49:24 +04: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 22:00:39 +04:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
NS_ENSURE_TRUE(fm, NS_ERROR_FAILURE);
|
2004-07-10 00:57:30 +04: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 22:00:39 +04: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);
|
1999-05-29 02:16:47 +04:00
|
|
|
}
|
|
|
|
|
1999-12-08 07:56:56 +03:00
|
|
|
NS_IMETHODIMP
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
nsXULCommandDispatcher::SetFocusedWindow(nsIDOMWindow* aWindow)
|
1999-12-08 07:56:56 +03: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 22:00:39 +04: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);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04: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 22:00:39 +04: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-24 03:39:17 +04: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 22:00:39 +04:00
|
|
|
if (frameElement)
|
|
|
|
return fm->SetFocus(frameElement, 0);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04: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 22:00:39 +04:00
|
|
|
return NS_OK;
|
1999-12-08 07:56:56 +03:00
|
|
|
}
|
|
|
|
|
2001-04-11 07:05:42 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::AdvanceFocus()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
return AdvanceFocusIntoSubtree(nullptr);
|
2001-04-11 07:05:42 +04: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 22:00:39 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win;
|
|
|
|
GetRootFocusedContentAndWindow(getter_AddRefs(win));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> result;
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm)
|
2012-07-30 18:20:58 +04: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 22:00:39 +04:00
|
|
|
0, getter_AddRefs(result));
|
|
|
|
return NS_OK;
|
2001-04-11 07:05:42 +04: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 22:00:39 +04: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;
|
2001-04-11 07:05:42 +04:00
|
|
|
}
|
|
|
|
|
1999-05-29 02:16:47 +04:00
|
|
|
NS_IMETHODIMP
|
1999-12-06 02:04:22 +03:00
|
|
|
nsXULCommandDispatcher::AddCommandUpdater(nsIDOMElement* aElement,
|
2002-03-24 01:46:13 +03:00
|
|
|
const nsAString& aEvents,
|
|
|
|
const nsAString& aTargets)
|
1999-05-29 02:16:47 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aElement != nullptr, "null ptr");
|
2000-11-04 11:21:20 +03:00
|
|
|
if (! aElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-08-30 06:45:54 +04:00
|
|
|
|
2012-04-03 11:25:38 +04:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2010-01-12 16:08:44 +03:00
|
|
|
nsresult rv = nsContentUtils::CheckSameOrigin(mDocument, aElement);
|
2002-07-18 09:53:28 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2002-07-16 17:09:15 +04:00
|
|
|
}
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
Updater* updater = mUpdaters;
|
|
|
|
Updater** link = &mUpdaters;
|
1999-09-17 08:01:46 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
while (updater) {
|
|
|
|
if (updater->mElement == aElement) {
|
2000-04-26 05:13:55 +04:00
|
|
|
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2015-06-04 01:22:28 +03:00
|
|
|
if (MOZ_LOG_TEST(gCommandLog, PR_LOG_NOTICE)) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString eventsC, targetsC, aeventsC, atargetsC;
|
2004-06-22 13:37:55 +04:00
|
|
|
eventsC.AssignWithConversion(updater->mEvents);
|
|
|
|
targetsC.AssignWithConversion(updater->mTargets);
|
|
|
|
CopyUTF16toUTF8(aEvents, aeventsC);
|
|
|
|
CopyUTF16toUTF8(aTargets, atargetsC);
|
2015-06-02 14:05:56 +03:00
|
|
|
MOZ_LOG(gCommandLog, PR_LOG_NOTICE,
|
2004-06-22 13:37:55 +04:00
|
|
|
("xulcmd[%p] replace %p(events=%s targets=%s) with (events=%s targets=%s)",
|
|
|
|
this, aElement,
|
|
|
|
eventsC.get(),
|
|
|
|
targetsC.get(),
|
|
|
|
aeventsC.get(),
|
|
|
|
atargetsC.get()));
|
|
|
|
}
|
2000-08-23 21:27:06 +04:00
|
|
|
#endif
|
1999-10-13 04:43:46 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
// 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;
|
1999-09-17 08:01:46 +04:00
|
|
|
}
|
1999-09-15 06:12:50 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
link = &(updater->mNext);
|
|
|
|
updater = updater->mNext;
|
|
|
|
}
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2015-06-04 01:22:28 +03:00
|
|
|
if (MOZ_LOG_TEST(gCommandLog, PR_LOG_NOTICE)) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString aeventsC, atargetsC;
|
2004-06-22 13:37:55 +04:00
|
|
|
CopyUTF16toUTF8(aEvents, aeventsC);
|
|
|
|
CopyUTF16toUTF8(aTargets, atargetsC);
|
|
|
|
|
2015-06-02 14:05:56 +03:00
|
|
|
MOZ_LOG(gCommandLog, PR_LOG_NOTICE,
|
2004-06-22 13:37:55 +04:00
|
|
|
("xulcmd[%p] add %p(events=%s targets=%s)",
|
|
|
|
this, aElement,
|
|
|
|
aeventsC.get(),
|
|
|
|
atargetsC.get()));
|
|
|
|
}
|
2000-08-23 21:27:06 +04:00
|
|
|
#endif
|
1999-10-13 04:43:46 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
// 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;
|
1999-09-15 06:12:50 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
*link = updater;
|
|
|
|
return NS_OK;
|
1999-05-29 02:16:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-12-06 02:04:22 +03:00
|
|
|
nsXULCommandDispatcher::RemoveCommandUpdater(nsIDOMElement* aElement)
|
1999-05-29 02:16:47 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aElement != nullptr, "null ptr");
|
2000-11-04 11:21:20 +03:00
|
|
|
if (! aElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-09-17 08:01:46 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
Updater* updater = mUpdaters;
|
|
|
|
Updater** link = &mUpdaters;
|
1999-09-17 08:01:46 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
while (updater) {
|
|
|
|
if (updater->mElement == aElement) {
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2015-06-04 01:22:28 +03:00
|
|
|
if (MOZ_LOG_TEST(gCommandLog, PR_LOG_NOTICE)) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString eventsC, targetsC;
|
2004-06-22 13:37:55 +04:00
|
|
|
eventsC.AssignWithConversion(updater->mEvents);
|
|
|
|
targetsC.AssignWithConversion(updater->mTargets);
|
2015-06-02 14:05:56 +03:00
|
|
|
MOZ_LOG(gCommandLog, PR_LOG_NOTICE,
|
2004-06-22 13:37:55 +04:00
|
|
|
("xulcmd[%p] remove %p(events=%s targets=%s)",
|
|
|
|
this, aElement,
|
|
|
|
eventsC.get(),
|
|
|
|
targetsC.get()));
|
|
|
|
}
|
2000-08-23 21:27:06 +04:00
|
|
|
#endif
|
1999-10-13 04:43:46 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
*link = updater->mNext;
|
|
|
|
delete updater;
|
|
|
|
return NS_OK;
|
1999-09-17 08:01:46 +04:00
|
|
|
}
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
link = &(updater->mNext);
|
|
|
|
updater = updater->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hmm. Not found. Oh well.
|
|
|
|
return NS_OK;
|
1999-05-29 02:16:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:46:13 +03:00
|
|
|
nsXULCommandDispatcher::UpdateCommands(const nsAString& aEventName)
|
1999-05-29 02:16:47 +04:00
|
|
|
{
|
2000-11-04 11:21:20 +03:00
|
|
|
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 22:00:39 +04:00
|
|
|
GetFocusedElement(getter_AddRefs(element));
|
2000-11-04 11:21:20 +03:00
|
|
|
if (element) {
|
2004-08-21 00:34:37 +04:00
|
|
|
nsresult rv = element->GetAttribute(NS_LITERAL_STRING("id"), id);
|
2000-11-04 11:21:20 +03:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element's id");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2000-07-15 02:06:31 +04:00
|
|
|
|
2010-10-25 18:06:26 +04:00
|
|
|
nsCOMArray<nsIContent> updaters;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
for (Updater* updater = mUpdaters; updater != nullptr; updater = updater->mNext) {
|
2000-11-04 11:21:20 +03:00
|
|
|
// Skip any nodes that don't match our 'events' or 'targets'
|
|
|
|
// filters.
|
|
|
|
if (! Matches(updater->mEvents, aEventName))
|
|
|
|
continue;
|
1999-08-25 05:49:24 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
if (! Matches(updater->mTargets, id))
|
|
|
|
continue;
|
1999-09-17 08:01:46 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(updater->mElement);
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(content != nullptr, "not an nsIContent");
|
2000-11-04 11:21:20 +03:00
|
|
|
if (! content)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-09-17 08:01:46 +04:00
|
|
|
|
2010-10-25 18:06:26 +04:00
|
|
|
updaters.AppendObject(content);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t u = 0; u < updaters.Count(); u++) {
|
2010-10-25 18:06:26 +04:00
|
|
|
nsIContent* content = updaters[u];
|
|
|
|
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2015-06-04 01:22:28 +03:00
|
|
|
if (MOZ_LOG_TEST(gCommandLog, PR_LOG_NOTICE)) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString aeventnameC;
|
2004-06-22 13:37:55 +04:00
|
|
|
CopyUTF16toUTF8(aEventName, aeventnameC);
|
2015-06-02 14:05:56 +03:00
|
|
|
MOZ_LOG(gCommandLog, PR_LOG_NOTICE,
|
2004-06-22 13:37:55 +04:00
|
|
|
("xulcmd[%p] update %p event=%s",
|
2010-10-25 18:06:26 +04:00
|
|
|
this, content,
|
2004-06-22 13:37:55 +04:00
|
|
|
aeventnameC.get()));
|
|
|
|
}
|
2000-08-23 21:27:06 +04:00
|
|
|
#endif
|
1999-10-13 04:43:46 +04:00
|
|
|
|
2014-08-23 00:11:27 +04:00
|
|
|
WidgetEvent event(true, NS_XUL_COMMAND_UPDATE);
|
|
|
|
EventDispatcher::Dispatch(content, nullptr, &event);
|
1999-12-08 07:56:56 +03:00
|
|
|
}
|
1999-05-29 02:16:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2000-08-23 21:27:06 +04:00
|
|
|
nsXULCommandDispatcher::Matches(const nsString& aList,
|
2002-03-24 01:46:13 +03:00
|
|
|
const nsAString& aElement)
|
1999-09-17 08:01:46 +04:00
|
|
|
{
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aList.EqualsLiteral("*"))
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // match _everything_!
|
2000-11-04 11:21:20 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t indx = aList.Find(PromiseFlatString(aElement));
|
2000-11-04 11:21:20 +03:00
|
|
|
if (indx == -1)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // not in the list at all
|
2000-11-04 11:21:20 +03:00
|
|
|
|
|
|
|
// okay, now make sure it's not a substring snafu; e.g., 'ur'
|
|
|
|
// found inside of 'blur'.
|
|
|
|
if (indx > 0) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = aList[indx - 1];
|
|
|
|
if (! nsCRT::IsAsciiSpace(ch) && ch != char16_t(','))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
2000-02-11 03:59:32 +03:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
if (indx + aElement.Length() < aList.Length()) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = aList[indx + aElement.Length()];
|
|
|
|
if (! nsCRT::IsAsciiSpace(ch) && ch != char16_t(','))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
2000-07-15 02:06:31 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2000-02-11 03:59:32 +03:00
|
|
|
}
|
2000-02-26 03:59:41 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-04 11:21:20 +03:00
|
|
|
nsXULCommandDispatcher::GetControllers(nsIControllers** aResult)
|
2000-02-26 03:59:41 +03:00
|
|
|
{
|
2010-02-20 19:07:03 +03:00
|
|
|
nsCOMPtr<nsPIWindowRoot> root = GetWindowRoot();
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
2004-07-10 00:57:30 +04:00
|
|
|
|
2010-02-20 19:07:03 +03:00
|
|
|
return root->GetControllers(aResult);
|
2000-02-26 03:59:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-07-16 02:04:13 +04:00
|
|
|
nsXULCommandDispatcher::GetControllerForCommand(const char *aCommand, nsIController** _retval)
|
2000-02-26 03:59:41 +03:00
|
|
|
{
|
2010-02-20 19:07:03 +03:00
|
|
|
nsCOMPtr<nsPIWindowRoot> root = GetWindowRoot();
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
2004-07-10 00:57:30 +04:00
|
|
|
|
2010-02-20 19:07:03 +03:00
|
|
|
return root->GetControllerForCommand(aCommand, _retval);
|
2000-02-28 23:50:38 +03:00
|
|
|
}
|
|
|
|
|
2003-12-07 12:44:40 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXULCommandDispatcher::GetSuppressFocusScroll(bool* aSuppressFocusScroll)
|
2003-12-07 12:44:40 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04: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 22:00:39 +04:00
|
|
|
return NS_OK;
|
2003-12-07 12:44:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXULCommandDispatcher::SetSuppressFocusScroll(bool aSuppressFocusScroll)
|
2003-12-07 12:44:40 +03: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 22:00:39 +04:00
|
|
|
return NS_OK;
|
2003-12-07 12:44:40 +03:00
|
|
|
}
|
|
|
|
|