2017-10-27 01:08:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-04-07 01:54:38 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
2012-06-08 18:20:55 +04:00
|
|
|
#ifndef mozilla_Selection_h__
|
|
|
|
#define mozilla_Selection_h__
|
2012-04-07 01:54:38 +04:00
|
|
|
|
2020-02-05 12:12:23 +03:00
|
|
|
#include "mozilla/dom/StyledRange.h"
|
2014-09-10 21:07:36 +04:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2020-02-11 04:23:12 +03:00
|
|
|
#include "mozilla/EventForwards.h"
|
2020-07-15 16:56:31 +03:00
|
|
|
#include "mozilla/PresShellForwards.h"
|
2017-11-07 09:29:15 +03:00
|
|
|
#include "mozilla/RangeBoundary.h"
|
2018-09-04 14:18:03 +03:00
|
|
|
#include "mozilla/SelectionChangeEventDispatcher.h"
|
2017-01-20 12:39:57 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2018-05-08 20:52:37 +03:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2018-05-08 20:52:38 +03:00
|
|
|
#include "nsDirection.h"
|
2012-04-07 01:54:38 +04:00
|
|
|
#include "nsISelectionController.h"
|
2015-12-01 23:25:06 +03:00
|
|
|
#include "nsISelectionListener.h"
|
2012-06-07 19:00:58 +04:00
|
|
|
#include "nsRange.h"
|
2018-05-08 20:52:38 +03:00
|
|
|
#include "nsTArrayForwardDeclare.h"
|
2013-08-07 00:19:11 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "nsWeakReference.h"
|
2013-12-17 18:12:33 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2012-04-07 01:54:38 +04:00
|
|
|
|
|
|
|
struct CachedOffsetForFrame;
|
2020-05-11 12:38:00 +03:00
|
|
|
class AutoScroller;
|
2012-04-07 01:54:38 +04:00
|
|
|
class nsIFrame;
|
2013-08-07 00:19:11 +04:00
|
|
|
class nsFrameSelection;
|
2017-03-14 04:36:21 +03:00
|
|
|
class nsPIDOMWindowOuter;
|
2012-04-07 01:54:38 +04:00
|
|
|
struct SelectionDetails;
|
2017-05-10 17:48:50 +03:00
|
|
|
struct SelectionCustomColors;
|
2017-02-25 13:33:34 +03:00
|
|
|
class nsCopySupport;
|
|
|
|
class nsHTMLCopyEncoder;
|
2020-11-23 19:21:38 +03:00
|
|
|
class nsPresContext;
|
|
|
|
struct nsPoint;
|
|
|
|
struct nsRect;
|
2012-04-07 01:54:38 +04:00
|
|
|
|
2013-12-17 18:12:33 +04:00
|
|
|
namespace mozilla {
|
2020-02-11 04:22:29 +03:00
|
|
|
class AccessibleCaretEventHub;
|
2013-12-17 18:12:33 +04:00
|
|
|
class ErrorResult;
|
2017-08-07 10:33:59 +03:00
|
|
|
class HTMLEditor;
|
2019-01-11 04:50:19 +03:00
|
|
|
class PostContentIterator;
|
2020-02-18 15:28:45 +03:00
|
|
|
enum class TableSelectionMode : uint32_t;
|
2015-02-21 07:27:59 +03:00
|
|
|
struct AutoPrepareFocusRange;
|
2017-11-27 11:10:27 +03:00
|
|
|
namespace dom {
|
|
|
|
class DocGroup;
|
|
|
|
} // namespace dom
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2018-05-08 20:52:36 +03:00
|
|
|
namespace mozilla {
|
2020-02-11 04:23:12 +03:00
|
|
|
|
2018-05-08 20:52:36 +03:00
|
|
|
namespace dom {
|
|
|
|
|
2014-04-10 20:09:40 +04:00
|
|
|
// Note, the ownership of mozilla::dom::Selection depends on which way the
|
|
|
|
// object is created. When nsFrameSelection has created Selection,
|
|
|
|
// addreffing/releasing the Selection object is aggregated to nsFrameSelection.
|
|
|
|
// Otherwise normal addref/release is used. This ensures that nsFrameSelection
|
|
|
|
// is never deleted before its Selections.
|
2018-05-08 20:52:42 +03:00
|
|
|
class Selection final : public nsSupportsWeakReference,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsWrapperCache,
|
2020-07-23 17:51:46 +03:00
|
|
|
public SupportsWeakPtr {
|
2014-06-24 02:40:01 +04:00
|
|
|
protected:
|
|
|
|
virtual ~Selection();
|
|
|
|
|
2012-04-07 01:54:38 +04:00
|
|
|
public:
|
2020-02-11 13:50:54 +03:00
|
|
|
/**
|
|
|
|
* @param aFrameSelection can be nullptr.
|
|
|
|
*/
|
2020-03-19 12:25:02 +03:00
|
|
|
explicit Selection(SelectionType aSelectionType,
|
|
|
|
nsFrameSelection* aFrameSelection);
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2012-04-07 01:54:38 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2018-05-08 20:52:42 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Selection)
|
2012-04-07 01:54:38 +04:00
|
|
|
|
2017-09-08 06:10:44 +03:00
|
|
|
// match this up with EndbatchChanges. will stop ui updates while multiple
|
|
|
|
// selection methods are called
|
|
|
|
void StartBatchChanges();
|
|
|
|
|
|
|
|
// match this up with StartBatchChanges
|
|
|
|
void EndBatchChanges(int16_t aReason = nsISelectionListener::NO_REASON);
|
2015-12-01 23:25:06 +03:00
|
|
|
|
2018-08-30 10:36:23 +03:00
|
|
|
/**
|
|
|
|
* NotifyAutoCopy() starts to notify AutoCopyListener of selection changes.
|
|
|
|
*/
|
2020-03-30 11:48:16 +03:00
|
|
|
void NotifyAutoCopy() {
|
|
|
|
MOZ_ASSERT(mSelectionType == SelectionType::eNormal);
|
|
|
|
|
|
|
|
mNotifyAutoCopy = true;
|
|
|
|
}
|
2018-08-30 10:36:23 +03:00
|
|
|
|
2018-09-01 00:19:44 +03:00
|
|
|
/**
|
|
|
|
* MaybeNotifyAccessibleCaretEventHub() starts to notify
|
|
|
|
* AccessibleCaretEventHub of selection change if aPresShell has it.
|
|
|
|
*/
|
2020-02-11 04:22:29 +03:00
|
|
|
void MaybeNotifyAccessibleCaretEventHub(PresShell* aPresShell);
|
2018-09-01 00:19:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* StopNotifyingAccessibleCaretEventHub() stops notifying
|
|
|
|
* AccessibleCaretEventHub of selection change.
|
|
|
|
*/
|
2020-02-11 04:22:29 +03:00
|
|
|
void StopNotifyingAccessibleCaretEventHub();
|
2018-09-01 00:19:44 +03:00
|
|
|
|
2018-09-01 00:22:57 +03:00
|
|
|
/**
|
2018-09-04 14:18:03 +03:00
|
|
|
* EnableSelectionChangeEvent() starts to notify
|
|
|
|
* SelectionChangeEventDispatcher of selection change to dispatch a
|
|
|
|
* selectionchange event at every selection change.
|
2018-09-01 00:22:57 +03:00
|
|
|
*/
|
|
|
|
void EnableSelectionChangeEvent() {
|
2018-09-04 14:18:03 +03:00
|
|
|
if (!mSelectionChangeEventDispatcher) {
|
|
|
|
mSelectionChangeEventDispatcher = new SelectionChangeEventDispatcher();
|
2018-09-01 00:22:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 14:50:06 +03:00
|
|
|
// Required for WebIDL bindings, see
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings#Adding_WebIDL_bindings_to_a_class.
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* GetParentObject() const;
|
2019-07-02 14:50:06 +03:00
|
|
|
|
2017-11-27 11:10:27 +03:00
|
|
|
DocGroup* GetDocGroup() const;
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2012-04-07 01:54:38 +04:00
|
|
|
// utility methods for scrolling the selection into view
|
2012-12-19 22:44:58 +04:00
|
|
|
nsPresContext* GetPresContext() const;
|
2019-04-03 10:53:23 +03:00
|
|
|
PresShell* GetPresShell() const;
|
2013-02-16 00:09:28 +04:00
|
|
|
nsFrameSelection* GetFrameSelection() const { return mFrameSelection; }
|
2012-04-07 01:54:38 +04:00
|
|
|
// Returns a rect containing the selection region, and frame that that
|
|
|
|
// position is relative to. For SELECTION_ANCHOR_REGION or
|
|
|
|
// SELECTION_FOCUS_REGION the rect is a zero-width rectangle. For
|
|
|
|
// SELECTION_WHOLE_SELECTION the rect contains both the anchor and focus
|
|
|
|
// region rects.
|
|
|
|
nsIFrame* GetSelectionAnchorGeometry(SelectionRegion aRegion, nsRect* aRect);
|
|
|
|
// Returns the position of the region (SELECTION_ANCHOR_REGION or
|
|
|
|
// SELECTION_FOCUS_REGION only), and frame that that position is relative to.
|
|
|
|
// The 'position' is a zero-width rectangle.
|
|
|
|
nsIFrame* GetSelectionEndPointGeometry(SelectionRegion aRegion,
|
|
|
|
nsRect* aRect);
|
|
|
|
|
2019-04-30 03:07:49 +03:00
|
|
|
nsresult PostScrollSelectionIntoViewEvent(SelectionRegion aRegion,
|
|
|
|
int32_t aFlags,
|
|
|
|
ScrollAxis aVertical,
|
|
|
|
ScrollAxis aHorizontal);
|
2012-04-07 01:54:38 +04:00
|
|
|
enum {
|
|
|
|
SCROLL_SYNCHRONOUS = 1 << 1,
|
|
|
|
SCROLL_FIRST_ANCESTOR_ONLY = 1 << 2,
|
2017-03-21 04:12:41 +03:00
|
|
|
SCROLL_DO_FLUSH =
|
|
|
|
1 << 3, // only matters if SCROLL_SYNCHRONOUS is passed too
|
2016-02-04 04:36:24 +03:00
|
|
|
SCROLL_OVERFLOW_HIDDEN = 1 << 5,
|
|
|
|
SCROLL_FOR_CARET_MOVE = 1 << 6
|
2012-04-07 01:54:38 +04:00
|
|
|
};
|
2017-03-21 04:12:41 +03:00
|
|
|
// If aFlags doesn't contain SCROLL_SYNCHRONOUS, then we'll flush when
|
|
|
|
// the scroll event fires so we make sure to scroll to the right place.
|
|
|
|
// Otherwise, if SCROLL_DO_FLUSH is also in aFlags, then this method will
|
|
|
|
// flush layout and you MUST hold a strong ref on 'this' for the duration
|
|
|
|
// of this call. This might destroy arbitrary layout objects.
|
2020-03-17 00:04:46 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
ScrollIntoView(SelectionRegion aRegion, ScrollAxis aVertical = ScrollAxis(),
|
|
|
|
ScrollAxis aHorizontal = ScrollAxis(), int32_t aFlags = 0);
|
2019-07-03 11:53:39 +03:00
|
|
|
|
|
|
|
private:
|
2020-05-04 13:11:13 +03:00
|
|
|
static bool IsUserSelectionCollapsed(
|
2020-03-31 16:59:09 +03:00
|
|
|
const nsRange& aRange, nsTArray<RefPtr<nsRange>>& aTempRangesToAdd);
|
2020-03-25 17:28:40 +03:00
|
|
|
/**
|
|
|
|
* https://w3c.github.io/selection-api/#selectstart-event.
|
|
|
|
*/
|
|
|
|
enum class DispatchSelectstartEvent {
|
|
|
|
No,
|
|
|
|
Maybe,
|
|
|
|
};
|
|
|
|
|
2020-03-25 18:36:54 +03:00
|
|
|
/**
|
|
|
|
* See `AddRangesForSelectableNodes`.
|
|
|
|
*/
|
2020-04-28 19:15:31 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult AddRangesForUserSelectableNodes(
|
2020-03-25 18:36:54 +03:00
|
|
|
nsRange* aRange, int32_t* aOutIndex,
|
|
|
|
const DispatchSelectstartEvent aDispatchSelectstartEvent);
|
|
|
|
|
2014-09-10 21:07:36 +04:00
|
|
|
/**
|
2019-07-03 11:53:39 +03:00
|
|
|
* Adds aRange to this Selection. If mUserInitiated is true,
|
2014-09-10 21:07:36 +04:00
|
|
|
* then aRange is first scanned for -moz-user-select:none nodes and split up
|
|
|
|
* into multiple ranges to exclude those before adding the resulting ranges
|
|
|
|
* to this Selection.
|
2020-01-20 15:39:26 +03:00
|
|
|
*
|
|
|
|
* @param aOutIndex points to the range last added, if at least one was added.
|
|
|
|
* If aRange is already contained, it points to the range
|
2020-03-27 14:21:25 +03:00
|
|
|
* containing it. -1 if mStyledRanges.mRanges was empty and
|
|
|
|
* no range was added.
|
2014-09-10 21:07:36 +04:00
|
|
|
*/
|
2020-10-17 01:22:48 +03:00
|
|
|
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult AddRangesForSelectableNodes(
|
2020-03-25 17:28:40 +03:00
|
|
|
nsRange* aRange, int32_t* aOutIndex,
|
|
|
|
DispatchSelectstartEvent aDispatchSelectstartEvent);
|
2020-02-12 15:27:32 +03:00
|
|
|
|
2019-07-03 11:53:39 +03:00
|
|
|
public:
|
2012-04-07 01:54:38 +04:00
|
|
|
nsresult RemoveCollapsedRanges();
|
2021-06-11 12:10:35 +03:00
|
|
|
void Clear(nsPresContext* aPresContext);
|
2020-10-17 01:22:48 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult CollapseInLimiter(nsINode* aContainer,
|
2021-06-30 10:07:28 +03:00
|
|
|
uint32_t aOffset) {
|
2017-11-07 09:29:15 +03:00
|
|
|
if (!aContainer) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2020-09-03 06:45:26 +03:00
|
|
|
return CollapseInLimiter(RawRangeBoundary(aContainer, aOffset));
|
2017-11-07 09:29:15 +03:00
|
|
|
}
|
2020-10-17 01:22:48 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult
|
|
|
|
CollapseInLimiter(const RawRangeBoundary& aPoint) {
|
2017-11-07 09:29:15 +03:00
|
|
|
ErrorResult result;
|
2020-09-03 06:45:26 +03:00
|
|
|
CollapseInLimiter(aPoint, result);
|
2017-11-07 09:29:15 +03:00
|
|
|
return result.StealNSResult();
|
|
|
|
}
|
2020-10-17 01:22:48 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void CollapseInLimiter(const RawRangeBoundary& aPoint,
|
|
|
|
ErrorResult& aRv) {
|
2020-09-03 14:55:22 +03:00
|
|
|
CollapseInternal(InLimiter::eYes, aPoint, aRv);
|
|
|
|
}
|
2018-09-01 00:19:44 +03:00
|
|
|
|
2021-02-04 00:52:15 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult Extend(nsINode* aContainer, int32_t aOffset);
|
2018-09-01 00:19:44 +03:00
|
|
|
|
2020-01-20 15:38:22 +03:00
|
|
|
/**
|
2020-03-27 14:21:25 +03:00
|
|
|
* See mStyledRanges.mRanges.
|
2020-01-20 15:38:22 +03:00
|
|
|
*/
|
2016-09-30 16:36:10 +03:00
|
|
|
nsRange* GetRangeAt(int32_t aIndex) const;
|
2012-04-07 01:54:38 +04:00
|
|
|
|
|
|
|
// Get the anchor-to-focus range if we don't care which end is
|
|
|
|
// anchor and which end is focus.
|
|
|
|
const nsRange* GetAnchorFocusRange() const { return mAnchorFocusRange; }
|
|
|
|
|
Bug 1506547 - Align user-select behavior more with other UAs. r=mats
There's a few subtle behavior changes here, which I'll try to break down in the
commit message.
The biggest one is the EditableDescendantCount stuff going away. This
was added in bug 1181130, to prevent clicking on the non-editable div from
selecting the editable div inside. This is problematic for multiple reasons:
* First, I don't think non-editable regions of an editable element should
be user-select: all.
* Second, it just doesn't work in Shadow DOM (the editable descendant count is
not kept up-to-date when not in the uncomposed doc), so nested
contenteditables behave differently inside vs. outside a Shadow Tree.
* Third, I think it's user hostile to just entirely disable selection if you
have a contenteditable descendant as a child of a user-select: all thing.
WebKit behaves like this patch in the following test-case (though not Blink):
https://crisal.io/tmp/user-select-all-contenteditable-descendant.html
Edge doesn't seem to support user-select: all at all (no pun intended).
But we don't allow to select anything at all which looks wrong.
* Fourth, it's not tested at all (which explains how we broke it in Shadow DOM
and not even notice...).
In any case I've verified that this doesn't regress the editor from that bug. If
this regresses anything we can fix it as outlined in the first bullet point
above, which should also make us more compatible with other UAs in that
test-case.
The other change is `all` not overriding everything else. So, something like:
<div style="-webkit-user-select: all">All <div style="-webkit-user-select: none">None</div></div>
Totally ignores the -webkit-user-select: none declaration in Firefox before this
change. This doesn't match any other UA nor the spec, and this patch aligns us
with WebKit / Blink.
This in turn makes us not need -moz-text anymore, whose only purpose was to
avoid this.
This also fixes a variety of bugs uncovered by the previous changes, like the
SetIgnoreUserModify(false) call in editor being completely useless, since
presShell->SetCaretEnabled ended in nsCaret::SetVisible, which overrode it.
This in turn uncovered even more bugs, from bugs in the caret painting code,
like not checking -moz-user-modify on the right frame if you're the last frame
of a line, to even funnier bits where before this patch you show the caret but
can't write at all...
In any case, the new setup I came up with is that when you're editing (the
selection is focused on an editable node) moving the caret forces it to end up
in an editable node, thus jumping over non-editable ones.
This has the nice effect of not completely disabling selection of
-moz-user-select: all elements that have editable descendants (which was a very
ad-hoc hack for bug 1181130, and somewhat broken per the above), and also
not needing the -moz-user-select: all for non-editable bits in contenteditable.css
at all.
This also fixes issues with br-skipping like not being able to insert content in
the following test-case:
<div contenteditable="true"><span contenteditable="false">xyz </span><br>editable</div>
If you start moving to the left from the second line, for example.
I think this yields way better behavior in all the relevant test-cases from bug
1181130 / bug 1109968 / bug 1132768, shouldn't cause any regression, and the
complexity is significantly reduced in some places.
There's still some other broken bits that this patch doesn't fix, but I'll file
follow-ups for those.
Differential Revision: https://phabricator.services.mozilla.com/D12687
--HG--
extra : moz-landing-system : lando
2018-11-26 12:21:37 +03:00
|
|
|
nsDirection GetDirection() const { return mDirection; }
|
|
|
|
|
2012-04-07 01:54:38 +04:00
|
|
|
void SetDirection(nsDirection aDir) { mDirection = aDir; }
|
2020-04-28 19:15:52 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult SetAnchorFocusToRange(nsRange* aRange);
|
|
|
|
|
2020-05-11 12:39:33 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void ReplaceAnchorFocusRange(nsRange* aRange);
|
2020-04-28 19:15:52 +03:00
|
|
|
|
2015-03-18 10:26:00 +03:00
|
|
|
void AdjustAnchorFocusForMultiRange(nsDirection aDirection);
|
2012-04-07 01:54:38 +04:00
|
|
|
|
2020-06-11 13:56:11 +03:00
|
|
|
nsIFrame* GetPrimaryFrameForAnchorNode() const;
|
|
|
|
nsIFrame* GetPrimaryFrameForFocusNode(bool aVisual,
|
|
|
|
int32_t* aOffsetUsed = nullptr) const;
|
2017-01-20 18:28:02 +03:00
|
|
|
|
|
|
|
UniquePtr<SelectionDetails> LookUpSelection(
|
|
|
|
nsIContent* aContent, int32_t aContentOffset, int32_t aContentLength,
|
|
|
|
UniquePtr<SelectionDetails> aDetailsHead, SelectionType aSelectionType,
|
|
|
|
bool aSlowCheck);
|
|
|
|
|
2012-04-07 01:54:38 +04:00
|
|
|
NS_IMETHOD Repaint(nsPresContext* aPresContext);
|
|
|
|
|
2019-05-06 16:57:46 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2017-11-15 13:26:10 +03:00
|
|
|
nsresult StartAutoScrollTimer(nsIFrame* aFrame, const nsPoint& aPoint,
|
2020-05-06 18:24:59 +03:00
|
|
|
uint32_t aDelayInMs);
|
2012-04-07 01:54:38 +04:00
|
|
|
|
|
|
|
nsresult StopAutoScrollTimer();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2020-10-13 12:23:51 +03:00
|
|
|
// WebIDL methods
|
2020-10-15 23:49:47 +03:00
|
|
|
nsINode* GetAnchorNode(CallerType aCallerType = CallerType::System) const {
|
2017-12-05 10:36:57 +03:00
|
|
|
const RangeBoundary& anchor = AnchorRef();
|
2020-10-15 23:49:47 +03:00
|
|
|
nsINode* anchorNode = anchor.IsSet() ? anchor.Container() : nullptr;
|
|
|
|
if (!anchorNode || aCallerType == CallerType::System ||
|
|
|
|
!anchorNode->ChromeOnlyAccess()) {
|
|
|
|
return anchorNode;
|
|
|
|
}
|
|
|
|
// anchor is nsIContent as ChromeOnlyAccess is nsIContent-only
|
|
|
|
return anchorNode->AsContent()->FindFirstNonChromeOnlyAccessContent();
|
2017-12-05 10:36:57 +03:00
|
|
|
}
|
2020-10-15 23:49:47 +03:00
|
|
|
uint32_t AnchorOffset(CallerType aCallerType = CallerType::System) const {
|
2017-12-05 10:36:57 +03:00
|
|
|
const RangeBoundary& anchor = AnchorRef();
|
2020-10-15 23:49:47 +03:00
|
|
|
if (aCallerType != CallerType::System && anchor.IsSet() &&
|
|
|
|
anchor.Container()->ChromeOnlyAccess()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2019-12-16 14:31:52 +03:00
|
|
|
const Maybe<uint32_t> offset =
|
|
|
|
anchor.Offset(RangeBoundary::OffsetFilter::kValidOffsets);
|
|
|
|
return offset ? *offset : 0;
|
2017-12-05 10:36:57 +03:00
|
|
|
}
|
2020-10-15 23:49:47 +03:00
|
|
|
nsINode* GetFocusNode(CallerType aCallerType = CallerType::System) const {
|
2017-12-05 10:36:57 +03:00
|
|
|
const RangeBoundary& focus = FocusRef();
|
2020-10-15 23:49:47 +03:00
|
|
|
nsINode* focusNode = focus.IsSet() ? focus.Container() : nullptr;
|
|
|
|
if (!focusNode || aCallerType == CallerType::System ||
|
|
|
|
!focusNode->ChromeOnlyAccess()) {
|
|
|
|
return focusNode;
|
|
|
|
}
|
|
|
|
// focus is nsIContent as ChromeOnlyAccess is nsIContent-only
|
|
|
|
return focusNode->AsContent()->FindFirstNonChromeOnlyAccessContent();
|
2017-12-05 10:36:57 +03:00
|
|
|
}
|
2020-10-15 23:49:47 +03:00
|
|
|
uint32_t FocusOffset(CallerType aCallerType = CallerType::System) const {
|
2017-12-05 10:36:57 +03:00
|
|
|
const RangeBoundary& focus = FocusRef();
|
2020-10-15 23:49:47 +03:00
|
|
|
if (aCallerType != CallerType::System && focus.IsSet() &&
|
|
|
|
focus.Container()->ChromeOnlyAccess()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2019-12-16 14:31:52 +03:00
|
|
|
const Maybe<uint32_t> offset =
|
|
|
|
focus.Offset(RangeBoundary::OffsetFilter::kValidOffsets);
|
|
|
|
return offset ? *offset : 0;
|
2017-12-05 10:36:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* GetChildAtAnchorOffset() {
|
|
|
|
const RangeBoundary& anchor = AnchorRef();
|
|
|
|
return anchor.IsSet() ? anchor.GetChildAtOffset() : nullptr;
|
|
|
|
}
|
|
|
|
nsIContent* GetChildAtFocusOffset() {
|
|
|
|
const RangeBoundary& focus = FocusRef();
|
|
|
|
return focus.IsSet() ? focus.GetChildAtOffset() : nullptr;
|
|
|
|
}
|
2013-12-17 18:12:33 +04:00
|
|
|
|
Bug 1506547 - Align user-select behavior more with other UAs. r=mats
There's a few subtle behavior changes here, which I'll try to break down in the
commit message.
The biggest one is the EditableDescendantCount stuff going away. This
was added in bug 1181130, to prevent clicking on the non-editable div from
selecting the editable div inside. This is problematic for multiple reasons:
* First, I don't think non-editable regions of an editable element should
be user-select: all.
* Second, it just doesn't work in Shadow DOM (the editable descendant count is
not kept up-to-date when not in the uncomposed doc), so nested
contenteditables behave differently inside vs. outside a Shadow Tree.
* Third, I think it's user hostile to just entirely disable selection if you
have a contenteditable descendant as a child of a user-select: all thing.
WebKit behaves like this patch in the following test-case (though not Blink):
https://crisal.io/tmp/user-select-all-contenteditable-descendant.html
Edge doesn't seem to support user-select: all at all (no pun intended).
But we don't allow to select anything at all which looks wrong.
* Fourth, it's not tested at all (which explains how we broke it in Shadow DOM
and not even notice...).
In any case I've verified that this doesn't regress the editor from that bug. If
this regresses anything we can fix it as outlined in the first bullet point
above, which should also make us more compatible with other UAs in that
test-case.
The other change is `all` not overriding everything else. So, something like:
<div style="-webkit-user-select: all">All <div style="-webkit-user-select: none">None</div></div>
Totally ignores the -webkit-user-select: none declaration in Firefox before this
change. This doesn't match any other UA nor the spec, and this patch aligns us
with WebKit / Blink.
This in turn makes us not need -moz-text anymore, whose only purpose was to
avoid this.
This also fixes a variety of bugs uncovered by the previous changes, like the
SetIgnoreUserModify(false) call in editor being completely useless, since
presShell->SetCaretEnabled ended in nsCaret::SetVisible, which overrode it.
This in turn uncovered even more bugs, from bugs in the caret painting code,
like not checking -moz-user-modify on the right frame if you're the last frame
of a line, to even funnier bits where before this patch you show the caret but
can't write at all...
In any case, the new setup I came up with is that when you're editing (the
selection is focused on an editable node) moving the caret forces it to end up
in an editable node, thus jumping over non-editable ones.
This has the nice effect of not completely disabling selection of
-moz-user-select: all elements that have editable descendants (which was a very
ad-hoc hack for bug 1181130, and somewhat broken per the above), and also
not needing the -moz-user-select: all for non-editable bits in contenteditable.css
at all.
This also fixes issues with br-skipping like not being able to insert content in
the following test-case:
<div contenteditable="true"><span contenteditable="false">xyz </span><br>editable</div>
If you start moving to the left from the second line, for example.
I think this yields way better behavior in all the relevant test-cases from bug
1181130 / bug 1109968 / bug 1132768, shouldn't cause any regression, and the
complexity is significantly reduced in some places.
There's still some other broken bits that this patch doesn't fix, but I'll file
follow-ups for those.
Differential Revision: https://phabricator.services.mozilla.com/D12687
--HG--
extra : moz-landing-system : lando
2018-11-26 12:21:37 +03:00
|
|
|
const RangeBoundary& AnchorRef() const;
|
|
|
|
const RangeBoundary& FocusRef() const;
|
2017-09-07 06:07:43 +03:00
|
|
|
|
2017-08-15 04:30:23 +03:00
|
|
|
/*
|
|
|
|
* IsCollapsed -- is the whole selection just one point, or unset?
|
|
|
|
*/
|
|
|
|
bool IsCollapsed() const {
|
2020-05-04 13:11:13 +03:00
|
|
|
uint32_t cnt = mStyledRanges.Length();
|
2017-08-15 04:30:23 +03:00
|
|
|
if (cnt == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-27 14:21:25 +03:00
|
|
|
return mStyledRanges.mRanges[0].mRange->Collapsed();
|
2017-08-15 04:30:23 +03:00
|
|
|
}
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2017-03-10 10:55:12 +03:00
|
|
|
// *JS() methods are mapped to Selection.*().
|
|
|
|
// They may move focus only when the range represents normal selection.
|
|
|
|
// These methods shouldn't be used by non-JS callers.
|
2020-10-17 01:22:48 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void CollapseJS(nsINode* aContainer, uint32_t aOffset,
|
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
MOZ_CAN_RUN_SCRIPT void CollapseToStartJS(mozilla::ErrorResult& aRv);
|
|
|
|
MOZ_CAN_RUN_SCRIPT void CollapseToEndJS(mozilla::ErrorResult& aRv);
|
2017-03-10 10:55:12 +03:00
|
|
|
|
2021-02-04 00:52:15 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void ExtendJS(nsINode& aContainer, uint32_t aOffset,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2017-03-10 10:55:12 +03:00
|
|
|
|
2021-02-04 00:52:22 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SelectAllChildrenJS(nsINode& aNode,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2018-05-08 20:52:42 +03:00
|
|
|
/**
|
|
|
|
* Deletes this selection from document the nodes belong to.
|
2020-02-14 13:58:06 +03:00
|
|
|
* Only if this has `SelectionType::eNormal`.
|
2018-05-08 20:52:42 +03:00
|
|
|
*/
|
2020-10-17 01:22:48 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void DeleteFromDocument(mozilla::ErrorResult& aRv);
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2020-05-04 13:11:13 +03:00
|
|
|
uint32_t RangeCount() const { return mStyledRanges.Length(); }
|
2017-08-03 17:13:24 +03:00
|
|
|
|
|
|
|
void GetType(nsAString& aOutType) const;
|
|
|
|
|
2013-12-17 18:12:33 +04:00
|
|
|
nsRange* GetRangeAt(uint32_t aIndex, mozilla::ErrorResult& aRv);
|
2020-03-13 18:46:13 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void AddRangeJS(nsRange& aRange,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2018-09-01 00:19:44 +03:00
|
|
|
|
2020-02-12 15:27:32 +03:00
|
|
|
/**
|
|
|
|
* Callers need to keep `aRange` alive.
|
|
|
|
*/
|
2020-03-06 15:03:23 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void RemoveRangeAndUnselectFramesAndNotifyListeners(
|
2019-07-02 17:17:05 +03:00
|
|
|
nsRange& aRange, mozilla::ErrorResult& aRv);
|
2018-09-01 00:19:44 +03:00
|
|
|
|
2021-02-04 00:52:48 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void RemoveAllRanges(mozilla::ErrorResult& aRv);
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2019-01-14 07:58:59 +03:00
|
|
|
/**
|
|
|
|
* Whether Stringify should flush layout or not.
|
|
|
|
*/
|
|
|
|
enum class FlushFrames { No, Yes };
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
void Stringify(nsAString& aResult, FlushFrames = FlushFrames::Yes);
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2018-05-08 20:52:42 +03:00
|
|
|
/**
|
|
|
|
* Indicates whether the node is part of the selection. If partlyContained
|
|
|
|
* is true, the function returns true when some part of the node
|
|
|
|
* is part of the selection. If partlyContained is false, the
|
|
|
|
* function only returns true when the entire node is part of the selection.
|
|
|
|
*/
|
2014-09-16 23:11:52 +04:00
|
|
|
bool ContainsNode(nsINode& aNode, bool aPartlyContained,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2016-09-30 16:36:10 +03:00
|
|
|
/**
|
|
|
|
* Check to see if the given point is contained within the selection area. In
|
|
|
|
* particular, this iterates through all the rects that make up the selection,
|
|
|
|
* not just the bounding box, and checks to see if the given point is
|
|
|
|
* contained in any one of them.
|
|
|
|
* @param aPoint The point to check, relative to the root frame.
|
|
|
|
*/
|
|
|
|
bool ContainsPoint(const nsPoint& aPoint);
|
|
|
|
|
2018-05-08 20:52:42 +03:00
|
|
|
/**
|
|
|
|
* Modifies the selection. Note that the parameters are case-insensitive.
|
|
|
|
*
|
|
|
|
* @param alter can be one of { "move", "extend" }
|
|
|
|
* - "move" collapses the selection to the end of the selection and
|
|
|
|
* applies the movement direction/granularity to the collapsed
|
|
|
|
* selection.
|
|
|
|
* - "extend" leaves the start of the selection unchanged, and applies
|
|
|
|
* movement direction/granularity to the end of the selection.
|
|
|
|
* @param direction can be one of { "forward", "backward", "left", "right" }
|
|
|
|
* @param granularity can be one of { "character", "word",
|
|
|
|
* "line", "lineboundary" }
|
|
|
|
*
|
|
|
|
* @throws NS_ERROR_NOT_IMPLEMENTED if the granularity is "sentence",
|
|
|
|
* "sentenceboundary", "paragraph", "paragraphboundary", or
|
|
|
|
* "documentboundary". Throws NS_ERROR_INVALID_ARG if alter, direction,
|
|
|
|
* or granularity has an unrecognized value.
|
|
|
|
*/
|
2020-10-17 01:22:48 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void Modify(const nsAString& aAlter,
|
|
|
|
const nsAString& aDirection,
|
|
|
|
const nsAString& aGranularity,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2019-03-26 13:06:00 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2017-03-10 10:55:12 +03:00
|
|
|
void SetBaseAndExtentJS(nsINode& aAnchorNode, uint32_t aAnchorOffset,
|
|
|
|
nsINode& aFocusNode, uint32_t aFocusOffset,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2016-12-19 18:48:37 +03:00
|
|
|
|
2013-12-17 18:12:33 +04:00
|
|
|
bool GetInterlinePosition(mozilla::ErrorResult& aRv);
|
|
|
|
void SetInterlinePosition(bool aValue, mozilla::ErrorResult& aRv);
|
|
|
|
|
2015-05-22 07:37:16 +03:00
|
|
|
Nullable<int16_t> GetCaretBidiLevel(mozilla::ErrorResult& aRv) const;
|
|
|
|
void SetCaretBidiLevel(const Nullable<int16_t>& aCaretBidiLevel,
|
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
|
2013-12-17 18:12:33 +04:00
|
|
|
void ToStringWithFormat(const nsAString& aFormatType, uint32_t aFlags,
|
|
|
|
int32_t aWrapColumn, nsAString& aReturn,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2018-05-08 20:52:37 +03:00
|
|
|
void AddSelectionListener(nsISelectionListener* aListener);
|
|
|
|
void RemoveSelectionListener(nsISelectionListener* aListener);
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2016-06-11 05:06:37 +03:00
|
|
|
RawSelectionType RawType() const {
|
|
|
|
return ToRawSelectionType(mSelectionType);
|
|
|
|
}
|
|
|
|
SelectionType Type() const { return mSelectionType; }
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2021-04-29 12:40:54 +03:00
|
|
|
/**
|
2021-05-20 12:03:29 +03:00
|
|
|
* See documentation of `GetRangesForInterval` in Selection.webidl.
|
|
|
|
*
|
2021-04-29 12:40:54 +03:00
|
|
|
* @param aReturn references, not copies, of the internal ranges.
|
|
|
|
*/
|
2013-12-17 18:12:33 +04:00
|
|
|
void GetRangesForInterval(nsINode& aBeginNode, int32_t aBeginOffset,
|
|
|
|
nsINode& aEndNode, int32_t aEndOffset,
|
|
|
|
bool aAllowAdjacent,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<nsRange>>& aReturn,
|
2013-12-17 18:12:33 +04:00
|
|
|
mozilla::ErrorResult& aRv);
|
2020-03-17 00:04:46 +03:00
|
|
|
|
|
|
|
MOZ_CAN_RUN_SCRIPT void ScrollIntoView(int16_t aRegion, bool aIsSynchronous,
|
|
|
|
WhereToScroll aVPercent,
|
|
|
|
WhereToScroll aHPercent,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2013-12-17 18:12:33 +04:00
|
|
|
|
2017-05-10 17:48:50 +03:00
|
|
|
void SetColors(const nsAString& aForeColor, const nsAString& aBackColor,
|
|
|
|
const nsAString& aAltForeColor, const nsAString& aAltBackColor,
|
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
|
|
|
|
void ResetColors(mozilla::ErrorResult& aRv);
|
|
|
|
|
2018-05-08 20:52:41 +03:00
|
|
|
/**
|
|
|
|
* Non-JS callers should use the following
|
|
|
|
* collapse/collapseToStart/extend/etc methods, instead of the *JS
|
|
|
|
* versions that bindings call.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Collapses the selection to a single point, at the specified offset
|
|
|
|
* in the given node. When the selection is collapsed, and the content
|
|
|
|
* is focused and editable, the caret will blink there.
|
|
|
|
* @param aContainer The given node where the selection will be set
|
2021-06-30 10:07:28 +03:00
|
|
|
* @param aOffset Where in given dom node to place the selection (the
|
2018-05-08 20:52:41 +03:00
|
|
|
* offset into the given node)
|
|
|
|
*/
|
2020-10-17 01:22:48 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void CollapseInLimiter(nsINode& aContainer,
|
|
|
|
uint32_t aOffset,
|
|
|
|
ErrorResult& aRv) {
|
2020-09-03 14:55:22 +03:00
|
|
|
CollapseInternal(InLimiter::eYes, RawRangeBoundary(&aContainer, aOffset),
|
|
|
|
aRv);
|
2017-11-07 09:29:15 +03:00
|
|
|
}
|
2018-09-01 00:19:44 +03:00
|
|
|
|
2020-09-03 14:55:22 +03:00
|
|
|
private:
|
|
|
|
enum class InLimiter {
|
|
|
|
// If eYes, the method may reset selection limiter and move focus if the
|
|
|
|
// given range is out of the limiter.
|
|
|
|
eYes,
|
|
|
|
// If eNo, the method won't reset selection limiter. So, if given range
|
|
|
|
// is out of bounds, the method may return error.
|
|
|
|
eNo,
|
|
|
|
};
|
2020-10-17 01:22:48 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2020-09-03 14:55:22 +03:00
|
|
|
void CollapseInternal(InLimiter aInLimiter, const RawRangeBoundary& aPoint,
|
|
|
|
ErrorResult& aRv);
|
2018-09-01 00:19:44 +03:00
|
|
|
|
2020-09-03 14:55:22 +03:00
|
|
|
public:
|
2018-05-08 20:52:41 +03:00
|
|
|
/**
|
|
|
|
* Collapses the whole selection to a single point at the start
|
|
|
|
* of the current selection (irrespective of direction). If content
|
|
|
|
* is focused and editable, the caret will blink there.
|
|
|
|
*/
|
2020-10-17 01:22:48 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void CollapseToStart(mozilla::ErrorResult& aRv);
|
2018-09-01 00:19:44 +03:00
|
|
|
|
2018-05-08 20:52:41 +03:00
|
|
|
/**
|
|
|
|
* Collapses the whole selection to a single point at the end
|
|
|
|
* of the current selection (irrespective of direction). If content
|
|
|
|
* is focused and editable, the caret will blink there.
|
|
|
|
*/
|
2020-10-17 01:22:48 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void CollapseToEnd(mozilla::ErrorResult& aRv);
|
2018-05-08 20:52:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extends the selection by moving the selection end to the specified node and
|
|
|
|
* offset, preserving the selection begin position. The new selection end
|
|
|
|
* result will always be from the anchorNode to the new focusNode, regardless
|
|
|
|
* of direction.
|
|
|
|
*
|
|
|
|
* @param aContainer The node where the selection will be extended to
|
|
|
|
* @param aOffset Where in aContainer to place the offset of the new
|
|
|
|
* selection end.
|
|
|
|
*/
|
2021-02-04 00:52:15 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void Extend(nsINode& aContainer, uint32_t aOffset,
|
|
|
|
ErrorResult& aRv);
|
2018-09-01 00:19:44 +03:00
|
|
|
|
2020-03-13 18:46:13 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void AddRangeAndSelectFramesAndNotifyListeners(
|
|
|
|
nsRange& aRange, mozilla::ErrorResult& aRv);
|
2018-09-01 00:19:44 +03:00
|
|
|
|
2018-05-08 20:52:42 +03:00
|
|
|
/**
|
|
|
|
* Adds all children of the specified node to the selection.
|
|
|
|
* @param aNode the parent of the children to be added to the selection.
|
|
|
|
*/
|
2021-02-04 00:52:22 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SelectAllChildren(nsINode& aNode,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2018-09-01 00:19:44 +03:00
|
|
|
|
2019-03-26 13:06:00 +03:00
|
|
|
/**
|
|
|
|
* SetStartAndEnd() removes all ranges and sets new range as given range.
|
|
|
|
* Different from SetBaseAndExtent(), this won't compare the DOM points of
|
|
|
|
* aStartRef and aEndRef for performance nor set direction to eDirPrevious.
|
|
|
|
* Note that this may reset the limiter and move focus. If you don't want
|
|
|
|
* that, use SetStartAndEndInLimiter() instead.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
void SetStartAndEnd(const RawRangeBoundary& aStartRef,
|
|
|
|
const RawRangeBoundary& aEndRef, ErrorResult& aRv) {
|
|
|
|
SetStartAndEndInternal(InLimiter::eNo, aStartRef, aEndRef, eDirNext, aRv);
|
|
|
|
}
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
void SetStartAndEnd(nsINode& aStartContainer, uint32_t aStartOffset,
|
|
|
|
nsINode& aEndContainer, uint32_t aEndOffset,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
SetStartAndEnd(RawRangeBoundary(&aStartContainer, aStartOffset),
|
|
|
|
RawRangeBoundary(&aEndContainer, aEndOffset), aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetStartAndEndInLimiter() is similar to SetStartAndEnd(), but this respects
|
|
|
|
* the selection limiter. If all or part of given range is not in the
|
|
|
|
* limiter, this returns error.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
void SetStartAndEndInLimiter(const RawRangeBoundary& aStartRef,
|
|
|
|
const RawRangeBoundary& aEndRef,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
SetStartAndEndInternal(InLimiter::eYes, aStartRef, aEndRef, eDirNext, aRv);
|
|
|
|
}
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
void SetStartAndEndInLimiter(nsINode& aStartContainer, uint32_t aStartOffset,
|
|
|
|
nsINode& aEndContainer, uint32_t aEndOffset,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
SetStartAndEndInLimiter(RawRangeBoundary(&aStartContainer, aStartOffset),
|
|
|
|
RawRangeBoundary(&aEndContainer, aEndOffset), aRv);
|
|
|
|
}
|
2021-06-12 14:04:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
Result<Ok, nsresult> SetStartAndEndInLimiter(
|
|
|
|
nsINode& aStartContainer, uint32_t aStartOffset, nsINode& aEndContainer,
|
|
|
|
uint32_t aEndOffset, nsDirection aDirection, int16_t aReason);
|
2019-03-26 13:06:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SetBaseAndExtent() is alternative of the JS API for internal use.
|
|
|
|
* Different from SetStartAndEnd(), this sets anchor and focus points as
|
|
|
|
* specified, then if anchor point is after focus node, this sets the
|
|
|
|
* direction to eDirPrevious.
|
|
|
|
* Note that this may reset the limiter and move focus. If you don't want
|
|
|
|
* that, use SetBaseAndExtentInLimier() instead.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2017-03-10 10:55:12 +03:00
|
|
|
void SetBaseAndExtent(nsINode& aAnchorNode, uint32_t aAnchorOffset,
|
|
|
|
nsINode& aFocusNode, uint32_t aFocusOffset,
|
2019-12-16 14:31:37 +03:00
|
|
|
ErrorResult& aRv);
|
2019-03-26 13:06:00 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
void SetBaseAndExtent(const RawRangeBoundary& aAnchorRef,
|
|
|
|
const RawRangeBoundary& aFocusRef, ErrorResult& aRv) {
|
|
|
|
SetBaseAndExtentInternal(InLimiter::eNo, aAnchorRef, aFocusRef, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-03 14:55:22 +03:00
|
|
|
* SetBaseAndExtentInLimiter() is similar to SetBaseAndExtent(), but this
|
2019-03-26 13:06:00 +03:00
|
|
|
* respects the selection limiter. If all or part of given range is not in
|
|
|
|
* the limiter, this returns error.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
void SetBaseAndExtentInLimiter(nsINode& aAnchorNode, uint32_t aAnchorOffset,
|
|
|
|
nsINode& aFocusNode, uint32_t aFocusOffset,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
SetBaseAndExtentInLimiter(RawRangeBoundary(&aAnchorNode, aAnchorOffset),
|
|
|
|
RawRangeBoundary(&aFocusNode, aFocusOffset), aRv);
|
|
|
|
}
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
void SetBaseAndExtentInLimiter(const RawRangeBoundary& aAnchorRef,
|
|
|
|
const RawRangeBoundary& aFocusRef,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
SetBaseAndExtentInternal(InLimiter::eYes, aAnchorRef, aFocusRef, aRv);
|
|
|
|
}
|
2017-03-10 10:55:12 +03:00
|
|
|
|
2015-08-12 20:26:01 +03:00
|
|
|
void AddSelectionChangeBlocker();
|
|
|
|
void RemoveSelectionChangeBlocker();
|
|
|
|
bool IsBlockingSelectionChangeEvents() const;
|
2017-08-24 10:56:12 +03:00
|
|
|
|
Bug 1506547 - Align user-select behavior more with other UAs. r=mats
There's a few subtle behavior changes here, which I'll try to break down in the
commit message.
The biggest one is the EditableDescendantCount stuff going away. This
was added in bug 1181130, to prevent clicking on the non-editable div from
selecting the editable div inside. This is problematic for multiple reasons:
* First, I don't think non-editable regions of an editable element should
be user-select: all.
* Second, it just doesn't work in Shadow DOM (the editable descendant count is
not kept up-to-date when not in the uncomposed doc), so nested
contenteditables behave differently inside vs. outside a Shadow Tree.
* Third, I think it's user hostile to just entirely disable selection if you
have a contenteditable descendant as a child of a user-select: all thing.
WebKit behaves like this patch in the following test-case (though not Blink):
https://crisal.io/tmp/user-select-all-contenteditable-descendant.html
Edge doesn't seem to support user-select: all at all (no pun intended).
But we don't allow to select anything at all which looks wrong.
* Fourth, it's not tested at all (which explains how we broke it in Shadow DOM
and not even notice...).
In any case I've verified that this doesn't regress the editor from that bug. If
this regresses anything we can fix it as outlined in the first bullet point
above, which should also make us more compatible with other UAs in that
test-case.
The other change is `all` not overriding everything else. So, something like:
<div style="-webkit-user-select: all">All <div style="-webkit-user-select: none">None</div></div>
Totally ignores the -webkit-user-select: none declaration in Firefox before this
change. This doesn't match any other UA nor the spec, and this patch aligns us
with WebKit / Blink.
This in turn makes us not need -moz-text anymore, whose only purpose was to
avoid this.
This also fixes a variety of bugs uncovered by the previous changes, like the
SetIgnoreUserModify(false) call in editor being completely useless, since
presShell->SetCaretEnabled ended in nsCaret::SetVisible, which overrode it.
This in turn uncovered even more bugs, from bugs in the caret painting code,
like not checking -moz-user-modify on the right frame if you're the last frame
of a line, to even funnier bits where before this patch you show the caret but
can't write at all...
In any case, the new setup I came up with is that when you're editing (the
selection is focused on an editable node) moving the caret forces it to end up
in an editable node, thus jumping over non-editable ones.
This has the nice effect of not completely disabling selection of
-moz-user-select: all elements that have editable descendants (which was a very
ad-hoc hack for bug 1181130, and somewhat broken per the above), and also
not needing the -moz-user-select: all for non-editable bits in contenteditable.css
at all.
This also fixes issues with br-skipping like not being able to insert content in
the following test-case:
<div contenteditable="true"><span contenteditable="false">xyz </span><br>editable</div>
If you start moving to the left from the second line, for example.
I think this yields way better behavior in all the relevant test-cases from bug
1181130 / bug 1109968 / bug 1132768, shouldn't cause any regression, and the
complexity is significantly reduced in some places.
There's still some other broken bits that this patch doesn't fix, but I'll file
follow-ups for those.
Differential Revision: https://phabricator.services.mozilla.com/D12687
--HG--
extra : moz-landing-system : lando
2018-11-26 12:21:37 +03:00
|
|
|
// Whether this selection is focused in an editable element.
|
|
|
|
bool IsEditorSelection() const;
|
|
|
|
|
2017-08-24 10:56:12 +03:00
|
|
|
/**
|
|
|
|
* Set the painting style for the range. The range must be a range in
|
|
|
|
* the selection. The textRangeStyle will be used by text frame
|
|
|
|
* when it is painting the selection.
|
|
|
|
*/
|
|
|
|
nsresult SetTextRangeStyle(nsRange* aRange,
|
|
|
|
const TextRangeStyle& aTextRangeStyle);
|
|
|
|
|
2018-05-08 20:52:37 +03:00
|
|
|
// Methods to manipulate our mFrameSelection's ancestor limiter.
|
|
|
|
nsIContent* GetAncestorLimiter() const;
|
|
|
|
void SetAncestorLimiter(nsIContent* aLimiter);
|
|
|
|
|
2018-05-08 20:52:37 +03:00
|
|
|
/*
|
|
|
|
* Frame Offset cache can be used just during calling
|
|
|
|
* nsEditor::EndPlaceHolderTransaction. EndPlaceHolderTransaction will give
|
|
|
|
* rise to reflow/refreshing view/scroll, and call times of
|
|
|
|
* nsTextFrame::GetPointFromOffset whose return value is to be cached. see
|
|
|
|
* bugs 35296 and 199412
|
|
|
|
*/
|
|
|
|
void SetCanCacheFrameOffset(bool aCanCacheFrameOffset);
|
|
|
|
|
2018-05-08 20:52:38 +03:00
|
|
|
// Selection::GetRangesForIntervalArray
|
|
|
|
//
|
|
|
|
// Fills a nsTArray with the ranges overlapping the range specified by
|
|
|
|
// the given endpoints. Ranges in the selection exactly adjacent to the
|
|
|
|
// input range are not returned unless aAllowAdjacent is set.
|
|
|
|
//
|
|
|
|
// For example, if the following ranges were in the selection
|
|
|
|
// (assume everything is within the same node)
|
|
|
|
//
|
|
|
|
// Start Offset: 0 2 7 9
|
|
|
|
// End Offset: 2 5 9 10
|
|
|
|
//
|
|
|
|
// and passed aBeginOffset of 2 and aEndOffset of 9, then with
|
|
|
|
// aAllowAdjacent set, all the ranges should be returned. If
|
|
|
|
// aAllowAdjacent was false, the ranges [2, 5] and [7, 9] only
|
|
|
|
// should be returned
|
|
|
|
//
|
|
|
|
// Now that overlapping ranges are disallowed, there can be a maximum of
|
|
|
|
// 2 adjacent ranges
|
|
|
|
nsresult GetRangesForIntervalArray(nsINode* aBeginNode, int32_t aBeginOffset,
|
|
|
|
nsINode* aEndNode, int32_t aEndOffset,
|
|
|
|
bool aAllowAdjacent,
|
|
|
|
nsTArray<nsRange*>* aRanges);
|
|
|
|
|
2018-05-08 20:52:38 +03:00
|
|
|
/**
|
|
|
|
* Modifies the cursor Bidi level after a change in keyboard direction
|
|
|
|
* @param langRTL is true if the new language is right-to-left or
|
|
|
|
* false if the new language is left-to-right.
|
|
|
|
*/
|
|
|
|
nsresult SelectionLanguageChange(bool aLangRTL);
|
|
|
|
|
2012-04-07 01:54:38 +04:00
|
|
|
private:
|
2019-07-01 18:20:28 +03:00
|
|
|
bool HasSameRootOrSameComposedDoc(const nsINode& aNode);
|
2017-08-10 15:02:08 +03:00
|
|
|
|
2017-02-25 13:33:34 +03:00
|
|
|
// XXX Please don't add additional uses of this method, it's only for
|
|
|
|
// XXX supporting broken code (bug 1245883) in the following classes:
|
|
|
|
friend class ::nsCopySupport;
|
|
|
|
friend class ::nsHTMLCopyEncoder;
|
2018-09-01 00:19:44 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-07-02 16:08:57 +03:00
|
|
|
void AddRangeAndSelectFramesAndNotifyListeners(nsRange& aRange,
|
|
|
|
Document* aDocument,
|
|
|
|
ErrorResult&);
|
2017-02-25 13:33:34 +03:00
|
|
|
|
2017-08-23 13:09:07 +03:00
|
|
|
// This is helper method for GetPrimaryFrameForFocusNode.
|
|
|
|
// If aVisual is true, this returns caret frame.
|
|
|
|
// If false, this returns primary frame.
|
2020-06-18 13:26:47 +03:00
|
|
|
nsIFrame* GetPrimaryOrCaretFrameForNodeOffset(nsIContent* aContent,
|
|
|
|
uint32_t aOffset,
|
|
|
|
int32_t* aOffsetUsed,
|
|
|
|
bool aVisual) const;
|
2017-08-23 13:09:07 +03:00
|
|
|
|
2018-05-08 20:52:37 +03:00
|
|
|
// Get the cached value for nsTextFrame::GetPointFromOffset.
|
|
|
|
nsresult GetCachedFrameOffset(nsIFrame* aFrame, int32_t inOffset,
|
|
|
|
nsPoint& aPoint);
|
|
|
|
|
2019-03-26 13:06:00 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
void SetStartAndEndInternal(InLimiter aInLimiter,
|
|
|
|
const RawRangeBoundary& aStartRef,
|
|
|
|
const RawRangeBoundary& aEndRef,
|
|
|
|
nsDirection aDirection, ErrorResult& aRv);
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
void SetBaseAndExtentInternal(InLimiter aInLimiter,
|
|
|
|
const RawRangeBoundary& aAnchorRef,
|
|
|
|
const RawRangeBoundary& aFocusRef,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2012-04-07 01:54:38 +04:00
|
|
|
public:
|
2016-06-11 05:06:37 +03:00
|
|
|
SelectionType GetType() const { return mSelectionType; }
|
2012-04-07 01:54:38 +04:00
|
|
|
|
2017-05-10 17:48:50 +03:00
|
|
|
SelectionCustomColors* GetCustomColors() const { return mCustomColors.get(); }
|
|
|
|
|
2021-06-11 12:10:35 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void NotifySelectionListeners(bool aCalledByJS);
|
|
|
|
MOZ_CAN_RUN_SCRIPT void NotifySelectionListeners();
|
2012-04-07 01:54:38 +04:00
|
|
|
|
2015-09-22 20:24:50 +03:00
|
|
|
friend struct AutoUserInitiated;
|
|
|
|
struct MOZ_RAII AutoUserInitiated {
|
2021-04-08 04:31:54 +03:00
|
|
|
explicit AutoUserInitiated(Selection& aSelectionRef)
|
|
|
|
: AutoUserInitiated(&aSelectionRef) {}
|
2020-07-30 17:22:38 +03:00
|
|
|
explicit AutoUserInitiated(Selection* aSelection)
|
2015-09-22 20:24:50 +03:00
|
|
|
: mSavedValue(aSelection->mUserInitiated) {
|
|
|
|
aSelection->mUserInitiated = true;
|
2014-09-10 21:07:36 +04:00
|
|
|
}
|
|
|
|
AutoRestore<bool> mSavedValue;
|
|
|
|
};
|
2015-08-12 20:26:01 +03:00
|
|
|
|
2012-04-07 01:54:38 +04:00
|
|
|
private:
|
2015-02-21 07:27:59 +03:00
|
|
|
friend struct mozilla::AutoPrepareFocusRange;
|
2012-04-07 01:54:38 +04:00
|
|
|
class ScrollSelectionIntoViewEvent;
|
|
|
|
friend class ScrollSelectionIntoViewEvent;
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class ScrollSelectionIntoViewEvent : public Runnable {
|
2012-04-07 01:54:38 +04:00
|
|
|
public:
|
2020-03-17 00:04:46 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_DECL_NSIRUNNABLE
|
|
|
|
|
2012-06-08 18:20:55 +04:00
|
|
|
ScrollSelectionIntoViewEvent(Selection* aSelection, SelectionRegion aRegion,
|
2019-04-30 03:07:49 +03:00
|
|
|
ScrollAxis aVertical, ScrollAxis aHorizontal,
|
2012-10-07 22:45:51 +04:00
|
|
|
int32_t aFlags)
|
2017-06-12 22:34:10 +03:00
|
|
|
: Runnable("dom::Selection::ScrollSelectionIntoViewEvent"),
|
|
|
|
mSelection(aSelection),
|
|
|
|
mRegion(aRegion),
|
|
|
|
mVerticalScroll(aVertical),
|
|
|
|
mHorizontalScroll(aHorizontal),
|
|
|
|
mFlags(aFlags) {
|
2012-06-08 18:20:55 +04:00
|
|
|
NS_ASSERTION(aSelection, "null parameter");
|
2012-04-07 01:54:38 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
void Revoke() { mSelection = nullptr; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-07 01:54:38 +04:00
|
|
|
private:
|
2012-06-08 18:20:55 +04:00
|
|
|
Selection* mSelection;
|
2012-04-07 01:54:38 +04:00
|
|
|
SelectionRegion mRegion;
|
2019-04-30 03:07:49 +03:00
|
|
|
ScrollAxis mVerticalScroll;
|
|
|
|
ScrollAxis mHorizontalScroll;
|
2012-10-07 22:45:51 +04:00
|
|
|
int32_t mFlags;
|
2012-04-07 01:54:38 +04:00
|
|
|
};
|
|
|
|
|
2017-05-30 07:26:09 +03:00
|
|
|
/**
|
2020-03-27 14:21:25 +03:00
|
|
|
* Set mAnchorFocusRange to mStyledRanges.mRanges[aIndex] if aIndex is a valid
|
|
|
|
* index. Set mAnchorFocusRange to nullptr if aIndex is negative. Otherwise,
|
|
|
|
* i.e., if aIndex is positive but out of bounds of mStyledRanges.mRanges, do
|
2017-05-30 07:26:09 +03:00
|
|
|
* nothing.
|
|
|
|
*/
|
|
|
|
void SetAnchorFocusRange(int32_t aIndex);
|
2020-01-21 19:02:20 +03:00
|
|
|
void SelectFramesOf(nsIContent* aContent, bool aSelected) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* https://dom.spec.whatwg.org/#concept-tree-inclusive-descendant.
|
|
|
|
*/
|
|
|
|
nsresult SelectFramesOfInclusiveDescendantsOfContent(
|
|
|
|
PostContentIterator& aPostOrderIter, nsIContent* aContent,
|
|
|
|
bool aSelected) const;
|
|
|
|
|
2017-05-29 06:27:09 +03:00
|
|
|
nsresult SelectFrames(nsPresContext* aPresContext, nsRange* aRange,
|
2020-02-12 15:27:32 +03:00
|
|
|
bool aSelect) const;
|
2018-05-08 20:52:36 +03:00
|
|
|
|
2019-03-26 13:16:20 +03:00
|
|
|
/**
|
|
|
|
* SelectFramesInAllRanges() calls SelectFrames() for all current
|
|
|
|
* ranges.
|
|
|
|
*/
|
|
|
|
void SelectFramesInAllRanges(nsPresContext* aPresContext);
|
|
|
|
|
2020-01-20 15:39:33 +03:00
|
|
|
/**
|
2020-03-27 14:21:25 +03:00
|
|
|
* @param aOutIndex points to the index of the range in mStyledRanges.mRanges.
|
2020-05-04 13:11:13 +03:00
|
|
|
* If aDidAddRange is true, it is in [0, mStyledRanges.Length()).
|
2020-01-20 15:39:33 +03:00
|
|
|
*/
|
2020-03-03 16:42:56 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult MaybeAddTableCellRange(nsRange& aRange,
|
|
|
|
bool* aDidAddRange,
|
|
|
|
int32_t* aOutIndex);
|
2012-04-07 01:54:38 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* GetDocument() const;
|
2017-03-14 04:36:21 +03:00
|
|
|
|
2018-12-13 16:07:19 +03:00
|
|
|
void Disconnect();
|
|
|
|
|
2020-03-27 14:21:25 +03:00
|
|
|
struct StyledRanges {
|
2020-05-04 13:11:13 +03:00
|
|
|
void Clear();
|
|
|
|
|
2020-03-27 14:05:48 +03:00
|
|
|
StyledRange* FindRangeData(nsRange* aRange);
|
|
|
|
|
2020-05-04 13:11:13 +03:00
|
|
|
using Elements = AutoTArray<StyledRange, 1>;
|
|
|
|
|
|
|
|
Elements::size_type Length() const;
|
|
|
|
|
2020-05-04 13:11:13 +03:00
|
|
|
nsresult RemoveCollapsedRanges();
|
|
|
|
|
2020-03-27 14:02:37 +03:00
|
|
|
nsresult RemoveRangeAndUnregisterSelection(nsRange& aRange);
|
|
|
|
|
2020-03-27 14:25:16 +03:00
|
|
|
/**
|
|
|
|
* Binary searches the given sorted array of ranges for the insertion point
|
|
|
|
* for the given node/offset. The given comparator is used, and the index
|
|
|
|
* where the point should appear in the array is returned.
|
|
|
|
|
|
|
|
* If there is an item in the array equal to the input point (aPointNode,
|
|
|
|
* aPointOffset), we will return the index of this item.
|
|
|
|
*
|
|
|
|
* @return the index where the point should appear in the array. In
|
|
|
|
* [0, `aElementArray->Length()`].
|
|
|
|
*/
|
|
|
|
static int32_t FindInsertionPoint(
|
|
|
|
const nsTArray<StyledRange>* aElementArray, const nsINode& aPointNode,
|
|
|
|
int32_t aPointOffset,
|
|
|
|
int32_t (*aComparator)(const nsINode&, int32_t, const nsRange&));
|
|
|
|
|
2020-03-27 14:19:50 +03:00
|
|
|
/**
|
|
|
|
* Works on the same principle as GetRangesForIntervalArray, however
|
|
|
|
* instead this returns the indices into mRanges between which
|
|
|
|
* the overlapping ranges lie.
|
|
|
|
*
|
|
|
|
* @param aStartIndex will be less or equal than aEndIndex.
|
|
|
|
* @param aEndIndex can be in [-1, mRanges.Length()].
|
|
|
|
*/
|
|
|
|
nsresult GetIndicesForInterval(const nsINode* aBeginNode,
|
|
|
|
int32_t aBeginOffset,
|
|
|
|
const nsINode* aEndNode, int32_t aEndOffset,
|
|
|
|
bool aAllowAdjacent, int32_t& aStartIndex,
|
|
|
|
int32_t& aEndIndex) const;
|
|
|
|
|
2020-03-27 14:03:57 +03:00
|
|
|
bool HasEqualRangeBoundariesAt(const nsRange& aRange,
|
|
|
|
int32_t aRangeIndex) const;
|
|
|
|
|
2020-03-27 14:26:25 +03:00
|
|
|
/**
|
|
|
|
* Preserves the sorting and disjunctiveness of mRanges.
|
|
|
|
*
|
|
|
|
* @param aOutIndex will point to the index of the added range, or if aRange
|
|
|
|
* is already contained, to the one containing it. Hence
|
|
|
|
* it'll always be in [0, mRanges.Length()).
|
|
|
|
*/
|
2020-04-01 14:42:16 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult MaybeAddRangeAndTruncateOverlaps(
|
2020-03-27 14:26:25 +03:00
|
|
|
nsRange* aRange, int32_t* aOutIndex, Selection& aSelection);
|
|
|
|
|
2020-03-27 14:05:43 +03:00
|
|
|
/**
|
2020-03-31 11:21:39 +03:00
|
|
|
* GetCommonEditingHost() returns common editing host of all
|
2020-03-27 14:05:43 +03:00
|
|
|
* ranges if there is. If at least one of the ranges is in non-editable
|
|
|
|
* element, returns nullptr. See following examples for the detail:
|
|
|
|
*
|
|
|
|
* <div id="a" contenteditable>
|
|
|
|
* an[cestor
|
|
|
|
* <div id="b" contenteditable="false">
|
|
|
|
* non-editable
|
|
|
|
* <div id="c" contenteditable>
|
|
|
|
* desc]endant
|
|
|
|
* in this case, this returns div#a because div#c is also in div#a.
|
|
|
|
*
|
|
|
|
* <div id="a" contenteditable>
|
|
|
|
* an[ce]stor
|
|
|
|
* <div id="b" contenteditable="false">
|
|
|
|
* non-editable
|
|
|
|
* <div id="c" contenteditable>
|
|
|
|
* de[sc]endant
|
|
|
|
* in this case, this returns div#a because second range is also in div#a
|
|
|
|
* and common ancestor of the range (i.e., div#c) is editable.
|
|
|
|
*
|
|
|
|
* <div id="a" contenteditable>
|
|
|
|
* an[ce]stor
|
|
|
|
* <div id="b" contenteditable="false">
|
|
|
|
* [non]-editable
|
|
|
|
* <div id="c" contenteditable>
|
|
|
|
* de[sc]endant
|
|
|
|
* in this case, this returns nullptr because the second range is in
|
|
|
|
* non-editable area.
|
|
|
|
*/
|
2020-03-31 11:21:39 +03:00
|
|
|
Element* GetCommonEditingHost() const;
|
|
|
|
|
2021-02-04 00:52:02 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void MaybeFocusCommonEditingHost(
|
2020-12-04 01:08:36 +03:00
|
|
|
PresShell* aPresShell) const;
|
2020-03-27 14:05:43 +03:00
|
|
|
|
2020-04-27 22:26:25 +03:00
|
|
|
static nsresult SubtractRange(StyledRange& aRange, nsRange& aSubtract,
|
|
|
|
nsTArray<StyledRange>* aOutput);
|
|
|
|
|
2020-05-04 13:11:13 +03:00
|
|
|
void UnregisterSelection();
|
|
|
|
|
2020-03-27 14:21:25 +03:00
|
|
|
// These are the ranges inside this selection. They are kept sorted in order
|
|
|
|
// of DOM start position.
|
|
|
|
//
|
|
|
|
// This data structure is sorted by the range beginnings. As the ranges are
|
|
|
|
// disjoint, it is also implicitly sorted by the range endings. This allows
|
|
|
|
// us to perform binary searches when searching for existence of a range,
|
|
|
|
// giving us O(log n) search time.
|
|
|
|
//
|
|
|
|
// Inserting a new range requires finding the overlapping interval,
|
|
|
|
// requiring two binary searches plus up to an additional 6 DOM comparisons.
|
|
|
|
// If this proves to be a performance concern, then an interval tree may be
|
|
|
|
// a possible solution, allowing the calculation of the overlap interval in
|
|
|
|
// O(log n) time, though this would require rebalancing and other overhead.
|
2020-05-04 13:11:13 +03:00
|
|
|
Elements mRanges;
|
2020-03-27 14:21:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
StyledRanges mStyledRanges;
|
2012-04-07 01:54:38 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsRange> mAnchorFocusRange;
|
|
|
|
RefPtr<nsFrameSelection> mFrameSelection;
|
2018-09-01 00:19:44 +03:00
|
|
|
RefPtr<AccessibleCaretEventHub> mAccessibleCaretEventHub;
|
2018-09-04 14:18:03 +03:00
|
|
|
RefPtr<SelectionChangeEventDispatcher> mSelectionChangeEventDispatcher;
|
2020-05-11 12:38:00 +03:00
|
|
|
RefPtr<AutoScroller> mAutoScroller;
|
2018-05-08 20:52:37 +03:00
|
|
|
nsTArray<nsCOMPtr<nsISelectionListener>> mSelectionListeners;
|
2012-04-07 01:54:38 +04:00
|
|
|
nsRevocableEventPtr<ScrollSelectionIntoViewEvent> mScrollEvent;
|
2017-05-10 17:48:50 +03:00
|
|
|
CachedOffsetForFrame* mCachedOffsetForFrame;
|
2012-04-07 01:54:38 +04:00
|
|
|
nsDirection mDirection;
|
2020-03-19 12:25:02 +03:00
|
|
|
const SelectionType mSelectionType;
|
2017-05-10 17:48:50 +03:00
|
|
|
UniquePtr<SelectionCustomColors> mCustomColors;
|
|
|
|
|
2018-08-30 10:36:23 +03:00
|
|
|
// Non-zero if we don't want any changes we make to the selection to be
|
|
|
|
// visible to content. If non-zero, content won't be notified about changes.
|
|
|
|
uint32_t mSelectionChangeBlockerCount;
|
|
|
|
|
2014-09-10 21:07:36 +04:00
|
|
|
/**
|
|
|
|
* True if the current selection operation was initiated by user action.
|
2015-08-12 20:26:01 +03:00
|
|
|
* It determines whether we exclude -moz-user-select:none nodes or not,
|
|
|
|
* as well as whether selectstart events will be fired.
|
2014-09-10 21:07:36 +04:00
|
|
|
*/
|
2015-09-22 20:24:50 +03:00
|
|
|
bool mUserInitiated;
|
2015-08-12 20:26:01 +03:00
|
|
|
|
2017-03-10 10:55:12 +03:00
|
|
|
/**
|
|
|
|
* When the selection change is caused by a call of Selection API,
|
|
|
|
* mCalledByJS is true. Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool mCalledByJS;
|
|
|
|
|
2018-08-30 10:36:23 +03:00
|
|
|
/**
|
|
|
|
* true if AutoCopyListner::OnSelectionChange() should be called.
|
|
|
|
*/
|
|
|
|
bool mNotifyAutoCopy;
|
2012-04-07 01:54:38 +04:00
|
|
|
};
|
|
|
|
|
2015-02-04 23:34:00 +03:00
|
|
|
// Stack-class to turn on/off selection batching.
|
2015-03-21 19:28:04 +03:00
|
|
|
class MOZ_STACK_CLASS SelectionBatcher final {
|
2015-02-04 23:34:00 +03:00
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Selection> mSelection;
|
2021-06-21 03:58:35 +03:00
|
|
|
int16_t mReason;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-02-04 23:34:00 +03:00
|
|
|
public:
|
2021-04-08 04:31:54 +03:00
|
|
|
explicit SelectionBatcher(Selection& aSelectionRef)
|
|
|
|
: SelectionBatcher(&aSelectionRef) {}
|
2021-06-21 03:58:35 +03:00
|
|
|
explicit SelectionBatcher(Selection* aSelection,
|
|
|
|
int16_t aReason = nsISelectionListener::NO_REASON) {
|
2015-02-04 23:34:00 +03:00
|
|
|
mSelection = aSelection;
|
2021-06-21 03:58:35 +03:00
|
|
|
mReason = aReason;
|
2015-02-04 23:34:00 +03:00
|
|
|
if (mSelection) {
|
|
|
|
mSelection->StartBatchChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~SelectionBatcher() {
|
|
|
|
if (mSelection) {
|
2021-06-21 03:58:35 +03:00
|
|
|
mSelection->EndBatchChanges(mReason);
|
2015-02-04 23:34:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-28 15:34:26 +03:00
|
|
|
class MOZ_RAII AutoHideSelectionChanges final {
|
2015-08-12 20:26:01 +03:00
|
|
|
public:
|
|
|
|
explicit AutoHideSelectionChanges(const nsFrameSelection* aFrame);
|
|
|
|
|
2021-04-08 04:31:54 +03:00
|
|
|
explicit AutoHideSelectionChanges(Selection& aSelectionRef)
|
|
|
|
: AutoHideSelectionChanges(&aSelectionRef) {}
|
|
|
|
|
|
|
|
~AutoHideSelectionChanges() {
|
2015-08-12 20:26:01 +03:00
|
|
|
if (mSelection) {
|
2021-04-08 04:31:54 +03:00
|
|
|
mSelection->RemoveSelectionChangeBlocker();
|
2015-08-12 20:26:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-08 04:31:54 +03:00
|
|
|
private:
|
|
|
|
explicit AutoHideSelectionChanges(Selection* aSelection)
|
|
|
|
: mSelection(aSelection) {
|
2015-08-12 20:26:01 +03:00
|
|
|
if (mSelection) {
|
2021-04-08 04:31:54 +03:00
|
|
|
mSelection->AddSelectionChangeBlocker();
|
2015-08-12 20:26:01 +03:00
|
|
|
}
|
|
|
|
}
|
2021-04-08 04:31:54 +03:00
|
|
|
|
|
|
|
RefPtr<Selection> mSelection;
|
2015-08-12 20:26:01 +03:00
|
|
|
};
|
|
|
|
|
2014-04-10 20:09:40 +04:00
|
|
|
} // namespace dom
|
2017-08-02 00:19:19 +03:00
|
|
|
|
2017-08-24 13:14:04 +03:00
|
|
|
inline bool IsValidRawSelectionType(RawSelectionType aRawSelectionType) {
|
|
|
|
return aRawSelectionType >= nsISelectionController::SELECTION_NONE &&
|
|
|
|
aRawSelectionType <= nsISelectionController::SELECTION_URLSTRIKEOUT;
|
2017-08-02 00:19:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline SelectionType ToSelectionType(RawSelectionType aRawSelectionType) {
|
2017-08-24 13:14:04 +03:00
|
|
|
if (!IsValidRawSelectionType(aRawSelectionType)) {
|
2017-08-02 00:19:19 +03:00
|
|
|
return SelectionType::eInvalid;
|
|
|
|
}
|
|
|
|
return static_cast<SelectionType>(aRawSelectionType);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline RawSelectionType ToRawSelectionType(SelectionType aSelectionType) {
|
2017-08-24 13:14:04 +03:00
|
|
|
MOZ_ASSERT(aSelectionType != SelectionType::eInvalid);
|
2017-08-02 00:19:19 +03:00
|
|
|
return static_cast<RawSelectionType>(aSelectionType);
|
|
|
|
}
|
|
|
|
|
2017-08-24 13:14:04 +03:00
|
|
|
inline RawSelectionType ToRawSelectionType(TextRangeType aTextRangeType) {
|
2017-08-02 00:19:19 +03:00
|
|
|
return ToRawSelectionType(ToSelectionType(aTextRangeType));
|
|
|
|
}
|
|
|
|
|
2017-08-24 13:14:04 +03:00
|
|
|
inline SelectionTypeMask ToSelectionTypeMask(SelectionType aSelectionType) {
|
|
|
|
MOZ_ASSERT(aSelectionType != SelectionType::eInvalid);
|
|
|
|
return aSelectionType == SelectionType::eNone
|
|
|
|
? 0
|
2019-04-02 20:00:45 +03:00
|
|
|
: static_cast<SelectionTypeMask>(
|
|
|
|
1 << (static_cast<uint8_t>(aSelectionType) - 1));
|
2017-08-02 00:19:19 +03:00
|
|
|
}
|
|
|
|
|
2012-06-08 18:20:55 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_Selection_h__
|