2003-06-24 01:46:50 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2003-06-24 01:46:50 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* 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/
|
2003-06-24 01:46:50 +00:00
|
|
|
*
|
|
|
|
* 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 mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2003-06-24 01:46:50 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* 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"),
|
2003-06-24 01:46:50 +00:00
|
|
|
* 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
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2003-06-24 01:46:50 +00:00
|
|
|
* 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
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2003-06-24 01:46:50 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2000-01-14 09:28:54 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2002-09-03 23:36:13 +00:00
|
|
|
#include "nsXPCOM.h"
|
2000-01-14 09:28:54 +00:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2001-02-06 02:41:15 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2003-06-24 01:46:50 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2003-11-10 05:52:29 +00:00
|
|
|
#include "nsLayoutErrors.h"
|
2005-01-27 22:52:53 +00:00
|
|
|
#include "nsPresState.h"
|
|
|
|
#include "nsString.h"
|
2000-01-14 09:28:54 +00:00
|
|
|
|
|
|
|
// Implementation /////////////////////////////////////////////////////////////////
|
|
|
|
|
2005-01-27 22:52:53 +00:00
|
|
|
nsresult
|
|
|
|
nsPresState::Init()
|
2000-01-14 09:28:54 +00:00
|
|
|
{
|
2005-01-27 22:52:53 +00:00
|
|
|
return mPropertyTable.Init(8) ? NS_OK : NS_ERROR_FAILURE;
|
2000-01-14 09:28:54 +00:00
|
|
|
}
|
|
|
|
|
2005-01-27 22:52:53 +00:00
|
|
|
nsresult
|
|
|
|
nsPresState::GetStateProperty(const nsAString& aName, nsAString& aResult)
|
2000-01-14 09:28:54 +00:00
|
|
|
{
|
2003-11-10 05:52:29 +00:00
|
|
|
nsresult rv = NS_STATE_PROPERTY_NOT_THERE;
|
|
|
|
aResult.Truncate();
|
2001-02-06 02:41:15 +00:00
|
|
|
|
2001-03-02 02:55:24 +00:00
|
|
|
// Retrieve from hashtable.
|
2005-01-27 22:52:53 +00:00
|
|
|
nsISupports *data = mPropertyTable.GetWeak(aName);
|
2001-03-02 02:55:24 +00:00
|
|
|
|
2005-01-27 22:52:53 +00:00
|
|
|
// Strings are stored in the table as UTF-8, to save space.
|
|
|
|
// XXX minimize conversions here...
|
2001-03-02 02:55:24 +00:00
|
|
|
|
2005-01-27 22:52:53 +00:00
|
|
|
nsCOMPtr<nsISupportsCString> supportsStr = do_QueryInterface(data);
|
|
|
|
if (supportsStr) {
|
|
|
|
nsCAutoString data;
|
|
|
|
supportsStr->GetData(data);
|
2001-03-02 02:55:24 +00:00
|
|
|
|
2005-01-27 22:52:53 +00:00
|
|
|
CopyUTF8toUTF16(data, aResult);
|
|
|
|
rv = NS_STATE_PROPERTY_EXISTS;
|
2000-01-14 09:28:54 +00:00
|
|
|
}
|
2001-03-02 02:55:24 +00:00
|
|
|
|
2003-11-10 05:52:29 +00:00
|
|
|
return rv;
|
2000-01-14 09:28:54 +00:00
|
|
|
}
|
|
|
|
|
2005-01-27 22:52:53 +00:00
|
|
|
nsresult
|
2002-03-23 22:26:36 +00:00
|
|
|
nsPresState::SetStateProperty(const nsAString& aName, const nsAString& aValue)
|
2000-01-14 09:28:54 +00:00
|
|
|
{
|
|
|
|
// Add to hashtable
|
2002-08-06 00:53:19 +00:00
|
|
|
nsCOMPtr<nsISupportsCString> supportsStr(do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID));
|
2001-02-06 02:41:15 +00:00
|
|
|
NS_ENSURE_TRUE(supportsStr, NS_ERROR_OUT_OF_MEMORY);
|
2000-01-14 09:28:54 +00:00
|
|
|
|
2002-08-26 21:20:34 +00:00
|
|
|
supportsStr->SetData(NS_ConvertUCS2toUTF8(aValue));
|
2000-08-23 17:27:06 +00:00
|
|
|
|
2005-01-27 22:52:53 +00:00
|
|
|
mPropertyTable.Put(aName, supportsStr);
|
2000-01-14 09:28:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-27 22:52:53 +00:00
|
|
|
nsresult
|
2002-03-23 22:26:36 +00:00
|
|
|
nsPresState::RemoveStateProperty(const nsAString& aName)
|
2000-10-02 23:23:55 +00:00
|
|
|
{
|
2005-01-27 22:52:53 +00:00
|
|
|
mPropertyTable.Remove(aName);
|
2000-10-02 23:23:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-27 22:52:53 +00:00
|
|
|
nsresult
|
|
|
|
nsPresState::GetStatePropertyAsSupports(const nsAString& aName,
|
|
|
|
nsISupports** aResult)
|
2000-01-14 09:28:54 +00:00
|
|
|
{
|
|
|
|
// Retrieve from hashtable.
|
2005-01-27 22:52:53 +00:00
|
|
|
mPropertyTable.Get(aName, aResult);
|
2000-01-14 09:28:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-27 22:52:53 +00:00
|
|
|
nsresult
|
|
|
|
nsPresState::SetStatePropertyAsSupports(const nsAString& aName,
|
|
|
|
nsISupports* aValue)
|
2000-01-14 09:28:54 +00:00
|
|
|
{
|
2005-01-27 22:52:53 +00:00
|
|
|
mPropertyTable.Put(aName, aValue);
|
2000-01-14 09:28:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2005-01-27 22:52:53 +00:00
|
|
|
NS_NewPresState(nsPresState** aState)
|
2000-01-14 09:28:54 +00:00
|
|
|
{
|
2005-01-27 22:52:53 +00:00
|
|
|
nsPresState *state;
|
|
|
|
|
|
|
|
*aState = nsnull;
|
|
|
|
state = new nsPresState();
|
|
|
|
if (!state)
|
2000-01-14 09:28:54 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2005-01-27 22:52:53 +00:00
|
|
|
|
|
|
|
nsresult rv = state->Init();
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
*aState = state;
|
|
|
|
else
|
|
|
|
delete state;
|
|
|
|
|
|
|
|
return rv;
|
2000-01-14 09:28:54 +00:00
|
|
|
}
|
|
|
|
|
2005-01-27 22:52:53 +00:00
|
|
|
|