Bug 1343037 part 2. Get rid of nsIDOMHTMLInputElement's selectionEnd accessors. r=ehsan

MozReview-Commit-ID: L2Ozu7Vvort
This commit is contained in:
Boris Zbarsky 2017-03-09 14:44:03 -05:00
Родитель bd425019e3
Коммит f57f010e10
3 изменённых файлов: 21 добавлений и 32 удалений

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

@ -6496,34 +6496,19 @@ HTMLInputElement::GetSelectionEnd(ErrorResult& aRv)
return Nullable<int32_t>(); return Nullable<int32_t>();
} }
int32_t selEnd;
nsresult rv = GetSelectionEnd(&selEnd);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
}
return Nullable<int32_t>(selEnd);
}
NS_IMETHODIMP
HTMLInputElement::GetSelectionEnd(int32_t* aSelectionEnd)
{
NS_ENSURE_ARG_POINTER(aSelectionEnd);
int32_t selEnd, selStart; int32_t selEnd, selStart;
nsresult rv = GetSelectionRange(&selStart, &selEnd); nsresult rv = GetSelectionRange(&selStart, &selEnd);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
nsTextEditorState* state = GetEditorState(); nsTextEditorState* state = GetEditorState();
if (state && state->IsSelectionCached()) { if (state && state->IsSelectionCached()) {
*aSelectionEnd = state->GetSelectionProperties().GetEnd(); return Nullable<int32_t>(state->GetSelectionProperties().GetEnd());
return NS_OK;
} }
return rv; aRv.Throw(rv);
return Nullable<int32_t>();
} }
*aSelectionEnd = selEnd; return Nullable<int32_t>(selEnd);
return NS_OK;
} }
void void
@ -6566,15 +6551,6 @@ HTMLInputElement::SetSelectionEnd(const Nullable<int32_t>& aSelectionEnd,
aRv = SetSelectionRange(start, end, direction); aRv = SetSelectionRange(start, end, direction);
} }
NS_IMETHODIMP
HTMLInputElement::SetSelectionEnd(int32_t aSelectionEnd)
{
ErrorResult rv;
Nullable<int32_t> selEnd(aSelectionEnd);
SetSelectionEnd(selEnd, rv);
return rv.StealNSResult();
}
NS_IMETHODIMP NS_IMETHODIMP
HTMLInputElement::GetFiles(nsIDOMFileList** aFileList) HTMLInputElement::GetFiles(nsIDOMFileList** aFileList)
{ {

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

@ -84,7 +84,6 @@ interface nsIDOMHTMLInputElement : nsISupports
void setCustomValidity(in DOMString error); void setCustomValidity(in DOMString error);
void select(); void select();
attribute long selectionEnd;
void setSelectionRange(in long selectionStart, in long selectionEnd, [optional] in DOMString direction); void setSelectionRange(in long selectionStart, in long selectionEnd, [optional] in DOMString direction);
attribute DOMString selectionDirection; attribute DOMString selectionDirection;

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

@ -6,6 +6,7 @@
#include "nsFormFillController.h" #include "nsFormFillController.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent() #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
#include "mozilla/dom/HTMLInputElement.h" #include "mozilla/dom/HTMLInputElement.h"
@ -44,6 +45,7 @@
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
using mozilla::ErrorResult;
NS_IMPL_CYCLE_COLLECTION(nsFormFillController, NS_IMPL_CYCLE_COLLECTION(nsFormFillController,
mController, mLoginManager, mFocusedPopup, mDocShells, mController, mLoginManager, mFocusedPopup, mDocShells,
@ -609,7 +611,7 @@ nsFormFillController::GetSelectionStart(int32_t *aSelectionStart)
ErrorResult rv; ErrorResult rv;
Nullable<int32_t> start = Nullable<int32_t> start =
HTMLInputElement::FromContent(content)->GetSelectionStart(rv); HTMLInputElement::FromContent(content)->GetSelectionStart(rv);
if (NS_FAILED(rv)) { if (rv.Failed()) {
return rv.StealNSResult(); return rv.StealNSResult();
} }
if (start.IsNull()) { if (start.IsNull()) {
@ -622,8 +624,20 @@ nsFormFillController::GetSelectionStart(int32_t *aSelectionStart)
NS_IMETHODIMP NS_IMETHODIMP
nsFormFillController::GetSelectionEnd(int32_t *aSelectionEnd) nsFormFillController::GetSelectionEnd(int32_t *aSelectionEnd)
{ {
if (mFocusedInput) nsCOMPtr<nsIContent> content = do_QueryInterface(mFocusedInput);
mFocusedInput->GetSelectionEnd(aSelectionEnd); if (!content) {
return NS_ERROR_UNEXPECTED;
}
ErrorResult rv;
Nullable<int32_t> end =
HTMLInputElement::FromContent(content)->GetSelectionEnd(rv);
if (rv.Failed()) {
return rv.StealNSResult();
}
if (end.IsNull()) {
return NS_ERROR_UNEXPECTED;
}
*aSelectionEnd = end.Value();
return NS_OK; return NS_OK;
} }