2001-12-21 01:10:07 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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-10-14 10:58:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
1999-12-05 23:04:22 +00:00
|
|
|
This file provides the implementation for the XUL "controllers"
|
|
|
|
object.
|
1999-10-14 10:58:25 +00:00
|
|
|
|
1999-12-05 23:04:22 +00:00
|
|
|
*/
|
1999-10-14 10:58:25 +00:00
|
|
|
|
2001-03-30 03:20:56 +00:00
|
|
|
#include "nsString.h"
|
|
|
|
|
1999-10-14 10:58:25 +00:00
|
|
|
#include "nsIControllers.h"
|
1999-12-05 23:04:22 +00:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsXULControllers.h"
|
2012-07-20 16:42:08 +00:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2013-09-22 23:23:30 +00:00
|
|
|
#include "nsIController.h"
|
1999-10-14 10:58:25 +00:00
|
|
|
|
1999-12-05 23:04:22 +00:00
|
|
|
//----------------------------------------------------------------------
|
1999-10-14 10:58:25 +00:00
|
|
|
|
1999-12-05 23:04:22 +00:00
|
|
|
nsXULControllers::nsXULControllers()
|
2001-03-30 03:20:56 +00:00
|
|
|
: mCurControllerID(0)
|
1999-10-14 10:58:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-12-05 23:04:22 +00:00
|
|
|
nsXULControllers::~nsXULControllers(void)
|
1999-10-14 10:58:25 +00:00
|
|
|
{
|
2001-03-30 03:20:56 +00:00
|
|
|
DeleteControllers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULControllers::DeleteControllers()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mControllers.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++)
|
2001-03-30 03:20:56 +00:00
|
|
|
{
|
2009-03-20 08:15:35 +00:00
|
|
|
nsXULControllerData* controllerData = mControllers.ElementAt(i);
|
2011-05-17 14:01:36 +00:00
|
|
|
delete controllerData; // releases the nsIController
|
2001-03-30 03:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mControllers.Clear();
|
1999-10-14 10:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
nsresult
|
1999-12-05 23:04:22 +00:00
|
|
|
NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
1999-10-14 10:58:25 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_PRECONDITION(aOuter == nullptr, "no aggregation");
|
2001-12-21 01:10:07 +00:00
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
nsXULControllers* controllers = new nsXULControllers();
|
|
|
|
nsresult rv;
|
|
|
|
NS_ADDREF(controllers);
|
|
|
|
rv = controllers->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(controllers);
|
|
|
|
return rv;
|
1999-12-05 23:04:22 +00:00
|
|
|
}
|
1999-10-14 10:58:25 +00:00
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULControllers)
|
|
|
|
|
2007-03-08 11:17:16 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULControllers)
|
|
|
|
tmp->DeleteControllers();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULControllers)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i, count = tmp->mControllers.Length();
|
2007-03-08 11:17:16 +00:00
|
|
|
for (i = 0; i < count; ++i) {
|
2009-03-20 08:15:35 +00:00
|
|
|
nsXULControllerData* controllerData = tmp->mControllers[i];
|
2007-03-08 11:17:16 +00:00
|
|
|
if (controllerData) {
|
|
|
|
cb.NoteXPCOMChild(controllerData->mController);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2007-04-25 16:35:27 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULControllers)
|
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 16:46:42 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIControllers)
|
2006-02-23 03:17:11 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIControllers)
|
2010-03-17 15:09:05 +00:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(XULControllers)
|
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 16:46:42 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 11:11:31 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULControllers)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULControllers)
|
1999-12-05 23:04:22 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-07-15 22:04:13 +00:00
|
|
|
nsXULControllers::GetControllerForCommand(const char *aCommand, nsIController** _retval)
|
1999-12-05 23:04:22 +00:00
|
|
|
{
|
2001-03-30 03:20:56 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
1999-10-14 10:58:25 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mControllers.Length();
|
|
|
|
for (uint32_t i=0; i < count; i++)
|
2001-03-30 03:20:56 +00:00
|
|
|
{
|
2009-03-20 08:15:35 +00:00
|
|
|
nsXULControllerData* controllerData = mControllers.ElementAt(i);
|
2001-03-30 03:20:56 +00:00
|
|
|
if (controllerData)
|
|
|
|
{
|
2001-12-21 01:10:07 +00:00
|
|
|
nsCOMPtr<nsIController> controller;
|
2001-03-30 03:20:56 +00:00
|
|
|
controllerData->GetController(getter_AddRefs(controller));
|
|
|
|
if (controller)
|
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool supportsCommand;
|
2001-03-30 03:20:56 +00:00
|
|
|
controller->SupportsCommand(aCommand, &supportsCommand);
|
|
|
|
if (supportsCommand) {
|
2015-03-31 14:03:49 +00:00
|
|
|
controller.forget(_retval);
|
2001-12-21 01:10:07 +00:00
|
|
|
return NS_OK;
|
1999-10-14 10:58:25 +00:00
|
|
|
}
|
2001-12-21 01:10:07 +00:00
|
|
|
}
|
1999-10-14 10:58:25 +00:00
|
|
|
}
|
2001-03-30 03:20:56 +00:00
|
|
|
}
|
|
|
|
|
2001-12-21 01:10:07 +00:00
|
|
|
return NS_OK;
|
1999-12-05 23:04:22 +00:00
|
|
|
}
|
1999-10-14 10:58:25 +00:00
|
|
|
|
1999-12-05 23:04:22 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULControllers::InsertControllerAt(uint32_t aIndex, nsIController *controller)
|
1999-12-05 23:04:22 +00:00
|
|
|
{
|
2002-11-20 11:36:05 +00:00
|
|
|
nsXULControllerData* controllerData = new nsXULControllerData(++mCurControllerID, controller);
|
2003-09-27 04:18:26 +00:00
|
|
|
#ifdef DEBUG
|
2009-03-20 08:15:35 +00:00
|
|
|
nsXULControllerData** inserted =
|
2003-09-27 04:18:26 +00:00
|
|
|
#endif
|
2009-03-20 08:15:35 +00:00
|
|
|
mControllers.InsertElementAt(aIndex, controllerData);
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(inserted != nullptr, "Insertion of controller failed");
|
2001-12-21 01:10:07 +00:00
|
|
|
return NS_OK;
|
1999-12-05 23:04:22 +00:00
|
|
|
}
|
1999-10-14 10:58:25 +00:00
|
|
|
|
1999-12-05 23:04:22 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULControllers::RemoveControllerAt(uint32_t aIndex, nsIController **_retval)
|
1999-12-05 23:04:22 +00:00
|
|
|
{
|
2001-03-30 03:20:56 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2001-12-21 01:10:07 +00:00
|
|
|
|
2009-03-20 08:15:35 +00:00
|
|
|
nsXULControllerData* controllerData = mControllers.SafeElementAt(aIndex);
|
2001-03-30 03:20:56 +00:00
|
|
|
if (!controllerData) return NS_ERROR_FAILURE;
|
2003-09-27 04:18:26 +00:00
|
|
|
|
|
|
|
mControllers.RemoveElementAt(aIndex);
|
|
|
|
|
2001-05-03 10:09:59 +00:00
|
|
|
controllerData->GetController(_retval);
|
2001-03-30 03:20:56 +00:00
|
|
|
delete controllerData;
|
|
|
|
|
2001-12-21 01:10:07 +00:00
|
|
|
return NS_OK;
|
1999-12-05 23:04:22 +00:00
|
|
|
}
|
1999-10-14 10:58:25 +00:00
|
|
|
|
1999-12-05 23:04:22 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULControllers::GetControllerAt(uint32_t aIndex, nsIController **_retval)
|
1999-12-05 23:04:22 +00:00
|
|
|
{
|
2001-03-30 03:20:56 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2001-03-30 03:20:56 +00:00
|
|
|
|
2009-03-20 08:15:35 +00:00
|
|
|
nsXULControllerData* controllerData = mControllers.SafeElementAt(aIndex);
|
2001-03-30 03:20:56 +00:00
|
|
|
if (!controllerData) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return controllerData->GetController(_retval); // does the addref
|
1999-12-05 23:04:22 +00:00
|
|
|
}
|
1999-10-14 10:58:25 +00:00
|
|
|
|
1999-12-05 23:04:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULControllers::AppendController(nsIController *controller)
|
|
|
|
{
|
2002-11-12 23:03:27 +00:00
|
|
|
// This assigns controller IDs starting at 1 so we can use 0 to test if an ID was obtained
|
|
|
|
nsXULControllerData* controllerData = new nsXULControllerData(++mCurControllerID, controller);
|
2003-09-27 04:18:26 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2009-03-20 08:15:35 +00:00
|
|
|
nsXULControllerData** appended =
|
2003-09-27 04:18:26 +00:00
|
|
|
#endif
|
2009-03-20 08:15:35 +00:00
|
|
|
mControllers.AppendElement(controllerData);
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(appended != nullptr, "Appending controller failed");
|
2001-12-21 01:10:07 +00:00
|
|
|
return NS_OK;
|
1999-12-05 23:04:22 +00:00
|
|
|
}
|
1999-10-14 10:58:25 +00:00
|
|
|
|
1999-12-05 23:04:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULControllers::RemoveController(nsIController *controller)
|
|
|
|
{
|
2001-04-05 02:45:17 +00:00
|
|
|
// first get the identity pointer
|
|
|
|
nsCOMPtr<nsISupports> controllerSup(do_QueryInterface(controller));
|
|
|
|
// then find it
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mControllers.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++)
|
2001-03-30 03:20:56 +00:00
|
|
|
{
|
2009-03-20 08:15:35 +00:00
|
|
|
nsXULControllerData* controllerData = mControllers.ElementAt(i);
|
2001-03-30 03:20:56 +00:00
|
|
|
if (controllerData)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIController> thisController;
|
|
|
|
controllerData->GetController(getter_AddRefs(thisController));
|
2001-04-05 02:45:17 +00:00
|
|
|
nsCOMPtr<nsISupports> thisControllerSup(do_QueryInterface(thisController)); // get identity
|
|
|
|
if (thisControllerSup == controllerSup)
|
2001-03-30 03:20:56 +00:00
|
|
|
{
|
|
|
|
mControllers.RemoveElementAt(i);
|
|
|
|
delete controllerData;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-10-14 10:58:25 +00:00
|
|
|
}
|
2001-03-30 03:20:56 +00:00
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE; // right thing to return if no controller found?
|
|
|
|
}
|
1999-10-14 10:58:25 +00:00
|
|
|
|
2001-03-30 03:20:56 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULControllers::GetControllerId(nsIController *controller, uint32_t *_retval)
|
2001-03-30 03:20:56 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mControllers.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++)
|
2001-03-30 03:20:56 +00:00
|
|
|
{
|
2009-03-20 08:15:35 +00:00
|
|
|
nsXULControllerData* controllerData = mControllers.ElementAt(i);
|
2001-03-30 03:20:56 +00:00
|
|
|
if (controllerData)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIController> thisController;
|
|
|
|
controllerData->GetController(getter_AddRefs(thisController));
|
|
|
|
if (thisController.get() == controller)
|
|
|
|
{
|
|
|
|
*_retval = controllerData->GetControllerID();
|
2001-12-21 01:10:07 +00:00
|
|
|
return NS_OK;
|
2001-03-30 03:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE; // none found
|
1999-12-05 23:04:22 +00:00
|
|
|
}
|
1999-10-14 10:58:25 +00:00
|
|
|
|
1999-12-05 23:04:22 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULControllers::GetControllerById(uint32_t controllerID, nsIController **_retval)
|
1999-12-05 23:04:22 +00:00
|
|
|
{
|
2001-03-30 03:20:56 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
1999-10-14 10:58:25 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mControllers.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++)
|
2001-03-30 03:20:56 +00:00
|
|
|
{
|
2009-03-20 08:15:35 +00:00
|
|
|
nsXULControllerData* controllerData = mControllers.ElementAt(i);
|
2001-03-30 03:20:56 +00:00
|
|
|
if (controllerData && controllerData->GetControllerID() == controllerID)
|
|
|
|
{
|
|
|
|
return controllerData->GetController(_retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE; // none found
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULControllers::GetControllerCount(uint32_t *_retval)
|
2001-03-30 03:20:56 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2009-03-20 08:15:35 +00:00
|
|
|
*_retval = mControllers.Length();
|
2001-12-21 01:10:07 +00:00
|
|
|
return NS_OK;
|
1999-10-14 10:58:25 +00:00
|
|
|
}
|
2006-02-23 03:17:11 +00:00
|
|
|
|