зеркало из https://github.com/mozilla/pjs.git
backing out jkeiser's last patch to fix linux orange, b=95622
This commit is contained in:
Родитель
1108659117
Коммит
90cb85f893
|
@ -72,7 +72,6 @@
|
|||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIPresState.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsDoubleHashtable.h"
|
||||
|
||||
// Notify/query select frame for selectedIndex
|
||||
#include "nsIDocument.h"
|
||||
|
@ -85,6 +84,7 @@
|
|||
|
||||
class nsHTMLSelectElement;
|
||||
|
||||
|
||||
/**
|
||||
* The collection of options in the select (what you get back when you do
|
||||
* select.options in DOM)
|
||||
|
@ -146,21 +146,6 @@ private:
|
|||
nsHTMLSelectElement* mSelect;
|
||||
};
|
||||
|
||||
/**
|
||||
* The restore state used by select
|
||||
*/
|
||||
class nsSelectState : public nsISupports {
|
||||
public:
|
||||
nsSelectState() { NS_INIT_ISUPPORTS(); mValues.Init(10); }
|
||||
virtual ~nsSelectState() { }
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsStringHashSet mValues;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS0(nsSelectState)
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of <select>
|
||||
|
@ -277,7 +262,7 @@ protected:
|
|||
* Restore state to a particular state string (representing the options)
|
||||
* @param aNewSelected the state string to restore to
|
||||
*/
|
||||
void RestoreStateTo(nsSelectState* aNewSelected);
|
||||
void RestoreStateTo(nsAString* aNewSelected);
|
||||
|
||||
#ifdef DEBUG_john
|
||||
// Don't remove these, por favor. They're very useful in debugging
|
||||
|
@ -392,7 +377,7 @@ protected:
|
|||
* The temporary restore state in case we try to restore before parser is
|
||||
* done adding options
|
||||
*/
|
||||
nsSelectState* mRestoreState;
|
||||
nsString* mRestoreState;
|
||||
};
|
||||
|
||||
|
||||
|
@ -452,7 +437,10 @@ nsHTMLSelectElement::~nsHTMLSelectElement()
|
|||
mOptions->DropReference();
|
||||
NS_RELEASE(mOptions);
|
||||
}
|
||||
NS_IF_RELEASE(mRestoreState);
|
||||
if (mRestoreState) {
|
||||
delete mRestoreState;
|
||||
mRestoreState = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
// ISupports
|
||||
|
@ -1186,6 +1174,7 @@ nsHTMLSelectElement::OnOptionSelected(nsISelectControlFrame* aSelectFrame,
|
|||
PRBool aSelected,
|
||||
PRBool aNotify)
|
||||
{
|
||||
//printf("OnOptionSelected(%d = '%c')\n", aIndex, (aSelected ? 'Y' : 'N'));
|
||||
// Set the selected index
|
||||
if (aSelected && (aIndex < mSelectedIndex || mSelectedIndex < 0)) {
|
||||
mSelectedIndex = aIndex;
|
||||
|
@ -1766,7 +1755,8 @@ nsHTMLSelectElement::DoneAddingChildren()
|
|||
// content, restore the rest of the options proper-like
|
||||
if (mRestoreState) {
|
||||
RestoreStateTo(mRestoreState);
|
||||
NS_RELEASE(mRestoreState);
|
||||
delete mRestoreState;
|
||||
mRestoreState = nsnull;
|
||||
}
|
||||
|
||||
// Notify the frame
|
||||
|
@ -1912,11 +1902,7 @@ nsHTMLSelectElement::GetType(PRInt32* aType)
|
|||
NS_IMETHODIMP
|
||||
nsHTMLSelectElement::SaveState()
|
||||
{
|
||||
nsSelectState* state = new nsSelectState();
|
||||
if (!state) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(state);
|
||||
nsAutoString stateStr;
|
||||
|
||||
PRUint32 len;
|
||||
GetLength(&len);
|
||||
|
@ -1928,36 +1914,36 @@ nsHTMLSelectElement::SaveState()
|
|||
PRBool isSelected;
|
||||
option->GetSelected(&isSelected);
|
||||
if (isSelected) {
|
||||
nsCOMPtr<nsIOptionElement> optionElem = do_QueryInterface(option);
|
||||
nsAutoString value;
|
||||
optionElem->GetValueOrText(value);
|
||||
state->mValues.Put(value);
|
||||
if (!stateStr.IsEmpty()) {
|
||||
stateStr.Append(PRUnichar(','));
|
||||
}
|
||||
stateStr.AppendInt(optIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPresState> presState;
|
||||
nsresult rv = GetPrimaryPresState(this, getter_AddRefs(presState));
|
||||
nsCOMPtr<nsIPresState> state;
|
||||
nsresult rv = GetPrimaryPresState(this, getter_AddRefs(state));
|
||||
if (state) {
|
||||
rv = presState->SetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"),
|
||||
state);
|
||||
rv = state->SetStateProperty(NS_LITERAL_STRING("selecteditems"),
|
||||
stateStr);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "selecteditems set failed!");
|
||||
}
|
||||
|
||||
NS_RELEASE(state);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLSelectElement::RestoreState(nsIPresState* aState)
|
||||
{
|
||||
// If RestoreState() is called a second time after SaveState() was
|
||||
// called, this will do nothing.
|
||||
|
||||
// Get the presentation state object to retrieve our stuff out of.
|
||||
nsCOMPtr<nsISupports> state;
|
||||
nsresult rv = aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"),
|
||||
getter_AddRefs(state));
|
||||
nsAutoString stateStr;
|
||||
nsresult rv = aState->GetStateProperty(NS_LITERAL_STRING("selecteditems"),
|
||||
stateStr);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
RestoreStateTo((nsSelectState*)(nsISupports*)state);
|
||||
RestoreStateTo(&stateStr);
|
||||
|
||||
// Don't flush, if the frame doesn't exist yet it doesn't care if
|
||||
// we're reset or not.
|
||||
|
@ -1983,11 +1969,14 @@ nsHTMLSelectElement::GetBoxObject(nsIBoxObject** aResult)
|
|||
}
|
||||
|
||||
void
|
||||
nsHTMLSelectElement::RestoreStateTo(nsSelectState* aNewSelected)
|
||||
nsHTMLSelectElement::RestoreStateTo(nsAString* aNewSelected)
|
||||
{
|
||||
if (!mIsDoneAddingChildren) {
|
||||
mRestoreState = aNewSelected;
|
||||
NS_ADDREF(mRestoreState);
|
||||
mRestoreState = new nsString;
|
||||
if (!mRestoreState) {
|
||||
return;
|
||||
}
|
||||
*mRestoreState = *aNewSelected;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1998,17 +1987,17 @@ nsHTMLSelectElement::RestoreStateTo(nsSelectState* aNewSelected)
|
|||
SetOptionsSelectedByIndex(-1, -1, PR_TRUE, PR_TRUE, PR_TRUE, PR_TRUE, nsnull);
|
||||
|
||||
// Next set the proper ones
|
||||
for (PRInt32 i = 0; i < (PRInt32)len; i++) {
|
||||
nsCOMPtr<nsIDOMHTMLOptionElement> option;
|
||||
mOptions->ItemAsOption(i, getter_AddRefs(option));
|
||||
if (option) {
|
||||
nsCOMPtr<nsIOptionElement> optionElem = do_QueryInterface(option);
|
||||
nsAutoString value;
|
||||
optionElem->GetValueOrText(value);
|
||||
if (aNewSelected->mValues.Contains(value)) {
|
||||
SetOptionsSelectedByIndex(i, i, PR_TRUE, PR_FALSE, PR_TRUE, PR_TRUE, nsnull);
|
||||
}
|
||||
PRUint32 currentInd = 0;
|
||||
while (currentInd < aNewSelected->Length()) {
|
||||
PRInt32 nextInd = aNewSelected->FindChar(',', currentInd);
|
||||
if (nextInd == -1) {
|
||||
nextInd = aNewSelected->Length();
|
||||
}
|
||||
nsDependentSubstring s = Substring(*aNewSelected,
|
||||
currentInd, (nextInd-currentInd));
|
||||
PRInt32 i = atoi(NS_ConvertUCS2toUTF8(s).get());
|
||||
SetOptionsSelectedByIndex(i, i, PR_TRUE, PR_FALSE, PR_TRUE, PR_TRUE, nsnull);
|
||||
currentInd = (PRUint32)nextInd+1;
|
||||
}
|
||||
|
||||
//CheckSelectSomething();
|
||||
|
|
Загрузка…
Ссылка в новой задаче