Bug 1635709: part 7) Move `nsFrameSelection::SetDesiredCaretPos` and `FetchDesiredCaretPos` to `DesiredCaretPos`. r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D74616
This commit is contained in:
Mirko Brodesser 2020-05-12 09:42:16 +00:00
Родитель ca24d8b332
Коммит 676b66d20f
2 изменённых файлов: 26 добавлений и 22 удалений

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

@ -416,23 +416,22 @@ NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsFrameSelection, Release)
// Get the x (or y, in vertical writing mode) position requested
// by the Key Handling for line-up/down
nsresult nsFrameSelection::FetchDesiredCaretPos(nsPoint& aDesiredCaretPos) {
if (!mPresShell) {
NS_ERROR("fetch desired position failed");
return NS_ERROR_FAILURE;
}
if (mDesiredCaretPos.mIsSet) {
aDesiredCaretPos = mDesiredCaretPos.mValue;
nsresult nsFrameSelection::DesiredCaretPos::FetchPos(
nsPoint& aDesiredCaretPos, const PresShell& aPresShell,
Selection& aNormalSelection) const {
MOZ_ASSERT(aNormalSelection.GetType() == SelectionType::eNormal);
if (mIsSet) {
aDesiredCaretPos = mValue;
return NS_OK;
}
RefPtr<nsCaret> caret = mPresShell->GetCaret();
RefPtr<nsCaret> caret = aPresShell.GetCaret();
if (!caret) {
return NS_ERROR_NULL_POINTER;
}
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
caret->SetSelection(mDomSelections[index]);
caret->SetSelection(&aNormalSelection);
nsRect coord;
nsIFrame* caretFrame = caret->GetGeometry(&coord);
@ -456,9 +455,9 @@ void nsFrameSelection::InvalidateDesiredCaretPos() // do not listen to
mDesiredCaretPos.mIsSet = false;
}
void nsFrameSelection::SetDesiredCaretPos(nsPoint aPos) {
mDesiredCaretPos.mValue = aPos;
mDesiredCaretPos.mIsSet = true;
void nsFrameSelection::DesiredCaretPos::Set(const nsPoint& aPos) {
mValue = aPos;
mIsSet = true;
}
nsresult nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree(
@ -707,11 +706,11 @@ nsresult nsFrameSelection::MoveCaret(nsDirection aDirection,
AutoPrepareFocusRange prep(sel, false);
if (aAmount == eSelectLine) {
nsresult result = FetchDesiredCaretPos(desiredPos);
nsresult result = mDesiredCaretPos.FetchPos(desiredPos, *mPresShell, *sel);
if (NS_FAILED(result)) {
return result;
}
SetDesiredCaretPos(desiredPos);
mDesiredCaretPos.Set(desiredPos);
}
if (doCollapse) {

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

@ -856,12 +856,8 @@ class nsFrameSelection final {
}
}
nsresult FetchDesiredCaretPos(
nsPoint& aDesiredCaretPos); // the position requested by the Key Handling
// for up down
void InvalidateDesiredCaretPos(); // do not listen to mDesiredCaretPos.mValue
// you must get another.
void SetDesiredCaretPos(nsPoint aPos); // set the mDesiredCaretPos.mValue
bool IsBatching() const { return mBatching.mCounter > 0; }
@ -1003,10 +999,19 @@ class nsFrameSelection final {
nsBidiLevel mKbdBidiLevel = NSBIDI_LTR;
// TODO: could presumably be transformed to a `mozilla::Maybe`.
struct DesiredCaretPos {
nsPoint mValue;
class DesiredCaretPos {
public:
// the position requested by the Key Handling for up down
nsresult FetchPos(nsPoint& aDesiredCaretPos,
const mozilla::PresShell& aPresShell,
mozilla::dom::Selection& aNormalSelection) const;
void Set(const nsPoint& aPos);
bool mIsSet = false;
private:
nsPoint mValue;
};
DesiredCaretPos mDesiredCaretPos;