1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/autocomplete/nsAutoCompleteSimpleResult.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,219 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "nsAutoCompleteSimpleResult.h" 1.9 + 1.10 +NS_IMPL_ISUPPORTS(nsAutoCompleteSimpleResult, 1.11 + nsIAutoCompleteResult, 1.12 + nsIAutoCompleteSimpleResult) 1.13 + 1.14 +nsAutoCompleteSimpleResult::nsAutoCompleteSimpleResult() : 1.15 + mDefaultIndex(-1), 1.16 + mSearchResult(RESULT_NOMATCH), 1.17 + mTypeAheadResult(false) 1.18 +{ 1.19 +} 1.20 + 1.21 +// searchString 1.22 +NS_IMETHODIMP 1.23 +nsAutoCompleteSimpleResult::GetSearchString(nsAString &aSearchString) 1.24 +{ 1.25 + aSearchString = mSearchString; 1.26 + return NS_OK; 1.27 +} 1.28 +NS_IMETHODIMP 1.29 +nsAutoCompleteSimpleResult::SetSearchString(const nsAString &aSearchString) 1.30 +{ 1.31 + mSearchString.Assign(aSearchString); 1.32 + return NS_OK; 1.33 +} 1.34 + 1.35 +// searchResult 1.36 +NS_IMETHODIMP 1.37 +nsAutoCompleteSimpleResult::GetSearchResult(uint16_t *aSearchResult) 1.38 +{ 1.39 + *aSearchResult = mSearchResult; 1.40 + return NS_OK; 1.41 +} 1.42 +NS_IMETHODIMP 1.43 +nsAutoCompleteSimpleResult::SetSearchResult(uint16_t aSearchResult) 1.44 +{ 1.45 + mSearchResult = aSearchResult; 1.46 + return NS_OK; 1.47 +} 1.48 + 1.49 +// defaultIndex 1.50 +NS_IMETHODIMP 1.51 +nsAutoCompleteSimpleResult::GetDefaultIndex(int32_t *aDefaultIndex) 1.52 +{ 1.53 + *aDefaultIndex = mDefaultIndex; 1.54 + return NS_OK; 1.55 +} 1.56 +NS_IMETHODIMP 1.57 +nsAutoCompleteSimpleResult::SetDefaultIndex(int32_t aDefaultIndex) 1.58 +{ 1.59 + mDefaultIndex = aDefaultIndex; 1.60 + return NS_OK; 1.61 +} 1.62 + 1.63 +// errorDescription 1.64 +NS_IMETHODIMP 1.65 +nsAutoCompleteSimpleResult::GetErrorDescription(nsAString & aErrorDescription) 1.66 +{ 1.67 + aErrorDescription = mErrorDescription; 1.68 + return NS_OK; 1.69 +} 1.70 +NS_IMETHODIMP 1.71 +nsAutoCompleteSimpleResult::SetErrorDescription( 1.72 + const nsAString &aErrorDescription) 1.73 +{ 1.74 + mErrorDescription.Assign(aErrorDescription); 1.75 + return NS_OK; 1.76 +} 1.77 + 1.78 +// typeAheadResult 1.79 +NS_IMETHODIMP 1.80 +nsAutoCompleteSimpleResult::GetTypeAheadResult(bool *aTypeAheadResult) 1.81 +{ 1.82 + *aTypeAheadResult = mTypeAheadResult; 1.83 + return NS_OK; 1.84 +} 1.85 +NS_IMETHODIMP 1.86 +nsAutoCompleteSimpleResult::SetTypeAheadResult(bool aTypeAheadResult) 1.87 +{ 1.88 + mTypeAheadResult = aTypeAheadResult; 1.89 + return NS_OK; 1.90 +} 1.91 + 1.92 +NS_IMETHODIMP 1.93 +nsAutoCompleteSimpleResult::AppendMatch(const nsAString& aValue, 1.94 + const nsAString& aComment, 1.95 + const nsAString& aImage, 1.96 + const nsAString& aStyle, 1.97 + const nsAString& aFinalCompleteValue) 1.98 +{ 1.99 + CheckInvariants(); 1.100 + 1.101 + if (! mValues.AppendElement(aValue)) 1.102 + return NS_ERROR_OUT_OF_MEMORY; 1.103 + if (! mComments.AppendElement(aComment)) { 1.104 + mValues.RemoveElementAt(mValues.Length() - 1); 1.105 + return NS_ERROR_OUT_OF_MEMORY; 1.106 + } 1.107 + if (! mImages.AppendElement(aImage)) { 1.108 + mValues.RemoveElementAt(mValues.Length() - 1); 1.109 + mComments.RemoveElementAt(mComments.Length() - 1); 1.110 + return NS_ERROR_OUT_OF_MEMORY; 1.111 + } 1.112 + if (! mStyles.AppendElement(aStyle)) { 1.113 + mValues.RemoveElementAt(mValues.Length() - 1); 1.114 + mComments.RemoveElementAt(mComments.Length() - 1); 1.115 + mImages.RemoveElementAt(mImages.Length() - 1); 1.116 + return NS_ERROR_OUT_OF_MEMORY; 1.117 + } 1.118 + if (!mFinalCompleteValues.AppendElement(aFinalCompleteValue)) { 1.119 + mValues.RemoveElementAt(mValues.Length() - 1); 1.120 + mComments.RemoveElementAt(mComments.Length() - 1); 1.121 + mImages.RemoveElementAt(mImages.Length() - 1); 1.122 + mStyles.RemoveElementAt(mStyles.Length() - 1); 1.123 + return NS_ERROR_OUT_OF_MEMORY; 1.124 + } 1.125 + return NS_OK; 1.126 +} 1.127 + 1.128 +NS_IMETHODIMP 1.129 +nsAutoCompleteSimpleResult::GetMatchCount(uint32_t *aMatchCount) 1.130 +{ 1.131 + CheckInvariants(); 1.132 + 1.133 + *aMatchCount = mValues.Length(); 1.134 + return NS_OK; 1.135 +} 1.136 + 1.137 +NS_IMETHODIMP 1.138 +nsAutoCompleteSimpleResult::GetValueAt(int32_t aIndex, nsAString& _retval) 1.139 +{ 1.140 + NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mValues.Length()), 1.141 + NS_ERROR_ILLEGAL_VALUE); 1.142 + CheckInvariants(); 1.143 + 1.144 + _retval = mValues[aIndex]; 1.145 + return NS_OK; 1.146 +} 1.147 + 1.148 +NS_IMETHODIMP 1.149 +nsAutoCompleteSimpleResult::GetLabelAt(int32_t aIndex, nsAString& _retval) 1.150 +{ 1.151 + return GetValueAt(aIndex, _retval); 1.152 +} 1.153 + 1.154 +NS_IMETHODIMP 1.155 +nsAutoCompleteSimpleResult::GetCommentAt(int32_t aIndex, nsAString& _retval) 1.156 +{ 1.157 + NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mComments.Length()), 1.158 + NS_ERROR_ILLEGAL_VALUE); 1.159 + CheckInvariants(); 1.160 + _retval = mComments[aIndex]; 1.161 + return NS_OK; 1.162 +} 1.163 + 1.164 +NS_IMETHODIMP 1.165 +nsAutoCompleteSimpleResult::GetImageAt(int32_t aIndex, nsAString& _retval) 1.166 +{ 1.167 + NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mImages.Length()), 1.168 + NS_ERROR_ILLEGAL_VALUE); 1.169 + CheckInvariants(); 1.170 + _retval = mImages[aIndex]; 1.171 + return NS_OK; 1.172 +} 1.173 + 1.174 +NS_IMETHODIMP 1.175 +nsAutoCompleteSimpleResult::GetStyleAt(int32_t aIndex, nsAString& _retval) 1.176 +{ 1.177 + NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mStyles.Length()), 1.178 + NS_ERROR_ILLEGAL_VALUE); 1.179 + CheckInvariants(); 1.180 + _retval = mStyles[aIndex]; 1.181 + return NS_OK; 1.182 +} 1.183 + 1.184 +NS_IMETHODIMP 1.185 +nsAutoCompleteSimpleResult::GetFinalCompleteValueAt(int32_t aIndex, 1.186 + nsAString& _retval) 1.187 +{ 1.188 + NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mFinalCompleteValues.Length()), 1.189 + NS_ERROR_ILLEGAL_VALUE); 1.190 + CheckInvariants(); 1.191 + _retval = mFinalCompleteValues[aIndex]; 1.192 + if (_retval.Length() == 0) 1.193 + _retval = mValues[aIndex]; 1.194 + return NS_OK; 1.195 +} 1.196 + 1.197 +NS_IMETHODIMP 1.198 +nsAutoCompleteSimpleResult::SetListener(nsIAutoCompleteSimpleResultListener* aListener) 1.199 +{ 1.200 + mListener = aListener; 1.201 + return NS_OK; 1.202 +} 1.203 + 1.204 +NS_IMETHODIMP 1.205 +nsAutoCompleteSimpleResult::RemoveValueAt(int32_t aRowIndex, 1.206 + bool aRemoveFromDb) 1.207 +{ 1.208 + NS_ENSURE_TRUE(aRowIndex >= 0 && aRowIndex < int32_t(mValues.Length()), 1.209 + NS_ERROR_ILLEGAL_VALUE); 1.210 + 1.211 + nsAutoString removedValue(mValues[aRowIndex]); 1.212 + mValues.RemoveElementAt(aRowIndex); 1.213 + mComments.RemoveElementAt(aRowIndex); 1.214 + mImages.RemoveElementAt(aRowIndex); 1.215 + mStyles.RemoveElementAt(aRowIndex); 1.216 + mFinalCompleteValues.RemoveElementAt(aRowIndex); 1.217 + 1.218 + if (mListener) 1.219 + mListener->OnValueRemoved(this, removedValue, aRemoveFromDb); 1.220 + 1.221 + return NS_OK; 1.222 +}