Bug 1278014 part.3 Define 2 constants for number of SelectionType and number of SelectionType except "none" r=smaug

This patch defines two constants kSelectionTypeCount and kPresentSelectionTypeCount.  The former is same as nsISelectionController::NUM_SELECTIONTYPES.  The latter is kSelectionTypeCount - 1 for excluding SELECTION_NONE.  The latter is useful in some loops which handle all selection types except SELECTION_NONE.

Note that this patch fixes a bug of nsFrameSelection.  That doesn't treat SELECTION_NONE as a selection (see the definition of index), however, it defines redundant item and doesn't use it actually.  Additionally, it computes invalid selection type in each loop.  Therefore, without this patch, debug build hits MOZ_ASSERT() in ToSelectionType(RawSelectionType).

Note that these constants are defined as anonymous enum because we cannot define as const (or static) even with extern.  If we'd try to do it, it caused link error or not available in nsFrameSelection.cpp as constant value since they were not initialized if they were initialized in nsSelection.cpp.  Therefore, these constants are defined as enum items but using "k" prefix.

MozReview-Commit-ID: H6sH7NBEXlE
This commit is contained in:
Masayuki Nakano
2016-06-11 11:12:26 +09:00
parent 4b3d1e8406
commit 4e5926428a
5 changed files with 23 additions and 13 deletions

View File

@@ -6200,8 +6200,7 @@ nsTextFrame::PaintTextWithSelection(
// higher-numbered selection rawSelectionTypes below lower-numered ones on the
// general principal that lower-numbered selections are higher priority.
allRawSelectionTypes &= kRawSelectionTypesWithDecorations;
for (int32_t i = nsISelectionController::NUM_SELECTIONTYPES - 1;
i >= 1; --i) {
for (size_t i = kSelectionTypeCount - 1; i >= 1; --i) {
SelectionType selectionType = ToSelectionType(1 << (i - 1));
if (selectionType & allRawSelectionTypes) {
// There is some selection of this selectionType. Try to paint its