2017-10-27 20:33:53 +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: */
|
2017-06-19 01:07:36 +03: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/. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of nsFrameSelection
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsFrameSelection.h"
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/AutoRestore.h"
|
|
|
|
#include "mozilla/EventStates.h"
|
2017-08-07 10:33:59 +03:00
|
|
|
#include "mozilla/HTMLEditor.h"
|
2017-08-02 04:18:23 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsISelectionListener.h"
|
|
|
|
#include "nsContentCID.h"
|
|
|
|
#include "nsDeviceContext.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsRange.h"
|
|
|
|
#include "nsITableCellLayout.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsTableWrapperFrame.h"
|
|
|
|
#include "nsTableCellFrame.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsCCUncollectableMarker.h"
|
|
|
|
#include "nsIDocumentEncoder.h"
|
|
|
|
#include "nsTextFragment.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include "nsContentUtils.h"
|
2018-03-06 12:25:52 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIFrameTraversal.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsLayoutCID.h"
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID);
|
|
|
|
#include "nsTextFrame.h"
|
|
|
|
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2017-06-19 01:07:36 +03:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsCaret.h"
|
|
|
|
|
|
|
|
#include "mozilla/MouseEvents.h"
|
|
|
|
#include "mozilla/TextEvents.h"
|
|
|
|
|
|
|
|
#include "nsITimer.h"
|
|
|
|
// notifications
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2017-06-19 01:07:36 +03:00
|
|
|
|
2017-11-13 12:54:18 +03:00
|
|
|
#include "nsISelectionController.h" //for the enums
|
2017-06-19 01:07:36 +03:00
|
|
|
#include "nsCopySupport.h"
|
|
|
|
#include "nsIClipboard.h"
|
|
|
|
#include "nsIFrameInlines.h"
|
|
|
|
|
|
|
|
#include "nsIBidiKeyboard.h"
|
|
|
|
|
|
|
|
#include "nsError.h"
|
2018-08-30 10:36:23 +03:00
|
|
|
#include "mozilla/AutoCopyListener.h"
|
2017-06-19 01:07:36 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/Selection.h"
|
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2018-03-19 22:15:39 +03:00
|
|
|
#include "mozilla/dom/Text.h"
|
2017-06-19 01:07:36 +03:00
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/SelectionBinding.h"
|
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
|
|
|
|
#include "nsFocusManager.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
//#define DEBUG_TABLE 1
|
|
|
|
|
|
|
|
static bool IsValidSelectionPoint(nsFrameSelection* aFrameSel, nsINode* aNode);
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
static nsAtom* GetTag(nsINode* aNode);
|
2017-06-19 01:07:36 +03:00
|
|
|
// returns the parent
|
|
|
|
static nsINode* ParentOffset(nsINode* aNode, int32_t* aChildOffset);
|
|
|
|
static nsINode* GetCellParent(nsINode* aDomNode);
|
|
|
|
|
|
|
|
#ifdef PRINT_RANGE
|
|
|
|
static void printRange(nsRange* aDomRange);
|
|
|
|
# define DEBUG_OUT_RANGE(x) printRange(x)
|
|
|
|
#else
|
2017-07-06 15:00:35 +03:00
|
|
|
# define DEBUG_OUT_RANGE(x)
|
2017-06-19 01:07:36 +03:00
|
|
|
#endif // PRINT_RANGE
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* nsPeekOffsetStruct
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
//#define DEBUG_SELECTION // uncomment for printf describing every collapse and
|
|
|
|
// extend. #define DEBUG_NAVIGATION
|
|
|
|
|
|
|
|
//#define DEBUG_TABLE_SELECTION 1
|
|
|
|
|
|
|
|
nsPeekOffsetStruct::nsPeekOffsetStruct(
|
|
|
|
nsSelectionAmount aAmount, nsDirection aDirection, int32_t aStartOffset,
|
|
|
|
nsPoint aDesiredPos, bool aJumpLines, bool aScrollViewStop,
|
|
|
|
bool aIsKeyboardSelect, bool aVisual, bool aExtend,
|
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
|
|
|
ForceEditableRegion aForceEditableRegion,
|
2019-02-23 00:12:48 +03:00
|
|
|
EWordMovementType aWordMovementType, bool aTrimSpaces)
|
2017-06-19 01:07:36 +03:00
|
|
|
: mAmount(aAmount),
|
|
|
|
mDirection(aDirection),
|
|
|
|
mStartOffset(aStartOffset),
|
|
|
|
mDesiredPos(aDesiredPos),
|
|
|
|
mWordMovementType(aWordMovementType),
|
|
|
|
mJumpLines(aJumpLines),
|
2019-02-23 00:12:48 +03:00
|
|
|
mTrimSpaces(aTrimSpaces),
|
2017-06-19 01:07:36 +03:00
|
|
|
mScrollViewStop(aScrollViewStop),
|
|
|
|
mIsKeyboardSelect(aIsKeyboardSelect),
|
|
|
|
mVisual(aVisual),
|
|
|
|
mExtend(aExtend),
|
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
|
|
|
mForceEditableRegion(aForceEditableRegion == ForceEditableRegion::Yes),
|
2017-06-19 01:07:36 +03:00
|
|
|
mResultContent(),
|
|
|
|
mResultFrame(nullptr),
|
|
|
|
mContentOffset(0),
|
|
|
|
mAttach(CARET_ASSOCIATE_BEFORE) {}
|
|
|
|
|
2017-08-24 14:01:20 +03:00
|
|
|
// Array which contains index of each SelecionType in Selection::mDOMSelections.
|
|
|
|
// For avoiding using if nor switch to retrieve the index, this needs to have
|
|
|
|
// -1 for SelectionTypes which won't be created its Selection instance.
|
|
|
|
static const int8_t kIndexOfSelections[] = {
|
|
|
|
-1, // SelectionType::eInvalid
|
|
|
|
-1, // SelectionType::eNone
|
|
|
|
0, // SelectionType::eNormal
|
|
|
|
1, // SelectionType::eSpellCheck
|
|
|
|
2, // SelectionType::eIMERawClause
|
|
|
|
3, // SelectionType::eIMESelectedRawClause
|
|
|
|
4, // SelectionType::eIMEConvertedClause
|
|
|
|
5, // SelectionType::eIMESelectedClause
|
|
|
|
6, // SelectionType::eAccessibility
|
|
|
|
7, // SelectionType::eFind
|
|
|
|
8, // SelectionType::eURLSecondary
|
|
|
|
9, // SelectionType::eURLStrikeout
|
|
|
|
};
|
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
inline int8_t GetIndexFromSelectionType(SelectionType aSelectionType) {
|
2017-08-24 14:01:20 +03:00
|
|
|
// The enum value of eInvalid is -1 and the others are sequential value
|
|
|
|
// starting from 0. Therefore, |SelectionType + 1| is the index of
|
|
|
|
// kIndexOfSelections.
|
|
|
|
return kIndexOfSelections[static_cast<int8_t>(aSelectionType) + 1];
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
The limiter is used specifically for the text areas and textfields
|
|
|
|
In that case it is the DIV tag that is anonymously created for the text
|
2017-07-06 15:00:35 +03:00
|
|
|
areas/fields. Text nodes and BR nodes fall beneath it. In the case of a
|
2017-06-19 01:07:36 +03:00
|
|
|
BR node the limiter will be the parent and the offset will point before or
|
2017-07-06 15:00:35 +03:00
|
|
|
after the BR node. In the case of the text node the parent content is
|
2017-06-19 01:07:36 +03:00
|
|
|
the text node itself and the offset will be the exact character position.
|
2017-07-06 15:00:35 +03:00
|
|
|
The offset is not important to check for validity. Simply look at the
|
2017-06-19 01:07:36 +03:00
|
|
|
passed in content. If it equals the limiter then the selection point is valid.
|
2017-07-06 15:00:35 +03:00
|
|
|
If its parent it the limiter then the point is also valid. In the case of
|
2017-06-19 01:07:36 +03:00
|
|
|
NO limiter all points are valid since you are in a topmost iframe. (browser
|
|
|
|
or composer)
|
|
|
|
*/
|
|
|
|
bool IsValidSelectionPoint(nsFrameSelection* aFrameSel, nsINode* aNode) {
|
|
|
|
if (!aFrameSel || !aNode) return false;
|
|
|
|
|
|
|
|
nsIContent* limiter = aFrameSel->GetLimiter();
|
|
|
|
if (limiter && limiter != aNode && limiter != aNode->GetParent()) {
|
|
|
|
// if newfocus == the limiter. that's ok. but if not there and not parent
|
|
|
|
// bad
|
|
|
|
return false; // not in the right content. tLimiter said so
|
|
|
|
}
|
|
|
|
|
|
|
|
limiter = aFrameSel->GetAncestorLimiter();
|
|
|
|
return !limiter || nsContentUtils::ContentIsDescendantOf(aNode, limiter);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
struct MOZ_RAII AutoPrepareFocusRange {
|
|
|
|
AutoPrepareFocusRange(Selection* aSelection, bool aContinueSelection,
|
|
|
|
bool aMultipleSelection
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
|
|
|
|
if (aSelection->mRanges.Length() <= 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSelection->mFrameSelection->IsUserSelectionReason()) {
|
|
|
|
mUserSelect.emplace(aSelection);
|
|
|
|
}
|
|
|
|
bool userSelection = aSelection->mUserInitiated;
|
|
|
|
|
|
|
|
nsTArray<RangeData>& ranges = aSelection->mRanges;
|
|
|
|
if (!userSelection || (!aContinueSelection && aMultipleSelection)) {
|
|
|
|
// Scripted command or the user is starting a new explicit multi-range
|
|
|
|
// selection.
|
|
|
|
for (RangeData& entry : ranges) {
|
|
|
|
entry.mRange->SetIsGenerated(false);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t reason = aSelection->mFrameSelection->mSelectionChangeReason;
|
|
|
|
bool isAnchorRelativeOp =
|
|
|
|
(reason & (nsISelectionListener::DRAG_REASON |
|
|
|
|
nsISelectionListener::MOUSEDOWN_REASON |
|
|
|
|
nsISelectionListener::MOUSEUP_REASON |
|
|
|
|
nsISelectionListener::COLLAPSETOSTART_REASON));
|
|
|
|
if (!isAnchorRelativeOp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This operation is against the anchor but our current mAnchorFocusRange
|
|
|
|
// represents the focus in a multi-range selection. The anchor from a user
|
|
|
|
// perspective is the most distant generated range on the opposite side.
|
|
|
|
// Find that range and make it the mAnchorFocusRange.
|
|
|
|
const size_t len = ranges.Length();
|
|
|
|
size_t newAnchorFocusIndex = size_t(-1);
|
|
|
|
if (aSelection->GetDirection() == eDirNext) {
|
|
|
|
for (size_t i = 0; i < len; ++i) {
|
|
|
|
if (ranges[i].mRange->IsGenerated()) {
|
|
|
|
newAnchorFocusIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
size_t i = len;
|
|
|
|
while (i--) {
|
|
|
|
if (ranges[i].mRange->IsGenerated()) {
|
|
|
|
newAnchorFocusIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newAnchorFocusIndex == size_t(-1)) {
|
|
|
|
// There are no generated ranges - that's fine.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the new mAnchorFocusRange and mark the old one as generated.
|
|
|
|
if (aSelection->mAnchorFocusRange) {
|
|
|
|
aSelection->mAnchorFocusRange->SetIsGenerated(true);
|
|
|
|
}
|
|
|
|
nsRange* range = ranges[newAnchorFocusIndex].mRange;
|
|
|
|
range->SetIsGenerated(false);
|
|
|
|
aSelection->mAnchorFocusRange = range;
|
|
|
|
|
|
|
|
// Remove all generated ranges (including the old mAnchorFocusRange).
|
|
|
|
RefPtr<nsPresContext> presContext = aSelection->GetPresContext();
|
|
|
|
size_t i = len;
|
|
|
|
while (i--) {
|
|
|
|
range = aSelection->mRanges[i].mRange;
|
|
|
|
if (range->IsGenerated()) {
|
|
|
|
range->SetSelection(nullptr);
|
|
|
|
aSelection->SelectFrames(presContext, range, false);
|
|
|
|
aSelection->mRanges.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aSelection->mFrameSelection) {
|
|
|
|
aSelection->mFrameSelection->InvalidateDesiredPos();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<Selection::AutoUserInitiated> mUserSelect;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
////////////BEGIN nsFrameSelection methods
|
|
|
|
|
|
|
|
nsFrameSelection::nsFrameSelection() {
|
2017-08-24 13:14:04 +03:00
|
|
|
for (size_t i = 0; i < ArrayLength(mDomSelections); i++) {
|
2017-06-19 01:07:36 +03:00
|
|
|
mDomSelections[i] = new Selection(this);
|
2017-08-24 13:14:04 +03:00
|
|
|
mDomSelections[i]->SetType(kPresentSelectionTypes[i]);
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2018-08-30 10:36:23 +03:00
|
|
|
// On macOS, cache the current selection to send to service menu of macOS.
|
|
|
|
bool enableAutoCopy = true;
|
|
|
|
AutoCopyListener::Init(nsIClipboard::kSelectionCache);
|
|
|
|
#else // #ifdef XP_MACOSX
|
|
|
|
// Check to see if the auto-copy pref is enabled and make the normal
|
|
|
|
// Selection notifies auto-copy listener of its changes.
|
|
|
|
bool enableAutoCopy = AutoCopyListener::IsPrefEnabled();
|
|
|
|
if (enableAutoCopy) {
|
|
|
|
AutoCopyListener::Init(nsIClipboard::kSelectionClipboard);
|
|
|
|
}
|
|
|
|
#endif // #ifdef XP_MACOSX #else
|
|
|
|
|
|
|
|
if (enableAutoCopy) {
|
2017-06-19 01:07:36 +03:00
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (mDomSelections[index]) {
|
2018-08-30 10:36:23 +03:00
|
|
|
mDomSelections[index]->NotifyAutoCopy();
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFrameSelection::~nsFrameSelection() {}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsFrameSelection)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsFrameSelection)
|
2017-08-24 13:14:04 +03:00
|
|
|
for (size_t i = 0; i < ArrayLength(tmp->mDomSelections); ++i) {
|
2017-06-19 01:07:36 +03:00
|
|
|
tmp->mDomSelections[i] = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCellParent)
|
2018-05-08 20:52:36 +03:00
|
|
|
tmp->mSelectingTableCellMode = TableSelection::None;
|
2017-06-19 01:07:36 +03:00
|
|
|
tmp->mDragSelectingCells = false;
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStartSelectedCell)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEndSelectedCell)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAppendStartSelectedCell)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mUnselectCellOnMouseUp)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMaintainRange)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLimiter)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAncestorLimiter)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFrameSelection)
|
2019-04-03 10:53:16 +03:00
|
|
|
if (tmp->mPresShell && tmp->mPresShell->GetDocument() &&
|
2017-06-19 01:07:36 +03:00
|
|
|
nsCCUncollectableMarker::InGeneration(
|
2019-04-03 10:53:16 +03:00
|
|
|
cb, tmp->mPresShell->GetDocument()->GetMarkedCCGeneration())) {
|
2017-06-19 01:07:36 +03:00
|
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
|
|
|
}
|
2017-08-24 13:14:04 +03:00
|
|
|
for (size_t i = 0; i < ArrayLength(tmp->mDomSelections); ++i) {
|
2017-06-19 01:07:36 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDomSelections[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCellParent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStartSelectedCell)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEndSelectedCell)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAppendStartSelectedCell)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mUnselectCellOnMouseUp)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMaintainRange)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLimiter)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAncestorLimiter)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsFrameSelection, AddRef)
|
|
|
|
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::FetchDesiredPos(nsPoint& aDesiredPos) {
|
2019-04-03 10:53:16 +03:00
|
|
|
if (!mPresShell) {
|
2017-06-19 01:07:36 +03:00
|
|
|
NS_ERROR("fetch desired position failed");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (mDesiredPosSet) {
|
|
|
|
aDesiredPos = mDesiredPos;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
RefPtr<nsCaret> caret = mPresShell->GetCaret();
|
2017-06-19 01:07:36 +03:00
|
|
|
if (!caret) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
caret->SetSelection(mDomSelections[index]);
|
|
|
|
|
|
|
|
nsRect coord;
|
|
|
|
nsIFrame* caretFrame = caret->GetGeometry(&coord);
|
|
|
|
if (!caretFrame) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsPoint viewOffset(0, 0);
|
|
|
|
nsView* view = nullptr;
|
|
|
|
caretFrame->GetOffsetFromView(viewOffset, &view);
|
|
|
|
if (view) {
|
|
|
|
coord += viewOffset;
|
|
|
|
}
|
|
|
|
aDesiredPos = coord.TopLeft();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsFrameSelection::InvalidateDesiredPos() // do not listen to mDesiredPos;
|
|
|
|
// you must get another.
|
|
|
|
{
|
|
|
|
mDesiredPosSet = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsFrameSelection::SetDesiredPos(nsPoint aPos) {
|
|
|
|
mDesiredPos = aPos;
|
|
|
|
mDesiredPosSet = true;
|
|
|
|
}
|
|
|
|
|
2017-11-15 13:26:10 +03:00
|
|
|
nsresult nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree(
|
|
|
|
nsIFrame* aFrame, const nsPoint& aPoint, nsIFrame** aRetFrame,
|
|
|
|
nsPoint& aRetPoint) {
|
2017-06-19 01:07:36 +03:00
|
|
|
//
|
|
|
|
// The whole point of this method is to return a frame and point that
|
|
|
|
// that lie within the same valid subtree as the anchor node's frame,
|
|
|
|
// for use with the method GetContentAndOffsetsFromPoint().
|
|
|
|
//
|
|
|
|
// A valid subtree is defined to be one where all the content nodes in
|
|
|
|
// the tree have a valid parent-child relationship.
|
|
|
|
//
|
|
|
|
// If the anchor frame and aFrame are in the same subtree, aFrame will
|
|
|
|
// be returned in aRetFrame. If they are in different subtrees, we
|
|
|
|
// return the frame for the root of the subtree.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (!aFrame || !aRetFrame) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aRetFrame = aFrame;
|
|
|
|
aRetPoint = aPoint;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the frame and content for the selection's anchor point!
|
|
|
|
//
|
|
|
|
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2018-05-08 20:52:38 +03:00
|
|
|
nsCOMPtr<nsIContent> anchorContent =
|
|
|
|
do_QueryInterface(mDomSelections[index]->GetAnchorNode());
|
2017-06-19 01:07:36 +03:00
|
|
|
if (!anchorContent) return NS_ERROR_FAILURE;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
//
|
|
|
|
// Now find the root of the subtree containing the anchor's content.
|
|
|
|
//
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
NS_ENSURE_STATE(mPresShell);
|
|
|
|
nsIContent* anchorRoot = anchorContent->GetSelectionRootContent(mPresShell);
|
2017-06-19 01:07:36 +03:00
|
|
|
NS_ENSURE_TRUE(anchorRoot, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now find the root of the subtree containing aFrame's content.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
|
|
|
|
if (content) {
|
2019-04-03 10:53:16 +03:00
|
|
|
nsIContent* contentRoot = content->GetSelectionRootContent(mPresShell);
|
2017-06-19 01:07:36 +03:00
|
|
|
NS_ENSURE_TRUE(contentRoot, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
if (anchorRoot == contentRoot) {
|
|
|
|
// If the aFrame's content isn't the capturing content, it should be
|
|
|
|
// a descendant. At this time, we can return simply.
|
2019-04-30 03:26:57 +03:00
|
|
|
nsIContent* capturedContent = PresShell::GetCapturingContent();
|
2017-06-19 01:07:36 +03:00
|
|
|
if (capturedContent != content) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the frame under the mouse cursor with the root frame.
|
|
|
|
// At this time, don't use the anchor's frame because it may not have
|
|
|
|
// fixed positioned frames.
|
2019-04-03 10:53:16 +03:00
|
|
|
nsIFrame* rootFrame = mPresShell->GetRootFrame();
|
2017-06-19 01:07:36 +03:00
|
|
|
nsPoint ptInRoot = aPoint + aFrame->GetOffsetTo(rootFrame);
|
|
|
|
nsIFrame* cursorFrame =
|
|
|
|
nsLayoutUtils::GetFrameForPoint(rootFrame, ptInRoot);
|
|
|
|
|
|
|
|
// If the mouse cursor in on a frame which is descendant of same
|
|
|
|
// selection root, we can expand the selection to the frame.
|
2019-04-03 10:53:16 +03:00
|
|
|
if (cursorFrame && cursorFrame->PresShell() == mPresShell) {
|
2017-06-19 01:07:36 +03:00
|
|
|
nsIContent* cursorContent = cursorFrame->GetContent();
|
|
|
|
NS_ENSURE_TRUE(cursorContent, NS_ERROR_FAILURE);
|
|
|
|
nsIContent* cursorContentRoot =
|
2019-04-03 10:53:16 +03:00
|
|
|
cursorContent->GetSelectionRootContent(mPresShell);
|
2017-06-19 01:07:36 +03:00
|
|
|
NS_ENSURE_TRUE(cursorContentRoot, NS_ERROR_UNEXPECTED);
|
|
|
|
if (cursorContentRoot == anchorRoot) {
|
|
|
|
*aRetFrame = cursorFrame;
|
|
|
|
aRetPoint = aPoint + aFrame->GetOffsetTo(cursorFrame);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Otherwise, e.g., the cursor isn't on any frames (e.g., the mouse
|
|
|
|
// cursor is out of the window), we should use the frame of the anchor
|
|
|
|
// root.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// When we can't find a frame which is under the mouse cursor and has a same
|
|
|
|
// selection root as the anchor node's, we should return the selection root
|
|
|
|
// frame.
|
|
|
|
//
|
|
|
|
|
|
|
|
*aRetFrame = anchorRoot->GetPrimaryFrame();
|
|
|
|
|
|
|
|
if (!*aRetFrame) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now make sure that aRetPoint is converted to the same coordinate
|
|
|
|
// system used by aRetFrame.
|
|
|
|
//
|
|
|
|
|
|
|
|
aRetPoint = aPoint + aFrame->GetOffsetTo(*aRetFrame);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsFrameSelection::SetCaretBidiLevel(nsBidiLevel aLevel) {
|
|
|
|
// If the current level is undefined, we have just inserted new text.
|
|
|
|
// In this case, we don't want to reset the keyboard language
|
|
|
|
mCaretBidiLevel = aLevel;
|
|
|
|
|
|
|
|
RefPtr<nsCaret> caret;
|
2019-04-03 10:53:16 +03:00
|
|
|
if (mPresShell && (caret = mPresShell->GetCaret())) {
|
2017-06-19 01:07:36 +03:00
|
|
|
caret->SchedulePaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBidiLevel nsFrameSelection::GetCaretBidiLevel() const {
|
|
|
|
return mCaretBidiLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsFrameSelection::UndefineCaretBidiLevel() {
|
|
|
|
mCaretBidiLevel |= BIDI_LEVEL_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PRINT_RANGE
|
|
|
|
void printRange(nsRange* aDomRange) {
|
|
|
|
if (!aDomRange) {
|
2018-03-27 07:35:22 +03:00
|
|
|
printf("NULL Range\n");
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
2017-07-11 14:53:04 +03:00
|
|
|
nsINode* startNode = aDomRange->GetStartContainer();
|
2017-07-11 15:11:37 +03:00
|
|
|
nsINode* endNode = aDomRange->GetEndContainer();
|
2017-06-19 01:07:36 +03:00
|
|
|
int32_t startOffset = aDomRange->StartOffset();
|
|
|
|
int32_t endOffset = aDomRange->EndOffset();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
printf("range: 0x%lx\t start: 0x%lx %ld, \t end: 0x%lx,%ld\n",
|
|
|
|
(unsigned long)aDomRange, (unsigned long)startNode, (long)startOffset,
|
|
|
|
(unsigned long)endNode, (long)endOffset);
|
|
|
|
}
|
|
|
|
#endif /* PRINT_RANGE */
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
static nsAtom* GetTag(nsINode* aNode) {
|
2017-06-19 01:07:36 +03:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
2017-07-06 15:00:35 +03:00
|
|
|
if (!content) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("bad node passed to GetTag()");
|
2017-06-19 01:07:36 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
return content->NodeInfo()->NameAtom();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the parent
|
|
|
|
nsINode* ParentOffset(nsINode* aNode, int32_t* aChildOffset) {
|
|
|
|
if (!aNode || !aChildOffset) return nullptr;
|
|
|
|
|
|
|
|
nsIContent* parent = aNode->GetParent();
|
|
|
|
if (parent) {
|
2018-01-23 16:30:18 +03:00
|
|
|
*aChildOffset = parent->ComputeIndexOf(aNode);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsINode* GetCellParent(nsINode* aDomNode) {
|
|
|
|
if (!aDomNode) return nullptr;
|
|
|
|
nsINode* current = aDomNode;
|
|
|
|
// Start with current node and look for a table cell
|
|
|
|
while (current) {
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* tag = GetTag(current);
|
2017-06-19 01:07:36 +03:00
|
|
|
if (tag == nsGkAtoms::td || tag == nsGkAtoms::th) return current;
|
|
|
|
current = current->GetParent();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
void nsFrameSelection::Init(mozilla::PresShell* aPresShell,
|
|
|
|
nsIContent* aLimiter,
|
2017-08-02 04:18:23 +03:00
|
|
|
bool aAccessibleCaretEnabled) {
|
2019-04-03 10:53:16 +03:00
|
|
|
mPresShell = aPresShell;
|
2017-06-19 01:07:36 +03:00
|
|
|
mDragState = false;
|
|
|
|
mDesiredPosSet = false;
|
|
|
|
mLimiter = aLimiter;
|
|
|
|
mCaretMovementStyle =
|
|
|
|
Preferences::GetInt("bidi.edit.caret_movement_style", 2);
|
|
|
|
|
|
|
|
// This should only ever be initialized on the main thread, so we are OK here.
|
|
|
|
static bool prefCachesInitialized = false;
|
|
|
|
if (!prefCachesInitialized) {
|
|
|
|
prefCachesInitialized = true;
|
|
|
|
|
|
|
|
Preferences::AddBoolVarCache(&sSelectionEventsEnabled,
|
|
|
|
"dom.select_events.enabled", false);
|
|
|
|
Preferences::AddBoolVarCache(&sSelectionEventsOnTextControlsEnabled,
|
|
|
|
"dom.select_events.textcontrols.enabled",
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
2017-08-02 04:18:23 +03:00
|
|
|
mAccessibleCaretEnabled = aAccessibleCaretEnabled;
|
|
|
|
if (mAccessibleCaretEnabled) {
|
2018-09-01 00:19:44 +03:00
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
2019-04-03 10:53:16 +03:00
|
|
|
mDomSelections[index]->MaybeNotifyAccessibleCaretEventHub(aPresShell);
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
2017-08-02 03:27:24 +03:00
|
|
|
bool plaintextControl = (aLimiter != nullptr);
|
|
|
|
bool initSelectEvents = plaintextControl
|
|
|
|
? sSelectionEventsOnTextControlsEnabled
|
|
|
|
: sSelectionEventsEnabled;
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
Document* doc = aPresShell->GetDocument();
|
2017-08-02 03:27:24 +03:00
|
|
|
if (initSelectEvents ||
|
2017-06-19 01:07:36 +03:00
|
|
|
(doc && nsContentUtils::IsSystemPrincipal(doc->NodePrincipal()))) {
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (mDomSelections[index]) {
|
2018-09-01 00:22:57 +03:00
|
|
|
mDomSelections[index]->EnableSelectionChangeEvent();
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsFrameSelection::sSelectionEventsEnabled = false;
|
|
|
|
bool nsFrameSelection::sSelectionEventsOnTextControlsEnabled = false;
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::MoveCaret(nsDirection aDirection,
|
|
|
|
bool aContinueSelection,
|
|
|
|
nsSelectionAmount aAmount,
|
|
|
|
CaretMovementStyle aMovementStyle) {
|
|
|
|
bool visualMovement = aMovementStyle == eVisual ||
|
|
|
|
(aMovementStyle == eUsePrefStyle &&
|
|
|
|
(mCaretMovementStyle == 1 ||
|
|
|
|
(mCaretMovementStyle == 2 && !aContinueSelection)));
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
NS_ENSURE_STATE(mPresShell);
|
2017-06-19 01:07:36 +03:00
|
|
|
// Flush out layout, since we need it to be up to date to do caret
|
|
|
|
// positioning.
|
2019-04-03 10:53:16 +03:00
|
|
|
OwningNonNull<PresShell> presShell(*mPresShell);
|
|
|
|
presShell->FlushPendingNotifications(FlushType::Layout);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
if (!mPresShell) {
|
2017-06-19 01:07:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
nsPresContext* context = mPresShell->GetPresContext();
|
2017-06-19 01:07:36 +03:00
|
|
|
if (!context) return NS_ERROR_FAILURE;
|
|
|
|
|
2018-12-05 21:44:05 +03:00
|
|
|
// we must keep this around and revalidate it when its just UP/DOWN
|
|
|
|
nsPoint desiredPos(0, 0);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
RefPtr<Selection> sel = mDomSelections[index];
|
|
|
|
if (!sel) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
int32_t scrollFlags = Selection::SCROLL_FOR_CARET_MOVE;
|
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 bool isEditorSelection = sel->IsEditorSelection();
|
|
|
|
if (isEditorSelection) {
|
2017-06-19 01:07:36 +03:00
|
|
|
// If caret moves in editor, it should cause scrolling even if it's in
|
|
|
|
// overflow: hidden;.
|
|
|
|
scrollFlags |= Selection::SCROLL_OVERFLOW_HIDDEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t caretStyle = Preferences::GetInt("layout.selection.caret_style", 0);
|
|
|
|
if (caretStyle == 0
|
|
|
|
#ifdef XP_WIN
|
|
|
|
&& aAmount != eSelectLine
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
// Put caret at the selection edge in the |aDirection| direction.
|
|
|
|
caretStyle = 2;
|
|
|
|
}
|
|
|
|
|
2018-05-08 20:52:39 +03:00
|
|
|
bool doCollapse = !sel->IsCollapsed() && !aContinueSelection &&
|
2017-06-19 01:07:36 +03:00
|
|
|
caretStyle == 2 && aAmount <= eSelectLine;
|
|
|
|
if (doCollapse) {
|
|
|
|
if (aDirection == eDirPrevious) {
|
|
|
|
PostReason(nsISelectionListener::COLLAPSETOSTART_REASON);
|
|
|
|
mHint = CARET_ASSOCIATE_AFTER;
|
|
|
|
} else {
|
|
|
|
PostReason(nsISelectionListener::COLLAPSETOEND_REASON);
|
|
|
|
mHint = CARET_ASSOCIATE_BEFORE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PostReason(nsISelectionListener::KEYPRESS_REASON);
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoPrepareFocusRange prep(sel, aContinueSelection, false);
|
|
|
|
|
|
|
|
if (aAmount == eSelectLine) {
|
2018-05-08 20:52:39 +03:00
|
|
|
nsresult result = FetchDesiredPos(desiredPos);
|
2017-06-19 01:07:36 +03:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
SetDesiredPos(desiredPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doCollapse) {
|
|
|
|
const nsRange* anchorFocusRange = sel->GetAnchorFocusRange();
|
|
|
|
if (anchorFocusRange) {
|
|
|
|
nsINode* node;
|
|
|
|
int32_t offset;
|
|
|
|
if (aDirection == eDirPrevious) {
|
2017-07-11 14:53:04 +03:00
|
|
|
node = anchorFocusRange->GetStartContainer();
|
2017-06-19 01:07:36 +03:00
|
|
|
offset = anchorFocusRange->StartOffset();
|
|
|
|
} else {
|
2017-07-11 15:11:37 +03:00
|
|
|
node = anchorFocusRange->GetEndContainer();
|
2017-06-19 01:07:36 +03:00
|
|
|
offset = anchorFocusRange->EndOffset();
|
|
|
|
}
|
|
|
|
sel->Collapse(node, offset);
|
|
|
|
}
|
|
|
|
sel->ScrollIntoView(nsISelectionController::SELECTION_FOCUS_REGION,
|
2019-04-30 03:07:49 +03:00
|
|
|
ScrollAxis(), ScrollAxis(), scrollFlags);
|
2017-06-19 01:07:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* frame;
|
|
|
|
int32_t offsetused = 0;
|
2018-05-08 20:52:39 +03:00
|
|
|
nsresult result =
|
|
|
|
sel->GetPrimaryFrameForFocusNode(&frame, &offsetused, visualMovement);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result) || !frame)
|
|
|
|
return NS_FAILED(result) ? result : NS_ERROR_FAILURE;
|
|
|
|
|
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 auto forceEditableRegion =
|
|
|
|
isEditorSelection ? nsPeekOffsetStruct::ForceEditableRegion::Yes
|
|
|
|
: nsPeekOffsetStruct::ForceEditableRegion::No;
|
2017-06-19 01:07:36 +03:00
|
|
|
// set data using mLimiter to stop on scroll views. If we have a limiter then
|
|
|
|
// we stop peeking when we hit scrollable views. If no limiter then just let
|
|
|
|
// it go ahead
|
|
|
|
nsPeekOffsetStruct pos(aAmount, eDirPrevious, offsetused, desiredPos, true,
|
|
|
|
mLimiter != nullptr, true, visualMovement,
|
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
|
|
|
aContinueSelection, forceEditableRegion);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
nsBidiDirection paraDir = nsBidiPresUtils::ParagraphDirection(frame);
|
|
|
|
|
|
|
|
CaretAssociateHint tHint(
|
|
|
|
mHint); // temporary variable so we dont set mHint until it is necessary
|
|
|
|
switch (aAmount) {
|
|
|
|
case eSelectCharacter:
|
|
|
|
case eSelectCluster:
|
|
|
|
case eSelectWord:
|
|
|
|
case eSelectWordNoSpace:
|
|
|
|
InvalidateDesiredPos();
|
|
|
|
pos.mAmount = aAmount;
|
|
|
|
pos.mDirection = (visualMovement && paraDir == NSBIDI_RTL)
|
|
|
|
? nsDirection(1 - aDirection)
|
|
|
|
: aDirection;
|
|
|
|
break;
|
|
|
|
case eSelectLine:
|
|
|
|
pos.mAmount = aAmount;
|
|
|
|
pos.mDirection = aDirection;
|
|
|
|
break;
|
|
|
|
case eSelectBeginLine:
|
|
|
|
case eSelectEndLine:
|
|
|
|
InvalidateDesiredPos();
|
|
|
|
pos.mAmount = aAmount;
|
|
|
|
pos.mDirection = (visualMovement && paraDir == NSBIDI_RTL)
|
|
|
|
? nsDirection(1 - aDirection)
|
|
|
|
: aDirection;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result = frame->PeekOffset(&pos)) && pos.mResultContent) {
|
|
|
|
nsIFrame* theFrame;
|
|
|
|
int32_t currentOffset, frameStart, frameEnd;
|
|
|
|
|
|
|
|
if (aAmount <= eSelectWordNoSpace) {
|
|
|
|
// For left/right, PeekOffset() sets pos.mResultFrame correctly, but does
|
|
|
|
// not set pos.mAttachForward, so determine the hint here based on the
|
|
|
|
// result frame and offset: If we're at the end of a text frame, set the
|
|
|
|
// hint to ASSOCIATE_BEFORE to indicate that we want the caret displayed
|
|
|
|
// at the end of this frame, not at the beginning of the next one.
|
|
|
|
theFrame = pos.mResultFrame;
|
|
|
|
theFrame->GetOffsets(frameStart, frameEnd);
|
|
|
|
currentOffset = pos.mContentOffset;
|
|
|
|
if (frameEnd == currentOffset && !(frameStart == 0 && frameEnd == 0))
|
|
|
|
tHint = CARET_ASSOCIATE_BEFORE;
|
|
|
|
else
|
|
|
|
tHint = CARET_ASSOCIATE_AFTER;
|
|
|
|
} else {
|
|
|
|
// For up/down and home/end, pos.mResultFrame might not be set correctly,
|
|
|
|
// or not at all. In these cases, get the frame based on the content and
|
|
|
|
// hint returned by PeekOffset().
|
|
|
|
tHint = pos.mAttach;
|
|
|
|
theFrame = GetFrameForNodeOffset(pos.mResultContent, pos.mContentOffset,
|
|
|
|
tHint, ¤tOffset);
|
|
|
|
if (!theFrame) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
theFrame->GetOffsets(frameStart, frameEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->BidiEnabled()) {
|
|
|
|
switch (aAmount) {
|
|
|
|
case eSelectBeginLine:
|
|
|
|
case eSelectEndLine: {
|
|
|
|
// In Bidi contexts, PeekOffset calculates pos.mContentOffset
|
|
|
|
// differently depending on whether the movement is visual or logical.
|
|
|
|
// For visual movement, pos.mContentOffset depends on the direction-
|
|
|
|
// ality of the first/last frame on the line (theFrame), and the caret
|
|
|
|
// directionality must correspond.
|
|
|
|
FrameBidiData bidiData = theFrame->GetBidiData();
|
|
|
|
SetCaretBidiLevel(visualMovement ? bidiData.embeddingLevel
|
|
|
|
: bidiData.baseLevel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// If the current position is not a frame boundary, it's enough just
|
|
|
|
// to take the Bidi level of the current frame
|
|
|
|
if ((pos.mContentOffset != frameStart &&
|
|
|
|
pos.mContentOffset != frameEnd) ||
|
|
|
|
eSelectLine == aAmount) {
|
|
|
|
SetCaretBidiLevel(theFrame->GetEmbeddingLevel());
|
|
|
|
} else {
|
2019-04-03 10:53:16 +03:00
|
|
|
BidiLevelFromMove(mPresShell, pos.mResultContent,
|
|
|
|
pos.mContentOffset, aAmount, tHint);
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 03:30:11 +03:00
|
|
|
// "pos" is on the stack, so pos.mResultContent has stack lifetime, so using
|
|
|
|
// MOZ_KnownLive is ok.
|
|
|
|
result = TakeFocus(MOZ_KnownLive(pos.mResultContent), pos.mContentOffset,
|
2017-06-19 01:07:36 +03:00
|
|
|
pos.mContentOffset, tHint, aContinueSelection, false);
|
|
|
|
} else if (aAmount <= eSelectWordNoSpace && aDirection == eDirNext &&
|
|
|
|
!aContinueSelection) {
|
|
|
|
// Collapse selection if PeekOffset failed, we either
|
|
|
|
// 1. bumped into the BRFrame, bug 207623
|
|
|
|
// 2. had select-all in a text input (DIV range), bug 352759.
|
|
|
|
bool isBRFrame = frame->IsBrFrame();
|
|
|
|
sel->Collapse(sel->GetFocusNode(), sel->FocusOffset());
|
|
|
|
// Note: 'frame' might be dead here.
|
|
|
|
if (!isBRFrame) {
|
|
|
|
mHint = CARET_ASSOCIATE_BEFORE; // We're now at the end of the frame to
|
|
|
|
// the left.
|
|
|
|
}
|
|
|
|
result = NS_OK;
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = mDomSelections[index]->ScrollIntoView(
|
2019-04-30 03:07:49 +03:00
|
|
|
nsISelectionController::SELECTION_FOCUS_REGION, ScrollAxis(),
|
|
|
|
ScrollAxis(), scrollFlags);
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPrevNextBidiLevels nsFrameSelection::GetPrevNextBidiLevels(
|
|
|
|
nsIContent* aNode, uint32_t aContentOffset, bool aJumpLines) const {
|
|
|
|
return GetPrevNextBidiLevels(aNode, aContentOffset, mHint, aJumpLines);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPrevNextBidiLevels nsFrameSelection::GetPrevNextBidiLevels(
|
|
|
|
nsIContent* aNode, uint32_t aContentOffset, CaretAssociateHint aHint,
|
|
|
|
bool aJumpLines) const {
|
|
|
|
// Get the level of the frames on each side
|
|
|
|
nsIFrame* currentFrame;
|
|
|
|
int32_t currentOffset;
|
|
|
|
int32_t frameStart, frameEnd;
|
|
|
|
nsDirection direction;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
nsPrevNextBidiLevels levels;
|
|
|
|
levels.SetData(nullptr, nullptr, 0, 0);
|
|
|
|
|
|
|
|
currentFrame =
|
|
|
|
GetFrameForNodeOffset(aNode, aContentOffset, aHint, ¤tOffset);
|
|
|
|
if (!currentFrame) return levels;
|
|
|
|
|
|
|
|
currentFrame->GetOffsets(frameStart, frameEnd);
|
|
|
|
|
|
|
|
if (0 == frameStart && 0 == frameEnd)
|
|
|
|
direction = eDirPrevious;
|
|
|
|
else if (frameStart == currentOffset)
|
|
|
|
direction = eDirPrevious;
|
|
|
|
else if (frameEnd == currentOffset)
|
|
|
|
direction = eDirNext;
|
|
|
|
else {
|
|
|
|
// we are neither at the beginning nor at the end of the frame, so we have
|
|
|
|
// no worries
|
|
|
|
nsBidiLevel currentLevel = currentFrame->GetEmbeddingLevel();
|
|
|
|
levels.SetData(currentFrame, currentFrame, currentLevel, currentLevel);
|
|
|
|
return levels;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* newFrame;
|
|
|
|
int32_t offset;
|
|
|
|
bool jumpedLine, movedOverNonSelectableText;
|
|
|
|
nsresult rv = currentFrame->GetFrameFromDirection(
|
|
|
|
direction, false, aJumpLines, true, false, &newFrame, &offset,
|
|
|
|
&jumpedLine, &movedOverNonSelectableText);
|
|
|
|
if (NS_FAILED(rv)) newFrame = nullptr;
|
|
|
|
|
|
|
|
FrameBidiData currentBidi = currentFrame->GetBidiData();
|
|
|
|
nsBidiLevel currentLevel = currentBidi.embeddingLevel;
|
|
|
|
nsBidiLevel newLevel =
|
|
|
|
newFrame ? newFrame->GetEmbeddingLevel() : currentBidi.baseLevel;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
// If not jumping lines, disregard br frames, since they might be positioned
|
|
|
|
// incorrectly.
|
|
|
|
// XXX This could be removed once bug 339786 is fixed.
|
|
|
|
if (!aJumpLines) {
|
|
|
|
if (currentFrame->IsBrFrame()) {
|
|
|
|
currentFrame = nullptr;
|
|
|
|
currentLevel = currentBidi.baseLevel;
|
|
|
|
}
|
|
|
|
if (newFrame && newFrame->IsBrFrame()) {
|
|
|
|
newFrame = nullptr;
|
|
|
|
newLevel = currentBidi.baseLevel;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
if (direction == eDirNext)
|
|
|
|
levels.SetData(currentFrame, newFrame, currentLevel, newLevel);
|
|
|
|
else
|
|
|
|
levels.SetData(newFrame, currentFrame, newLevel, currentLevel);
|
|
|
|
|
|
|
|
return levels;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::GetFrameFromLevel(nsIFrame* aFrameIn,
|
|
|
|
nsDirection aDirection,
|
|
|
|
nsBidiLevel aBidiLevel,
|
|
|
|
nsIFrame** aFrameOut) const {
|
2019-04-03 10:53:16 +03:00
|
|
|
NS_ENSURE_STATE(mPresShell);
|
2017-06-19 01:07:36 +03:00
|
|
|
nsBidiLevel foundLevel = 0;
|
|
|
|
nsIFrame* foundFrame = aFrameIn;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFrameEnumerator> frameTraversal;
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIFrameTraversal> trav(
|
|
|
|
do_CreateInstance(kFrameTraversalCID, &result));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
result =
|
|
|
|
trav->NewFrameTraversal(getter_AddRefs(frameTraversal),
|
|
|
|
mPresShell->GetPresContext(), aFrameIn, eLeaf,
|
|
|
|
false, // aVisual
|
|
|
|
false, // aLockInScrollView
|
|
|
|
false, // aFollowOOFs
|
|
|
|
false // aSkipPopupChecks
|
|
|
|
);
|
2017-06-19 01:07:36 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
do {
|
|
|
|
*aFrameOut = foundFrame;
|
|
|
|
if (aDirection == eDirNext)
|
|
|
|
frameTraversal->Next();
|
|
|
|
else
|
|
|
|
frameTraversal->Prev();
|
|
|
|
|
|
|
|
foundFrame = frameTraversal->CurrentItem();
|
|
|
|
if (!foundFrame) return NS_ERROR_FAILURE;
|
|
|
|
foundLevel = foundFrame->GetEmbeddingLevel();
|
|
|
|
|
|
|
|
} while (foundLevel > aBidiLevel);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::MaintainSelection(nsSelectionAmount aAmount) {
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
mMaintainedAmount = aAmount;
|
|
|
|
|
|
|
|
const nsRange* anchorFocusRange =
|
|
|
|
mDomSelections[index]->GetAnchorFocusRange();
|
|
|
|
if (anchorFocusRange && aAmount != eSelectNoAmount) {
|
|
|
|
mMaintainRange = anchorFocusRange->CloneRange();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMaintainRange = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-12-05 21:44:05 +03:00
|
|
|
/**
|
|
|
|
* After moving the caret, its Bidi level is set according to the following
|
2017-06-19 01:07:36 +03:00
|
|
|
* rules:
|
|
|
|
*
|
2018-12-05 21:44:05 +03:00
|
|
|
* After moving over a character with left/right arrow, set to the Bidi level
|
2017-06-19 01:07:36 +03:00
|
|
|
* of the last moved over character. After Home and End, set to the paragraph
|
|
|
|
* embedding level. After up/down arrow, PageUp/Down, set to the lower level of
|
|
|
|
* the 2 surrounding characters. After mouse click, set to the level of the
|
|
|
|
* current frame.
|
|
|
|
*
|
2018-12-05 21:44:05 +03:00
|
|
|
* The following two methods use GetPrevNextBidiLevels to determine the new
|
2017-06-19 01:07:36 +03:00
|
|
|
* Bidi level. BidiLevelFromMove is called when the caret is moved in response
|
|
|
|
* to a keyboard event
|
|
|
|
*
|
|
|
|
* @param aPresShell is the presentation shell
|
|
|
|
* @param aNode is the content node
|
|
|
|
* @param aContentOffset is the new caret position, as an offset into aNode
|
|
|
|
* @param aAmount is the amount of the move that gave the caret its new position
|
|
|
|
* @param aHint is the hint indicating in what logical direction the caret moved
|
|
|
|
*/
|
2019-04-03 10:53:16 +03:00
|
|
|
void nsFrameSelection::BidiLevelFromMove(PresShell* aPresShell,
|
2017-06-19 01:07:36 +03:00
|
|
|
nsIContent* aNode,
|
|
|
|
uint32_t aContentOffset,
|
|
|
|
nsSelectionAmount aAmount,
|
|
|
|
CaretAssociateHint aHint) {
|
|
|
|
switch (aAmount) {
|
|
|
|
// Movement within the line: the new cursor Bidi level is the level of the
|
|
|
|
// last character moved over
|
|
|
|
case eSelectCharacter:
|
|
|
|
case eSelectCluster:
|
|
|
|
case eSelectWord:
|
|
|
|
case eSelectWordNoSpace:
|
|
|
|
case eSelectBeginLine:
|
|
|
|
case eSelectEndLine:
|
|
|
|
case eSelectNoAmount: {
|
|
|
|
nsPrevNextBidiLevels levels =
|
|
|
|
GetPrevNextBidiLevels(aNode, aContentOffset, aHint, false);
|
|
|
|
|
|
|
|
SetCaretBidiLevel(aHint == CARET_ASSOCIATE_BEFORE ? levels.mLevelBefore
|
|
|
|
: levels.mLevelAfter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
2017-07-06 15:00:35 +03:00
|
|
|
// Up and Down: the new cursor Bidi level is the smaller of the two
|
|
|
|
surrounding characters case eSelectLine: case eSelectParagraph:
|
2017-06-19 01:07:36 +03:00
|
|
|
GetPrevNextBidiLevels(aContext, aNode, aContentOffset, &firstFrame,
|
|
|
|
&secondFrame, &firstLevel, &secondLevel);
|
|
|
|
aPresShell->SetCaretBidiLevel(std::min(firstLevel, secondLevel));
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
|
|
|
|
default:
|
|
|
|
UndefineCaretBidiLevel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BidiLevelFromClick is called when the caret is repositioned by clicking the
|
|
|
|
* mouse
|
|
|
|
*
|
|
|
|
* @param aNode is the content node
|
|
|
|
* @param aContentOffset is the new caret position, as an offset into aNode
|
|
|
|
*/
|
|
|
|
void nsFrameSelection::BidiLevelFromClick(nsIContent* aNode,
|
|
|
|
uint32_t aContentOffset) {
|
|
|
|
nsIFrame* clickInFrame = nullptr;
|
|
|
|
int32_t OffsetNotUsed;
|
|
|
|
|
|
|
|
clickInFrame =
|
|
|
|
GetFrameForNodeOffset(aNode, aContentOffset, mHint, &OffsetNotUsed);
|
|
|
|
if (!clickInFrame) return;
|
|
|
|
|
|
|
|
SetCaretBidiLevel(clickInFrame->GetEmbeddingLevel());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsFrameSelection::AdjustForMaintainedSelection(nsIContent* aContent,
|
|
|
|
int32_t aOffset) {
|
|
|
|
if (!mMaintainRange) return false;
|
|
|
|
|
|
|
|
if (!aContent) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return false;
|
|
|
|
|
2017-07-11 14:53:04 +03:00
|
|
|
nsINode* rangeStartNode = mMaintainRange->GetStartContainer();
|
2017-07-11 15:11:37 +03:00
|
|
|
nsINode* rangeEndNode = mMaintainRange->GetEndContainer();
|
2017-06-19 01:07:36 +03:00
|
|
|
int32_t rangeStartOffset = mMaintainRange->StartOffset();
|
|
|
|
int32_t rangeEndOffset = mMaintainRange->EndOffset();
|
|
|
|
|
|
|
|
int32_t relToStart = nsContentUtils::ComparePoints(
|
|
|
|
rangeStartNode, rangeStartOffset, aContent, aOffset);
|
|
|
|
int32_t relToEnd = nsContentUtils::ComparePoints(rangeEndNode, rangeEndOffset,
|
|
|
|
aContent, aOffset);
|
|
|
|
|
|
|
|
// If aContent/aOffset is inside the maintained selection, or if it is on the
|
|
|
|
// "anchor" side of the maintained selection, we need to do something.
|
|
|
|
if ((relToStart < 0 && relToEnd > 0) ||
|
|
|
|
(relToStart > 0 && mDomSelections[index]->GetDirection() == eDirNext) ||
|
|
|
|
(relToEnd < 0 && mDomSelections[index]->GetDirection() == eDirPrevious)) {
|
2017-07-06 15:00:35 +03:00
|
|
|
// Set the current range to the maintained range.
|
2017-06-19 01:07:36 +03:00
|
|
|
mDomSelections[index]->ReplaceAnchorFocusRange(mMaintainRange);
|
|
|
|
if (relToStart < 0 && relToEnd > 0) {
|
|
|
|
// We're inside the maintained selection, just keep it selected.
|
|
|
|
return true;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
// Reverse the direction of the selection so that the anchor will be on the
|
2017-06-19 01:07:36 +03:00
|
|
|
// far side of the maintained selection, relative to aContent/aOffset.
|
|
|
|
mDomSelections[index]->SetDirection(relToStart > 0 ? eDirPrevious
|
|
|
|
: eDirNext);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::HandleClick(nsIContent* aNewFocus,
|
|
|
|
uint32_t aContentOffset,
|
|
|
|
uint32_t aContentEndOffset,
|
|
|
|
bool aContinueSelection,
|
|
|
|
bool aMultipleSelection,
|
|
|
|
CaretAssociateHint aHint) {
|
|
|
|
if (!aNewFocus) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
InvalidateDesiredPos();
|
|
|
|
|
|
|
|
if (!aContinueSelection) {
|
|
|
|
mMaintainRange = nullptr;
|
|
|
|
if (!IsValidSelectionPoint(this, aNewFocus)) {
|
|
|
|
mAncestorLimiter = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't take focus when dragging off of a table
|
|
|
|
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(SelectionType::eNormal);
|
|
|
|
AutoPrepareFocusRange prep(mDomSelections[index], aContinueSelection,
|
|
|
|
aMultipleSelection);
|
|
|
|
return TakeFocus(aNewFocus, aContentOffset, aContentEndOffset, aHint,
|
|
|
|
aContinueSelection, aMultipleSelection);
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-15 12:55:36 +03:00
|
|
|
void nsFrameSelection::HandleDrag(nsIFrame* aFrame, const nsPoint& aPoint) {
|
2019-04-03 10:53:16 +03:00
|
|
|
if (!aFrame || !mPresShell) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
nsIFrame* newFrame = 0;
|
|
|
|
nsPoint newPoint;
|
|
|
|
|
|
|
|
result = ConstrainFrameAndPointToAnchorSubtree(aFrame, aPoint, &newFrame,
|
|
|
|
newPoint);
|
|
|
|
if (NS_FAILED(result)) return;
|
|
|
|
if (!newFrame) return;
|
|
|
|
|
|
|
|
nsIFrame::ContentOffsets offsets =
|
|
|
|
newFrame->GetContentOffsetsFromPoint(newPoint);
|
|
|
|
if (!offsets.content) return;
|
|
|
|
|
|
|
|
if (newFrame->IsSelected() &&
|
|
|
|
AdjustForMaintainedSelection(offsets.content, offsets.offset))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Adjust offsets according to maintained amount
|
2017-07-06 15:00:35 +03:00
|
|
|
if (mMaintainRange && mMaintainedAmount != eSelectNoAmount) {
|
2017-07-11 14:53:04 +03:00
|
|
|
nsINode* rangenode = mMaintainRange->GetStartContainer();
|
2017-06-19 01:07:36 +03:00
|
|
|
int32_t rangeOffset = mMaintainRange->StartOffset();
|
|
|
|
int32_t relativePosition = nsContentUtils::ComparePoints(
|
|
|
|
rangenode, rangeOffset, offsets.content, offsets.offset);
|
|
|
|
|
|
|
|
nsDirection direction = relativePosition > 0 ? eDirPrevious : eDirNext;
|
|
|
|
nsSelectionAmount amount = mMaintainedAmount;
|
|
|
|
if (amount == eSelectBeginLine && direction == eDirNext)
|
|
|
|
amount = eSelectEndLine;
|
|
|
|
|
|
|
|
int32_t offset;
|
|
|
|
nsIFrame* frame = GetFrameForNodeOffset(offsets.content, offsets.offset,
|
|
|
|
CARET_ASSOCIATE_AFTER, &offset);
|
|
|
|
|
|
|
|
if (frame && amount == eSelectWord && direction == eDirPrevious) {
|
|
|
|
// To avoid selecting the previous word when at start of word,
|
|
|
|
// first move one character forward.
|
|
|
|
nsPeekOffsetStruct charPos(eSelectCharacter, eDirNext, offset,
|
|
|
|
nsPoint(0, 0), false, mLimiter != nullptr,
|
|
|
|
false, false, false);
|
|
|
|
if (NS_SUCCEEDED(frame->PeekOffset(&charPos))) {
|
|
|
|
frame = charPos.mResultFrame;
|
|
|
|
offset = charPos.mContentOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPeekOffsetStruct pos(amount, direction, offset, nsPoint(0, 0), false,
|
|
|
|
mLimiter != nullptr, false, false, false);
|
|
|
|
|
|
|
|
if (frame && NS_SUCCEEDED(frame->PeekOffset(&pos)) && pos.mResultContent) {
|
|
|
|
offsets.content = pos.mResultContent;
|
|
|
|
offsets.offset = pos.mContentOffset;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
HandleClick(offsets.content, offsets.offset, offsets.offset, true, false,
|
|
|
|
offsets.associate);
|
|
|
|
}
|
|
|
|
|
2017-11-15 12:55:36 +03:00
|
|
|
nsresult nsFrameSelection::StartAutoScrollTimer(nsIFrame* aFrame,
|
|
|
|
const nsPoint& aPoint,
|
2017-06-19 01:07:36 +03:00
|
|
|
uint32_t aDelay) {
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2019-05-06 16:57:46 +03:00
|
|
|
RefPtr<Selection> selection = mDomSelections[index];
|
|
|
|
return selection->StartAutoScrollTimer(aFrame, aPoint, aDelay);
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsFrameSelection::StopAutoScrollTimer() {
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDomSelections[index]->StopAutoScrollTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
hard to go from nodes to frames, easy the other way!
|
|
|
|
*/
|
|
|
|
nsresult nsFrameSelection::TakeFocus(nsIContent* aNewFocus,
|
|
|
|
uint32_t aContentOffset,
|
|
|
|
uint32_t aContentEndOffset,
|
|
|
|
CaretAssociateHint aHint,
|
|
|
|
bool aContinueSelection,
|
|
|
|
bool aMultipleSelection) {
|
|
|
|
if (!aNewFocus) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
NS_ENSURE_STATE(mPresShell);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
if (!IsValidSelectionPoint(this, aNewFocus)) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Clear all table selection data
|
2018-05-08 20:52:36 +03:00
|
|
|
mSelectingTableCellMode = TableSelection::None;
|
2017-06-19 01:07:36 +03:00
|
|
|
mDragSelectingCells = false;
|
|
|
|
mStartSelectedCell = nullptr;
|
|
|
|
mEndSelectedCell = nullptr;
|
|
|
|
mAppendStartSelectedCell = nullptr;
|
|
|
|
mHint = aHint;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
Maybe<Selection::AutoUserInitiated> userSelect;
|
|
|
|
if (IsUserSelectionReason()) {
|
|
|
|
userSelect.emplace(mDomSelections[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// traverse through document and unselect crap here
|
|
|
|
if (!aContinueSelection) { // single click? setting cursor down
|
|
|
|
uint32_t batching = mBatching; // hack to use the collapse code.
|
|
|
|
bool changes = mChangesDuringBatching;
|
|
|
|
mBatching = 1;
|
|
|
|
|
|
|
|
if (aMultipleSelection) {
|
2017-07-06 15:00:35 +03:00
|
|
|
// Remove existing collapsed ranges as there's no point in having
|
2017-06-19 01:07:36 +03:00
|
|
|
// non-anchor/focus collapsed ranges.
|
|
|
|
mDomSelections[index]->RemoveCollapsedRanges();
|
|
|
|
|
|
|
|
RefPtr<nsRange> newRange = new nsRange(aNewFocus);
|
|
|
|
|
|
|
|
newRange->CollapseTo(aNewFocus, aContentOffset);
|
2018-03-27 07:35:22 +03:00
|
|
|
mDomSelections[index]->AddRange(*newRange, IgnoreErrors());
|
2017-06-19 01:07:36 +03:00
|
|
|
mBatching = batching;
|
|
|
|
mChangesDuringBatching = changes;
|
|
|
|
} else {
|
2018-12-05 21:44:05 +03:00
|
|
|
bool oldDesiredPosSet = mDesiredPosSet; // need to keep old desired
|
|
|
|
// position if it was set.
|
2017-06-19 01:07:36 +03:00
|
|
|
mDomSelections[index]->Collapse(aNewFocus, aContentOffset);
|
|
|
|
mDesiredPosSet = oldDesiredPosSet; // now reset desired pos back.
|
|
|
|
mBatching = batching;
|
|
|
|
mChangesDuringBatching = changes;
|
|
|
|
}
|
|
|
|
if (aContentEndOffset != aContentOffset) {
|
|
|
|
mDomSelections[index]->Extend(aNewFocus, aContentEndOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// find out if we are inside a table. if so, find out which one and which
|
2017-07-06 15:00:35 +03:00
|
|
|
// cell once we do that, the next time we get a takefocus, check the parent
|
2017-06-19 01:07:36 +03:00
|
|
|
// tree. if we are no longer inside same table ,cell then switch to table
|
|
|
|
// selection mode.
|
|
|
|
// BUT only do this in an editor
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
NS_ENSURE_STATE(mPresShell);
|
2017-06-19 01:07:36 +03:00
|
|
|
bool editableCell = false;
|
2018-01-09 09:00:00 +03:00
|
|
|
mCellParent = nullptr;
|
2019-04-03 10:53:16 +03:00
|
|
|
RefPtr<nsPresContext> context = mPresShell->GetPresContext();
|
2017-06-19 01:07:36 +03:00
|
|
|
if (context) {
|
2017-08-07 10:33:59 +03:00
|
|
|
RefPtr<HTMLEditor> htmlEditor = nsContentUtils::GetHTMLEditor(context);
|
|
|
|
if (htmlEditor) {
|
2017-06-19 01:07:36 +03:00
|
|
|
nsINode* cellparent = GetCellParent(aNewFocus);
|
2017-08-07 10:33:59 +03:00
|
|
|
nsCOMPtr<nsINode> editorHostNode = htmlEditor->GetActiveEditingHost();
|
2017-07-06 15:00:35 +03:00
|
|
|
editableCell =
|
|
|
|
cellparent && editorHostNode &&
|
2017-06-19 01:07:36 +03:00
|
|
|
nsContentUtils::ContentIsDescendantOf(cellparent, editorHostNode);
|
|
|
|
if (editableCell) {
|
|
|
|
mCellParent = cellparent;
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(" * TakeFocus - Collapsing into new cell\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Now update the range list:
|
|
|
|
if (aContinueSelection && aNewFocus) {
|
|
|
|
int32_t offset;
|
|
|
|
nsINode* cellparent = GetCellParent(aNewFocus);
|
|
|
|
if (mCellParent && cellparent &&
|
|
|
|
cellparent != mCellParent) // switch to cell selection mode
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(" * TakeFocus - moving into new cell\n");
|
|
|
|
#endif
|
|
|
|
WidgetMouseEvent event(false, eVoidEvent, nullptr,
|
|
|
|
WidgetMouseEvent::eReal);
|
|
|
|
|
|
|
|
// Start selecting in the cell we were in before
|
|
|
|
nsINode* parent = ParentOffset(mCellParent, &offset);
|
|
|
|
if (parent)
|
2018-05-08 20:52:36 +03:00
|
|
|
HandleTableSelection(parent, offset, TableSelection::Cell, &event);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
// Find the parent of this new cell and extend selection to it
|
|
|
|
parent = ParentOffset(cellparent, &offset);
|
|
|
|
|
|
|
|
// XXXX We need to REALLY get the current key shift state
|
|
|
|
// (we'd need to add event listener -- let's not bother for now)
|
|
|
|
event.mModifiers &= ~MODIFIER_SHIFT; // aContinueSelection;
|
|
|
|
if (parent) {
|
|
|
|
mCellParent = cellparent;
|
|
|
|
// Continue selection into next cell
|
2018-05-08 20:52:36 +03:00
|
|
|
HandleTableSelection(parent, offset, TableSelection::Cell, &event);
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// XXXX Problem: Shift+click in browser is appending text selection to
|
|
|
|
// selected table!!!
|
|
|
|
// is this the place to erase seleced cells ?????
|
2017-07-06 15:00:35 +03:00
|
|
|
if (mDomSelections[index]->GetDirection() == eDirNext &&
|
|
|
|
aContentEndOffset > aContentOffset) // didn't go far enough
|
2017-06-19 01:07:36 +03:00
|
|
|
{
|
2017-07-06 15:00:35 +03:00
|
|
|
mDomSelections[index]->Extend(
|
|
|
|
aNewFocus, aContentEndOffset); // this will only redraw the diff
|
2017-06-19 01:07:36 +03:00
|
|
|
} else
|
|
|
|
mDomSelections[index]->Extend(aNewFocus, aContentOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't notify selection listeners if batching is on:
|
|
|
|
if (GetBatching()) return NS_OK;
|
|
|
|
|
|
|
|
// Be aware, the Selection instance may be destroyed after this call.
|
|
|
|
return NotifySelectionListeners(SelectionType::eNormal);
|
|
|
|
}
|
|
|
|
|
|
|
|
UniquePtr<SelectionDetails> nsFrameSelection::LookUpSelection(
|
|
|
|
nsIContent* aContent, int32_t aContentOffset, int32_t aContentLength,
|
|
|
|
bool aSlowCheck) const {
|
2019-04-03 10:53:16 +03:00
|
|
|
if (!aContent || !mPresShell) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
UniquePtr<SelectionDetails> details;
|
|
|
|
|
2017-08-24 13:14:04 +03:00
|
|
|
for (size_t j = 0; j < ArrayLength(mDomSelections); j++) {
|
2017-06-19 01:07:36 +03:00
|
|
|
if (mDomSelections[j]) {
|
|
|
|
details = mDomSelections[j]->LookUpSelection(
|
2018-05-30 22:15:35 +03:00
|
|
|
aContent, aContentOffset, aContentLength, std::move(details),
|
2017-08-24 13:14:04 +03:00
|
|
|
kPresentSelectionTypes[j], aSlowCheck);
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return details;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsFrameSelection::SetDragState(bool aState) {
|
|
|
|
if (mDragState == aState) return;
|
|
|
|
|
|
|
|
mDragState = aState;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
if (!mDragState) {
|
|
|
|
mDragSelectingCells = false;
|
|
|
|
// Notify that reason is mouse up.
|
|
|
|
PostReason(nsISelectionListener::MOUSEUP_REASON);
|
|
|
|
// Be aware, the Selection instance may be destroyed after this call.
|
|
|
|
NotifySelectionListeners(SelectionType::eNormal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Selection* nsFrameSelection::GetSelection(SelectionType aSelectionType) const {
|
|
|
|
int8_t index = GetIndexFromSelectionType(aSelectionType);
|
|
|
|
if (index < 0) return nullptr;
|
|
|
|
|
|
|
|
return mDomSelections[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::ScrollSelectionIntoView(SelectionType aSelectionType,
|
|
|
|
SelectionRegion aRegion,
|
|
|
|
int16_t aFlags) const {
|
|
|
|
int8_t index = GetIndexFromSelectionType(aSelectionType);
|
|
|
|
if (index < 0) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2019-04-30 03:07:49 +03:00
|
|
|
ScrollAxis verticalScroll = ScrollAxis();
|
2017-06-19 01:07:36 +03:00
|
|
|
int32_t flags = Selection::SCROLL_DO_FLUSH;
|
|
|
|
if (aFlags & nsISelectionController::SCROLL_SYNCHRONOUS) {
|
|
|
|
flags |= Selection::SCROLL_SYNCHRONOUS;
|
|
|
|
} else if (aFlags & nsISelectionController::SCROLL_FIRST_ANCESTOR_ONLY) {
|
|
|
|
flags |= Selection::SCROLL_FIRST_ANCESTOR_ONLY;
|
|
|
|
}
|
|
|
|
if (aFlags & nsISelectionController::SCROLL_OVERFLOW_HIDDEN) {
|
|
|
|
flags |= Selection::SCROLL_OVERFLOW_HIDDEN;
|
|
|
|
}
|
|
|
|
if (aFlags & nsISelectionController::SCROLL_CENTER_VERTICALLY) {
|
2019-04-30 03:07:49 +03:00
|
|
|
verticalScroll =
|
|
|
|
ScrollAxis(kScrollToCenter, WhenToScroll::IfNotFullyVisible);
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
if (aFlags & nsISelectionController::SCROLL_FOR_CARET_MOVE) {
|
|
|
|
flags |= Selection::SCROLL_FOR_CARET_MOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// After ScrollSelectionIntoView(), the pending notifications might be
|
|
|
|
// flushed and PresShell/PresContext/Frames may be dead. See bug 418470.
|
|
|
|
RefPtr<Selection> sel = mDomSelections[index];
|
2019-04-30 03:07:49 +03:00
|
|
|
return sel->ScrollIntoView(aRegion, verticalScroll, ScrollAxis(), flags);
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::RepaintSelection(SelectionType aSelectionType) {
|
|
|
|
int8_t index = GetIndexFromSelectionType(aSelectionType);
|
|
|
|
if (index < 0) return NS_ERROR_INVALID_ARG;
|
|
|
|
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
|
2019-04-03 10:53:16 +03:00
|
|
|
NS_ENSURE_STATE(mPresShell);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
// On macOS, update the selection cache to the new active selection
|
|
|
|
// aka the current selection.
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
// Check an active window exists otherwise there cannot be a current selection
|
|
|
|
// and that it's a normal selection.
|
|
|
|
if (fm->GetActiveWindow() && aSelectionType == SelectionType::eNormal) {
|
|
|
|
UpdateSelectionCacheOnRepaintSelection(mDomSelections[index]);
|
|
|
|
}
|
|
|
|
#endif
|
2019-04-03 10:53:16 +03:00
|
|
|
return mDomSelections[index]->Repaint(mPresShell->GetPresContext());
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
Bug 1303605: Remove the undisplayed maps. r=bz,mats
This is mostly code removal, changing GetDisplayContentsStyle(..) checks by an
FFI call to Servo.
The tricky parts are:
* MaybeCreateLazily, which I fixed to avoid setting bits under display: none
stuff. This was a pre-existing problem, which was wallpapered by the
sc->IsInDisplayNoneSubtree() check, which effectively made the whole
assertion useless (see bug 1381017 for the only crashtest that hit this
though).
* ContentRemoved, where we can no longer know for sure whether the element is
actually display: contents if we're removing it as a response to a style
change. See the comment there. That kinda sucks, but that case is relatively
weird, and it's better than adding tons of complexity to handle that.
* GetParentComputedStyle, which also has a comment there. Also, this function
has only one caller now, so we should maybe try to remove it.
The different assertions after DestroyFramesForAndRestyle are changed for a
single assertion in the function itself, and the node bit used as an
optimization to avoid hashtable lookups is taken back.
MozReview-Commit-ID: AZm822QnhF9
2018-03-29 04:49:26 +03:00
|
|
|
static bool IsDisplayContents(const nsIContent* aContent) {
|
2018-04-26 03:14:08 +03:00
|
|
|
return aContent->IsElement() && aContent->AsElement()->IsDisplayContents();
|
Bug 1303605: Remove the undisplayed maps. r=bz,mats
This is mostly code removal, changing GetDisplayContentsStyle(..) checks by an
FFI call to Servo.
The tricky parts are:
* MaybeCreateLazily, which I fixed to avoid setting bits under display: none
stuff. This was a pre-existing problem, which was wallpapered by the
sc->IsInDisplayNoneSubtree() check, which effectively made the whole
assertion useless (see bug 1381017 for the only crashtest that hit this
though).
* ContentRemoved, where we can no longer know for sure whether the element is
actually display: contents if we're removing it as a response to a style
change. See the comment there. That kinda sucks, but that case is relatively
weird, and it's better than adding tons of complexity to handle that.
* GetParentComputedStyle, which also has a comment there. Also, this function
has only one caller now, so we should maybe try to remove it.
The different assertions after DestroyFramesForAndRestyle are changed for a
single assertion in the function itself, and the node bit used as an
optimization to avoid hashtable lookups is taken back.
MozReview-Commit-ID: AZm822QnhF9
2018-03-29 04:49:26 +03:00
|
|
|
}
|
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
nsIFrame* nsFrameSelection::GetFrameForNodeOffset(
|
|
|
|
nsIContent* aNode, int32_t aOffset, CaretAssociateHint aHint,
|
|
|
|
int32_t* aReturnOffset) const {
|
2019-04-03 10:53:16 +03:00
|
|
|
if (!aNode || !aReturnOffset || !mPresShell) return nullptr;
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
if (aOffset < 0) return nullptr;
|
|
|
|
|
Bug 1303605: Remove the undisplayed maps. r=bz,mats
This is mostly code removal, changing GetDisplayContentsStyle(..) checks by an
FFI call to Servo.
The tricky parts are:
* MaybeCreateLazily, which I fixed to avoid setting bits under display: none
stuff. This was a pre-existing problem, which was wallpapered by the
sc->IsInDisplayNoneSubtree() check, which effectively made the whole
assertion useless (see bug 1381017 for the only crashtest that hit this
though).
* ContentRemoved, where we can no longer know for sure whether the element is
actually display: contents if we're removing it as a response to a style
change. See the comment there. That kinda sucks, but that case is relatively
weird, and it's better than adding tons of complexity to handle that.
* GetParentComputedStyle, which also has a comment there. Also, this function
has only one caller now, so we should maybe try to remove it.
The different assertions after DestroyFramesForAndRestyle are changed for a
single assertion in the function itself, and the node bit used as an
optimization to avoid hashtable lookups is taken back.
MozReview-Commit-ID: AZm822QnhF9
2018-03-29 04:49:26 +03:00
|
|
|
if (!aNode->GetPrimaryFrame() && !IsDisplayContents(aNode)) {
|
2017-06-19 01:07:36 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* returnFrame = nullptr;
|
|
|
|
nsCOMPtr<nsIContent> theNode;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
*aReturnOffset = aOffset;
|
|
|
|
|
|
|
|
theNode = aNode;
|
|
|
|
|
|
|
|
if (aNode->IsElement()) {
|
|
|
|
int32_t childIndex = 0;
|
|
|
|
int32_t numChildren = theNode->GetChildCount();
|
|
|
|
|
|
|
|
if (aHint == CARET_ASSOCIATE_BEFORE) {
|
|
|
|
if (aOffset > 0) {
|
|
|
|
childIndex = aOffset - 1;
|
|
|
|
} else {
|
|
|
|
childIndex = aOffset;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(aHint == CARET_ASSOCIATE_AFTER, "unknown direction");
|
|
|
|
if (aOffset >= numChildren) {
|
|
|
|
if (numChildren > 0) {
|
|
|
|
childIndex = numChildren - 1;
|
|
|
|
} else {
|
|
|
|
childIndex = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
childIndex = aOffset;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
if (childIndex > 0 || numChildren > 0) {
|
2018-01-03 15:59:54 +03:00
|
|
|
nsCOMPtr<nsIContent> childNode =
|
|
|
|
theNode->GetChildAt_Deprecated(childIndex);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
if (!childNode) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
theNode = childNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that we have the child node, check if it too
|
|
|
|
// can contain children. If so, descend into child.
|
|
|
|
if (theNode->IsElement() && theNode->GetChildCount() &&
|
|
|
|
!theNode->HasIndependentSelection()) {
|
|
|
|
aNode = theNode;
|
|
|
|
aOffset = aOffset > childIndex ? theNode->GetChildCount() : 0;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// Check to see if theNode is a text node. If it is, translate
|
|
|
|
// aOffset into an offset into the text node.
|
|
|
|
|
2018-03-19 22:15:39 +03:00
|
|
|
RefPtr<Text> textNode = theNode->GetAsText();
|
2017-06-19 01:07:36 +03:00
|
|
|
if (textNode) {
|
|
|
|
if (theNode->GetPrimaryFrame()) {
|
|
|
|
if (aOffset > childIndex) {
|
2018-03-19 22:15:39 +03:00
|
|
|
uint32_t textLength = textNode->Length();
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
*aReturnOffset = (int32_t)textLength;
|
|
|
|
} else {
|
|
|
|
*aReturnOffset = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int32_t numChildren = aNode->GetChildCount();
|
|
|
|
int32_t newChildIndex = aHint == CARET_ASSOCIATE_BEFORE
|
|
|
|
? childIndex - 1
|
|
|
|
: childIndex + 1;
|
|
|
|
|
|
|
|
if (newChildIndex >= 0 && newChildIndex < numChildren) {
|
2018-01-03 15:59:54 +03:00
|
|
|
nsCOMPtr<nsIContent> newChildNode =
|
|
|
|
aNode->GetChildAt_Deprecated(newChildIndex);
|
2017-06-19 01:07:36 +03:00
|
|
|
if (!newChildNode) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
aNode = newChildNode;
|
|
|
|
aOffset =
|
|
|
|
aHint == CARET_ASSOCIATE_BEFORE ? aNode->GetChildCount() : 0;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// newChildIndex is illegal which means we're at first or last
|
|
|
|
// child. Just use original node to get the frame.
|
|
|
|
theNode = aNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the node is a ShadowRoot, the frame needs to be adjusted,
|
|
|
|
// because a ShadowRoot does not get a frame. Its children are rendered
|
|
|
|
// as children of the host.
|
2017-12-31 22:57:32 +03:00
|
|
|
if (ShadowRoot* shadow = ShadowRoot::FromNode(theNode)) {
|
|
|
|
theNode = shadow->GetHost();
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
returnFrame = theNode->GetPrimaryFrame();
|
|
|
|
if (!returnFrame) {
|
|
|
|
if (aHint == CARET_ASSOCIATE_BEFORE) {
|
|
|
|
if (aOffset > 0) {
|
|
|
|
--aOffset;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int32_t end = theNode->GetChildCount();
|
|
|
|
if (aOffset < end) {
|
|
|
|
++aOffset;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} // end while
|
|
|
|
|
|
|
|
if (!returnFrame) return nullptr;
|
|
|
|
|
|
|
|
// If we ended up here and were asked to position the caret after a visible
|
|
|
|
// break, let's return the frame on the next line instead if it exists.
|
|
|
|
if (aOffset > 0 && (uint32_t)aOffset >= aNode->Length() &&
|
|
|
|
theNode == aNode->GetLastChild()) {
|
|
|
|
nsIFrame* newFrame;
|
|
|
|
nsLayoutUtils::IsInvisibleBreak(theNode, &newFrame);
|
|
|
|
if (newFrame) {
|
|
|
|
returnFrame = newFrame;
|
|
|
|
*aReturnOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the child frame containing the offset we want
|
|
|
|
returnFrame->GetChildFrameContainingOffset(
|
|
|
|
*aReturnOffset, aHint == CARET_ASSOCIATE_AFTER, &aOffset, &returnFrame);
|
|
|
|
return returnFrame;
|
|
|
|
}
|
|
|
|
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
nsIFrame* nsFrameSelection::GetFrameToPageSelect() const {
|
2019-04-03 10:53:16 +03:00
|
|
|
if (NS_WARN_IF(!mPresShell)) {
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* rootFrameToSelect;
|
|
|
|
if (mLimiter) {
|
|
|
|
rootFrameToSelect = mLimiter->GetPrimaryFrame();
|
|
|
|
if (NS_WARN_IF(!rootFrameToSelect)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} else if (mAncestorLimiter) {
|
|
|
|
rootFrameToSelect = mAncestorLimiter->GetPrimaryFrame();
|
|
|
|
if (NS_WARN_IF(!rootFrameToSelect)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
2019-04-03 10:53:16 +03:00
|
|
|
rootFrameToSelect = mPresShell->GetRootScrollFrame();
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
if (NS_WARN_IF(!rootFrameToSelect)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
nsCOMPtr<nsIContent> contentToSelect = mPresShell->GetContentForScrolling();
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
if (contentToSelect) {
|
|
|
|
// If there is selected content, look for nearest and vertical scrollable
|
|
|
|
// parent under the root frame.
|
|
|
|
for (nsIFrame* frame = contentToSelect->GetPrimaryFrame();
|
|
|
|
frame && frame != rootFrameToSelect; frame = frame->GetParent()) {
|
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(frame);
|
|
|
|
if (!scrollableFrame) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ScrollStyles scrollStyles = scrollableFrame->GetScrollStyles();
|
2018-12-11 03:50:32 +03:00
|
|
|
if (scrollStyles.mVertical == StyleOverflow::Hidden) {
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
uint32_t directions = scrollableFrame->GetPerceivedScrollingDirections();
|
|
|
|
if (directions & nsIScrollableFrame::VERTICAL) {
|
|
|
|
// If there is sub scrollable frame, let's use its page size to select.
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Otherwise, i.e., there is no scrollable frame or only the root frame is
|
|
|
|
// scrollable, let's return the root frame because Shift + PageUp/PageDown
|
|
|
|
// should expand the selection in the root content even if it's not
|
|
|
|
// scrollable.
|
|
|
|
return rootFrameToSelect;
|
|
|
|
}
|
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
void nsFrameSelection::CommonPageMove(bool aForward, bool aExtend,
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
nsIFrame* aFrame) {
|
|
|
|
MOZ_ASSERT(aFrame);
|
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
// expected behavior for PageMove is to scroll AND move the caret
|
|
|
|
// and remain relative position of the caret in view. see Bug 4302.
|
|
|
|
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
// Get the scrollable frame. If aFrame is not scrollable, this is nullptr.
|
|
|
|
nsIScrollableFrame* scrollableFrame = aFrame->GetScrollTargetFrame();
|
|
|
|
// Get the scrolled frame. If aFrame is not scrollable, this is aFrame
|
|
|
|
// itself.
|
|
|
|
nsIFrame* scrolledFrame =
|
|
|
|
scrollableFrame ? scrollableFrame->GetScrolledFrame() : aFrame;
|
|
|
|
if (!scrolledFrame) {
|
2017-06-19 01:07:36 +03:00
|
|
|
return;
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
}
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
// find out where the caret is.
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
// we should know mDesiredPos value of nsFrameSelection, but I havent seen
|
|
|
|
// that behavior in other windows applications yet.
|
2018-05-08 20:52:42 +03:00
|
|
|
Selection* domSel = GetSelection(SelectionType::eNormal);
|
2017-06-19 01:07:36 +03:00
|
|
|
if (!domSel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect caretPos;
|
|
|
|
nsIFrame* caretFrame = nsCaret::GetGeometry(domSel, &caretPos);
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
if (!caretFrame) {
|
2017-06-19 01:07:36 +03:00
|
|
|
return;
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
Bug 1498816 - part 1: Make nsFrameSelection::CommonPageMove() emulate click in current selection limiter r=smaug
nsFrameSelection::CommonPageMove() is called only by
nsTextInputSelectionImpl::PageMove() and PresShell::PageMove(). So, this is
the only implementation of (Shift+) PageDown and (Shift+) PageUp.
This scrolls down/up the specific frame. However, this allows to scroll
outside of selection limiter, for example, even when an editing host is
focused, its parent scrollable element may be scrolled. This is same behavior
as Blink so that we should keep this behavior.
However, it also emulates to click same position after scroll and this behavior
is different from Blink. At this time, it does not check selection limiter and
then, nsFrameSelection::HandleClick() may reset selection limiter the scrolled
frame is a parent frame of the limiter.
Therefore, this patch makes it check if the scrolled frame is a parent of the
limiter, and if so, use result of GetFrameToPageSelect() to emulate a click
instead. The result won't be a parent of the limiter because it is used when
handling Shift + PageDown and Shift + PageUp which are always handled in the
limiter.
Differential Revision: https://phabricator.services.mozilla.com/D13202
--HG--
extra : moz-landing-system : lando
2018-11-29 09:16:15 +03:00
|
|
|
// If the scrolled frame is outside of current selection limiter,
|
|
|
|
// we need to scroll the frame but keep moving selection in the limiter.
|
|
|
|
nsIFrame* frameToClick = scrolledFrame;
|
|
|
|
if (!IsValidSelectionPoint(this, scrolledFrame->GetContent())) {
|
|
|
|
frameToClick = GetFrameToPageSelect();
|
|
|
|
if (NS_WARN_IF(!frameToClick)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scrollableFrame && scrolledFrame == frameToClick) {
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
// If aFrame is scrollable, adjust pseudo-click position with page scroll
|
|
|
|
// amount.
|
|
|
|
if (aForward) {
|
|
|
|
caretPos.y += scrollableFrame->GetPageScrollAmount().height;
|
|
|
|
} else {
|
|
|
|
caretPos.y -= scrollableFrame->GetPageScrollAmount().height;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Otherwise, adjust pseudo-click position with the frame size.
|
|
|
|
if (aForward) {
|
Bug 1498816 - part 1: Make nsFrameSelection::CommonPageMove() emulate click in current selection limiter r=smaug
nsFrameSelection::CommonPageMove() is called only by
nsTextInputSelectionImpl::PageMove() and PresShell::PageMove(). So, this is
the only implementation of (Shift+) PageDown and (Shift+) PageUp.
This scrolls down/up the specific frame. However, this allows to scroll
outside of selection limiter, for example, even when an editing host is
focused, its parent scrollable element may be scrolled. This is same behavior
as Blink so that we should keep this behavior.
However, it also emulates to click same position after scroll and this behavior
is different from Blink. At this time, it does not check selection limiter and
then, nsFrameSelection::HandleClick() may reset selection limiter the scrolled
frame is a parent frame of the limiter.
Therefore, this patch makes it check if the scrolled frame is a parent of the
limiter, and if so, use result of GetFrameToPageSelect() to emulate a click
instead. The result won't be a parent of the limiter because it is used when
handling Shift + PageDown and Shift + PageUp which are always handled in the
limiter.
Differential Revision: https://phabricator.services.mozilla.com/D13202
--HG--
extra : moz-landing-system : lando
2018-11-29 09:16:15 +03:00
|
|
|
caretPos.y += frameToClick->GetSize().height;
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
} else {
|
Bug 1498816 - part 1: Make nsFrameSelection::CommonPageMove() emulate click in current selection limiter r=smaug
nsFrameSelection::CommonPageMove() is called only by
nsTextInputSelectionImpl::PageMove() and PresShell::PageMove(). So, this is
the only implementation of (Shift+) PageDown and (Shift+) PageUp.
This scrolls down/up the specific frame. However, this allows to scroll
outside of selection limiter, for example, even when an editing host is
focused, its parent scrollable element may be scrolled. This is same behavior
as Blink so that we should keep this behavior.
However, it also emulates to click same position after scroll and this behavior
is different from Blink. At this time, it does not check selection limiter and
then, nsFrameSelection::HandleClick() may reset selection limiter the scrolled
frame is a parent frame of the limiter.
Therefore, this patch makes it check if the scrolled frame is a parent of the
limiter, and if so, use result of GetFrameToPageSelect() to emulate a click
instead. The result won't be a parent of the limiter because it is used when
handling Shift + PageDown and Shift + PageUp which are always handled in the
limiter.
Differential Revision: https://phabricator.services.mozilla.com/D13202
--HG--
extra : moz-landing-system : lando
2018-11-29 09:16:15 +03:00
|
|
|
caretPos.y -= frameToClick->GetSize().height;
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
}
|
|
|
|
}
|
2017-06-19 01:07:36 +03:00
|
|
|
|
Bug 1498816 - part 1: Make nsFrameSelection::CommonPageMove() emulate click in current selection limiter r=smaug
nsFrameSelection::CommonPageMove() is called only by
nsTextInputSelectionImpl::PageMove() and PresShell::PageMove(). So, this is
the only implementation of (Shift+) PageDown and (Shift+) PageUp.
This scrolls down/up the specific frame. However, this allows to scroll
outside of selection limiter, for example, even when an editing host is
focused, its parent scrollable element may be scrolled. This is same behavior
as Blink so that we should keep this behavior.
However, it also emulates to click same position after scroll and this behavior
is different from Blink. At this time, it does not check selection limiter and
then, nsFrameSelection::HandleClick() may reset selection limiter the scrolled
frame is a parent frame of the limiter.
Therefore, this patch makes it check if the scrolled frame is a parent of the
limiter, and if so, use result of GetFrameToPageSelect() to emulate a click
instead. The result won't be a parent of the limiter because it is used when
handling Shift + PageDown and Shift + PageUp which are always handled in the
limiter.
Differential Revision: https://phabricator.services.mozilla.com/D13202
--HG--
extra : moz-landing-system : lando
2018-11-29 09:16:15 +03:00
|
|
|
caretPos += caretFrame->GetOffsetTo(frameToClick);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
// get a content at desired location
|
|
|
|
nsPoint desiredPoint;
|
|
|
|
desiredPoint.x = caretPos.x;
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
desiredPoint.y = caretPos.y + caretPos.height / 2;
|
2017-06-19 01:07:36 +03:00
|
|
|
nsIFrame::ContentOffsets offsets =
|
Bug 1498816 - part 1: Make nsFrameSelection::CommonPageMove() emulate click in current selection limiter r=smaug
nsFrameSelection::CommonPageMove() is called only by
nsTextInputSelectionImpl::PageMove() and PresShell::PageMove(). So, this is
the only implementation of (Shift+) PageDown and (Shift+) PageUp.
This scrolls down/up the specific frame. However, this allows to scroll
outside of selection limiter, for example, even when an editing host is
focused, its parent scrollable element may be scrolled. This is same behavior
as Blink so that we should keep this behavior.
However, it also emulates to click same position after scroll and this behavior
is different from Blink. At this time, it does not check selection limiter and
then, nsFrameSelection::HandleClick() may reset selection limiter the scrolled
frame is a parent frame of the limiter.
Therefore, this patch makes it check if the scrolled frame is a parent of the
limiter, and if so, use result of GetFrameToPageSelect() to emulate a click
instead. The result won't be a parent of the limiter because it is used when
handling Shift + PageDown and Shift + PageUp which are always handled in the
limiter.
Differential Revision: https://phabricator.services.mozilla.com/D13202
--HG--
extra : moz-landing-system : lando
2018-11-29 09:16:15 +03:00
|
|
|
frameToClick->GetContentOffsetsFromPoint(desiredPoint);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
if (!offsets.content) {
|
2017-06-19 01:07:36 +03:00
|
|
|
return;
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
}
|
2017-06-19 01:07:36 +03:00
|
|
|
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
// Scroll one page if necessary.
|
|
|
|
if (scrollableFrame) {
|
|
|
|
scrollableFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
|
2019-04-26 02:03:04 +03:00
|
|
|
nsIScrollableFrame::PAGES, ScrollMode::Smooth);
|
Bug 1482425 - PresShell::PageMove() should use different rules to look for a container element for aExtend value r=smaug
PresShell::PageMove() climbs up to parent document when there is no scrollable
parent in current document. However, if aExtend is true, it should expand
Selection in the document itself. Therefore, it needs different rules to
look for container of expanding Selection from scrollable element to scroll.
Additionally, old rules (i.e., before the fix of bug 1369072 which caused
this regression) were also buggy. It used parent scrollable element or
root scrollable element simply. Therefore, if found scrollable element is
ancestor of selection limiter, it didn't work as expected.
This patch creates nsFrameSelection::GetFrameToPageSelect() to retrieve
per-page selection container element with the following rules:
- look for a scrollable element in selection limiter.
- if there is no scrollable element, use selection limiter.
- if there is no selection limiter, use the root frame.
So, nsFrameSelection::CommonPageMove() should take nsIFrame rather than
nsIScrollableFrame since container of per-page selection may be used in
non-scrollable contenteditable element. If it's called with non-scrollable
frame, it needs to compute the expanding range with the frame size.
Differential Revision: https://phabricator.services.mozilla.com/D8954
--HG--
extra : moz-landing-system : lando
2018-10-18 07:42:53 +03:00
|
|
|
}
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
// place the caret
|
|
|
|
HandleClick(offsets.content, offsets.offset, offsets.offset, aExtend, false,
|
|
|
|
CARET_ASSOCIATE_AFTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::PhysicalMove(int16_t aDirection, int16_t aAmount,
|
|
|
|
bool aExtend) {
|
2019-04-03 10:53:16 +03:00
|
|
|
NS_ENSURE_STATE(mPresShell);
|
2017-06-19 01:07:36 +03:00
|
|
|
// Flush out layout, since we need it to be up to date to do caret
|
|
|
|
// positioning.
|
2019-04-03 10:53:16 +03:00
|
|
|
OwningNonNull<PresShell> presShell(*mPresShell);
|
|
|
|
presShell->FlushPendingNotifications(FlushType::Layout);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
if (!mPresShell) {
|
2017-06-19 01:07:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that parameters are safe
|
|
|
|
if (aDirection < 0 || aDirection > 3 || aAmount < 0 || aAmount > 1) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-04-03 10:53:16 +03:00
|
|
|
nsPresContext* context = mPresShell->GetPresContext();
|
2017-06-19 01:07:36 +03:00
|
|
|
if (!context) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
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[] = {eSelectCluster, eSelectWord};
|
|
|
|
static const nsSelectionAmount blockPrevAmount[] = {eSelectLine,
|
|
|
|
eSelectBeginLine};
|
|
|
|
static const nsSelectionAmount blockNextAmount[] = {eSelectLine,
|
|
|
|
eSelectEndLine};
|
|
|
|
|
|
|
|
struct PhysicalToLogicalMapping {
|
|
|
|
nsDirection direction;
|
|
|
|
const nsSelectionAmount* amounts;
|
|
|
|
};
|
|
|
|
static const PhysicalToLogicalMapping verticalLR[4] = {
|
|
|
|
{eDirPrevious, blockPrevAmount}, // left
|
|
|
|
{eDirNext, blockNextAmount}, // right
|
|
|
|
{eDirPrevious, inlineAmount}, // up
|
|
|
|
{eDirNext, inlineAmount} // down
|
|
|
|
};
|
|
|
|
static const PhysicalToLogicalMapping verticalRL[4] = {
|
|
|
|
{eDirNext, blockNextAmount},
|
|
|
|
{eDirPrevious, blockPrevAmount},
|
|
|
|
{eDirPrevious, inlineAmount},
|
|
|
|
{eDirNext, inlineAmount}};
|
|
|
|
static const PhysicalToLogicalMapping horizontal[4] = {
|
|
|
|
{eDirPrevious, inlineAmount},
|
|
|
|
{eDirNext, inlineAmount},
|
|
|
|
{eDirPrevious, blockPrevAmount},
|
|
|
|
{eDirNext, blockNextAmount}};
|
|
|
|
|
|
|
|
WritingMode wm;
|
|
|
|
nsIFrame* frame = nullptr;
|
|
|
|
int32_t offsetused = 0;
|
|
|
|
if (NS_SUCCEEDED(
|
|
|
|
sel->GetPrimaryFrameForFocusNode(&frame, &offsetused, true))) {
|
|
|
|
if (frame) {
|
2018-03-22 21:20:41 +03:00
|
|
|
if (!frame->Style()->IsTextCombined()) {
|
2017-06-19 01:07:36 +03:00
|
|
|
wm = frame->GetWritingMode();
|
|
|
|
} else {
|
|
|
|
// Using different direction for horizontal-in-vertical would
|
|
|
|
// make it hard to navigate via keyboard. Inherit the moving
|
|
|
|
// direction from its parent.
|
|
|
|
MOZ_ASSERT(frame->IsTextFrame());
|
|
|
|
wm = frame->GetParent()->GetWritingMode();
|
|
|
|
MOZ_ASSERT(wm.IsVertical(),
|
|
|
|
"Text combined "
|
|
|
|
"can only appear in vertical text");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const PhysicalToLogicalMapping& mapping =
|
|
|
|
wm.IsVertical()
|
|
|
|
? wm.IsVerticalLR() ? verticalLR[aDirection] : verticalRL[aDirection]
|
|
|
|
: horizontal[aDirection];
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
MoveCaret(mapping.direction, aExtend, mapping.amounts[aAmount], eVisual);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// If we tried to do a line move, but couldn't move in the given direction,
|
|
|
|
// then we'll "promote" this to a line-edge move instead.
|
|
|
|
if (mapping.amounts[aAmount] == eSelectLine) {
|
|
|
|
rv = MoveCaret(mapping.direction, aExtend, mapping.amounts[aAmount + 1],
|
|
|
|
eVisual);
|
|
|
|
}
|
|
|
|
// And if it was a next-word move that failed (which can happen when
|
|
|
|
// eat_space_to_next_word is true, see bug 1153237), then just move forward
|
|
|
|
// to the line-edge.
|
|
|
|
else if (mapping.amounts[aAmount] == eSelectWord &&
|
|
|
|
mapping.direction == eDirNext) {
|
|
|
|
rv = MoveCaret(eDirNext, aExtend, eSelectEndLine, eVisual);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::CharacterMove(bool aForward, bool aExtend) {
|
|
|
|
return MoveCaret(aForward ? eDirNext : eDirPrevious, aExtend, eSelectCluster,
|
|
|
|
eUsePrefStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::CharacterExtendForDelete() {
|
|
|
|
return MoveCaret(eDirNext, true, eSelectCluster, eLogical);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::CharacterExtendForBackspace() {
|
|
|
|
return MoveCaret(eDirPrevious, true, eSelectCharacter, eLogical);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::WordMove(bool aForward, bool aExtend) {
|
|
|
|
return MoveCaret(aForward ? eDirNext : eDirPrevious, aExtend, eSelectWord,
|
|
|
|
eUsePrefStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::WordExtendForDelete(bool aForward) {
|
|
|
|
return MoveCaret(aForward ? eDirNext : eDirPrevious, true, eSelectWord,
|
|
|
|
eLogical);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::LineMove(bool aForward, bool aExtend) {
|
|
|
|
return MoveCaret(aForward ? eDirNext : eDirPrevious, aExtend, eSelectLine,
|
|
|
|
eUsePrefStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::IntraLineMove(bool aForward, bool aExtend) {
|
|
|
|
if (aForward) {
|
|
|
|
return MoveCaret(eDirNext, aExtend, eSelectEndLine, eLogical);
|
|
|
|
} else {
|
|
|
|
return MoveCaret(eDirPrevious, aExtend, eSelectBeginLine, eLogical);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::SelectAll() {
|
|
|
|
nsCOMPtr<nsIContent> rootContent;
|
|
|
|
if (mLimiter) {
|
|
|
|
rootContent = mLimiter; // addrefit
|
|
|
|
} else if (mAncestorLimiter) {
|
|
|
|
rootContent = mAncestorLimiter;
|
|
|
|
} else {
|
2019-04-03 10:53:16 +03:00
|
|
|
NS_ENSURE_STATE(mPresShell);
|
|
|
|
Document* doc = mPresShell->GetDocument();
|
2017-06-19 01:07:36 +03:00
|
|
|
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(SelectionType::eNormal);
|
|
|
|
AutoPrepareFocusRange prep(mDomSelections[index], false, false);
|
|
|
|
return TakeFocus(rootContent, 0, numChildren, CARET_ASSOCIATE_BEFORE, false,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////END FRAMESELECTION
|
|
|
|
|
|
|
|
void nsFrameSelection::StartBatchChanges() { mBatching++; }
|
|
|
|
|
|
|
|
void nsFrameSelection::EndBatchChanges(int16_t aReason) {
|
|
|
|
mBatching--;
|
|
|
|
NS_ASSERTION(mBatching >= 0, "Bad mBatching");
|
|
|
|
|
|
|
|
if (mBatching == 0 && mChangesDuringBatching) {
|
|
|
|
int16_t postReason = PopReason() | aReason;
|
|
|
|
PostReason(postReason);
|
|
|
|
mChangesDuringBatching = false;
|
|
|
|
// Be aware, the Selection instance may be destroyed after this call.
|
|
|
|
NotifySelectionListeners(SelectionType::eNormal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::NotifySelectionListeners(
|
|
|
|
SelectionType aSelectionType) {
|
|
|
|
int8_t index = GetIndexFromSelectionType(aSelectionType);
|
|
|
|
if (index >= 0 && mDomSelections[index]) {
|
|
|
|
RefPtr<Selection> selection = mDomSelections[index];
|
|
|
|
return selection->NotifySelectionListeners();
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start of Table Selection methods
|
|
|
|
|
|
|
|
static bool IsCell(nsIContent* aContent) {
|
|
|
|
return aContent->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsITableCellLayout* nsFrameSelection::GetCellLayout(
|
|
|
|
nsIContent* aCellContent) const {
|
2019-04-03 10:53:16 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, nullptr);
|
2017-06-19 01:07:36 +03:00
|
|
|
nsITableCellLayout* cellLayoutObject =
|
|
|
|
do_QueryFrame(aCellContent->GetPrimaryFrame());
|
|
|
|
return cellLayoutObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::ClearNormalSelection() {
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2018-03-27 07:35:23 +03:00
|
|
|
ErrorResult err;
|
|
|
|
mDomSelections[index]->RemoveAllRanges(err);
|
|
|
|
return err.StealNSResult();
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsIContent* GetFirstSelectedContent(nsRange* aRange) {
|
|
|
|
if (!aRange) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aRange->GetStartContainer(), "Must have start parent!");
|
|
|
|
MOZ_ASSERT(aRange->GetStartContainer()->IsElement(), "Unexpected parent");
|
2017-06-19 01:07:36 +03:00
|
|
|
|
2018-01-12 17:33:14 +03:00
|
|
|
return aRange->GetChildAtStartOffset();
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Table selection support.
|
|
|
|
// TODO: Separate table methods into a separate nsITableSelection interface
|
|
|
|
nsresult nsFrameSelection::HandleTableSelection(nsINode* aParentContent,
|
|
|
|
int32_t aContentOffset,
|
2018-05-08 20:52:36 +03:00
|
|
|
TableSelection aTarget,
|
2017-06-19 01:07:36 +03:00
|
|
|
WidgetMouseEvent* aMouseEvent) {
|
|
|
|
NS_ENSURE_TRUE(aParentContent, NS_ERROR_NULL_POINTER);
|
|
|
|
NS_ENSURE_TRUE(aMouseEvent, NS_ERROR_NULL_POINTER);
|
|
|
|
|
2018-05-08 20:52:36 +03:00
|
|
|
if (mDragState && mDragSelectingCells && aTarget == TableSelection::Table) {
|
2017-06-19 01:07:36 +03:00
|
|
|
// We were selecting cells and user drags mouse in table border or inbetween
|
|
|
|
// cells,
|
|
|
|
// just do nothing
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2018-01-03 15:59:54 +03:00
|
|
|
nsIContent* childContent =
|
|
|
|
aParentContent->GetChildAt_Deprecated(aContentOffset);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
// 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(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
mDomSelections[index]->SetDirection(eDirNext);
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
// Stack-class to wrap all table selection changes in
|
2017-06-19 01:07:36 +03:00
|
|
|
// BeginBatchChanges() / EndBatchChanges()
|
|
|
|
SelectionBatcher selectionBatcher(mDomSelections[index]);
|
|
|
|
|
|
|
|
int32_t startRowIndex, startColIndex, curRowIndex, curColIndex;
|
|
|
|
if (mDragState && mDragSelectingCells) {
|
|
|
|
// We are drag-selecting
|
2018-05-08 20:52:36 +03:00
|
|
|
if (aTarget != TableSelection::Table) {
|
2017-06-19 01:07:36 +03:00
|
|
|
// If dragging in the same cell as last event, do nothing
|
|
|
|
if (mEndSelectedCell == childContent) return NS_OK;
|
|
|
|
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(
|
|
|
|
" mStartSelectedCell = %p, mEndSelectedCell = %p, childContent = %p "
|
|
|
|
"\n",
|
|
|
|
mStartSelectedCell.get(), mEndSelectedCell.get(), childContent);
|
|
|
|
#endif
|
|
|
|
// aTarget can be any "cell mode",
|
2017-07-06 15:00:35 +03:00
|
|
|
// so we can easily drag-select rows and columns
|
2017-06-19 01:07:36 +03:00
|
|
|
// Once we are in row or column mode,
|
|
|
|
// we can drift into any cell to stay in that mode
|
2018-05-08 20:52:36 +03:00
|
|
|
// even if aTarget = TableSelection::Cell
|
2017-06-19 01:07:36 +03:00
|
|
|
|
2018-05-08 20:52:36 +03:00
|
|
|
if (mSelectingTableCellMode == TableSelection::Row ||
|
|
|
|
mSelectingTableCellMode == TableSelection::Column) {
|
2017-06-19 01:07:36 +03:00
|
|
|
if (mEndSelectedCell) {
|
|
|
|
// Also check if cell is in same row/col
|
|
|
|
result =
|
|
|
|
GetCellIndexes(mEndSelectedCell, startRowIndex, startColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
result = GetCellIndexes(childContent, curRowIndex, curColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(
|
|
|
|
" curRowIndex = %d, startRowIndex = %d, curColIndex = %d, "
|
|
|
|
"startColIndex = %d\n",
|
|
|
|
curRowIndex, startRowIndex, curColIndex, startColIndex);
|
|
|
|
#endif
|
2018-05-08 20:52:36 +03:00
|
|
|
if ((mSelectingTableCellMode == TableSelection::Row &&
|
|
|
|
startRowIndex == curRowIndex) ||
|
|
|
|
(mSelectingTableCellMode == TableSelection::Column &&
|
|
|
|
startColIndex == curColIndex))
|
2017-06-19 01:07:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(" Dragged into a new column or row\n");
|
|
|
|
#endif
|
|
|
|
// Continue dragging row or column selection
|
|
|
|
return SelectRowOrColumn(childContent, mSelectingTableCellMode);
|
2018-05-08 20:52:36 +03:00
|
|
|
} else if (mSelectingTableCellMode == TableSelection::Cell) {
|
2017-06-19 01:07:36 +03:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf("HandleTableSelection: Dragged into a new cell\n");
|
|
|
|
#endif
|
|
|
|
// Trick for quick selection of rows and columns
|
|
|
|
// Hold down shift, then start selecting in one direction
|
|
|
|
// If next cell dragged into is in same row, select entire row,
|
|
|
|
// if next cell is in same column, select entire column
|
|
|
|
if (mStartSelectedCell && aMouseEvent->IsShift()) {
|
|
|
|
result =
|
|
|
|
GetCellIndexes(mStartSelectedCell, startRowIndex, startColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
result = GetCellIndexes(childContent, curRowIndex, curColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
|
|
|
if (startRowIndex == curRowIndex || startColIndex == curColIndex) {
|
2017-06-19 01:07:36 +03:00
|
|
|
// Force new selection block
|
|
|
|
mStartSelectedCell = nullptr;
|
2018-03-27 07:35:23 +03:00
|
|
|
mDomSelections[index]->RemoveAllRanges(IgnoreErrors());
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
if (startRowIndex == curRowIndex)
|
2018-05-08 20:52:36 +03:00
|
|
|
mSelectingTableCellMode = TableSelection::Row;
|
2017-06-19 01:07:36 +03:00
|
|
|
else
|
2018-05-08 20:52:36 +03:00
|
|
|
mSelectingTableCellMode = TableSelection::Column;
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
return SelectRowOrColumn(childContent, mSelectingTableCellMode);
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
// Reselect block of cells to new end location
|
|
|
|
return SelectBlockOfCells(mStartSelectedCell, childContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Do nothing if dragging in table, but outside a cell
|
|
|
|
return NS_OK;
|
2017-07-06 15:00:35 +03:00
|
|
|
} else {
|
2017-06-19 01:07:36 +03:00
|
|
|
// Not dragging -- mouse event is down or up
|
|
|
|
if (mDragState) {
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf("HandleTableSelection: Mouse down event\n");
|
|
|
|
#endif
|
|
|
|
// Clear cell we stored in mouse-down
|
|
|
|
mUnselectCellOnMouseUp = nullptr;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2018-05-08 20:52:36 +03:00
|
|
|
if (aTarget == TableSelection::Cell) {
|
2017-06-19 01:07:36 +03:00
|
|
|
bool isSelected = false;
|
|
|
|
|
|
|
|
// Check if we have other selected cells
|
|
|
|
nsIContent* previousCellNode =
|
|
|
|
GetFirstSelectedContent(GetFirstCellRange());
|
|
|
|
if (previousCellNode) {
|
|
|
|
// We have at least 1 other selected cell
|
|
|
|
|
|
|
|
// Check if new cell is already selected
|
|
|
|
nsIFrame* cellFrame = childContent->GetPrimaryFrame();
|
|
|
|
if (!cellFrame) return NS_ERROR_NULL_POINTER;
|
|
|
|
isSelected = cellFrame->IsSelected();
|
|
|
|
} else {
|
|
|
|
// No cells selected -- remove non-cell selection
|
2018-03-27 07:35:23 +03:00
|
|
|
mDomSelections[index]->RemoveAllRanges(IgnoreErrors());
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
mDragSelectingCells = true; // Signal to start drag-cell-selection
|
|
|
|
mSelectingTableCellMode = aTarget;
|
|
|
|
// Set start for new drag-selection block (not appended)
|
|
|
|
mStartSelectedCell = childContent;
|
|
|
|
// The initial block end is same as the start
|
|
|
|
mEndSelectedCell = childContent;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
if (isSelected) {
|
|
|
|
// Remember this cell to (possibly) unselect it on mouseup
|
|
|
|
mUnselectCellOnMouseUp = childContent;
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf("HandleTableSelection: Saving mUnselectCellOnMouseUp\n");
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
// Select an unselected cell
|
|
|
|
// but first remove existing selection if not in same table
|
|
|
|
if (previousCellNode &&
|
|
|
|
!IsInSameTable(previousCellNode, childContent)) {
|
2018-03-27 07:35:23 +03:00
|
|
|
mDomSelections[index]->RemoveAllRanges(IgnoreErrors());
|
2017-06-19 01:07:36 +03:00
|
|
|
// Reset selection mode that is cleared in RemoveAllRanges
|
|
|
|
mSelectingTableCellMode = aTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SelectCellElement(childContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2018-05-08 20:52:36 +03:00
|
|
|
} else if (aTarget == TableSelection::Table) {
|
2017-06-19 01:07:36 +03:00
|
|
|
// TODO: We currently select entire table when clicked between cells,
|
|
|
|
// should we restrict to only around border?
|
|
|
|
// *** How do we get location data for cell and click?
|
|
|
|
mDragSelectingCells = false;
|
|
|
|
mStartSelectedCell = nullptr;
|
|
|
|
mEndSelectedCell = nullptr;
|
|
|
|
|
|
|
|
// Remove existing selection and select the table
|
2018-03-27 07:35:23 +03:00
|
|
|
mDomSelections[index]->RemoveAllRanges(IgnoreErrors());
|
2017-06-19 01:07:36 +03:00
|
|
|
return CreateAndAddRange(aParentContent, aContentOffset);
|
2018-05-08 20:52:36 +03:00
|
|
|
} else if (aTarget == TableSelection::Row ||
|
|
|
|
aTarget == TableSelection::Column) {
|
2017-06-19 01:07:36 +03:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf("aTarget == %d\n", aTarget);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Start drag-selecting mode so multiple rows/cols can be selected
|
|
|
|
// Note: Currently, nsFrame::GetDataForTableSelection
|
|
|
|
// will never call us for row or column selection on mouse down
|
|
|
|
mDragSelectingCells = true;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
// Force new selection block
|
|
|
|
mStartSelectedCell = nullptr;
|
2018-03-27 07:35:23 +03:00
|
|
|
mDomSelections[index]->RemoveAllRanges(IgnoreErrors());
|
2017-06-19 01:07:36 +03:00
|
|
|
// Always do this AFTER RemoveAllRanges
|
|
|
|
mSelectingTableCellMode = aTarget;
|
|
|
|
return SelectRowOrColumn(childContent, aTarget);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(
|
|
|
|
"HandleTableSelection: Mouse UP event. mDragSelectingCells=%d, "
|
|
|
|
"mStartSelectedCell=%p\n",
|
|
|
|
mDragSelectingCells, mStartSelectedCell.get());
|
|
|
|
#endif
|
|
|
|
// First check if we are extending a block selection
|
2018-03-27 07:35:22 +03:00
|
|
|
uint32_t rangeCount = mDomSelections[index]->RangeCount();
|
2017-06-19 01:07:36 +03:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
if (rangeCount > 0 && aMouseEvent->IsShift() &&
|
2017-06-19 01:07:36 +03:00
|
|
|
mAppendStartSelectedCell &&
|
|
|
|
mAppendStartSelectedCell != childContent) {
|
|
|
|
// Shift key is down: append a block selection
|
|
|
|
mDragSelectingCells = false;
|
|
|
|
return SelectBlockOfCells(mAppendStartSelectedCell, childContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDragSelectingCells) mAppendStartSelectedCell = mStartSelectedCell;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
mDragSelectingCells = false;
|
|
|
|
mStartSelectedCell = nullptr;
|
|
|
|
mEndSelectedCell = nullptr;
|
|
|
|
|
|
|
|
// Any other mouseup actions require that Ctrl or Cmd key is pressed
|
|
|
|
// else stop table selection mode
|
|
|
|
bool doMouseUpAction = false;
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
doMouseUpAction = aMouseEvent->IsMeta();
|
|
|
|
#else
|
|
|
|
doMouseUpAction = aMouseEvent->IsControl();
|
|
|
|
#endif
|
|
|
|
if (!doMouseUpAction) {
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(
|
|
|
|
"HandleTableSelection: Ending cell selection on mouseup: "
|
|
|
|
"mAppendStartSelectedCell=%p\n",
|
|
|
|
mAppendStartSelectedCell.get());
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// Unselect a cell only if it wasn't
|
|
|
|
// just selected on mousedown
|
|
|
|
if (childContent == mUnselectCellOnMouseUp) {
|
|
|
|
// Scan ranges to find the cell to unselect (the selection range to
|
|
|
|
// remove)
|
|
|
|
// XXXbz it's really weird that this lives outside the loop, so once we
|
|
|
|
// find one we keep looking at it even if we find no more cells...
|
|
|
|
nsINode* previousCellParent = nullptr;
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(
|
|
|
|
"HandleTableSelection: Unselecting mUnselectCellOnMouseUp; "
|
|
|
|
"rangeCount=%d\n",
|
|
|
|
rangeCount);
|
|
|
|
#endif
|
2018-03-27 07:35:22 +03:00
|
|
|
for (uint32_t i = 0; i < rangeCount; i++) {
|
2017-06-19 01:07:36 +03:00
|
|
|
// Strong reference, because sometimes we want to remove
|
|
|
|
// this range, and then we might be the only owner.
|
|
|
|
RefPtr<nsRange> range = mDomSelections[index]->GetRangeAt(i);
|
|
|
|
if (!range) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2017-07-11 17:52:39 +03:00
|
|
|
nsINode* container = range->GetStartContainer();
|
|
|
|
if (!container) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
int32_t offset = range->StartOffset();
|
|
|
|
// Be sure previous selection is a table cell
|
2018-01-12 17:33:14 +03:00
|
|
|
nsIContent* child = range->GetChildAtStartOffset();
|
2017-07-11 17:52:39 +03:00
|
|
|
if (child && IsCell(child)) {
|
|
|
|
previousCellParent = container;
|
|
|
|
}
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
// We're done if we didn't find parent of a previously-selected cell
|
|
|
|
if (!previousCellParent) break;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
if (previousCellParent == aParentContent &&
|
|
|
|
offset == aContentOffset) {
|
|
|
|
// Cell is already selected
|
|
|
|
if (rangeCount == 1) {
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(
|
|
|
|
"HandleTableSelection: Unselecting single selected cell\n");
|
|
|
|
#endif
|
|
|
|
// This was the only cell selected.
|
|
|
|
// Collapse to "normal" selection inside the cell
|
|
|
|
mStartSelectedCell = nullptr;
|
|
|
|
mEndSelectedCell = nullptr;
|
|
|
|
mAppendStartSelectedCell = nullptr;
|
|
|
|
// TODO: We need a "Collapse to just before deepest child" routine
|
|
|
|
// Even better, should we collapse to just after the LAST deepest
|
|
|
|
// child
|
|
|
|
// (i.e., at the end of the cell's contents)?
|
|
|
|
return mDomSelections[index]->Collapse(childContent, 0);
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(
|
|
|
|
"HandleTableSelection: Removing cell from multi-cell "
|
|
|
|
"selection\n");
|
|
|
|
#endif
|
2017-07-06 15:00:35 +03:00
|
|
|
// Unselecting the start of previous block
|
2017-06-19 01:07:36 +03:00
|
|
|
// XXX What do we use now!
|
|
|
|
if (childContent == mAppendStartSelectedCell)
|
|
|
|
mAppendStartSelectedCell = nullptr;
|
|
|
|
|
|
|
|
// Deselect cell by removing its range from selection
|
2018-03-27 07:35:22 +03:00
|
|
|
ErrorResult err;
|
|
|
|
mDomSelections[index]->RemoveRange(*range, err);
|
|
|
|
return err.StealNSResult();
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mUnselectCellOnMouseUp = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::SelectBlockOfCells(nsIContent* aStartCell,
|
|
|
|
nsIContent* aEndCell) {
|
|
|
|
NS_ENSURE_TRUE(aStartCell, NS_ERROR_NULL_POINTER);
|
|
|
|
NS_ENSURE_TRUE(aEndCell, NS_ERROR_NULL_POINTER);
|
|
|
|
mEndSelectedCell = aEndCell;
|
|
|
|
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
// If new end cell is in a different table, do nothing
|
|
|
|
nsIContent* table = IsInSameTable(aStartCell, aEndCell);
|
|
|
|
if (!table) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get starting and ending cells' location in the cellmap
|
|
|
|
int32_t startRowIndex, startColIndex, endRowIndex, endColIndex;
|
|
|
|
result = GetCellIndexes(aStartCell, startRowIndex, startColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
result = GetCellIndexes(aEndCell, endRowIndex, endColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
if (mDragSelectingCells) {
|
|
|
|
// Drag selecting: remove selected cells outside of new block limits
|
|
|
|
UnselectCells(table, startRowIndex, startColIndex, endRowIndex, endColIndex,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that we select block in the direction of user's mouse dragging,
|
|
|
|
// which means start cell may be after the end cell in either row or column
|
|
|
|
return AddCellsToSelection(table, startRowIndex, startColIndex, endRowIndex,
|
|
|
|
endColIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::UnselectCells(nsIContent* aTableContent,
|
|
|
|
int32_t aStartRowIndex,
|
|
|
|
int32_t aStartColumnIndex,
|
|
|
|
int32_t aEndRowIndex,
|
|
|
|
int32_t aEndColumnIndex,
|
|
|
|
bool aRemoveOutsideOfCellRange) {
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsTableWrapperFrame* tableFrame =
|
|
|
|
do_QueryFrame(aTableContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
int32_t minRowIndex = std::min(aStartRowIndex, aEndRowIndex);
|
|
|
|
int32_t maxRowIndex = std::max(aStartRowIndex, aEndRowIndex);
|
|
|
|
int32_t minColIndex = std::min(aStartColumnIndex, aEndColumnIndex);
|
|
|
|
int32_t maxColIndex = std::max(aStartColumnIndex, aEndColumnIndex);
|
|
|
|
|
|
|
|
// Strong reference because we sometimes remove the range
|
|
|
|
RefPtr<nsRange> range = GetFirstCellRange();
|
|
|
|
nsIContent* cellNode = GetFirstSelectedContent(range);
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(!range || cellNode, "Must have cellNode if had a range");
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
int32_t curRowIndex, curColIndex;
|
|
|
|
while (cellNode) {
|
|
|
|
nsresult result = GetCellIndexes(cellNode, curRowIndex, curColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
if (!range) printf("RemoveCellsToSelection -- range is null\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (range) {
|
|
|
|
if (aRemoveOutsideOfCellRange) {
|
2017-07-06 15:00:35 +03:00
|
|
|
if (curRowIndex < minRowIndex || curRowIndex > maxRowIndex ||
|
2017-06-19 01:07:36 +03:00
|
|
|
curColIndex < minColIndex || curColIndex > maxColIndex) {
|
2018-03-27 07:35:22 +03:00
|
|
|
mDomSelections[index]->RemoveRange(*range, IgnoreErrors());
|
2017-06-19 01:07:36 +03:00
|
|
|
// Since we've removed the range, decrement pointer to next range
|
|
|
|
mSelectedCellIndex--;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Remove cell from selection if it belongs to the given cells range or
|
|
|
|
// it is spanned onto the cells range.
|
|
|
|
nsTableCellFrame* cellFrame =
|
|
|
|
tableFrame->GetCellFrameAt(curRowIndex, curColIndex);
|
|
|
|
|
2017-10-17 22:39:36 +03:00
|
|
|
uint32_t origRowIndex = cellFrame->RowIndex();
|
|
|
|
uint32_t origColIndex = cellFrame->ColIndex();
|
2017-06-19 01:07:36 +03:00
|
|
|
uint32_t actualRowSpan =
|
|
|
|
tableFrame->GetEffectiveRowSpanAt(origRowIndex, origColIndex);
|
|
|
|
uint32_t actualColSpan =
|
|
|
|
tableFrame->GetEffectiveColSpanAt(curRowIndex, curColIndex);
|
2017-10-17 22:39:36 +03:00
|
|
|
if (origRowIndex <= static_cast<uint32_t>(maxRowIndex) &&
|
|
|
|
maxRowIndex >= 0 &&
|
2017-06-19 01:07:36 +03:00
|
|
|
origRowIndex + actualRowSpan - 1 >=
|
|
|
|
static_cast<uint32_t>(minRowIndex) &&
|
2017-10-17 22:39:36 +03:00
|
|
|
origColIndex <= static_cast<uint32_t>(maxColIndex) &&
|
|
|
|
maxColIndex >= 0 &&
|
2017-06-19 01:07:36 +03:00
|
|
|
origColIndex + actualColSpan - 1 >=
|
|
|
|
static_cast<uint32_t>(minColIndex)) {
|
2018-03-27 07:35:22 +03:00
|
|
|
mDomSelections[index]->RemoveRange(*range, IgnoreErrors());
|
2017-06-19 01:07:36 +03:00
|
|
|
// Since we've removed the range, decrement pointer to next range
|
|
|
|
mSelectedCellIndex--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
range = GetNextCellRange();
|
|
|
|
cellNode = GetFirstSelectedContent(range);
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(!range || cellNode, "Must have cellNode if had a range");
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::AddCellsToSelection(nsIContent* aTableContent,
|
|
|
|
int32_t aStartRowIndex,
|
|
|
|
int32_t aStartColumnIndex,
|
|
|
|
int32_t aEndRowIndex,
|
|
|
|
int32_t aEndColumnIndex) {
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsTableWrapperFrame* tableFrame =
|
|
|
|
do_QueryFrame(aTableContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame) // Check that |table| is a table.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult result = NS_OK;
|
2017-10-17 22:39:36 +03:00
|
|
|
uint32_t row = aStartRowIndex;
|
2017-06-19 01:07:36 +03:00
|
|
|
while (true) {
|
2017-10-17 22:39:36 +03:00
|
|
|
uint32_t col = aStartColumnIndex;
|
2017-06-19 01:07:36 +03:00
|
|
|
while (true) {
|
|
|
|
nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(row, col);
|
|
|
|
|
|
|
|
// Skip cells that are spanned from previous locations or are already
|
|
|
|
// selected
|
|
|
|
if (cellFrame) {
|
2017-10-17 22:39:36 +03:00
|
|
|
uint32_t origRow = cellFrame->RowIndex();
|
|
|
|
uint32_t origCol = cellFrame->ColIndex();
|
2017-06-19 01:07:36 +03:00
|
|
|
if (origRow == row && origCol == col && !cellFrame->IsSelected()) {
|
|
|
|
result = SelectCellElement(cellFrame->GetContent());
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Done when we reach end column
|
2017-10-17 22:39:36 +03:00
|
|
|
if (col == static_cast<uint32_t>(aEndColumnIndex)) break;
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
if (aStartColumnIndex < aEndColumnIndex)
|
|
|
|
col++;
|
|
|
|
else
|
|
|
|
col--;
|
|
|
|
}
|
2017-10-17 22:39:36 +03:00
|
|
|
if (row == static_cast<uint32_t>(aEndRowIndex)) break;
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
if (aStartRowIndex < aEndRowIndex)
|
|
|
|
row++;
|
|
|
|
else
|
|
|
|
row--;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::RemoveCellsFromSelection(nsIContent* aTable,
|
|
|
|
int32_t aStartRowIndex,
|
|
|
|
int32_t aStartColumnIndex,
|
|
|
|
int32_t aEndRowIndex,
|
|
|
|
int32_t aEndColumnIndex) {
|
|
|
|
return UnselectCells(aTable, aStartRowIndex, aStartColumnIndex, aEndRowIndex,
|
|
|
|
aEndColumnIndex, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::RestrictCellsToSelection(nsIContent* aTable,
|
|
|
|
int32_t aStartRowIndex,
|
|
|
|
int32_t aStartColumnIndex,
|
|
|
|
int32_t aEndRowIndex,
|
|
|
|
int32_t aEndColumnIndex) {
|
|
|
|
return UnselectCells(aTable, aStartRowIndex, aStartColumnIndex, aEndRowIndex,
|
|
|
|
aEndColumnIndex, true);
|
|
|
|
}
|
|
|
|
|
2018-05-08 20:52:36 +03:00
|
|
|
nsresult nsFrameSelection::SelectRowOrColumn(nsIContent* aCellContent,
|
|
|
|
TableSelection aTarget) {
|
2017-06-19 01:07:36 +03:00
|
|
|
if (!aCellContent) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsIContent* table = GetParentTable(aCellContent);
|
|
|
|
if (!table) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// Get table and cell layout interfaces to access
|
|
|
|
// cell data based on cellmap location
|
|
|
|
// Frames are not ref counted, so don't use an nsCOMPtr
|
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(table->GetPrimaryFrame());
|
|
|
|
if (!tableFrame) return NS_ERROR_FAILURE;
|
|
|
|
nsITableCellLayout* cellLayout = GetCellLayout(aCellContent);
|
|
|
|
if (!cellLayout) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Get location of target cell:
|
|
|
|
int32_t rowIndex, colIndex;
|
|
|
|
nsresult result = cellLayout->GetCellIndexes(rowIndex, colIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
// Be sure we start at proper beginning
|
|
|
|
// (This allows us to select row or col given ANY cell!)
|
2018-05-08 20:52:36 +03:00
|
|
|
if (aTarget == TableSelection::Row) colIndex = 0;
|
|
|
|
if (aTarget == TableSelection::Column) rowIndex = 0;
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> firstCell, lastCell;
|
|
|
|
while (true) {
|
|
|
|
// Loop through all cells in column or row to find first and last
|
|
|
|
nsCOMPtr<nsIContent> curCellContent =
|
|
|
|
tableFrame->GetCellAt(rowIndex, colIndex);
|
|
|
|
if (!curCellContent) break;
|
|
|
|
|
|
|
|
if (!firstCell) firstCell = curCellContent;
|
|
|
|
|
|
|
|
lastCell = curCellContent.forget();
|
|
|
|
|
|
|
|
// Move to next cell in cellmap, skipping spanned locations
|
2018-05-08 20:52:36 +03:00
|
|
|
if (aTarget == TableSelection::Row)
|
2017-06-19 01:07:36 +03:00
|
|
|
colIndex += tableFrame->GetEffectiveRowSpanAt(rowIndex, colIndex);
|
|
|
|
else
|
|
|
|
rowIndex += tableFrame->GetEffectiveRowSpanAt(rowIndex, colIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use SelectBlockOfCells:
|
|
|
|
// This will replace existing selection,
|
|
|
|
// but allow unselecting by dragging out of selected region
|
|
|
|
if (firstCell && lastCell) {
|
|
|
|
if (!mStartSelectedCell) {
|
|
|
|
// We are starting a new block, so select the first cell
|
|
|
|
result = SelectCellElement(firstCell);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
mStartSelectedCell = firstCell;
|
|
|
|
}
|
2018-08-13 12:05:19 +03:00
|
|
|
result = SelectBlockOfCells(mStartSelectedCell, lastCell);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
// This gets set to the cell at end of row/col,
|
2017-06-19 01:07:36 +03:00
|
|
|
// but we need it to be the cell under cursor
|
|
|
|
mEndSelectedCell = aCellContent;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// This is a more efficient strategy that appends row to current selection,
|
|
|
|
// but doesn't allow dragging OFF of an existing selection to unselect!
|
|
|
|
do {
|
|
|
|
// Loop through all cells in column or row
|
|
|
|
result = tableLayout->GetCellDataAt(rowIndex, colIndex,
|
|
|
|
getter_AddRefs(cellElement),
|
|
|
|
curRowIndex, curColIndex,
|
|
|
|
rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan,
|
|
|
|
isSelected);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
// We're done when cell is not found
|
|
|
|
if (!cellElement) break;
|
|
|
|
|
|
|
|
|
|
|
|
// Check spans else we infinitely loop
|
|
|
|
NS_ASSERTION(actualColSpan, "actualColSpan is 0!");
|
|
|
|
NS_ASSERTION(actualRowSpan, "actualRowSpan is 0!");
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
// Skip cells that are already selected or span from outside our region
|
|
|
|
if (!isSelected && rowIndex == curRowIndex && colIndex == curColIndex)
|
|
|
|
{
|
|
|
|
result = SelectCellElement(cellElement);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
}
|
|
|
|
// Move to next row or column in cellmap, skipping spanned locations
|
2018-05-08 20:52:36 +03:00
|
|
|
if (aTarget == TableSelection::Row)
|
2017-06-19 01:07:36 +03:00
|
|
|
colIndex += actualColSpan;
|
|
|
|
else
|
|
|
|
rowIndex += actualRowSpan;
|
|
|
|
}
|
|
|
|
while (cellElement);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* nsFrameSelection::GetFirstCellNodeInRange(nsRange* aRange) const {
|
|
|
|
if (!aRange) return nullptr;
|
|
|
|
|
2018-01-12 17:33:14 +03:00
|
|
|
nsIContent* childContent = aRange->GetChildAtStartOffset();
|
2017-06-19 01:07:36 +03:00
|
|
|
if (!childContent) return nullptr;
|
|
|
|
// Don't return node if not a cell
|
|
|
|
if (!IsCell(childContent)) return nullptr;
|
|
|
|
|
|
|
|
return childContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRange* nsFrameSelection::GetFirstCellRange() {
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return nullptr;
|
|
|
|
|
|
|
|
nsRange* firstRange = mDomSelections[index]->GetRangeAt(0);
|
|
|
|
if (!GetFirstCellNodeInRange(firstRange)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup for next cell
|
|
|
|
mSelectedCellIndex = 1;
|
|
|
|
|
|
|
|
return firstRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRange* nsFrameSelection::GetNextCellRange() {
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup for next cell
|
|
|
|
mSelectedCellIndex++;
|
|
|
|
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::GetCellIndexes(nsIContent* aCell, int32_t& aRowIndex,
|
|
|
|
int32_t& aColIndex) {
|
|
|
|
if (!aCell) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
aColIndex = 0; // initialize out params
|
|
|
|
aRowIndex = 0;
|
|
|
|
|
|
|
|
nsITableCellLayout* cellLayoutObject = GetCellLayout(aCell);
|
|
|
|
if (!cellLayoutObject) return NS_ERROR_FAILURE;
|
|
|
|
return cellLayoutObject->GetCellIndexes(aRowIndex, aColIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* nsFrameSelection::IsInSameTable(nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2) const {
|
|
|
|
if (!aContent1 || !aContent2) return nullptr;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
nsIContent* tableNode1 = GetParentTable(aContent1);
|
|
|
|
nsIContent* tableNode2 = GetParentTable(aContent2);
|
|
|
|
|
|
|
|
// Must be in the same table. Note that we want to return false for
|
|
|
|
// the test if both tables are null.
|
|
|
|
return (tableNode1 == tableNode2) ? tableNode1 : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* nsFrameSelection::GetParentTable(nsIContent* aCell) const {
|
|
|
|
if (!aCell) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (nsIContent* parent = aCell->GetParent(); parent;
|
|
|
|
parent = parent->GetParent()) {
|
|
|
|
if (parent->IsHTMLElement(nsGkAtoms::table)) {
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::SelectCellElement(nsIContent* aCellElement) {
|
|
|
|
nsIContent* parent = aCellElement->GetParent();
|
|
|
|
|
|
|
|
// Get child offset
|
2018-01-23 16:30:18 +03:00
|
|
|
int32_t offset = parent->ComputeIndexOf(aCellElement);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
return CreateAndAddRange(parent, offset);
|
|
|
|
}
|
|
|
|
|
2017-07-11 17:33:04 +03:00
|
|
|
nsresult nsFrameSelection::CreateAndAddRange(nsINode* aContainer,
|
|
|
|
int32_t aOffset) {
|
|
|
|
if (!aContainer) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2017-06-19 01:07:36 +03:00
|
|
|
|
2017-07-11 17:33:04 +03:00
|
|
|
RefPtr<nsRange> range = new nsRange(aContainer);
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
// Set range around child at given offset
|
2017-07-11 17:33:04 +03:00
|
|
|
nsresult rv =
|
|
|
|
range->SetStartAndEnd(aContainer, aOffset, aContainer, aOffset + 1);
|
2017-06-19 01:07:36 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2018-03-27 07:35:22 +03:00
|
|
|
ErrorResult err;
|
|
|
|
mDomSelections[index]->AddRange(*range, err);
|
|
|
|
return err.StealNSResult();
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// End of Table Selection
|
|
|
|
|
|
|
|
void nsFrameSelection::SetAncestorLimiter(nsIContent* aLimiter) {
|
|
|
|
if (mAncestorLimiter != aLimiter) {
|
|
|
|
mAncestorLimiter = aLimiter;
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return;
|
|
|
|
|
|
|
|
if (!IsValidSelectionPoint(this, mDomSelections[index]->GetFocusNode())) {
|
|
|
|
ClearNormalSelection();
|
|
|
|
if (mAncestorLimiter) {
|
|
|
|
PostReason(nsISelectionListener::NO_REASON);
|
2019-03-13 03:30:11 +03:00
|
|
|
nsCOMPtr<nsIContent> limiter(mAncestorLimiter);
|
|
|
|
TakeFocus(limiter, 0, 0, CARET_ASSOCIATE_BEFORE, false, false);
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsFrameSelection::DeleteFromDocument() {
|
|
|
|
// If we're already collapsed, then we do nothing (bug 719503).
|
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2018-05-08 20:52:39 +03:00
|
|
|
if (mDomSelections[index]->IsCollapsed()) {
|
2017-06-19 01:07:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Selection> selection = mDomSelections[index];
|
|
|
|
for (uint32_t rangeIdx = 0; rangeIdx < selection->RangeCount(); ++rangeIdx) {
|
|
|
|
RefPtr<nsRange> range = selection->GetRangeAt(rangeIdx);
|
2018-03-27 07:35:21 +03:00
|
|
|
ErrorResult res;
|
|
|
|
range->DeleteContents(res);
|
|
|
|
if (res.Failed()) {
|
|
|
|
return res.StealNSResult();
|
|
|
|
}
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collapse to the new location.
|
|
|
|
// If we deleted one character, then we move back one element.
|
|
|
|
// FIXME We don't know how to do this past frame boundaries yet.
|
2017-09-06 22:48:20 +03:00
|
|
|
if (mDomSelections[index]->AnchorOffset() > 0)
|
2017-06-19 01:07:36 +03:00
|
|
|
mDomSelections[index]->Collapse(mDomSelections[index]->GetAnchorNode(),
|
|
|
|
mDomSelections[index]->AnchorOffset());
|
|
|
|
#ifdef DEBUG
|
|
|
|
else
|
|
|
|
printf("Don't know how to set selection back past frame boundary\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsFrameSelection::SetDelayedCaretData(WidgetMouseEvent* aMouseEvent) {
|
|
|
|
if (aMouseEvent) {
|
|
|
|
mDelayedMouseEventValid = true;
|
|
|
|
mDelayedMouseEventIsShift = aMouseEvent->IsShift();
|
|
|
|
mDelayedMouseEventClickCount = aMouseEvent->mClickCount;
|
|
|
|
} else {
|
|
|
|
mDelayedMouseEventValid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsFrameSelection::DisconnectFromPresShell() {
|
2017-08-02 04:18:23 +03:00
|
|
|
if (mAccessibleCaretEnabled) {
|
2018-09-01 00:19:44 +03:00
|
|
|
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
|
|
|
mDomSelections[index]->StopNotifyingAccessibleCaretEventHub();
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
StopAutoScrollTimer();
|
2017-08-24 13:14:04 +03:00
|
|
|
for (size_t i = 0; i < ArrayLength(mDomSelections); i++) {
|
2017-06-19 01:07:36 +03:00
|
|
|
mDomSelections[i]->Clear(nullptr);
|
|
|
|
}
|
2019-04-03 10:53:16 +03:00
|
|
|
mPresShell = nullptr;
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See Bug 1288453.
|
|
|
|
*
|
|
|
|
* Update the selection cache on repaint to handle when a pre-existing
|
|
|
|
* selection becomes active aka the current selection.
|
|
|
|
*
|
|
|
|
* 1. Change the current selection by click n dragging another selection.
|
|
|
|
* - Make a selection on content page. Make a selection in a text editor.
|
|
|
|
* - You can click n drag the content selection to make it active again.
|
|
|
|
* 2. Change the current selection when switching to a tab with a selection.
|
|
|
|
* - Make selection in tab.
|
|
|
|
* - Switching tabs will make its respective selection active.
|
|
|
|
*
|
|
|
|
* Therefore, we only update the selection cache on a repaint
|
|
|
|
* if the current selection being repainted is not an empty selection.
|
|
|
|
*
|
|
|
|
* If the current selection is empty. The current selection cache
|
2018-08-30 10:36:23 +03:00
|
|
|
* would be cleared by AutoCopyListener::OnSelectionChange().
|
2017-06-19 01:07:36 +03:00
|
|
|
*/
|
|
|
|
nsresult nsFrameSelection::UpdateSelectionCacheOnRepaintSelection(
|
|
|
|
Selection* aSel) {
|
2019-04-16 10:25:10 +03:00
|
|
|
PresShell* presShell = aSel->GetPresShell();
|
2019-04-03 10:53:16 +03:00
|
|
|
if (!presShell) {
|
2017-06-19 01:07:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-04-03 10:53:16 +03:00
|
|
|
nsCOMPtr<Document> aDoc = presShell->GetDocument();
|
2017-06-19 01:07:36 +03:00
|
|
|
|
2018-05-08 20:52:39 +03:00
|
|
|
if (aDoc && aSel && !aSel->IsCollapsed()) {
|
2017-06-19 01:07:36 +03:00
|
|
|
return nsCopySupport::HTMLCopy(aSel, aDoc, nsIClipboard::kSelectionCache,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-08-30 10:36:23 +03:00
|
|
|
// mozilla::AutoCopyListener
|
2017-06-19 01:07:36 +03:00
|
|
|
|
2018-08-30 10:36:23 +03:00
|
|
|
int16_t AutoCopyListener::sClipboardID = -1;
|
2017-06-19 01:07:36 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* What we do now:
|
|
|
|
* On every selection change, we copy to the clipboard anew, creating a
|
|
|
|
* HTML buffer, a transferable, an nsISupportsString and
|
2019-05-01 05:28:59 +03:00
|
|
|
* a huge mess every time. This is basically what nsCopySupport::HTMLCopy()
|
|
|
|
* does to move the selection into the clipboard for Edit->Copy.
|
2017-07-06 15:00:35 +03:00
|
|
|
*
|
2017-06-19 01:07:36 +03:00
|
|
|
* What we should do, to make our end of the deal faster:
|
|
|
|
* Create a singleton transferable with our own magic converter. When selection
|
|
|
|
* changes (use a quick cache to detect ``real'' changes), we put the new
|
2018-05-08 20:52:42 +03:00
|
|
|
* Selection in the transferable. Our magic converter will take care of
|
2017-06-19 01:07:36 +03:00
|
|
|
* transferable->whatever-other-format when the time comes to actually
|
|
|
|
* hand over the clipboard contents.
|
|
|
|
*
|
|
|
|
* Other issues:
|
|
|
|
* - which X clipboard should we populate?
|
|
|
|
* - should we use a different one than Edit->Copy, so that inadvertant
|
|
|
|
* selections (or simple clicks, which currently cause a selection
|
|
|
|
* notification, regardless of if they're in the document which currently has
|
|
|
|
* selection!) don't lose the contents of the ``application''? Or should we
|
|
|
|
* just put some intelligence in the ``is this a real selection?'' code to
|
|
|
|
* protect our selection against clicks in other documents that don't create
|
|
|
|
* selections?
|
2017-07-06 15:00:35 +03:00
|
|
|
* - maybe we should just never clear the X clipboard? That would make this
|
2017-06-19 01:07:36 +03:00
|
|
|
* problem just go away, which is very tempting.
|
|
|
|
*
|
|
|
|
* On macOS,
|
|
|
|
* nsIClipboard::kSelectionCache is the flag for current selection cache.
|
|
|
|
* Set the current selection cache on the parent process in
|
|
|
|
* widget cocoa nsClipboard whenever selection changes.
|
|
|
|
*/
|
|
|
|
|
2018-08-30 10:36:23 +03:00
|
|
|
// static
|
2019-01-02 16:05:23 +03:00
|
|
|
void AutoCopyListener::OnSelectionChange(Document* aDocument,
|
2018-08-30 10:36:23 +03:00
|
|
|
Selection& aSelection,
|
|
|
|
int16_t aReason) {
|
|
|
|
MOZ_ASSERT(IsValidClipboardID(sClipboardID));
|
|
|
|
|
|
|
|
if (sClipboardID == nsIClipboard::kSelectionCache) {
|
2017-06-19 01:07:36 +03:00
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
// If no active window, do nothing because a current selection changed
|
|
|
|
// cannot occur unless it is in the active window.
|
|
|
|
if (!fm->GetActiveWindow()) {
|
2018-08-30 10:36:23 +03:00
|
|
|
return;
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 10:36:23 +03:00
|
|
|
static const int16_t kResasonsToHandle =
|
|
|
|
nsISelectionListener::MOUSEUP_REASON |
|
|
|
|
nsISelectionListener::SELECTALL_REASON |
|
|
|
|
nsISelectionListener::KEYPRESS_REASON;
|
|
|
|
if (!(aReason & kResasonsToHandle)) {
|
|
|
|
return; // Don't care if we are still dragging.
|
|
|
|
}
|
2017-06-19 01:07:36 +03:00
|
|
|
|
2018-08-30 10:36:23 +03:00
|
|
|
if (!aDocument || aSelection.IsCollapsed()) {
|
2017-06-19 01:07:36 +03:00
|
|
|
#ifdef DEBUG_CLIPBOARD
|
|
|
|
fprintf(stderr, "CLIPBOARD: no selection/collapsed selection\n");
|
|
|
|
#endif
|
2018-08-30 10:36:23 +03:00
|
|
|
if (sClipboardID != nsIClipboard::kSelectionCache) {
|
|
|
|
// XXX Should we clear X clipboard?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-19 01:07:36 +03:00
|
|
|
// If on macOS, clear the current selection transferable cached
|
|
|
|
// on the parent process (nsClipboard) when the selection is empty.
|
2018-08-30 10:36:23 +03:00
|
|
|
DebugOnly<nsresult> rv = nsCopySupport::ClearSelectionCache();
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"nsCopySupport::ClearSelectionCache() failed");
|
|
|
|
return;
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|
|
|
|
|
2018-08-30 10:36:23 +03:00
|
|
|
// Call the copy code.
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
nsCopySupport::HTMLCopy(&aSelection, aDocument, sClipboardID, false);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "nsCopySupport::HTMLCopy() failed");
|
2017-06-19 01:07:36 +03:00
|
|
|
}
|