Bug 1385788 - Move the ownership of preview value from PresState to HTMLSelectElement. r=bz

MozReview-Commit-ID: 9NC8h6SyWdh

--HG--
extra : rebase_source : 4facdc9cc36c779a2f87d9b3e3f6a3f51b3e9812
This commit is contained in:
Ray Lin 2017-10-25 11:57:57 +08:00
Родитель 0cd2b5d266
Коммит 1959be8b2a
6 изменённых файлов: 19 добавлений и 53 удалений

Просмотреть файл

@ -1931,23 +1931,15 @@ HTMLSelectElement::SetOpenInParentProcess(bool aVal)
}
}
void
HTMLSelectElement::GetPreviewValue(nsAString& aValue)
{
nsIFormControlFrame* formControlFrame = GetFormControlFrame(false);
nsIComboboxControlFrame* comboFrame = do_QueryFrame(formControlFrame);
if (comboFrame) {
comboFrame->GetPreviewText(aValue);
}
}
void
HTMLSelectElement::SetPreviewValue(const nsAString& aValue)
{
mPreviewValue = aValue;
nsContentUtils::RemoveNewlines(mPreviewValue);
nsIFormControlFrame* formControlFrame = GetFormControlFrame(false);
nsIComboboxControlFrame* comboFrame = do_QueryFrame(formControlFrame);
if (comboFrame) {
comboFrame->SetPreviewText(aValue);
comboFrame->RedisplaySelectedText();
}
}

Просмотреть файл

@ -444,7 +444,10 @@ public:
bool OpenInParentProcess();
void SetOpenInParentProcess(bool aVal);
void GetPreviewValue(nsAString& aValue);
void GetPreviewValue(nsAString& aValue)
{
aValue = mPreviewValue;
}
void SetPreviewValue(const nsAString& aValue);
protected:
@ -661,6 +664,11 @@ protected:
*/
RefPtr<nsContentList> mSelectedOptions;
/**
* The current displayed preview text.
*/
nsString mPreviewValue;
private:
static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
GenericSpecifiedValues* aGenericData);

Просмотреть файл

@ -111,16 +111,6 @@ public:
return mDroppedDown;
}
void SetPreviewText(const nsAString& aValue)
{
mPreviewText = aValue;
}
void GetPreviewText(nsAString& aValue)
{
aValue = mPreviewText;
}
// MEMBER VARIABLES
protected:
nsCOMPtr<nsISupports> mContentData;
@ -131,7 +121,6 @@ protected:
bool mDisabledSet;
bool mDisabled;
bool mDroppedDown;
nsString mPreviewText;
};
#endif /* nsPresState_h_ */

Просмотреть файл

@ -27,6 +27,7 @@
#include "nsIDOMNode.h"
#include "nsISelectControlFrame.h"
#include "nsContentUtils.h"
#include "mozilla/dom/HTMLSelectElement.h"
#include "nsIDocument.h"
#include "nsIScrollableFrame.h"
#include "nsListControlFrame.h"
@ -968,15 +969,6 @@ nsComboboxControlFrame::GetDropDown()
///////////////////////////////////////////////////////////////
void
nsComboboxControlFrame::SetPreviewText(const nsAString& aValue)
{
nsAutoString previewValue(aValue);
nsContentUtils::RemoveNewlines(previewValue);
mPreviewText = previewValue;
RedisplayText();
}
NS_IMETHODIMP
nsComboboxControlFrame::RedisplaySelectedText()
@ -990,10 +982,14 @@ nsComboboxControlFrame::RedisplaySelectedText()
nsresult
nsComboboxControlFrame::RedisplayText()
{
nsString previewValue;
nsString previousText(mDisplayedOptionTextOrPreview);
auto* selectElement = static_cast<dom::HTMLSelectElement*>(GetContent());
selectElement->GetPreviewValue(previewValue);
// Get the text to display
if (!mPreviewText.IsEmpty()) {
mDisplayedOptionTextOrPreview = mPreviewText;
if (!previewValue.IsEmpty()) {
mDisplayedOptionTextOrPreview = previewValue;
} else if (mDisplayedIndex != -1) {
mListControlFrame->GetOptionText(mDisplayedIndex, mDisplayedOptionTextOrPreview);
} else {
@ -1674,7 +1670,6 @@ nsComboboxControlFrame::SaveState(nsPresState** aState)
MOZ_ASSERT(!(*aState));
(*aState) = new nsPresState();
(*aState)->SetDroppedDown(mDroppedDown);
(*aState)->SetPreviewText(mPreviewText);
return NS_OK;
}
@ -1684,7 +1679,6 @@ nsComboboxControlFrame::RestoreState(nsPresState* aState)
if (!aState) {
return NS_ERROR_FAILURE;
}
aState->GetPreviewText(mPreviewText);
ShowList(aState->GetDroppedDown()); // might destroy us
return NS_OK;
}

Просмотреть файл

@ -173,12 +173,6 @@ public:
mIsOpenInParentProcess = aVal;
}
void GetPreviewText(nsAString& aValue) override
{
aValue = mPreviewText;
}
void SetPreviewText(const nsAString& aValue) override;
// nsISelectControlFrame
NS_IMETHOD AddOption(int32_t index) override;
NS_IMETHOD RemoveOption(int32_t index) override;
@ -304,7 +298,6 @@ protected:
int32_t mRecentSelectedIndex;
int32_t mDisplayedIndex;
nsString mDisplayedOptionTextOrPreview;
nsString mPreviewText;
// make someone to listen to the button. If its programmatically pressed by someone like Accessibility
// then open or close the combo box.

Просмотреть файл

@ -53,16 +53,6 @@ public:
*/
NS_IMETHOD RedisplaySelectedText() = 0;
/*
* Update preview text for the select control.
*/
virtual void SetPreviewText(const nsAString& aValue) = 0;
/**
* Get the current preview text for select control.
*/
virtual void GetPreviewText(nsAString& aValue) = 0;
/**
* Method for the listbox to set and get the recent index
*/