Bug 1278014 part.2 Define mozilla::SelectionType as an enum class and use it instead of RawSelectionType as far as possible r=smaug

This patch defines mozilla::SelectionType as an enum class.  This is safer than nsISelectionController::SELECTION_* since setting illegal value to its variable is checked at build time.  So, as far as possible, this should be used everywhere (but of course, this isn't available in scriptable interfaces).

And also this implements some useful methods for managing SelectionType and RawSelectionType which are implemented in layout/nsSelection.cpp because nsISelectionController is implemented by both PresShell and nsTextEditorState.  Therefore, implementing one of them may make hard to find them.  On the other hand, nsSelection.cpp is a better file name to look for them.

Note that this patch creates mozilla::Selection::RawType() for binding.  Native code should keep using Selection::Type() but the binding code needs to use RawType() due to impossible to convert from SelectionType to RawSelectionType without explicit cast.

MozReview-Commit-ID: 81vX7A0hHQN
This commit is contained in:
Masayuki Nakano
2016-06-11 11:06:37 +09:00
parent 71befe7dcf
commit 4b3d1e8406
28 changed files with 454 additions and 335 deletions

View File

@@ -228,11 +228,13 @@ public:
NS_IMETHOD GetDisplaySelection(int16_t* _retval) override;
NS_IMETHOD SetSelectionFlags(int16_t aInEnable) override;
NS_IMETHOD GetSelectionFlags(int16_t *aOutEnable) override;
NS_IMETHOD GetSelection(int16_t type, nsISelection** _retval) override;
NS_IMETHOD ScrollSelectionIntoView(int16_t aType, int16_t aRegion, int16_t aFlags) override;
NS_IMETHOD RepaintSelection(int16_t type) override;
NS_IMETHOD RepaintSelection(nsPresContext* aPresContext,
RawSelectionType aRawSelectionType);
NS_IMETHOD GetSelection(RawSelectionType aRawSelectionType,
nsISelection** aSelection) override;
NS_IMETHOD ScrollSelectionIntoView(RawSelectionType aRawSelectionType,
int16_t aRegion, int16_t aFlags) override;
NS_IMETHOD RepaintSelection(RawSelectionType aRawSelectionType) override;
nsresult RepaintSelection(nsPresContext* aPresContext,
SelectionType aSelectionType);
NS_IMETHOD SetCaretEnabled(bool enabled) override;
NS_IMETHOD SetCaretReadOnly(bool aReadOnly) override;
NS_IMETHOD GetCaretEnabled(bool* _retval) override;
@@ -336,46 +338,55 @@ nsTextInputSelectionImpl::GetSelectionFlags(int16_t *aOutEnable)
}
NS_IMETHODIMP
nsTextInputSelectionImpl::GetSelection(int16_t type, nsISelection **_retval)
nsTextInputSelectionImpl::GetSelection(RawSelectionType aRawSelectionType,
nsISelection** aSelection)
{
if (!mFrameSelection)
return NS_ERROR_NULL_POINTER;
*_retval = mFrameSelection->GetSelection(type);
if (!(*_retval))
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
*aSelection =
mFrameSelection->GetSelection(ToSelectionType(aRawSelectionType));
// GetSelection() fails only when aRawSelectionType is invalid value.
if (!(*aSelection)) {
return NS_ERROR_INVALID_ARG;
}
NS_ADDREF(*aSelection);
return NS_OK;
}
NS_IMETHODIMP
nsTextInputSelectionImpl::ScrollSelectionIntoView(int16_t aType, int16_t aRegion, int16_t aFlags)
nsTextInputSelectionImpl::ScrollSelectionIntoView(
RawSelectionType aRawSelectionType,
int16_t aRegion,
int16_t aFlags)
{
if (!mFrameSelection)
return NS_ERROR_FAILURE;
return mFrameSelection->ScrollSelectionIntoView(aType, aRegion, aFlags);
return mFrameSelection->ScrollSelectionIntoView(
ToSelectionType(aRawSelectionType),
aRegion, aFlags);
}
NS_IMETHODIMP
nsTextInputSelectionImpl::RepaintSelection(int16_t type)
nsTextInputSelectionImpl::RepaintSelection(RawSelectionType aRawSelectionType)
{
if (!mFrameSelection)
return NS_ERROR_FAILURE;
return mFrameSelection->RepaintSelection(type);
return mFrameSelection->RepaintSelection(ToSelectionType(aRawSelectionType));
}
NS_IMETHODIMP
nsresult
nsTextInputSelectionImpl::RepaintSelection(nsPresContext* aPresContext,
RawSelectionType aRawSelectionType)
SelectionType aSelectionType)
{
if (!mFrameSelection)
return NS_ERROR_FAILURE;
return mFrameSelection->RepaintSelection(aRawSelectionType);
return mFrameSelection->RepaintSelection(aSelectionType);
}
NS_IMETHODIMP
@@ -405,8 +416,8 @@ nsTextInputSelectionImpl::SetCaretReadOnly(bool aReadOnly)
{
RefPtr<nsCaret> caret = shell->GetCaret();
if (caret) {
nsISelection* domSel = mFrameSelection->
GetSelection(nsISelectionController::SELECTION_NORMAL);
nsISelection* domSel =
mFrameSelection->GetSelection(SelectionType::SELECTION_NORMAL);
if (domSel)
caret->SetCaretReadOnly(aReadOnly);
return NS_OK;
@@ -448,8 +459,8 @@ nsTextInputSelectionImpl::SetCaretVisibilityDuringSelection(bool aVisibility)
{
RefPtr<nsCaret> caret = shell->GetCaret();
if (caret) {
nsISelection* domSel = mFrameSelection->
GetSelection(nsISelectionController::SELECTION_NORMAL);
nsISelection* domSel =
mFrameSelection->GetSelection(SelectionType::SELECTION_NORMAL);
if (domSel)
caret->SetVisibilityDuringSelection(aVisibility);
return NS_OK;