2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla browser.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications, Inc.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* David W. Hyatt <hyatt@netscape.com> (Original Author)
|
|
|
|
* Dan Rosen <dr@netscape.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIControllers.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMHTMLDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMNSHTMLInputElement.h"
|
|
|
|
#include "nsIDOMNSHTMLTextAreaElement.h"
|
|
|
|
#include "nsIDOMNSEvent.h"
|
|
|
|
#include "nsIDOMWindowInternal.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsFocusController.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
#include "nsGlobalWindow.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
|
|
|
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
#include "nsIDOMXULDocument.h"
|
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsFocusController)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsFocusController, nsIFocusController)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsFocusController,
|
|
|
|
nsIFocusController)
|
|
|
|
|
2007-04-25 09:35:27 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFocusController)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFocusController)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsSupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIFocusController)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsFocusController)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFocusController)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPopupNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2009-09-21 10:39:44 -07:00
|
|
|
static nsIContent*
|
|
|
|
GetRootFocusedContentAndWindow(nsPIDOMWindow* aContextWindow,
|
|
|
|
nsPIDOMWindow** aWindow)
|
|
|
|
{
|
|
|
|
*aWindow = nsnull;
|
|
|
|
|
|
|
|
if (aContextWindow) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> rootWindow = aContextWindow->GetPrivateRoot();
|
|
|
|
if (rootWindow) {
|
|
|
|
return nsFocusManager::GetFocusedDescendant(rootWindow, PR_TRUE, aWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFocusController::Create(nsIFocusController** aResult)
|
|
|
|
{
|
|
|
|
nsFocusController* controller = new nsFocusController();
|
|
|
|
if (!controller)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*aResult = controller;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-21 10:39:44 -07:00
|
|
|
nsFocusController::GetControllers(nsPIDOMWindow* aContextWindow, nsIControllers** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-09-21 10:39:44 -07:00
|
|
|
*aResult = nsnull;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX: we should fix this so there's a generic interface that
|
|
|
|
// describes controllers, so this code would have no special
|
|
|
|
// knowledge of what object might have controllers.
|
|
|
|
|
2009-09-21 10:39:44 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> focusedWindow;
|
|
|
|
nsIContent* focusedContent =
|
|
|
|
GetRootFocusedContentAndWindow(aContextWindow, getter_AddRefs(focusedWindow));
|
|
|
|
if (focusedContent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_XUL
|
2009-09-21 10:39:44 -07:00
|
|
|
nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(focusedContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (xulElement)
|
|
|
|
return xulElement->GetControllers(aResult);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNSHTMLTextAreaElement> htmlTextArea =
|
2009-09-21 10:39:44 -07:00
|
|
|
do_QueryInterface(focusedContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (htmlTextArea)
|
|
|
|
return htmlTextArea->GetControllers(aResult);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNSHTMLInputElement> htmlInputElement =
|
2009-09-21 10:39:44 -07:00
|
|
|
do_QueryInterface(focusedContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (htmlInputElement)
|
|
|
|
return htmlInputElement->GetControllers(aResult);
|
2007-07-18 03:24:37 -07:00
|
|
|
|
2009-09-21 10:39:44 -07:00
|
|
|
if (focusedContent->IsEditable() && focusedWindow)
|
|
|
|
return focusedWindow->GetControllers(aResult);
|
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
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(focusedWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (domWindow)
|
|
|
|
return domWindow->GetControllers(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-21 10:39:44 -07:00
|
|
|
nsFocusController::GetControllerForCommand(nsPIDOMWindow* aContextWindow,
|
|
|
|
const char * aCommand,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIController** _retval)
|
|
|
|
{
|
2009-09-21 10:39:44 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
*_retval = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
|
2009-09-21 10:39:44 -07:00
|
|
|
GetControllers(aContextWindow, getter_AddRefs(controllers));
|
2007-03-22 10:30:00 -07:00
|
|
|
if(controllers) {
|
|
|
|
controllers->GetControllerForCommand(aCommand, getter_AddRefs(controller));
|
|
|
|
if(controller) {
|
|
|
|
controller.swap(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2009-09-21 10:39:44 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> focusedWindow;
|
|
|
|
GetRootFocusedContentAndWindow(aContextWindow, getter_AddRefs(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 11:00:39 -07:00
|
|
|
while (focusedWindow) {
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> domWindow(do_QueryInterface(focusedWindow));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIControllers> controllers2;
|
|
|
|
domWindow->GetControllers(getter_AddRefs(controllers2));
|
|
|
|
if(controllers2) {
|
|
|
|
controllers2->GetControllerForCommand(aCommand,
|
|
|
|
getter_AddRefs(controller));
|
|
|
|
if(controller) {
|
|
|
|
controller.swap(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// XXXndeakin P3 is this casting safe?
|
|
|
|
nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(focusedWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGlobalWindow *win =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsGlobalWindow *>
|
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
|
|
|
(static_cast<nsIDOMWindowInternal *>(piWindow));
|
|
|
|
focusedWindow = win->GetPrivateParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFocusController::GetPopupNode(nsIDOMNode** aNode)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_dr
|
|
|
|
printf("dr :: nsFocusController::GetPopupNode\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*aNode = mPopupNode;
|
|
|
|
NS_IF_ADDREF(*aNode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFocusController::SetPopupNode(nsIDOMNode* aNode)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_dr
|
|
|
|
printf("dr :: nsFocusController::SetPopupNode\n");
|
|
|
|
#endif
|
|
|
|
|
2009-02-17 02:23:35 -08:00
|
|
|
if (aNode) {
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
NS_ENSURE_ARG(node);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
mPopupNode = aNode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|