2000-01-14 12:28:54 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIPresState.h"
|
|
|
|
#include "nsHashtable.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2001-02-06 05:41:15 +03:00
|
|
|
#include "nsXPIDLString.h"
|
2000-01-14 12:28:54 +03:00
|
|
|
|
|
|
|
// Static IIDs/CIDs. Try to minimize these.
|
|
|
|
// None
|
|
|
|
|
|
|
|
|
|
|
|
class nsPresState: public nsIPresState
|
|
|
|
{
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2002-03-24 01:26:36 +03:00
|
|
|
NS_IMETHOD GetStatePropertyAsSupports(const nsAString& aName, nsISupports** aResult);
|
|
|
|
NS_IMETHOD SetStatePropertyAsSupports(const nsAString& aName, nsISupports* aValue);
|
2000-01-14 12:28:54 +03:00
|
|
|
|
2002-03-24 01:26:36 +03:00
|
|
|
NS_IMETHOD GetStateProperty(const nsAString& aProperty, nsAString& aResult);
|
|
|
|
NS_IMETHOD SetStateProperty(const nsAString& aProperty, const nsAString& aValue);
|
2000-01-14 12:28:54 +03:00
|
|
|
|
2002-03-24 01:26:36 +03:00
|
|
|
NS_IMETHOD RemoveStateProperty(const nsAString& aProperty);
|
2000-10-03 03:23:55 +04:00
|
|
|
|
2000-01-14 12:28:54 +03:00
|
|
|
public:
|
|
|
|
nsPresState();
|
|
|
|
virtual ~nsPresState();
|
|
|
|
|
|
|
|
// Static members
|
|
|
|
|
|
|
|
// Internal member functions
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// MEMBER VARIABLES
|
|
|
|
protected:
|
|
|
|
// A string table that holds property/value pairs.
|
|
|
|
nsSupportsHashtable* mPropertyTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Static initialization
|
|
|
|
|
|
|
|
|
|
|
|
// Implementation /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Implement our nsISupports methods
|
|
|
|
NS_IMPL_ISUPPORTS1(nsPresState, nsIPresState)
|
|
|
|
|
|
|
|
// Constructors/Destructors
|
|
|
|
nsPresState::nsPresState(void)
|
|
|
|
:mPropertyTable(nsnull)
|
|
|
|
{
|
2001-03-02 05:55:24 +03:00
|
|
|
NS_INIT_ISUPPORTS();
|
2000-01-14 12:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresState::~nsPresState(void)
|
|
|
|
{
|
|
|
|
delete mPropertyTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIPresState Interface ////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:26:36 +03:00
|
|
|
nsPresState::GetStateProperty(const nsAString& aName,
|
|
|
|
nsAString& aResult)
|
2000-01-14 12:28:54 +03:00
|
|
|
{
|
2000-11-28 05:35:41 +03:00
|
|
|
aResult.SetLength(0);
|
2001-02-06 05:41:15 +03:00
|
|
|
|
2001-03-02 05:55:24 +03:00
|
|
|
// Retrieve from hashtable.
|
|
|
|
if (mPropertyTable) {
|
2002-04-16 02:39:43 +04:00
|
|
|
const nsPromiseFlatString& flatString = PromiseFlatString(aName);
|
|
|
|
nsStringKey key(flatString);
|
2001-03-02 05:55:24 +03:00
|
|
|
|
2002-08-06 04:53:19 +04:00
|
|
|
nsCOMPtr<nsISupportsCString> supportsStr =
|
|
|
|
dont_AddRef(NS_STATIC_CAST(nsISupportsCString*,
|
2001-03-02 05:55:24 +03:00
|
|
|
mPropertyTable->Get(&key)));
|
|
|
|
|
|
|
|
if (supportsStr) {
|
2002-08-27 01:20:34 +04:00
|
|
|
nsCAutoString data;
|
|
|
|
supportsStr->GetData(data);
|
2001-03-02 05:55:24 +03:00
|
|
|
|
|
|
|
aResult.Append(NS_ConvertUTF8toUCS2(data));
|
|
|
|
}
|
2000-01-14 12:28:54 +03:00
|
|
|
}
|
2001-03-02 05:55:24 +03:00
|
|
|
|
2000-01-14 12:28:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:26:36 +03:00
|
|
|
nsPresState::SetStateProperty(const nsAString& aName, const nsAString& aValue)
|
2000-01-14 12:28:54 +03:00
|
|
|
{
|
2001-02-06 05:41:15 +03:00
|
|
|
if (!mPropertyTable) {
|
2000-01-14 12:28:54 +03:00
|
|
|
mPropertyTable = new nsSupportsHashtable(8);
|
2001-02-06 05:41:15 +03:00
|
|
|
NS_ENSURE_TRUE(mPropertyTable, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
2000-01-14 12:28:54 +03:00
|
|
|
|
|
|
|
// Add to hashtable
|
2002-04-16 02:39:43 +04:00
|
|
|
const nsPromiseFlatString& flatString = PromiseFlatString(aName);
|
|
|
|
nsStringKey key(flatString);
|
2000-01-14 12:28:54 +03:00
|
|
|
|
2002-08-06 04:53:19 +04:00
|
|
|
nsCOMPtr<nsISupportsCString> supportsStr(do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID));
|
2001-02-06 05:41:15 +03:00
|
|
|
NS_ENSURE_TRUE(supportsStr, NS_ERROR_OUT_OF_MEMORY);
|
2000-01-14 12:28:54 +03:00
|
|
|
|
2002-08-27 01:20:34 +04:00
|
|
|
supportsStr->SetData(NS_ConvertUCS2toUTF8(aValue));
|
2000-08-23 21:27:06 +04:00
|
|
|
|
2000-01-14 12:28:54 +03:00
|
|
|
mPropertyTable->Put(&key, supportsStr);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-10-03 03:23:55 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:26:36 +03:00
|
|
|
nsPresState::RemoveStateProperty(const nsAString& aName)
|
2000-10-03 03:23:55 +04:00
|
|
|
{
|
|
|
|
if (!mPropertyTable)
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-04-16 02:39:43 +04:00
|
|
|
const nsPromiseFlatString& flatString = PromiseFlatString(aName);
|
|
|
|
nsStringKey key(flatString);
|
2000-10-03 03:23:55 +04:00
|
|
|
|
|
|
|
mPropertyTable->Remove(&key);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-14 12:28:54 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:26:36 +03:00
|
|
|
nsPresState::GetStatePropertyAsSupports(const nsAString& aName, nsISupports** aResult)
|
2000-01-14 12:28:54 +03:00
|
|
|
{
|
|
|
|
// Retrieve from hashtable.
|
|
|
|
nsCOMPtr<nsISupports> supp;
|
2001-03-02 05:55:24 +03:00
|
|
|
|
|
|
|
if (mPropertyTable) {
|
2002-04-16 02:39:43 +04:00
|
|
|
const nsPromiseFlatString& flatString = PromiseFlatString(aName);
|
|
|
|
nsStringKey key(flatString);
|
2000-02-01 05:14:29 +03:00
|
|
|
supp = dont_AddRef(NS_STATIC_CAST(nsISupports*, mPropertyTable->Get(&key)));
|
2001-03-02 05:55:24 +03:00
|
|
|
}
|
2000-02-01 05:14:29 +03:00
|
|
|
|
2000-01-14 12:28:54 +03:00
|
|
|
*aResult = supp;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:26:36 +03:00
|
|
|
nsPresState::SetStatePropertyAsSupports(const nsAString& aName, nsISupports* aValue)
|
2000-01-14 12:28:54 +03:00
|
|
|
{
|
2001-02-06 05:41:15 +03:00
|
|
|
if (!mPropertyTable) {
|
2000-01-14 12:28:54 +03:00
|
|
|
mPropertyTable = new nsSupportsHashtable(8);
|
2001-02-06 05:41:15 +03:00
|
|
|
NS_ENSURE_TRUE(mPropertyTable, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
2000-01-14 12:28:54 +03:00
|
|
|
|
|
|
|
// Add to hashtable
|
2002-04-16 02:39:43 +04:00
|
|
|
const nsPromiseFlatString& flatString = PromiseFlatString(aName);
|
|
|
|
nsStringKey key(flatString);
|
|
|
|
|
2000-01-14 12:28:54 +03:00
|
|
|
mPropertyTable->Put(&key, aValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creation Routine ///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewPresState(nsIPresState** aResult)
|
|
|
|
{
|
|
|
|
*aResult = new nsPresState;
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|