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"
|
2011-07-15 14:31:34 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.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 "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"
|
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;
|
2018-04-26 17:37:46 +03:00
|
|
|
using mozilla::dom::Element;
|
2013-10-02 07:46:04 +04:00
|
|
|
|
2015-11-23 22:09:25 +03:00
|
|
|
static LazyLogModule gCommandLog("nsXULCommandDispatcher");
|
1999-10-13 04:43:46 +04:00
|
|
|
|
1999-05-29 02:16:47 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsXULCommandDispatcher::nsXULCommandDispatcher(Document* aDocument)
|
2017-05-01 17:42:33 +03:00
|
|
|
: mDocument(aDocument), mUpdaters(nullptr), mLocked(false) {}
|
1999-05-29 02:16:47 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
nsXULCommandDispatcher::~nsXULCommandDispatcher() { 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)
|
|
|
|
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() {
|
|
|
|
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() {
|
|
|
|
if (mDocument) {
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetWindow()) {
|
2010-02-20 19:07:03 +03:00
|
|
|
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
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
Element* nsXULCommandDispatcher::GetRootFocusedContentAndWindow(
|
|
|
|
nsPIDOMWindowOuter** 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
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
if (!mDocument) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> win = mDocument->GetWindow()) {
|
|
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> rootWindow = win->GetPrivateRoot()) {
|
2017-09-07 16:54:49 +03:00
|
|
|
return nsFocusManager::GetFocusedDescendant(
|
|
|
|
rootWindow, nsFocusManager::eIncludeAllDescendants, 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
|
2018-04-26 17:37:46 +03:00
|
|
|
nsXULCommandDispatcher::GetFocusedElement(Element** 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
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
|
2018-04-26 17:37:47 +03:00
|
|
|
RefPtr<Element> focusedContent =
|
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
|
|
|
GetRootFocusedContentAndWindow(getter_AddRefs(focusedWindow));
|
|
|
|
if (focusedContent) {
|
|
|
|
// Make sure the caller can access the focused element.
|
2018-04-26 17:37:47 +03:00
|
|
|
if (!nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller()->Subsumes(
|
|
|
|
focusedContent->NodePrincipal())) {
|
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
|
|
|
// 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.
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
2005-10-25 05:34:16 +04:00
|
|
|
}
|
|
|
|
|
2018-04-26 17:37:47 +03:00
|
|
|
focusedContent.forget(aElement);
|
2005-10-25 05:34:16 +04:00
|
|
|
return NS_OK;
|
1999-12-08 07:56:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsXULCommandDispatcher::GetFocusedWindow(mozIDOMWindowProxy** aWindow) {
|
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
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window;
|
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
|
|
|
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.
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> doc = window->GetDoc();
|
2005-10-25 05:34:16 +04:00
|
|
|
|
|
|
|
// 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.
|
2015-10-27 00:37:32 +03:00
|
|
|
if (doc && !nsContentUtils::CanCallerAccess(doc))
|
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
|
2018-04-26 17:37:46 +03:00
|
|
|
nsXULCommandDispatcher::SetFocusedElement(Element* 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 22:00:39 +04:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
NS_ENSURE_TRUE(fm, NS_ERROR_FAILURE);
|
2004-07-10 00:57:30 +04:00
|
|
|
|
2018-04-26 17:37:46 +03:00
|
|
|
if (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 22:00:39 +04:00
|
|
|
return fm->SetFocus(aElement, 0);
|
2018-04-26 17:37:46 +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
|
|
|
|
|
|
|
// if aElement is null, clear the focus in the currently focused child window
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
|
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
|
|
|
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
|
2016-01-30 20:05:36 +03:00
|
|
|
nsXULCommandDispatcher::SetFocusedWindow(mozIDOMWindowProxy* 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
|
|
|
NS_ENSURE_TRUE(aWindow, NS_OK); // do nothing if set to null
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(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
|
|
|
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.
|
2018-04-26 17:37:46 +03:00
|
|
|
RefPtr<Element> frameElement = window->GetFrameElementInternal();
|
|
|
|
if (frameElement) {
|
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 fm->SetFocus(frameElement, 0);
|
2018-04-26 17:37:46 +03: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
|
|
|
|
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() {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> win;
|
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
|
|
|
GetRootFocusedContentAndWindow(getter_AddRefs(win));
|
|
|
|
|
2018-04-26 17:37:47 +03:00
|
|
|
RefPtr<Element> result;
|
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();
|
|
|
|
if (fm)
|
2012-07-30 18:20:58 +04:00
|
|
|
return fm->MoveFocus(win, nullptr, nsIFocusManager::MOVEFOCUS_BACKWARD, 0,
|
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
|
|
|
getter_AddRefs(result));
|
|
|
|
return NS_OK;
|
2001-04-11 07:05:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-26 17:37:47 +03:00
|
|
|
nsXULCommandDispatcher::AdvanceFocusIntoSubtree(Element* aElt) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> win;
|
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
|
|
|
GetRootFocusedContentAndWindow(getter_AddRefs(win));
|
|
|
|
|
2018-04-26 17:37:47 +03:00
|
|
|
RefPtr<Element> result;
|
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();
|
|
|
|
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
|
2018-04-27 06:36:10 +03:00
|
|
|
nsXULCommandDispatcher::AddCommandUpdater(Element* aElement,
|
2002-03-24 01:46:13 +03:00
|
|
|
const nsAString& aEvents,
|
|
|
|
const nsAString& aTargets) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(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) {
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2015-06-04 01:25:57 +03:00
|
|
|
if (MOZ_LOG_TEST(gCommandLog, LogLevel::Debug)) {
|
2017-07-06 15:00:35 +03:00
|
|
|
nsAutoCString eventsC, targetsC, aeventsC, atargetsC;
|
2017-07-24 20:23:52 +03:00
|
|
|
LossyCopyUTF16toASCII(updater->mEvents, eventsC);
|
|
|
|
LossyCopyUTF16toASCII(updater->mTargets, targetsC);
|
2004-06-22 13:37:55 +04:00
|
|
|
CopyUTF16toUTF8(aEvents, aeventsC);
|
|
|
|
CopyUTF16toUTF8(aTargets, atargetsC);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gCommandLog, LogLevel::Debug,
|
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:25:57 +03:00
|
|
|
if (MOZ_LOG_TEST(gCommandLog, LogLevel::Debug)) {
|
2017-07-06 15:00:35 +03:00
|
|
|
nsAutoCString aeventsC, atargetsC;
|
2004-06-22 13:37:55 +04:00
|
|
|
CopyUTF16toUTF8(aEvents, aeventsC);
|
|
|
|
CopyUTF16toUTF8(aTargets, atargetsC);
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gCommandLog, LogLevel::Debug,
|
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.
|
2015-08-14 00:24:59 +03:00
|
|
|
*link = new Updater(aElement, aEvents, aTargets);
|
2000-11-04 11:21:20 +03:00
|
|
|
return NS_OK;
|
1999-05-29 02:16:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-27 06:36:10 +03:00
|
|
|
nsXULCommandDispatcher::RemoveCommandUpdater(Element* aElement) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(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:25:57 +03:00
|
|
|
if (MOZ_LOG_TEST(gCommandLog, LogLevel::Debug)) {
|
2017-07-06 15:00:35 +03:00
|
|
|
nsAutoCString eventsC, targetsC;
|
2017-07-24 20:23:52 +03:00
|
|
|
LossyCopyUTF16toASCII(updater->mEvents, eventsC);
|
|
|
|
LossyCopyUTF16toASCII(updater->mTargets, targetsC);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gCommandLog, LogLevel::Debug,
|
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) {
|
2017-05-01 17:42:33 +03:00
|
|
|
if (mLocked) {
|
|
|
|
if (!mPendingUpdates.Contains(aEventName)) {
|
|
|
|
mPendingUpdates.AppendElement(aEventName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
nsAutoString id;
|
2018-04-26 17:37:46 +03:00
|
|
|
RefPtr<Element> element;
|
|
|
|
GetFocusedElement(getter_AddRefs(element));
|
2000-11-04 11:21:20 +03:00
|
|
|
if (element) {
|
2018-01-30 07:28:00 +03:00
|
|
|
element->GetAttribute(NS_LITERAL_STRING("id"), id);
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
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
|
|
|
|
2018-08-13 12:05:19 +03:00
|
|
|
nsIContent* content = updater->mElement;
|
|
|
|
NS_ASSERTION(content != nullptr, "mElement is null");
|
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:25:57 +03:00
|
|
|
if (MOZ_LOG_TEST(gCommandLog, LogLevel::Debug)) {
|
2017-07-06 15:00:35 +03:00
|
|
|
nsAutoCString aeventnameC;
|
2004-06-22 13:37:55 +04:00
|
|
|
CopyUTF16toUTF8(aEventName, aeventnameC);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
gCommandLog, LogLevel::Debug,
|
2004-06-22 13:37:55 +04:00
|
|
|
("xulcmd[%p] update %p event=%s", this, content, aeventnameC.get()));
|
|
|
|
}
|
2000-08-23 21:27:06 +04:00
|
|
|
#endif
|
1999-10-13 04:43:46 +04:00
|
|
|
|
2015-09-04 13:54:12 +03:00
|
|
|
WidgetEvent event(true, eXULCommandUpdate);
|
2014-08-23 00:11:27 +04:00
|
|
|
EventDispatcher::Dispatch(content, nullptr, &event);
|
1999-12-08 07:56:56 +03:00
|
|
|
}
|
1999-05-29 02:16:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
bool nsXULCommandDispatcher::Matches(const nsString& aList,
|
2002-03-24 01:46:13 +03:00
|
|
|
const nsAString& aElement) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (aList.EqualsLiteral("*")) 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));
|
2011-10-17 18:59:28 +04:00
|
|
|
if (indx == -1) 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(',')) 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(',')) 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) {
|
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
|
|
|
|
2017-09-07 16:54:49 +03:00
|
|
|
return root->GetControllers(false /* for any window */, 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) {
|
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
|
|
|
|
2017-09-07 16:54:49 +03:00
|
|
|
return root->GetControllerForCommand(aCommand, false /* for any window */,
|
|
|
|
_retval);
|
2000-02-28 23:50:38 +03:00
|
|
|
}
|
|
|
|
|
2017-05-01 17:42:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::Lock() {
|
|
|
|
// Since locking is used only as a performance optimization, we don't worry
|
|
|
|
// about nested lock calls. If that does happen, it just means we will unlock
|
|
|
|
// and process updates earlier.
|
|
|
|
mLocked = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULCommandDispatcher::Unlock() {
|
|
|
|
if (mLocked) {
|
|
|
|
mLocked = false;
|
|
|
|
|
|
|
|
// Handle any pending updates one at a time. In the unlikely case where a
|
|
|
|
// lock is added during the update, break out.
|
|
|
|
while (!mLocked && mPendingUpdates.Length() > 0) {
|
|
|
|
nsString name = mPendingUpdates.ElementAt(0);
|
|
|
|
mPendingUpdates.RemoveElementAt(0);
|
|
|
|
UpdateCommands(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|