--- a/dom/base/nsISelectionController.idl
+++ b/dom/base/nsISelectionController.idl
@@ -2,41 +2,42 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISelectionDisplay.idl"
%{C++
-typedef short SelectionType;
typedef short SelectionRegion;
%}
interface nsIContent;
interface nsIDOMNode;
interface nsISelection;
interface nsISelectionDisplay;
[scriptable, uuid(3801c9d4-8e69-4bfc-9edb-b58278621f8f)]
interface nsISelectionController : nsISelectionDisplay
{
+ // RawSelectionType values:
const short SELECTION_NONE=0;
const short SELECTION_NORMAL=1;
const short SELECTION_SPELLCHECK=2;
const short SELECTION_IME_RAWINPUT=4;
const short SELECTION_IME_SELECTEDRAWTEXT=8;
const short SELECTION_IME_CONVERTEDTEXT=16;
const short SELECTION_IME_SELECTEDCONVERTEDTEXT=32;
const short SELECTION_ACCESSIBILITY=64; // For accessibility API usage
const short SELECTION_FIND=128;
const short SELECTION_URLSECONDARY=256;
const short SELECTION_URLSTRIKEOUT=512;
const short NUM_SELECTIONTYPES=11;
+ // SelectionRegion values:
const short SELECTION_ANCHOR_REGION = 0;
const short SELECTION_FOCUS_REGION = 1;
const short SELECTION_WHOLE_SELECTION = 2;
const short NUM_SELECTION_REGIONS = 3;
const short SELECTION_OFF = 0;
const short SELECTION_HIDDEN =1;//>HIDDEN displays selection
const short SELECTION_ON = 2;
@@ -52,32 +53,34 @@ interface nsISelectionController : nsISe
* GetDisplaySelection will get the display mode for the selection. OFF,ON,DISABLED
*/
short getDisplaySelection();
/**
* GetSelection will return the selection that the presentation
* shell may implement.
*
- * @param aType will hold the type of selection //SelectionType
+ * @param aType This will hold the type of selection. This value must be one
+ * of RawSelectionType values.
* @param _return will hold the return value
*/
nsISelection getSelection(in short type);
const short SCROLL_SYNCHRONOUS = 1<<1;
const short SCROLL_FIRST_ANCESTOR_ONLY = 1<<2;
const short SCROLL_CENTER_VERTICALLY = 1<<4;
const short SCROLL_OVERFLOW_HIDDEN = 1<<5;
const short SCROLL_FOR_CARET_MOVE = 1<<6;
/**
* ScrollSelectionIntoView scrolls a region of the selection,
* so that it is visible in the scrolled view.
*
- * @param aType the selection to scroll into view. //SelectionType
+ * @param aType the selection to scroll into view. This value must be one
+ * of RawSelectionType values.
* @param aRegion the region inside the selection to scroll into view. //SelectionRegion
* @param aFlags the scroll flags. Valid bits include:
* SCROLL_SYNCHRONOUS: when set, scrolls the selection into view
* before returning. If not set, posts a request which is processed
* at some point after the method returns.
* SCROLL_FIRST_ANCESTOR_ONLY: if set, only the first ancestor will be scrolled
* into view.
* SCROLL_OVERFLOW_HIDDEN: if set, scrolls even if the overflow is specified
@@ -270,9 +273,15 @@ interface nsISelectionController : nsISe
*/
boolean checkVisibility(in nsIDOMNode node, in short startOffset, in short endOffset);
[noscript,nostdcall] boolean checkVisibilityContent(in nsIContent node, in short startOffset, in short endOffset);
};
%{ C++
#define NS_ISELECTIONCONTROLLER_CID \
{ 0x513b9460, 0xd56a, 0x4c4e, \
{ 0xb6, 0xf9, 0x0b, 0x8a, 0xe4, 0x37, 0x2a, 0x3b }}
+
+namespace mozilla {
+
+typedef short RawSelectionType;
+
+} // namespace mozilla
%}
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -226,17 +226,18 @@ public:
//NSISELECTIONCONTROLLER INTERFACES
NS_IMETHOD SetDisplaySelection(int16_t toggle) override;
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, SelectionType aSelectionType);
+ NS_IMETHOD RepaintSelection(nsPresContext* aPresContext,
+ RawSelectionType aRawSelectionType);
NS_IMETHOD SetCaretEnabled(bool enabled) override;
NS_IMETHOD SetCaretReadOnly(bool aReadOnly) override;
NS_IMETHOD GetCaretEnabled(bool* _retval) override;
NS_IMETHOD GetCaretVisible(bool* _retval) override;
NS_IMETHOD SetCaretVisibilityDuringSelection(bool aVisibility) override;
NS_IMETHOD PhysicalMove(int16_t aDirection, int16_t aAmount, bool aExtend) override;
NS_IMETHOD CharacterMove(bool aForward, bool aExtend) override;
NS_IMETHOD CharacterExtendForDelete() override;
@@ -363,22 +364,23 @@ nsTextInputSelectionImpl::RepaintSelecti
{
if (!mFrameSelection)
return NS_ERROR_FAILURE;
return mFrameSelection->RepaintSelection(type);
}
NS_IMETHODIMP
-nsTextInputSelectionImpl::RepaintSelection(nsPresContext* aPresContext, SelectionType aSelectionType)
+nsTextInputSelectionImpl::RepaintSelection(nsPresContext* aPresContext,
+ RawSelectionType aRawSelectionType)
{
if (!mFrameSelection)
return NS_ERROR_FAILURE;
- return mFrameSelection->RepaintSelection(aSelectionType);
+ return mFrameSelection->RepaintSelection(aRawSelectionType);
}
NS_IMETHODIMP
nsTextInputSelectionImpl::SetCaretEnabled(bool enabled)
{
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShellWeak);
--- a/editor/libeditor/IMETextTxn.cpp
+++ b/editor/libeditor/IMETextTxn.cpp
@@ -129,18 +129,18 @@ NS_IMETHODIMP
IMETextTxn::GetTxnDescription(nsAString& aString)
{
aString.AssignLiteral("IMETextTxn: ");
aString += mStringToInsert;
return NS_OK;
}
/* ============ private methods ================== */
-static SelectionType
-ToSelectionType(TextRangeType aTextRangeType)
+static RawSelectionType
+ToRawSelectionType(TextRangeType aTextRangeType)
{
switch (aTextRangeType) {
case TextRangeType::eRawClause:
return nsISelectionController::SELECTION_IME_RAWINPUT;
case TextRangeType::eSelectedRawClause:
return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;
case TextRangeType::eConvertedClause:
return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;
@@ -169,17 +169,17 @@ IMETextTxn::SetIMESelection(nsEditor& aE
{
RefPtr<Selection> selection = aEditor.GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
nsresult rv = selection->StartBatchChanges();
NS_ENSURE_SUCCESS(rv, rv);
// First, remove all selections of IME composition.
- static const SelectionType kIMESelections[] = {
+ static const RawSelectionType kIMESelections[] = {
nsISelectionController::SELECTION_IME_RAWINPUT,
nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT,
nsISelectionController::SELECTION_IME_CONVERTEDTEXT,
nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT
};
nsCOMPtr<nsISelectionController> selCon;
aEditor.GetSelectionController(getter_AddRefs(selCon));
@@ -254,17 +254,17 @@ IMETextTxn::SetIMESelection(nsEditor& aE
getter_AddRefs(clauseRange));
if (NS_FAILED(rv)) {
NS_WARNING("Failed to create a DOM range for a clause of composition");
break;
}
// Set the range of the clause to selection.
nsCOMPtr<nsISelection> selectionOfIME;
- rv = selCon->GetSelection(ToSelectionType(textRange.mRangeType),
+ rv = selCon->GetSelection(ToRawSelectionType(textRange.mRangeType),
getter_AddRefs(selectionOfIME));
if (NS_FAILED(rv)) {
NS_WARNING("Failed to get IME selection");
break;
}
rv = selectionOfIME->AddRange(clauseRange);
if (NS_FAILED(rv)) {
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -2665,17 +2665,17 @@ struct SavedRange {
nsresult
nsEditor::SplitNodeImpl(nsIContent& aExistingRightNode,
int32_t aOffset,
nsIContent& aNewLeftNode)
{
// Remember all selection points.
AutoTArray<SavedRange, 10> savedRanges;
for (size_t i = 0; i < nsISelectionController::NUM_SELECTIONTYPES - 1; ++i) {
- SelectionType type(1 << i);
+ RawSelectionType type(1 << i);
SavedRange range;
range.mSelection = GetSelection(type);
if (type == nsISelectionController::SELECTION_NORMAL) {
NS_ENSURE_TRUE(range.mSelection, NS_ERROR_NULL_POINTER);
} else if (!range.mSelection) {
// For non-normal selections, skip over the non-existing ones.
continue;
}
@@ -2812,17 +2812,17 @@ nsEditor::JoinNodesImpl(nsINode* aNodeTo
int32_t joinOffset;
GetNodeLocation(aNodeToJoin, &joinOffset);
int32_t keepOffset;
nsINode* parent = GetNodeLocation(aNodeToKeep, &keepOffset);
// Remember all selection points.
AutoTArray<SavedRange, 10> savedRanges;
for (size_t i = 0; i < nsISelectionController::NUM_SELECTIONTYPES - 1; ++i) {
- SelectionType type(1 << i);
+ RawSelectionType type(1 << i);
SavedRange range;
range.mSelection = GetSelection(type);
if (type == nsISelectionController::SELECTION_NORMAL) {
NS_ENSURE_TRUE(range.mSelection, NS_ERROR_NULL_POINTER);
} else if (!range.mSelection) {
// For non-normal selections, skip over the non-existing ones.
continue;
}
@@ -5142,24 +5142,24 @@ nsEditor::GetIMESelectionStartOffsetIn(n
MOZ_ASSERT(aTextNode, "aTextNode must not be nullptr");
nsCOMPtr<nsISelectionController> selectionController;
nsresult rv = GetSelectionController(getter_AddRefs(selectionController));
NS_ENSURE_SUCCESS(rv, -1);
NS_ENSURE_TRUE(selectionController, -1);
int32_t minOffset = INT32_MAX;
- static const SelectionType kIMESelectionTypes[] = {
+ static const RawSelectionType kIMERawSelectionTypes[] = {
nsISelectionController::SELECTION_IME_RAWINPUT,
nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT,
nsISelectionController::SELECTION_IME_CONVERTEDTEXT,
nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT
};
- for (auto selectionType : kIMESelectionTypes) {
- RefPtr<Selection> selection = GetSelection(selectionType);
+ for (auto rawSelectionType : kIMERawSelectionTypes) {
+ RefPtr<Selection> selection = GetSelection(rawSelectionType);
if (!selection) {
continue;
}
for (uint32_t i = 0; i < selection->RangeCount(); i++) {
RefPtr<nsRange> range = selection->GetRangeAt(i);
if (NS_WARN_IF(!range)) {
continue;
}
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -27,16 +27,17 @@
#include "mozilla/StyleSetHandle.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/WeakPtr.h"
#include "gfxPoint.h"
#include "nsTHashtable.h"
#include "nsHashKeys.h"
#include "nsISupports.h"
#include "nsIContent.h"
+#include "nsISelectionController.h"
#include "nsQueryFrame.h"
#include "nsCoord.h"
#include "nsColor.h"
#include "nsFrameManagerBase.h"
#include "nsRect.h"
#include "nsRegionFwd.h"
#include "mozFlushType.h"
#include "nsWeakReference.h"
@@ -96,18 +97,16 @@ namespace mozilla {
namespace a11y {
class DocAccessible;
} // namespace a11y
} // namespace mozilla
#endif
struct nsArenaMemoryStats;
class nsITimer;
-typedef short SelectionType;
-
namespace mozilla {
class EventStates;
namespace dom {
class Element;
class Touch;
class Selection;
class ShadowRoot;
@@ -828,17 +827,18 @@ public:
/**
* Gets the current state of non text selection effects
* @return current state of non text selection,
* as set by SetDisplayNonTextSelection
*/
int16_t GetSelectionFlags() const { return mSelectionFlags; }
- virtual mozilla::dom::Selection* GetCurrentSelection(SelectionType aType) = 0;
+ virtual mozilla::dom::Selection*
+ GetCurrentSelection(mozilla::RawSelectionType aType) = 0;
/**
* Interface to dispatch events via the presshell
* @note The caller must have a strong reference to the PresShell.
*/
virtual nsresult HandleEventWithTarget(
mozilla::WidgetEvent* aEvent,
nsIFrame* aFrame,
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -1526,57 +1526,60 @@ PresShell::SetDisplaySelection(int16_t a
NS_IMETHODIMP
PresShell::GetDisplaySelection(int16_t *aToggle)
{
*aToggle = mSelection->GetDisplaySelection();
return NS_OK;
}
NS_IMETHODIMP
-PresShell::GetSelection(SelectionType aType, nsISelection **aSelection)
+PresShell::GetSelection(RawSelectionType aRawSelectionType,
+ nsISelection **aSelection)
{
if (!aSelection || !mSelection)
return NS_ERROR_NULL_POINTER;
- *aSelection = mSelection->GetSelection(aType);
+ *aSelection = mSelection->GetSelection(aRawSelectionType);
if (!(*aSelection))
return NS_ERROR_INVALID_ARG;
NS_ADDREF(*aSelection);
return NS_OK;
}
Selection*
-PresShell::GetCurrentSelection(SelectionType aType)
+PresShell::GetCurrentSelection(RawSelectionType aRawSelectionType)
{
if (!mSelection)
return nullptr;
- return mSelection->GetSelection(aType);
+ return mSelection->GetSelection(aRawSelectionType);
}
NS_IMETHODIMP
-PresShell::ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion,
+PresShell::ScrollSelectionIntoView(RawSelectionType aRawSelectionType,
+ SelectionRegion aRegion,
int16_t aFlags)
{
if (!mSelection)
return NS_ERROR_NULL_POINTER;
- return mSelection->ScrollSelectionIntoView(aType, aRegion, aFlags);
+ return mSelection->ScrollSelectionIntoView(aRawSelectionType, aRegion,
+ aFlags);
}
NS_IMETHODIMP
-PresShell::RepaintSelection(SelectionType aType)
+PresShell::RepaintSelection(RawSelectionType aRawSelectionType)
{
if (!mSelection)
return NS_ERROR_NULL_POINTER;
- return mSelection->RepaintSelection(aType);
+ return mSelection->RepaintSelection(aRawSelectionType);
}
// Make shell be a document observer
void
PresShell::BeginObservingDocument()
{
if (mDocument && !mIsDestroying) {
mDocument->AddObserver(this);
--- a/layout/base/nsPresShell.h
+++ b/layout/base/nsPresShell.h
@@ -74,16 +74,17 @@ class PresShell final : public nsIPresSh
public nsStubDocumentObserver,
public nsISelectionController,
public nsIObserver,
public nsSupportsWeakReference
{
template <typename T> using Maybe = mozilla::Maybe<T>;
using Nothing = mozilla::Nothing;
using OnNonvisible = mozilla::OnNonvisible;
+ using RawSelectionType = mozilla::RawSelectionType;
template <typename T> using UniquePtr = mozilla::UniquePtr<T>;
using VisibilityCounter = mozilla::VisibilityCounter;
using VisibleFrames = mozilla::VisibleFrames;
using VisibleRegions = mozilla::VisibleRegions;
public:
PresShell();
@@ -101,24 +102,27 @@ public:
void Init(nsIDocument* aDocument, nsPresContext* aPresContext,
nsViewManager* aViewManager, mozilla::StyleSetHandle aStyleSet);
virtual void Destroy() override;
virtual void MakeZombie() override;
virtual void UpdatePreferenceStyles() override;
- NS_IMETHOD GetSelection(SelectionType aType, nsISelection** aSelection) override;
- virtual mozilla::dom::Selection* GetCurrentSelection(SelectionType aType) override;
+ NS_IMETHOD GetSelection(RawSelectionType aRawSelectionType,
+ nsISelection** aSelection) override;
+ virtual mozilla::dom::Selection*
+ GetCurrentSelection(RawSelectionType aRawSelectionType) override;
NS_IMETHOD SetDisplaySelection(int16_t aToggle) override;
NS_IMETHOD GetDisplaySelection(int16_t *aToggle) override;
- NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion,
+ NS_IMETHOD ScrollSelectionIntoView(RawSelectionType aRawSelectionType,
+ SelectionRegion aRegion,
int16_t aFlags) override;
- NS_IMETHOD RepaintSelection(SelectionType aType) override;
+ NS_IMETHOD RepaintSelection(RawSelectionType aRawSelectionType) override;
virtual void BeginObservingDocument() override;
virtual void EndObservingDocument() override;
virtual nsresult Initialize(nscoord aWidth, nscoord aHeight) override;
virtual nsresult ResizeReflow(nscoord aWidth, nscoord aHeight, nscoord aOldWidth = 0, nscoord aOldHeight = 0) override;
virtual nsresult ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight, nscoord aOldWidth, nscoord aOldHeight) override;
virtual nsIPageSequenceFrame* GetPageSequenceFrame() const override;
virtual nsCanvasFrame* GetCanvasFrame() const override;
--- a/layout/generic/Selection.h
+++ b/layout/generic/Selection.h
@@ -130,18 +130,22 @@ public:
void SetDirection(nsDirection aDir){mDirection = aDir;}
nsresult SetAnchorFocusToRange(nsRange *aRange);
void ReplaceAnchorFocusRange(nsRange *aRange);
void AdjustAnchorFocusForMultiRange(nsDirection aDirection);
// NS_IMETHOD GetPrimaryFrameForRangeEndpoint(nsIDOMNode *aNode, int32_t aOffset, bool aIsEndNode, nsIFrame **aResultFrame);
NS_IMETHOD GetPrimaryFrameForAnchorNode(nsIFrame **aResultFrame);
NS_IMETHOD GetPrimaryFrameForFocusNode(nsIFrame **aResultFrame, int32_t *aOffset, bool aVisual);
- NS_IMETHOD LookUpSelection(nsIContent *aContent, int32_t aContentOffset, int32_t aContentLength,
- SelectionDetails **aReturnDetails, SelectionType aType, bool aSlowCheck);
+ NS_IMETHOD LookUpSelection(nsIContent *aContent,
+ int32_t aContentOffset,
+ int32_t aContentLength,
+ SelectionDetails** aReturnDetails,
+ RawSelectionType aRawSelectionType,
+ bool aSlowCheck);
NS_IMETHOD Repaint(nsPresContext* aPresContext);
// Note: StartAutoScrollTimer might destroy arbitrary frames etc.
nsresult StartAutoScrollTimer(nsIFrame *aFrame,
nsPoint& aPoint,
uint32_t aDelay);
nsresult StopAutoScrollTimer();
@@ -191,17 +195,17 @@ public:
int32_t aWrapColumn,
nsAString& aReturn,
mozilla::ErrorResult& aRv);
void AddSelectionListener(nsISelectionListener* aListener,
mozilla::ErrorResult& aRv);
void RemoveSelectionListener(nsISelectionListener* aListener,
mozilla::ErrorResult& aRv);
- int16_t Type() const { return mType; }
+ int16_t Type() const { return mRawSelectionType; }
void GetRangesForInterval(nsINode& aBeginNode, int32_t aBeginOffset,
nsINode& aEndNode, int32_t aEndOffset,
bool aAllowAdjacent,
nsTArray<RefPtr<nsRange>>& aReturn,
mozilla::ErrorResult& aRv);
void ScrollIntoView(int16_t aRegion, bool aIsSynchronous,
@@ -213,18 +217,21 @@ public:
bool IsBlockingSelectionChangeEvents() const;
private:
friend class ::nsAutoScrollTimer;
// Note: DoAutoScroll might destroy arbitrary frames etc.
nsresult DoAutoScroll(nsIFrame *aFrame, nsPoint& aPoint);
public:
- SelectionType GetType(){return mType;}
- void SetType(SelectionType aType){mType = aType;}
+ RawSelectionType GetType() const { return mRawSelectionType; }
+ void SetType(RawSelectionType aRawSelectionType)
+ {
+ mRawSelectionType = aRawSelectionType;
+ }
nsresult NotifySelectionListeners();
friend struct AutoUserInitiated;
struct MOZ_RAII AutoUserInitiated
{
explicit AutoUserInitiated(Selection* aSelection
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
@@ -314,17 +321,17 @@ private:
RefPtr<nsRange> mAnchorFocusRange;
RefPtr<nsFrameSelection> mFrameSelection;
RefPtr<nsAutoScrollTimer> mAutoScrollTimer;
nsCOMArray<nsISelectionListener> mSelectionListeners;
nsRevocableEventPtr<ScrollSelectionIntoViewEvent> mScrollEvent;
CachedOffsetForFrame *mCachedOffsetForFrame;
nsDirection mDirection;
- SelectionType mType;
+ RawSelectionType mRawSelectionType;
/**
* True if the current selection operation was initiated by user action.
* It determines whether we exclude -moz-user-select:none nodes or not,
* as well as whether selectstart events will be fired.
*/
bool mUserInitiated;
// Non-zero if we don't want any changes we make to the selection to be
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -1818,17 +1818,17 @@ nsFrame::DisplaySelectionOverlay(nsDispl
SelectionDetails *details;
//look up to see what selection(s) are on this frame
details = frameSelection->LookUpSelection(newContent, offset, 1, false);
if (!details)
return;
bool normal = false;
while (details) {
- if (details->mType == nsISelectionController::SELECTION_NORMAL) {
+ if (details->mRawSelectionType == nsISelectionController::SELECTION_NORMAL) {
normal = true;
}
SelectionDetails *next = details->mNext;
delete details;
details = next;
}
if (!normal && aContentType == nsISelectionDisplay::DISPLAY_IMAGES) {
@@ -3370,20 +3370,20 @@ nsFrame::HandlePress(nsPresContext* aPre
while (curDetail)
{
//
// If the user clicked inside a selection, then just
// return without doing anything. We will handle placing
// the caret later on when the mouse is released. We ignore
// the spellcheck, find and url formatting selections.
//
- if (curDetail->mType != nsISelectionController::SELECTION_SPELLCHECK &&
- curDetail->mType != nsISelectionController::SELECTION_FIND &&
- curDetail->mType != nsISelectionController::SELECTION_URLSECONDARY &&
- curDetail->mType != nsISelectionController::SELECTION_URLSTRIKEOUT &&
+ if (curDetail->mRawSelectionType != nsISelectionController::SELECTION_SPELLCHECK &&
+ curDetail->mRawSelectionType != nsISelectionController::SELECTION_FIND &&
+ curDetail->mRawSelectionType != nsISelectionController::SELECTION_URLSECONDARY &&
+ curDetail->mRawSelectionType != nsISelectionController::SELECTION_URLSTRIKEOUT &&
curDetail->mStart <= offsets.StartOffset() &&
offsets.EndOffset() <= curDetail->mEnd)
{
inSelection = true;
}
SelectionDetails *nextDetail = curDetail->mNext;
delete curDetail;
--- a/layout/generic/nsFrameSelection.h
+++ b/layout/generic/nsFrameSelection.h
@@ -40,17 +40,17 @@ struct SelectionDetails
MOZ_COUNT_CTOR(SelectionDetails);
}
~SelectionDetails() {
MOZ_COUNT_DTOR(SelectionDetails);
}
#endif
int32_t mStart;
int32_t mEnd;
- SelectionType mType;
+ mozilla::RawSelectionType mRawSelectionType;
mozilla::TextRangeStyle mTextRangeStyle;
SelectionDetails *mNext;
};
class nsIPresShell;
class nsIScrollableFrame;
/** PeekOffsetStruct is used to group various arguments (both input and output)
@@ -340,44 +340,47 @@ public:
/**
if we are in table cell selection mode. aka ctrl click in table cell
*/
bool GetTableCellSelection() const { return mSelectingTableCellMode != 0; }
void ClearTableCellSelection() { mSelectingTableCellMode = 0; }
/** GetSelection
* no query interface for selection. must use this method now.
- * @param aSelectionType enum value defined in nsISelection for the seleciton you want.
+ * @param aRawSelectionType The constants defined in nsISelectionController
+ * for the selection you want.
*/
- mozilla::dom::Selection* GetSelection(SelectionType aType) const;
+ mozilla::dom::Selection*
+ GetSelection(mozilla::RawSelectionType aRawSelectionType) const;
/**
* ScrollSelectionIntoView scrolls a region of the selection,
* so that it is visible in the scrolled view.
*
- * @param aType the selection to scroll into view.
+ * @param aRawSelectionType the selection to scroll into view.
* @param aRegion the region inside the selection to scroll into view.
* @param aFlags the scroll flags. Valid bits include:
* SCROLL_SYNCHRONOUS: when set, scrolls the selection into view
* before returning. If not set, posts a request which is processed
* at some point after the method returns.
* SCROLL_FIRST_ANCESTOR_ONLY: if set, only the first ancestor will be scrolled
* into view.
*
*/
/*unsafe*/
- nsresult ScrollSelectionIntoView(SelectionType aType,
+ nsresult ScrollSelectionIntoView(mozilla::RawSelectionType aRawSelectionType,
SelectionRegion aRegion,
int16_t aFlags) const;
/** RepaintSelection repaints the selected frames that are inside the selection
- * specified by aSelectionType.
- * @param aSelectionType enum value defined in nsISelection for the seleciton you want.
+ * specified by aRawSelectionType.
+ * @param aRawSelectionType The constants defined in nsISelectionController
+ * for the seleciton you want.
*/
- nsresult RepaintSelection(SelectionType aType) const;
+ nsresult RepaintSelection(mozilla::RawSelectionType aRawSelectionType) const;
/** GetFrameForNodeOffset given a node and its child offset, return the nsIFrame and
* the offset into that frame.
* @param aNode input parameter for the node to look at
* @param aOffset offset into above node.
* @param aReturnOffset will contain offset into frame.
*/
virtual nsIFrame* GetFrameForNodeOffset(nsIContent* aNode,
@@ -674,17 +677,18 @@ private:
void SetDesiredPos(nsPoint aPos); //set the mDesiredPos
uint32_t GetBatching() const {return mBatching; }
bool GetNotifyFrames() const { return mNotifyFrames; }
void SetDirty(bool aDirty=true){if (mBatching) mChangesDuringBatching = aDirty;}
// nsFrameSelection may get deleted when calling this,
// so remember to use nsCOMPtr when needed.
- nsresult NotifySelectionListeners(SelectionType aType); // add parameters to say collapsed etc?
+ nsresult NotifySelectionListeners(
+ mozilla::RawSelectionType aRawSelectionType);
RefPtr<mozilla::dom::Selection> mDomSelections[nsISelectionController::NUM_SELECTIONTYPES];
// Table selection support.
nsITableCellLayout* GetCellLayout(nsIContent *aCellContent) const;
nsresult SelectBlockOfCells(nsIContent *aStartNode, nsIContent *aEndNode);
nsresult SelectRowOrColumn(nsIContent *aCellContent, uint32_t aTarget);
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -258,38 +258,37 @@ nsresult NS_NewDomSelection(nsISelection
{
Selection* rlist = new Selection;
*aDomSelection = (nsISelection *)rlist;
NS_ADDREF(rlist);
return NS_OK;
}
static int8_t
-GetIndexFromSelectionType(SelectionType aType)
-{
- switch (aType)
- {
+GetIndexFromRawSelectionType(RawSelectionType aRawSelectionType)
+{
+ switch (aRawSelectionType) {
case nsISelectionController::SELECTION_NORMAL: return 0;
case nsISelectionController::SELECTION_SPELLCHECK: return 1;
case nsISelectionController::SELECTION_IME_RAWINPUT: return 2;
case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT: return 3;
case nsISelectionController::SELECTION_IME_CONVERTEDTEXT: return 4;
case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT: return 5;
case nsISelectionController::SELECTION_ACCESSIBILITY: return 6;
case nsISelectionController::SELECTION_FIND: return 7;
case nsISelectionController::SELECTION_URLSECONDARY: return 8;
case nsISelectionController::SELECTION_URLSTRIKEOUT: return 9;
default:
return -1;
}
/* NOTREACHED */
}
-static SelectionType
-GetSelectionTypeFromIndex(int8_t aIndex)
+static RawSelectionType
+GetRawSelectionTypeFromIndex(int8_t aIndex)
{
switch (aIndex)
{
case 0: return nsISelectionController::SELECTION_NORMAL;
case 1: return nsISelectionController::SELECTION_SPELLCHECK;
case 2: return nsISelectionController::SELECTION_IME_RAWINPUT;
case 3: return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;
case 4: return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;
@@ -432,17 +431,17 @@ struct MOZ_RAII AutoPrepareFocusRange
////////////BEGIN nsFrameSelection methods
nsFrameSelection::nsFrameSelection()
{
int32_t i;
for (i = 0;i<nsISelectionController::NUM_SELECTIONTYPES;i++){
mDomSelections[i] = new Selection(this);
- mDomSelections[i]->SetType(GetSelectionTypeFromIndex(i));
+ mDomSelections[i]->SetType(GetRawSelectionTypeFromIndex(i));
}
mBatching = 0;
mChangesDuringBatching = false;
mNotifyFrames = true;
mMouseDoubleDownState = false;
mHint = CARET_ASSOCIATE_BEFORE;
@@ -455,17 +454,17 @@ nsFrameSelection::nsFrameSelection()
// Check to see if the autocopy pref is enabled
// and add the autocopy listener if it is
if (Preferences::GetBool("clipboard.autocopy")) {
nsAutoCopyListener *autoCopy = nsAutoCopyListener::GetInstance();
if (autoCopy) {
int8_t index =
- GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (mDomSelections[index]) {
autoCopy->Listen(mDomSelections[index]);
}
}
}
mDisplaySelection = nsISelectionController::SELECTION_OFF;
mSelectionChangeReason = nsISelectionListener::NO_REASON;
@@ -540,17 +539,18 @@ nsFrameSelection::FetchDesiredPos(nsPoin
return NS_OK;
}
RefPtr<nsCaret> caret = mShell->GetCaret();
if (!caret) {
return NS_ERROR_NULL_POINTER;
}
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
caret->SetSelection(mDomSelections[index]);
nsRect coord;
nsIFrame* caretFrame = caret->GetGeometry(&coord);
if (!caretFrame) {
return NS_ERROR_FAILURE;
}
nsPoint viewOffset(0, 0);
@@ -605,17 +605,18 @@ nsFrameSelection::ConstrainFrameAndPoint
//
// Get the frame and content for the selection's anchor point!
//
nsresult result;
nsCOMPtr<nsIDOMNode> anchorNode;
int32_t anchorOffset = 0;
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
result = mDomSelections[index]->GetAnchorNode(getter_AddRefs(anchorNode));
if (NS_FAILED(result))
return result;
@@ -823,25 +824,26 @@ nsFrameSelection::Init(nsIPresShell *aSh
prefCachesInitialized = true;
Preferences::AddBoolVarCache(&sSelectionEventsEnabled,
"dom.select_events.enabled", false);
}
RefPtr<AccessibleCaretEventHub> eventHub = mShell->GetAccessibleCaretEventHub();
if (eventHub) {
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (mDomSelections[index]) {
mDomSelections[index]->AddSelectionListener(eventHub);
}
}
if (sSelectionEventsEnabled) {
int8_t index =
- GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (mDomSelections[index]) {
// The Selection instance will hold a strong reference to its selectionchangelistener
// so we don't have to worry about that!
RefPtr<SelectionChangeListener> listener = new SelectionChangeListener;
mDomSelections[index]->AddSelectionListener(listener);
}
}
}
@@ -870,17 +872,18 @@ nsFrameSelection::MoveCaret(nsDirection
nsPresContext *context = mShell->GetPresContext();
if (!context)
return NS_ERROR_FAILURE;
bool isCollapsed;
nsPoint desiredPos(0, 0); //we must keep this around and revalidate it when its just UP/DOWN
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
RefPtr<Selection> sel = mDomSelections[index];
if (!sel)
return NS_ERROR_NULL_POINTER;
int32_t scrollFlags = Selection::SCROLL_FOR_CARET_MOVE;
nsINode* focusNode = sel->GetFocusNode();
if (focusNode &&
(focusNode->IsEditable() ||
@@ -1357,17 +1360,18 @@ nsFrameSelection::GetFrameFromLevel(nsIF
return NS_OK;
}
nsresult
nsFrameSelection::MaintainSelection(nsSelectionAmount aAmount)
{
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
mMaintainedAmount = aAmount;
const nsRange* anchorFocusRange =
mDomSelections[index]->GetAnchorFocusRange();
if (anchorFocusRange && aAmount != eSelectNoAmount) {
@@ -1461,17 +1465,18 @@ nsFrameSelection::AdjustForMaintainedSel
{
if (!mMaintainRange)
return false;
if (!aContent) {
return false;
}
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return false;
nsINode* rangeStartNode = mMaintainRange->GetStartParent();
nsINode* rangeEndNode = mMaintainRange->GetEndParent();
int32_t rangeStartOffset = mMaintainRange->StartOffset();
int32_t rangeEndOffset = mMaintainRange->EndOffset();
@@ -1527,17 +1532,18 @@ nsFrameSelection::HandleClick(nsIContent
if (!mDragSelectingCells)
{
BidiLevelFromClick(aNewFocus, aContentOffset);
PostReason(nsISelectionListener::MOUSEDOWN_REASON + nsISelectionListener::DRAG_REASON);
if (aContinueSelection &&
AdjustForMaintainedSelection(aNewFocus, aContentOffset))
return NS_OK; //shift clicked to maintained selection. rejected.
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
AutoPrepareFocusRange prep(mDomSelections[index], aContinueSelection, aMultipleSelection);
return TakeFocus(aNewFocus, aContentOffset, aContentEndOffset, aHint,
aContinueSelection, aMultipleSelection);
}
return NS_OK;
}
@@ -1610,27 +1616,29 @@ nsFrameSelection::HandleDrag(nsIFrame *a
true, false, offsets.associate);
}
nsresult
nsFrameSelection::StartAutoScrollTimer(nsIFrame *aFrame,
nsPoint aPoint,
uint32_t aDelay)
{
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
return mDomSelections[index]->StartAutoScrollTimer(aFrame, aPoint, aDelay);
}
void
nsFrameSelection::StopAutoScrollTimer()
{
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return;
mDomSelections[index]->StopAutoScrollTimer();
}
/**
hard to go from nodes to frames, easy the other way!
@@ -1654,17 +1662,18 @@ nsFrameSelection::TakeFocus(nsIContent*
// Clear all table selection data
mSelectingTableCellMode = 0;
mDragSelectingCells = false;
mStartSelectedCell = nullptr;
mEndSelectedCell = nullptr;
mAppendStartSelectedCell = nullptr;
mHint = aHint;
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
Maybe<Selection::AutoUserInitiated> userSelect;
if (IsUserSelectionReason()) {
userSelect.emplace(mDomSelections[index]);
}
@@ -1785,17 +1794,19 @@ nsFrameSelection::LookUpSelection(nsICon
if (!aContent || !mShell)
return nullptr;
SelectionDetails* details = nullptr;
for (int32_t j = 0; j < nsISelectionController::NUM_SELECTIONTYPES; j++) {
if (mDomSelections[j]) {
mDomSelections[j]->LookUpSelection(aContent, aContentOffset,
- aContentLength, &details, (SelectionType)(1<<j), aSlowCheck);
+ aContentLength, &details,
+ static_cast<RawSelectionType>(1<<j),
+ aSlowCheck);
}
}
return details;
}
void
nsFrameSelection::SetDragState(bool aState)
@@ -1809,31 +1820,31 @@ nsFrameSelection::SetDragState(bool aSta
{
mDragSelectingCells = false;
PostReason(nsISelectionListener::MOUSEUP_REASON);
NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); //notify that reason is mouse up please.
}
}
Selection*
-nsFrameSelection::GetSelection(SelectionType aType) const
-{
- int8_t index = GetIndexFromSelectionType(aType);
+nsFrameSelection::GetSelection(RawSelectionType aRawSelectionType) const
+{
+ int8_t index = GetIndexFromRawSelectionType(aRawSelectionType);
if (index < 0)
return nullptr;
return mDomSelections[index];
}
nsresult
-nsFrameSelection::ScrollSelectionIntoView(SelectionType aType,
+nsFrameSelection::ScrollSelectionIntoView(RawSelectionType aRawSelectionType,
SelectionRegion aRegion,
int16_t aFlags) const
{
- int8_t index = GetIndexFromSelectionType(aType);
+ int8_t index = GetIndexFromRawSelectionType(aRawSelectionType);
if (index < 0)
return NS_ERROR_INVALID_ARG;
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
nsIPresShell::ScrollAxis verticalScroll = nsIPresShell::ScrollAxis();
int32_t flags = Selection::SCROLL_DO_FLUSH;
@@ -1857,19 +1868,19 @@ nsFrameSelection::ScrollSelectionIntoVie
// flushed and PresShell/PresContext/Frames may be dead. See bug 418470.
return mDomSelections[index]->ScrollIntoView(aRegion,
verticalScroll,
nsIPresShell::ScrollAxis(),
flags);
}
nsresult
-nsFrameSelection::RepaintSelection(SelectionType aType) const
-{
- int8_t index = GetIndexFromSelectionType(aType);
+nsFrameSelection::RepaintSelection(RawSelectionType aRawSelectionType) const
+{
+ int8_t index = GetIndexFromRawSelectionType(aRawSelectionType);
if (index < 0)
return NS_ERROR_INVALID_ARG;
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
NS_ENSURE_STATE(mShell);
return mDomSelections[index]->Repaint(mShell->GetPresContext());
}
@@ -2097,17 +2108,18 @@ nsFrameSelection::PhysicalMove(int16_t a
return NS_ERROR_FAILURE;
}
nsPresContext *context = mShell->GetPresContext();
if (!context) {
return NS_ERROR_FAILURE;
}
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
RefPtr<Selection> sel = mDomSelections[index];
if (!sel) {
return NS_ERROR_NULL_POINTER;
}
// Map the abstract movement amounts (0-1) to direction-specific
// selection units.
static const nsSelectionAmount inlineAmount[] =
@@ -2254,17 +2266,18 @@ nsFrameSelection::SelectAll()
if (!doc)
return NS_ERROR_FAILURE;
rootContent = doc->GetRootElement();
if (!rootContent)
return NS_ERROR_FAILURE;
}
int32_t numChildren = rootContent->GetChildCount();
PostReason(nsISelectionListener::NO_REASON);
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
AutoPrepareFocusRange prep(mDomSelections[index], false, false);
return TakeFocus(rootContent, 0, numChildren, CARET_ASSOCIATE_BEFORE, false, false);
}
//////////END FRAMESELECTION
void
nsFrameSelection::StartBatchChanges()
@@ -2283,19 +2296,19 @@ nsFrameSelection::EndBatchChanges(int16_
PostReason(postReason);
mChangesDuringBatching = false;
NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL);
}
}
nsresult
-nsFrameSelection::NotifySelectionListeners(SelectionType aType)
-{
- int8_t index = GetIndexFromSelectionType(aType);
+nsFrameSelection::NotifySelectionListeners(RawSelectionType aRawSelectionType)
+{
+ int8_t index = GetIndexFromRawSelectionType(aRawSelectionType);
if (index >=0 && mDomSelections[index])
{
return mDomSelections[index]->NotifySelectionListeners();
}
return NS_ERROR_FAILURE;
}
// Start of Table Selection methods
@@ -2312,17 +2325,18 @@ nsFrameSelection::GetCellLayout(nsIConte
nsITableCellLayout *cellLayoutObject =
do_QueryFrame(aCellContent->GetPrimaryFrame());
return cellLayoutObject;
}
nsresult
nsFrameSelection::ClearNormalSelection()
{
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
return mDomSelections[index]->RemoveAllRanges();
}
static nsIContent*
GetFirstSelectedContent(nsRange* aRange)
@@ -2358,17 +2372,18 @@ nsFrameSelection::HandleTableSelection(n
nsresult result = NS_OK;
nsIContent *childContent = aParentContent->GetChildAt(aContentOffset);
// When doing table selection, always set the direction to next so
// we can be sure that anchorNode's offset always points to the
// selected cell
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
mDomSelections[index]->SetDirection(eDirNext);
// Stack-class to wrap all table selection changes in
// BeginBatchChanges() / EndBatchChanges()
SelectionBatcher selectionBatcher(mDomSelections[index]);
@@ -2702,17 +2717,17 @@ nsresult
nsFrameSelection::UnselectCells(nsIContent *aTableContent,
int32_t aStartRowIndex,
int32_t aStartColumnIndex,
int32_t aEndRowIndex,
int32_t aEndColumnIndex,
bool aRemoveOutsideOfCellRange)
{
int8_t index =
- GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
nsTableOuterFrame* tableFrame = do_QueryFrame(aTableContent->GetPrimaryFrame());
if (!tableFrame)
return NS_ERROR_FAILURE;
int32_t minRowIndex = std::min(aStartRowIndex, aEndRowIndex);
@@ -2782,17 +2797,18 @@ nsFrameSelection::UnselectCells(nsIConte
nsresult
nsFrameSelection::AddCellsToSelection(nsIContent *aTableContent,
int32_t aStartRowIndex,
int32_t aStartColumnIndex,
int32_t aEndRowIndex,
int32_t aEndColumnIndex)
{
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
nsTableOuterFrame* tableFrame = do_QueryFrame(aTableContent->GetPrimaryFrame());
if (!tableFrame) // Check that |table| is a table.
return NS_ERROR_FAILURE;
nsresult result = NS_OK;
@@ -2980,17 +2996,18 @@ nsFrameSelection::GetFirstCellNodeInRang
return nullptr;
return childContent;
}
nsRange*
nsFrameSelection::GetFirstCellRange()
{
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return nullptr;
nsRange* firstRange = mDomSelections[index]->GetRangeAt(0);
if (!GetFirstCellNodeInRange(firstRange)) {
return nullptr;
}
@@ -2998,17 +3015,18 @@ nsFrameSelection::GetFirstCellRange()
mSelectedCellIndex = 1;
return firstRange;
}
nsRange*
nsFrameSelection::GetNextCellRange()
{
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return nullptr;
nsRange* range = mDomSelections[index]->GetRangeAt(mSelectedCellIndex);
// Get first node in next range of selection - test if it's a cell
if (!GetFirstCellNodeInRange(range)) {
return nullptr;
@@ -3225,32 +3243,33 @@ nsFrameSelection::CreateAndAddRange(nsIN
RefPtr<nsRange> range = new nsRange(aParentNode);
// Set range around child at given offset
nsresult result = range->SetStart(aParentNode, aOffset);
if (NS_FAILED(result)) return result;
result = range->SetEnd(aParentNode, aOffset+1);
if (NS_FAILED(result)) return result;
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
return mDomSelections[index]->AddRange(range);
}
// End of Table Selection
void
nsFrameSelection::SetAncestorLimiter(nsIContent *aLimiter)
{
if (mAncestorLimiter != aLimiter) {
mAncestorLimiter = aLimiter;
int8_t index =
- GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return;
if (!IsValidSelectionPoint(this, mDomSelections[index]->GetFocusNode())) {
ClearNormalSelection();
if (mAncestorLimiter) {
PostReason(nsISelectionListener::NO_REASON);
TakeFocus(mAncestorLimiter, 0, 0, CARET_ASSOCIATE_BEFORE, false, false);
@@ -3268,17 +3287,18 @@ nsFrameSelection::SetAncestorLimiter(nsI
nsresult
nsFrameSelection::DeleteFromDocument()
{
nsresult res;
// If we're already collapsed, then we do nothing (bug 719503).
bool isCollapsed;
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
mDomSelections[index]->GetIsCollapsed( &isCollapsed);
if (isCollapsed)
{
return NS_OK;
}
@@ -3318,17 +3338,18 @@ nsFrameSelection::SetDelayedCaretData(Wi
}
}
void
nsFrameSelection::DisconnectFromPresShell()
{
RefPtr<AccessibleCaretEventHub> eventHub = mShell->GetAccessibleCaretEventHub();
if (eventHub) {
- int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
+ int8_t index =
+ GetIndexFromRawSelectionType(nsISelectionController::SELECTION_NORMAL);
mDomSelections[index]->RemoveSelectionListener(eventHub);
}
StopAutoScrollTimer();
for (int32_t i = 0; i < nsISelectionController::NUM_SELECTIONTYPES; i++) {
mDomSelections[i]->Clear(nullptr);
}
mShell = nullptr;
@@ -3342,27 +3363,27 @@ nsFrameSelection::DisconnectFromPresShel
// mozilla::dom::Selection implementation
// note: this can return a nil anchor node
Selection::Selection()
: mCachedOffsetForFrame(nullptr)
, mDirection(eDirNext)
- , mType(nsISelectionController::SELECTION_NORMAL)
+ , mRawSelectionType(nsISelectionController::SELECTION_NORMAL)
, mUserInitiated(false)
, mSelectionChangeBlockerCount(0)
{
}
Selection::Selection(nsFrameSelection* aList)
: mFrameSelection(aList)
, mCachedOffsetForFrame(nullptr)
, mDirection(eDirNext)
- , mType(nsISelectionController::SELECTION_NORMAL)
+ , mRawSelectionType(nsISelectionController::SELECTION_NORMAL)
, mUserInitiated(false)
, mSelectionChangeBlockerCount(0)
{
}
Selection::~Selection()
{
setAnchorFocusRange(-1);
@@ -3716,17 +3737,18 @@ Selection::AddItem(nsRange* aItem, int32
return NS_ERROR_UNEXPECTED;
NS_ASSERTION(aOutIndex, "aOutIndex can't be null");
if (mUserInitiated) {
AutoTArray<RefPtr<nsRange>, 4> rangesToAdd;
*aOutIndex = -1;
- if (!aNoStartSelect && mType == nsISelectionController::SELECTION_NORMAL &&
+ if (!aNoStartSelect &&
+ mRawSelectionType == nsISelectionController::SELECTION_NORMAL &&
nsFrameSelection::sSelectionEventsEnabled && Collapsed() &&
!IsBlockingSelectionChangeEvents()) {
// First, we generate the ranges to add with a scratch range, which is a
// clone of the original range passed in. We do this seperately, because the
// selectstart event could have caused the world to change, and required
// ranges to be re-generated
RefPtr<nsRange> scratchRange = aItem->CloneRange();
UserSelectRangesToAdd(scratchRange, rangesToAdd);
@@ -4308,28 +4330,30 @@ Selection::SelectAllFramesForContent(nsI
nsresult result = aInnerIter->Init(aContent);
nsIFrame *frame;
if (NS_SUCCEEDED(result))
{
// First select frame of content passed in
frame = aContent->GetPrimaryFrame();
if (frame && frame->GetType() == nsGkAtoms::textFrame) {
nsTextFrame* textFrame = static_cast<nsTextFrame*>(frame);
- textFrame->SetSelectedRange(0, aContent->GetText()->GetLength(), aSelected, mType);
+ textFrame->SetSelectedRange(0, aContent->GetText()->GetLength(),
+ aSelected, mRawSelectionType);
}
// Now iterated through the child frames and set them
while (!aInnerIter->IsDone()) {
nsCOMPtr<nsIContent> innercontent =
do_QueryInterface(aInnerIter->GetCurrentNode());
frame = innercontent->GetPrimaryFrame();
if (frame) {
if (frame->GetType() == nsGkAtoms::textFrame) {
nsTextFrame* textFrame = static_cast<nsTextFrame*>(frame);
- textFrame->SetSelectedRange(0, innercontent->GetText()->GetLength(), aSelected, mType);
+ textFrame->SetSelectedRange(0, innercontent->GetText()->GetLength(),
+ aSelected, mRawSelectionType);
} else {
frame->InvalidateFrameSubtree(); // frame continuations?
}
}
aInnerIter->Next();
}
@@ -4382,17 +4406,18 @@ Selection::selectFrames(nsPresContext* a
nsTextFrame* textFrame = static_cast<nsTextFrame*>(frame);
uint32_t startOffset = aRange->StartOffset();
uint32_t endOffset;
if (aRange->GetEndParent() == content) {
endOffset = aRange->EndOffset();
} else {
endOffset = content->Length();
}
- textFrame->SetSelectedRange(startOffset, endOffset, aSelect, mType);
+ textFrame->SetSelectedRange(startOffset, endOffset, aSelect,
+ mRawSelectionType);
}
}
iter->First();
nsCOMPtr<nsIContentIterator> inneriter = NS_NewContentIterator();
for (iter->First(); !iter->IsDone(); iter->Next()) {
content = do_QueryInterface(iter->GetCurrentNode());
SelectAllFramesForContent(inneriter, content, aSelect);
@@ -4405,17 +4430,18 @@ Selection::selectFrames(nsPresContext* a
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(content, res);
if (content->IsNodeOfType(nsINode::eTEXT)) {
nsIFrame* frame = content->GetPrimaryFrame();
// The frame could be an SVG text frame, in which case we'll ignore it.
if (frame && frame->GetType() == nsGkAtoms::textFrame) {
nsTextFrame* textFrame = static_cast<nsTextFrame*>(frame);
- textFrame->SetSelectedRange(0, aRange->EndOffset(), aSelect, mType);
+ textFrame->SetSelectedRange(0, aRange->EndOffset(), aSelect,
+ mRawSelectionType);
}
}
}
return NS_OK;
}
// Selection::LookUpSelection
@@ -4441,17 +4467,18 @@ Selection::selectFrames(nsPresContext* a
// this case to make it faster by doing the same thing the previous version
// of this function did in the case of 1 range. This would also mean that
// the aSlowCheck flag would have meaning again.
NS_IMETHODIMP
Selection::LookUpSelection(nsIContent* aContent, int32_t aContentOffset,
int32_t aContentLength,
SelectionDetails** aReturnDetails,
- SelectionType aType, bool aSlowCheck)
+ RawSelectionType aRawSelectionType,
+ bool aSlowCheck)
{
nsresult rv;
if (!aContent || ! aReturnDetails)
return NS_ERROR_NULL_POINTER;
// it is common to have no ranges, to optimize that
if (mRanges.Length() == 0)
return NS_OK;
@@ -4507,17 +4534,17 @@ Selection::LookUpSelection(nsIContent* a
if (start < 0)
continue; // the ranges do not overlap the input range
SelectionDetails* details = new SelectionDetails;
details->mNext = *aReturnDetails;
details->mStart = start;
details->mEnd = end;
- details->mType = aType;
+ details->mRawSelectionType = aRawSelectionType;
RangeData *rd = FindRangeData(range);
if (rd) {
details->mTextRangeStyle = rd->mTextRangeStyle;
}
*aReturnDetails = details;
}
return NS_OK;
}
@@ -4823,18 +4850,19 @@ Selection::AddRange(nsRange& aRange, Err
if (rangeIndex < 0) {
return;
}
setAnchorFocusRange(rangeIndex);
// Make sure the caret appears on the next line, if at a newline
- if (mType == nsISelectionController::SELECTION_NORMAL)
+ if (mRawSelectionType == nsISelectionController::SELECTION_NORMAL) {
SetInterlinePosition(true);
+ }
RefPtr<nsPresContext> presContext = GetPresContext();
selectFrames(presContext, &aRange, true);
if (!mFrameSelection)
return;//nothing to do
result = mFrameSelection->NotifySelectionListeners(GetType());
@@ -4919,18 +4947,20 @@ Selection::RemoveRange(nsRange& aRange,
if (&aRange == mAnchorFocusRange) {
// Reset anchor to LAST range or clear it if there are no ranges.
setAnchorFocusRange(cnt - 1);
// When the selection is user-created it makes sense to scroll the range
// into view. The spell-check selection, however, is created and destroyed
// in the background. We don't want to scroll in this case or the view
// might appear to be moving randomly (bug 337871).
- if (mType != nsISelectionController::SELECTION_SPELLCHECK && cnt > 0)
+ if (mRawSelectionType != nsISelectionController::SELECTION_SPELLCHECK &&
+ cnt > 0) {
ScrollIntoView(nsISelectionController::SELECTION_FOCUS_REGION);
+ }
}
if (!mFrameSelection)
return;//nothing to do
rv = mFrameSelection->NotifySelectionListeners(GetType());
if (NS_FAILED(rv)) {
aRv.Throw(rv);
}
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -335,19 +335,20 @@ public:
enum {
eIndexRawInput = 0,
eIndexSelRawText,
eIndexConvText,
eIndexSelConvText,
eIndexSpellChecker
};
- static int32_t GetUnderlineStyleIndexForSelectionType(int32_t aSelectionType)
+ static int32_t GetUnderlineStyleIndexForRawSelectionType(
+ RawSelectionType aRawSelectionType)
{
- switch (aSelectionType) {
+ switch (aRawSelectionType) {
case nsISelectionController::SELECTION_IME_RAWINPUT:
return eIndexRawInput;
case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT:
return eIndexSelRawText;
case nsISelectionController::SELECTION_IME_CONVERTEDTEXT:
return eIndexConvText;
case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT:
return eIndexSelConvText;
@@ -5408,32 +5409,32 @@ nsTextFrame::ComputeDescentLimitForSelec
if (lineHeight <= aFontMetrics.maxHeight) {
return aFontMetrics.maxDescent;
}
return aFontMetrics.maxDescent + (lineHeight - aFontMetrics.maxHeight) / 2;
}
// Make sure this stays in sync with DrawSelectionDecorations below
-static const SelectionType SelectionTypesWithDecorations =
+static const RawSelectionType RawSelectionTypesWithDecorations =
nsISelectionController::SELECTION_SPELLCHECK |
nsISelectionController::SELECTION_URLSTRIKEOUT |
nsISelectionController::SELECTION_IME_RAWINPUT |
nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT |
nsISelectionController::SELECTION_IME_CONVERTEDTEXT |
nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT;
/* static */
gfxFloat
nsTextFrame::ComputeSelectionUnderlineHeight(
nsPresContext* aPresContext,
const gfxFont::Metrics& aFontMetrics,
- SelectionType aSelectionType)
-{
- switch (aSelectionType) {
+ RawSelectionType aRawSelectionType)
+{
+ switch (aRawSelectionType) {
case nsISelectionController::SELECTION_IME_RAWINPUT:
case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT:
case nsISelectionController::SELECTION_IME_CONVERTEDTEXT:
case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT:
return aFontMetrics.underlineSize;
case nsISelectionController::SELECTION_SPELLCHECK: {
// The thickness of the spellchecker underline shouldn't honor the font
// metrics. It should be constant pixels value which is decided from the
@@ -5489,23 +5490,23 @@ nsTextFrame::PaintDecorationLine(const P
}
} else {
nsCSSRendering::PaintDecorationLine(
this, *aParams.context->GetDrawTarget(), params);
}
}
/**
- * This, plus SelectionTypesWithDecorations, encapsulates all knowledge about
+ * This, plus RawSelectionTypesWithDecorations, encapsulates all knowledge about
* drawing text decoration for selections.
*/
void
nsTextFrame::DrawSelectionDecorations(gfxContext* aContext,
const LayoutDeviceRect& aDirtyRect,
- SelectionType aType,
+ RawSelectionType aRawSelectionType,
nsTextPaintStyle& aTextPaintStyle,
const TextRangeStyle &aRangeStyle,
const Point& aPt,
gfxFloat aICoordInFrame,
gfxFloat aWidth,
gfxFloat aAscent,
const gfxFont::Metrics& aFontMetrics,
DrawPathCallbacks* aCallbacks,
@@ -5514,37 +5515,38 @@ nsTextFrame::DrawSelectionDecorations(gf
uint8_t aDecoration)
{
PaintDecorationLineParams params;
params.context = aContext;
params.dirtyRect = aDirtyRect;
params.pt = aPt;
params.lineSize = Size(
aWidth, ComputeSelectionUnderlineHeight(aTextPaintStyle.PresContext(),
- aFontMetrics, aType));
+ aFontMetrics, aRawSelectionType));
params.ascent = aAscent;
params.offset = aDecoration == NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE ?
aFontMetrics.underlineOffset : aFontMetrics.maxAscent;
params.decoration = aDecoration;
params.decorationType = DecorationType::Selection;
params.callbacks = aCallbacks;
params.vertical = aVertical;
params.descentLimit =
ComputeDescentLimitForSelectionUnderline(aTextPaintStyle.PresContext(),
aFontMetrics);
float relativeSize;
int32_t index =
- nsTextPaintStyle::GetUnderlineStyleIndexForSelectionType(aType);
+ nsTextPaintStyle::GetUnderlineStyleIndexForRawSelectionType(
+ aRawSelectionType);
bool weDefineSelectionUnderline =
aTextPaintStyle.GetSelectionUnderlineForPaint(index, ¶ms.color,
&relativeSize, ¶ms.style);
- switch (aType) {
+ switch (aRawSelectionType) {
case nsISelectionController::SELECTION_IME_RAWINPUT:
case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT:
case nsISelectionController::SELECTION_IME_CONVERTEDTEXT:
case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT: {
// IME decoration lines should not be drawn on the both ends, i.e., we
// need to cut both edges of the decoration lines. Because same style
// IME selections can adjoin, but the users need to be able to know
// where are the boundaries of the selections.
@@ -5580,18 +5582,18 @@ nsTextFrame::DrawSelectionDecorations(gf
}
// If foreground color or background color is defined, the both colors
// are computed by GetSelectionTextColors(). Then, we should use its
// foreground color always. The color should have sufficient contrast
// with the background color.
else if (aRangeStyle.IsForegroundColorDefined() ||
aRangeStyle.IsBackgroundColorDefined()) {
nscolor bg;
- GetSelectionTextColors(aType, aTextPaintStyle, aRangeStyle,
- ¶ms.color, &bg);
+ GetSelectionTextColors(aRawSelectionType, aTextPaintStyle,
+ aRangeStyle, ¶ms.color, &bg);
}
// Otherwise, use the foreground color of the frame.
else {
params.color = aTextPaintStyle.GetTextColor();
}
} else if (!weDefineSelectionUnderline) {
// IME doesn't specify the selection style and we don't define selection
// underline.
@@ -5624,23 +5626,23 @@ nsTextFrame::DrawSelectionDecorations(gf
params.lineSize.height *= relativeSize;
params.icoordInFrame = (aVertical ? params.pt.y - aPt.y
: params.pt.x - aPt.x) + aICoordInFrame;
PaintDecorationLine(params);
}
/* static */
bool
-nsTextFrame::GetSelectionTextColors(SelectionType aType,
+nsTextFrame::GetSelectionTextColors(RawSelectionType aRawSelectionType,
nsTextPaintStyle& aTextPaintStyle,
const TextRangeStyle &aRangeStyle,
nscolor* aForeground,
nscolor* aBackground)
{
- switch (aType) {
+ switch (aRawSelectionType) {
case nsISelectionController::SELECTION_NORMAL:
return aTextPaintStyle.GetSelectionColors(aForeground, aBackground);
case nsISelectionController::SELECTION_FIND:
aTextPaintStyle.GetHighlightColors(aForeground, aBackground);
return true;
case nsISelectionController::SELECTION_URLSECONDARY:
aTextPaintStyle.GetURLSecondaryColor(aForeground);
*aBackground = NS_RGBA(0,0,0,0);
@@ -5671,38 +5673,39 @@ nsTextFrame::GetSelectionTextColors(Sele
// If background color is defined but foreground color isn't defined,
// we can assume that IME must expect that the foreground color is
// same as system's field text color.
*aForeground = aTextPaintStyle.GetSystemFieldForegroundColor();
}
return true;
}
aTextPaintStyle.GetIMESelectionColors(
- nsTextPaintStyle::GetUnderlineStyleIndexForSelectionType(aType),
+ nsTextPaintStyle::GetUnderlineStyleIndexForRawSelectionType(
+ aRawSelectionType),
aForeground, aBackground);
return true;
default:
*aForeground = aTextPaintStyle.GetTextColor();
*aBackground = NS_RGBA(0,0,0,0);
return false;
}
}
/**
* This sets *aShadow to the appropriate shadow, if any, for the given
* type of selection. Returns true if *aShadow was set.
* If text-shadow was not specified, *aShadow is left untouched
* (NOT reset to null), and the function returns false.
*/
static bool GetSelectionTextShadow(nsIFrame* aFrame,
- SelectionType aType,
+ RawSelectionType aRawSelectionType,
nsTextPaintStyle& aTextPaintStyle,
nsCSSShadowArray** aShadow)
{
- switch (aType) {
+ switch (aRawSelectionType) {
case nsISelectionController::SELECTION_NORMAL:
return aTextPaintStyle.GetSelectionShadow(aShadow);
default:
return false;
}
}
/**
@@ -5728,22 +5731,23 @@ public:
/**
* Returns the next segment of uniformly selected (or not) text.
* @param aXOffset the offset from the origin of the frame to the start
* of the text (the left baseline origin for LTR, the right baseline origin
* for RTL)
* @param aRange the transformed string range of the text for this segment
* @param aHyphenWidth if a hyphen is to be rendered after the text, the
* width of the hyphen, otherwise zero
- * @param aType the selection type for this segment
+ * @param aRawSelectionType the selection type for this segment
* @param aStyle the selection style for this segment
* @return false if there are no more segments
*/
bool GetNextSegment(gfxFloat* aXOffset, gfxTextRun::Range* aRange,
- gfxFloat* aHyphenWidth, SelectionType* aType,
+ gfxFloat* aHyphenWidth,
+ RawSelectionType* aRawSelectionType,
TextRangeStyle* aStyle);
void UpdateWithAdvance(gfxFloat aAdvance) {
mXOffset += aAdvance*mTextRun->GetDirection();
}
private:
SelectionDetails** mSelectionDetails;
PropertyProvider& mProvider;
@@ -5762,29 +5766,29 @@ SelectionIterator::SelectionIterator(Sel
mOriginalRange(aRange), mXOffset(aXOffset)
{
mIterator.SetOriginalOffset(aRange.start);
}
bool SelectionIterator::GetNextSegment(gfxFloat* aXOffset,
gfxTextRun::Range* aRange,
gfxFloat* aHyphenWidth,
- SelectionType* aType,
+ RawSelectionType* aRawSelectionType,
TextRangeStyle* aStyle)
{
if (mIterator.GetOriginalOffset() >= int32_t(mOriginalRange.end))
return false;
// save offset into transformed string now
uint32_t runOffset = mIterator.GetSkippedOffset();
uint32_t index = mIterator.GetOriginalOffset() - mOriginalRange.start;
SelectionDetails* sdptr = mSelectionDetails[index];
- SelectionType type =
- sdptr ? sdptr->mType : nsISelectionController::SELECTION_NONE;
+ RawSelectionType rawSelectionType =
+ sdptr ? sdptr->mRawSelectionType : nsISelectionController::SELECTION_NONE;
TextRangeStyle style;
if (sdptr) {
style = sdptr->mTextRangeStyle;
}
for (++index; index < mOriginalRange.Length(); ++index) {
if (sdptr != mSelectionDetails[index])
break;
}
@@ -5802,17 +5806,17 @@ bool SelectionIterator::GetNextSegment(g
aRange->start = runOffset;
aRange->end = mIterator.GetSkippedOffset();
*aXOffset = mXOffset;
*aHyphenWidth = 0;
if (mIterator.GetOriginalOffset() == int32_t(mOriginalRange.end) &&
haveHyphenBreak) {
*aHyphenWidth = mProvider.GetHyphenWidth();
}
- *aType = type;
+ *aRawSelectionType = rawSelectionType;
*aStyle = style;
return true;
}
static void
AddHyphenToMetrics(nsTextFrame* aTextFrame, gfxTextRun* aBaseTextRun,
gfxTextRun::Metrics* aMetrics,
gfxFont::BoundingBoxType aBoundingBoxType,
@@ -5914,89 +5918,89 @@ nsTextFrame::PaintOneShadow(const PaintS
aParams.context->Restore();
}
// Paints selection backgrounds and text in the correct colors. Also computes
// aAllTypes, the union of all selection types that are applying to this text.
bool
nsTextFrame::PaintTextWithSelectionColors(
const PaintTextSelectionParams& aParams,
- SelectionDetails* aDetails, SelectionType* aAllTypes,
+ SelectionDetails* aDetails, RawSelectionType* aAllRawSelectionTypes,
const nsCharClipDisplayItem::ClipEdges& aClipEdges)
{
const gfxTextRun::Range& contentRange = aParams.contentRange;
// Figure out which selections control the colors to use for each character.
AutoTArray<SelectionDetails*,BIG_TEXT_NODE_SIZE> prevailingSelectionsBuffer;
SelectionDetails** prevailingSelections =
prevailingSelectionsBuffer.AppendElements(contentRange.Length(), fallible);
if (!prevailingSelections) {
return false;
}
- SelectionType allTypes = 0;
+ RawSelectionType allRawSelectionTypes = 0;
for (uint32_t i = 0; i < contentRange.Length(); ++i) {
prevailingSelections[i] = nullptr;
}
SelectionDetails *sdptr = aDetails;
bool anyBackgrounds = false;
while (sdptr) {
int32_t start = std::max(0, sdptr->mStart - int32_t(contentRange.start));
int32_t end = std::min(int32_t(contentRange.Length()),
sdptr->mEnd - int32_t(contentRange.start));
- SelectionType type = sdptr->mType;
+ RawSelectionType rawSelectionType = sdptr->mRawSelectionType;
if (start < end) {
- allTypes |= type;
+ allRawSelectionTypes |= rawSelectionType;
// Ignore selections that don't set colors
nscolor foreground, background;
- if (GetSelectionTextColors(type, *aParams.textPaintStyle,
+ if (GetSelectionTextColors(rawSelectionType, *aParams.textPaintStyle,
sdptr->mTextRangeStyle,
&foreground, &background)) {
if (NS_GET_A(background) > 0) {
anyBackgrounds = true;
}
for (int32_t i = start; i < end; ++i) {
// Favour normal selection over IME selections
if (!prevailingSelections[i] ||
- type < prevailingSelections[i]->mType) {
+ rawSelectionType < prevailingSelections[i]->mRawSelectionType) {
prevailingSelections[i] = sdptr;
}
}
}
}
sdptr = sdptr->mNext;
}
- *aAllTypes = allTypes;
-
- if (!allTypes) {
+ *aAllRawSelectionTypes = allRawSelectionTypes;
+
+ if (!allRawSelectionTypes) {
// Nothing is selected in the given text range. XXX can this still occur?
return false;
}
bool vertical = mTextRun->IsVertical();
const gfxFloat startIOffset = vertical ?
aParams.textBaselinePt.y - aParams.framePt.y :
aParams.textBaselinePt.x - aParams.framePt.x;
gfxFloat iOffset, hyphenWidth;
Range range; // in transformed string
- SelectionType type;
+ RawSelectionType rawSelectionType;
TextRangeStyle rangeStyle;
// Draw background colors
if (anyBackgrounds && (!aParams.generateTextMask ||
aParams.paintSelectionBackground)) {
int32_t appUnitsPerDevPixel =
aParams.textPaintStyle->PresContext()->AppUnitsPerDevPixel();
SelectionIterator iterator(prevailingSelections, contentRange,
*aParams.provider, mTextRun, startIOffset);
while (iterator.GetNextSegment(&iOffset, &range, &hyphenWidth,
- &type, &rangeStyle)) {
+ &rawSelectionType, &rangeStyle)) {
nscolor foreground, background;
- GetSelectionTextColors(type, *aParams.textPaintStyle, rangeStyle,
- &foreground, &background);
+ GetSelectionTextColors(rawSelectionType, *aParams.textPaintStyle,
+ rangeStyle, &foreground, &background);
// Draw background color
gfxFloat advance = hyphenWidth +
mTextRun->GetAdvanceWidth(range, aParams.provider);
if (NS_GET_A(background) > 0) {
nsRect bgRect;
gfxFloat offs = iOffset - (mTextRun->IsInlineReversed() ? advance : 0);
if (vertical) {
bgRect = nsRect(aParams.framePt.x, aParams.framePt.y + offs,
@@ -6032,33 +6036,34 @@ nsTextFrame::PaintTextWithSelectionColor
shadowParams.provider = aParams.provider;
shadowParams.clipEdges = &aClipEdges;
// Draw text
const nsStyleText* textStyle = StyleText();
SelectionIterator iterator(prevailingSelections, contentRange,
*aParams.provider, mTextRun, startIOffset);
while (iterator.GetNextSegment(&iOffset, &range, &hyphenWidth,
- &type, &rangeStyle)) {
+ &rawSelectionType, &rangeStyle)) {
nscolor foreground, background;
if (aParams.generateTextMask) {
foreground = NS_RGBA(0, 0, 0, 255);
} else {
- GetSelectionTextColors(type, *aParams.textPaintStyle, rangeStyle,
- &foreground, &background);
+ GetSelectionTextColors(rawSelectionType, *aParams.textPaintStyle,
+ rangeStyle, &foreground, &background);
}
gfxPoint textBaselinePt = vertical ?
gfxPoint(aParams.textBaselinePt.x, aParams.framePt.y + iOffset) :
gfxPoint(aParams.framePt.x + iOffset, aParams.textBaselinePt.y);
// Determine what shadow, if any, to draw - either from textStyle
// or from the ::-moz-selection pseudo-class if specified there
nsCSSShadowArray* shadow = textStyle->GetTextShadow();
- GetSelectionTextShadow(this, type, *aParams.textPaintStyle, &shadow);
+ GetSelectionTextShadow(this, rawSelectionType, *aParams.textPaintStyle,
+ &shadow);
if (shadow) {
nscoord startEdge = iOffset;
if (mTextRun->IsInlineReversed()) {
startEdge -= hyphenWidth +
mTextRun->GetAdvanceWidth(range, aParams.provider);
}
shadowParams.range = range;
shadowParams.textBaselinePt = textBaselinePt;
@@ -6077,17 +6082,17 @@ nsTextFrame::PaintTextWithSelectionColor
iterator.UpdateWithAdvance(advance);
}
return true;
}
void
nsTextFrame::PaintTextSelectionDecorations(
const PaintTextSelectionParams& aParams,
- SelectionDetails* aDetails, SelectionType aSelectionType)
+ SelectionDetails* aDetails, RawSelectionType aRawSelectionType)
{
// Hide text decorations if we're currently hiding @font-face fallback text
if (aParams.provider->GetFontGroup()->ShouldSkipDrawing())
return;
// Figure out which characters will be decorated for this selection.
const gfxTextRun::Range& contentRange = aParams.contentRange;
AutoTArray<SelectionDetails*, BIG_TEXT_NODE_SIZE> selectedCharsBuffer;
@@ -6097,17 +6102,17 @@ nsTextFrame::PaintTextSelectionDecoratio
return;
}
for (uint32_t i = 0; i < contentRange.Length(); ++i) {
selectedChars[i] = nullptr;
}
SelectionDetails *sdptr = aDetails;
while (sdptr) {
- if (sdptr->mType == aSelectionType) {
+ if (sdptr->mRawSelectionType == aRawSelectionType) {
int32_t start = std::max(0, sdptr->mStart - int32_t(contentRange.start));
int32_t end = std::min(int32_t(contentRange.Length()),
sdptr->mEnd - int32_t(contentRange.start));
for (int32_t i = start; i < end; ++i) {
selectedChars[i] = sdptr;
}
}
sdptr = sdptr->mNext;
@@ -6141,34 +6146,34 @@ nsTextFrame::PaintTextSelectionDecoratio
// XXX aTextBaselinePt is in AppUnits, shouldn't it be nsFloatPoint?
Point pt;
if (verticalRun) {
pt.x = (aParams.textBaselinePt.x - mAscent) / app;
} else {
pt.y = (aParams.textBaselinePt.y - mAscent) / app;
}
gfxFloat decorationOffsetDir = mTextRun->IsSidewaysLeft() ? -1.0 : 1.0;
- SelectionType type;
+ RawSelectionType rawSelectionType;
TextRangeStyle selectedStyle;
while (iterator.GetNextSegment(&iOffset, &range, &hyphenWidth,
- &type, &selectedStyle)) {
+ &rawSelectionType, &selectedStyle)) {
gfxFloat advance = hyphenWidth +
mTextRun->GetAdvanceWidth(range, aParams.provider);
- if (type == aSelectionType) {
+ if (rawSelectionType == aRawSelectionType) {
if (verticalRun) {
pt.y = (aParams.framePt.y + iOffset -
(mTextRun->IsInlineReversed() ? advance : 0)) / app;
} else {
pt.x = (aParams.framePt.x + iOffset -
(mTextRun->IsInlineReversed() ? advance : 0)) / app;
}
gfxFloat width = Abs(advance) / app;
gfxFloat xInFrame = pt.x - (aParams.framePt.x / app);
DrawSelectionDecorations(
- aParams.context, aParams.dirtyRect, aSelectionType,
+ aParams.context, aParams.dirtyRect, aRawSelectionType,
*aParams.textPaintStyle, selectedStyle, pt, xInFrame,
width, mAscent / app, decorationMetrics, aParams.callbacks,
verticalRun, decorationOffsetDir, kDecoration);
}
iterator.UpdateWithAdvance(advance);
}
}
@@ -6179,34 +6184,35 @@ nsTextFrame::PaintTextWithSelection(
{
NS_ASSERTION(GetContent()->IsSelectionDescendant(), "wrong paint path");
SelectionDetails* details = GetSelectionDetails();
if (!details) {
return false;
}
- SelectionType allTypes;
- if (!PaintTextWithSelectionColors(aParams, details, &allTypes, aClipEdges)) {
+ RawSelectionType allRawSelectionTypes;
+ if (!PaintTextWithSelectionColors(aParams, details, &allRawSelectionTypes,
+ aClipEdges)) {
DestroySelectionDetails(details);
return false;
}
- // Iterate through just the selection types that paint decorations and
- // paint decorations for any that actually occur in this frame. Paint
- // higher-numbered selection types below lower-numered ones on the
+ // Iterate through just the selection rawSelectionTypes that paint decorations
+ // and paint decorations for any that actually occur in this frame. Paint
+ // higher-numbered selection rawSelectionTypes below lower-numered ones on the
// general principal that lower-numbered selections are higher priority.
- allTypes &= SelectionTypesWithDecorations;
+ allRawSelectionTypes &= RawSelectionTypesWithDecorations;
for (int32_t i = nsISelectionController::NUM_SELECTIONTYPES - 1;
i >= 1; --i) {
- SelectionType type = 1 << (i - 1);
- if (allTypes & type) {
- // There is some selection of this type. Try to paint its decorations
- // (there might not be any for this type but that's OK,
+ RawSelectionType rawSelectionType = 1 << (i - 1);
+ if (allRawSelectionTypes & rawSelectionType) {
+ // There is some selection of this rawSelectionType. Try to paint its
+ // decorations (there might not be any for this type but that's OK,
// PaintTextSelectionDecorations will exit early).
- PaintTextSelectionDecorations(aParams, details, type);
+ PaintTextSelectionDecorations(aParams, details, rawSelectionType);
}
}
DestroySelectionDetails(details);
return true;
}
void
@@ -6282,33 +6288,34 @@ nsTextFrame::GetCaretColorAt(int32_t aOf
isSolidTextColor = false;
}
}
nsTextPaintStyle textPaintStyle(this);
textPaintStyle.SetResolveColors(isSolidTextColor);
SelectionDetails* details = GetSelectionDetails();
SelectionDetails* sdptr = details;
- SelectionType type = 0;
+ RawSelectionType rawSelectionType = 0;
while (sdptr) {
int32_t start = std::max(0, sdptr->mStart - contentOffset);
int32_t end = std::min(contentLength, sdptr->mEnd - contentOffset);
if (start <= offsetInFrame && offsetInFrame < end &&
- (type == 0 || sdptr->mType < type)) {
+ (rawSelectionType == 0 ||
+ sdptr->mRawSelectionType < rawSelectionType)) {
nscolor foreground, background;
- if (GetSelectionTextColors(sdptr->mType, textPaintStyle,
+ if (GetSelectionTextColors(sdptr->mRawSelectionType, textPaintStyle,
sdptr->mTextRangeStyle,
&foreground, &background)) {
if (!isSolidTextColor &&
NS_IS_SELECTION_SPECIAL_COLOR(foreground)) {
result = NS_RGBA(0, 0, 0, 255);
} else {
result = foreground;
}
- type = sdptr->mType;
+ rawSelectionType = sdptr->mRawSelectionType;
}
}
sdptr = sdptr->mNext;
}
DestroySelectionDetails(details);
return result;
}
@@ -6894,17 +6901,17 @@ nsTextFrame::IsVisibleInSelection(nsISel
SelectionDetails* details = GetSelectionDetails();
bool found = false;
// where are the selection points "really"
SelectionDetails *sdptr = details;
while (sdptr) {
if (sdptr->mEnd > GetContentOffset() &&
sdptr->mStart < GetContentEnd() &&
- sdptr->mType == nsISelectionController::SELECTION_NORMAL) {
+ sdptr->mRawSelectionType == nsISelectionController::SELECTION_NORMAL) {
found = true;
break;
}
sdptr = sdptr->mNext;
}
DestroySelectionDetails(details);
return found;
@@ -7064,23 +7071,25 @@ nsTextFrame::CombineSelectionUnderlineRe
params.ascent = aPresContext->AppUnitsToGfxUnits(mAscent);
params.offset = fontGroup->GetUnderlineOffset();
params.descentLimit =
ComputeDescentLimitForSelectionUnderline(aPresContext, metrics);
params.vertical = verticalRun;
SelectionDetails *details = GetSelectionDetails();
for (SelectionDetails *sd = details; sd; sd = sd->mNext) {
- if (sd->mStart == sd->mEnd || !(sd->mType & SelectionTypesWithDecorations))
+ if (sd->mStart == sd->mEnd ||
+ !(sd->mRawSelectionType & RawSelectionTypesWithDecorations))
continue;
float relativeSize;
int32_t index =
- nsTextPaintStyle::GetUnderlineStyleIndexForSelectionType(sd->mType);
- if (sd->mType == nsISelectionController::SELECTION_SPELLCHECK) {
+ nsTextPaintStyle::GetUnderlineStyleIndexForRawSelectionType(
+ sd->mRawSelectionType);
+ if (sd->mRawSelectionType == nsISelectionController::SELECTION_SPELLCHECK) {
if (!nsTextPaintStyle::GetSelectionUnderline(aPresContext, index, nullptr,
&relativeSize,
¶ms.style)) {
continue;
}
} else {
// IME selections
TextRangeStyle& rangeStyle = sd->mTextRangeStyle;
@@ -7094,19 +7103,20 @@ nsTextFrame::CombineSelectionUnderlineRe
} else if (!nsTextPaintStyle::GetSelectionUnderline(aPresContext, index,
nullptr, &relativeSize,
¶ms.style)) {
continue;
}
}
nsRect decorationArea;
- params.lineSize = Size(aPresContext->AppUnitsToGfxUnits(aRect.width),
- ComputeSelectionUnderlineHeight(aPresContext,
- metrics, sd->mType));
+ params.lineSize =
+ Size(aPresContext->AppUnitsToGfxUnits(aRect.width),
+ ComputeSelectionUnderlineHeight(aPresContext, metrics,
+ sd->mRawSelectionType));
relativeSize = std::max(relativeSize, 1.0f);
params.lineSize.height *= relativeSize;
decorationArea =
nsCSSRendering::GetTextDecorationRect(aPresContext, params);
aRect.UnionRect(aRect, decorationArea);
}
DestroySelectionDetails(details);
@@ -7119,17 +7129,17 @@ nsTextFrame::IsFrameSelected() const
NS_ASSERTION(!GetContent() || GetContent()->IsSelectionDescendant(),
"use the public IsSelected() instead");
return nsRange::IsNodeSelected(GetContent(), GetContentOffset(),
GetContentEnd());
}
void
nsTextFrame::SetSelectedRange(uint32_t aStart, uint32_t aEnd, bool aSelected,
- SelectionType aType)
+ RawSelectionType aRawSelectionType)
{
NS_ASSERTION(!GetPrevContinuation(), "Should only be called for primary frame");
DEBUG_VERIFY_NOT_DIRTY(mState);
// Selection is collapsed, which can't affect text frame rendering
if (aStart == aEnd)
return;
@@ -7138,17 +7148,17 @@ nsTextFrame::SetSelectedRange(uint32_t a
f = static_cast<nsTextFrame*>(f->GetNextContinuation());
}
nsPresContext* presContext = PresContext();
while (f && f->GetContentOffset() < int32_t(aEnd)) {
// We may need to reflow to recompute the overflow area for
// spellchecking or IME underline if their underline is thicker than
// the normal decoration line.
- if (aType & SelectionTypesWithDecorations) {
+ if (aRawSelectionType & RawSelectionTypesWithDecorations) {
bool didHaveOverflowingSelection =
(f->GetStateBits() & TEXT_SELECTION_UNDERLINE_OVERFLOWED) != 0;
nsRect r(nsPoint(0, 0), GetSize());
bool willHaveOverflowingSelection =
aSelected && f->CombineSelectionUnderlineRect(presContext, r);
if (didHaveOverflowingSelection || willHaveOverflowingSelection) {
presContext->PresShell()->FrameNeedsReflow(f,
nsIPresShell::eStyleChange,
--- a/layout/generic/nsTextFrame.h
+++ b/layout/generic/nsTextFrame.h
@@ -28,16 +28,17 @@ class PropertyProvider;
struct SelectionDetails;
class nsTextFragment;
class nsDisplayTextGeometry;
class nsDisplayText;
class nsTextFrame : public nsFrame {
typedef mozilla::LayoutDeviceRect LayoutDeviceRect;
+ typedef mozilla::RawSelectionType RawSelectionType;
typedef mozilla::TextRangeStyle TextRangeStyle;
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::Point Point;
typedef mozilla::gfx::Rect Rect;
typedef mozilla::gfx::Size Size;
typedef gfxTextRun::Range Range;
public:
@@ -154,17 +155,17 @@ public:
* the selection state of the given character range has changed.
* Text in the range is unconditionally invalidated
* (Selection::Repaint depends on this).
* @param aSelected true if the selection has been added to the range,
* false otherwise
* @param aType the type of selection added or removed
*/
void SetSelectedRange(uint32_t aStart, uint32_t aEnd, bool aSelected,
- SelectionType aType);
+ RawSelectionType aRawSelectionType);
virtual FrameSearchResult PeekOffsetNoAmount(bool aForward, int32_t* aOffset) override;
virtual FrameSearchResult PeekOffsetCharacter(bool aForward, int32_t* aOffset,
bool aRespectClusters = true) override;
virtual FrameSearchResult PeekOffsetWord(bool aForward, bool aWordSelectEatSpace, bool aIsKeyboardSelect,
int32_t* aOffset, PeekWordState* aState) override;
virtual nsresult CheckVisibility(nsPresContext* aContext, int32_t aStartIndex, int32_t aEndIndex, bool aRecurse, bool *aFinished, bool *_retval) override;
@@ -443,24 +444,25 @@ public:
// the fast path.
bool PaintTextWithSelection(const PaintTextSelectionParams& aParams,
const nsCharClipDisplayItem::ClipEdges& aClipEdges);
// helper: paint text with foreground and background colors determined
// by selection(s). Also computes a mask of all selection types applying to
// our text, returned in aAllTypes.
// Return false if the text was not painted and we should continue with
// the fast path.
- bool PaintTextWithSelectionColors(const PaintTextSelectionParams& aParams,
- SelectionDetails* aDetails,
- SelectionType* aAllTypes,
- const nsCharClipDisplayItem::ClipEdges& aClipEdges);
+ bool PaintTextWithSelectionColors(
+ const PaintTextSelectionParams& aParams,
+ SelectionDetails* aDetails,
+ RawSelectionType* aAllRawSelectionTypes,
+ const nsCharClipDisplayItem::ClipEdges& aClipEdges);
// helper: paint text decorations for text selected by aSelectionType
void PaintTextSelectionDecorations(const PaintTextSelectionParams& aParams,
SelectionDetails* aDetails,
- SelectionType aSelectionType);
+ RawSelectionType aRawSelectionType);
void DrawEmphasisMarks(gfxContext* aContext,
mozilla::WritingMode aWM,
const gfxPoint& aTextBaselinePt,
const gfxPoint& aFramePt, Range aRange,
const nscolor* aDecorationOverrideColor,
PropertyProvider* aProvider);
@@ -729,17 +731,17 @@ protected:
bool CombineSelectionUnderlineRect(nsPresContext* aPresContext,
nsRect& aRect);
/**
* Utility methods to paint selection.
*/
void DrawSelectionDecorations(gfxContext* aContext,
const LayoutDeviceRect& aDirtyRect,
- SelectionType aType,
+ mozilla::RawSelectionType aRawSelectionType,
nsTextPaintStyle& aTextPaintStyle,
const TextRangeStyle &aRangeStyle,
const Point& aPt,
gfxFloat aICoordInFrame,
gfxFloat aWidth,
gfxFloat aAscent,
const gfxFont::Metrics& aFontMetrics,
DrawPathCallbacks* aCallbacks,
@@ -762,29 +764,29 @@ protected:
/**
* This function encapsulates all knowledge of how selections affect
* foreground and background colors.
* @param aForeground the foreground color to use
* @param aBackground the background color to use, or RGBA(0,0,0,0) if no
* background should be painted
* @return true if the selection affects colors, false otherwise
*/
- static bool GetSelectionTextColors(SelectionType aType,
+ static bool GetSelectionTextColors(RawSelectionType aRawSelectionType,
nsTextPaintStyle& aTextPaintStyle,
const TextRangeStyle &aRangeStyle,
nscolor* aForeground,
nscolor* aBackground);
/**
* ComputeSelectionUnderlineHeight() computes selection underline height of
* the specified selection type from the font metrics.
*/
static gfxFloat ComputeSelectionUnderlineHeight(
nsPresContext* aPresContext,
const gfxFont::Metrics& aFontMetrics,
- SelectionType aSelectionType);
+ RawSelectionType aRawSelectionType);
ContentOffsets GetCharacterOffsetAtFramePointInternal(nsPoint aPoint,
bool aForInsertionPoint);
void ClearFrameOffsetCache();
virtual bool HasAnyNoncollapsedCharacters() override;