Files
tubestation/layout/base/CaretAssociationHint.h
Masayuki Nakano 9fd27e7690 Bug 1937289 - Make AutoRangeArray::ExtendAnchorFocusRangeFor stop using nsFrameSelection r=m_kato,jjaschke,dom-core
`AutoRangeArray` is created for making some handlers of the editor classes free
from `Selection` and `nsFrameSelection` while handling the edit actions.
However, the method still depends on `nsFrameSelection` instance since its
callees are instance methods of `nsFrameSelection`.

However, `EditContext` requires completely free methods to compute target
ranges of `beforeinput`.  Therefore, we need to make it not depend on
`Selection` nor `nsFrameSelection`.

The common method, `nsFrameSelection::CreateRangeExtendedToSomewhere`, requires
`PresShell`, selection limiter which is set only when the selection is an
independent selection like in a selection for a text control, selection
ancestor limiter which is set only when an editing host has focus, caret
association hint to put caret to end of preceding line or start of following
line if selection range is collapsed at a line break and caret bidi level for
considering caret position around line break in bidi text.  They are now stored
by `nsFrameSelection` and modified when selection range is changed in some
cases.  Basically, the method is called without updating its ranges and if and
only if it's initialized with `Selection`.  So, simply caching the
`nsFrameSelection`'s values solves the issues in the most cases, but this
patch makes `AutoRangeArray` adjust the value only when its `Collapse` is
called because `Selection` automatically updates it and we can compute the
value without `Selection` nor `nsFrameSelection`.

After applying this patch, `AutoRangeArray` has two meanings, one is the
instance is a proxy for `Selection`.  The other is a container for a range to
call methods which take pointer or reference to it.  To make this differences
checked at build time, this patch creates a new subclass of it, and renamed to
`AutoClonedRangeArray` to make it clearer that what are stored in the array.

Oddly, `AutoRangeArray(nsRange&)` constructor has not been cloned.  Therefore,
I make it and its subclass version clone before storing into the array.  Then,
one caller needs to change which range should be tracked.

Differential Revision: https://phabricator.services.mozilla.com/D232174
2025-01-07 01:56:52 +00:00

39 lines
1.2 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_CaretAssociationHint_h
#define mozilla_CaretAssociationHint_h
namespace mozilla {
template <typename PT, typename CT>
class RangeBoundaryBase;
namespace intl {
class BidiEmbeddingLevel;
};
/**
* Hint whether a caret is associated with the content before a
* given character offset (Before), or with the content after a given
* character offset (After).
*/
enum class CaretAssociationHint { Before, After };
/**
* Return better caret association hint for aCaretPoint than aDefault.
* This computes the result from layout. Therefore, you should flush pending
* layout before calling this.
*/
template <typename PT, typename CT>
CaretAssociationHint ComputeCaretAssociationHint(
CaretAssociationHint aDefault, intl::BidiEmbeddingLevel aBidiLevel,
const RangeBoundaryBase<PT, CT>& aCaretPoint);
} // namespace mozilla
#endif