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: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2006-03-30 09:56:38 +04:00
|
|
|
/* the caret is the text cursor used, e.g., when editing */
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
#ifndef nsCaret_h__
|
|
|
|
#define nsCaret_h__
|
|
|
|
|
2014-06-23 02:02:59 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2017-08-15 22:12:11 +03:00
|
|
|
#include "mozilla/dom/Selection.h"
|
1999-02-12 02:49:08 +03:00
|
|
|
#include "nsCoord.h"
|
2000-09-14 15:45:01 +04:00
|
|
|
#include "nsISelectionListener.h"
|
2013-08-20 02:55:18 +04:00
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2014-08-06 09:19:27 +04:00
|
|
|
#include "CaretAssociationHint.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsRect.h"
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
class nsDisplayListBuilder;
|
2014-08-06 09:19:27 +04:00
|
|
|
class nsFrameSelection;
|
|
|
|
class nsIContent;
|
|
|
|
class nsIFrame;
|
|
|
|
class nsINode;
|
2013-08-20 02:55:18 +04:00
|
|
|
class nsITimer;
|
2000-09-08 00:21:22 +04:00
|
|
|
|
2014-08-06 09:19:27 +04:00
|
|
|
namespace mozilla {
|
2019-04-16 10:25:10 +03:00
|
|
|
class PresShell;
|
2014-10-29 20:07:11 +03:00
|
|
|
namespace gfx {
|
|
|
|
class DrawTarget;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2014-08-06 09:19:27 +04:00
|
|
|
|
1999-02-12 02:49:08 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsCaret final : public nsISelectionListener {
|
2014-10-29 20:07:11 +03:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2000-09-07 09:26:25 +04:00
|
|
|
public:
|
2014-06-24 02:40:01 +04:00
|
|
|
nsCaret();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-24 02:40:01 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsCaret();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-24 02:40:01 +04:00
|
|
|
public:
|
2008-07-16 14:52:01 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-06 09:19:27 +04:00
|
|
|
typedef mozilla::CaretAssociationHint CaretAssociationHint;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-04-16 10:25:10 +03:00
|
|
|
nsresult Init(mozilla::PresShell* aPresShell);
|
2014-08-06 09:19:24 +04:00
|
|
|
void Terminate();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-08 20:52:37 +03:00
|
|
|
void SetSelection(mozilla::dom::Selection* aDOMSel);
|
2018-05-08 20:52:38 +03:00
|
|
|
mozilla::dom::Selection* GetSelection();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-06 09:19:24 +04:00
|
|
|
/**
|
|
|
|
* Sets whether the caret should only be visible in nodes that are not
|
|
|
|
* user-modify: read-only, or whether it should be visible in all nodes.
|
|
|
|
*
|
|
|
|
* @param aIgnoreUserModify true to have the cursor visible in all nodes,
|
|
|
|
* false to have it visible in all nodes except
|
|
|
|
* those with user-modify: read-only
|
|
|
|
*/
|
|
|
|
void SetIgnoreUserModify(bool aIgnoreUserModify);
|
2014-08-06 09:19:29 +04:00
|
|
|
/** SetVisible will set the visibility of the caret
|
2014-08-06 09:19:24 +04:00
|
|
|
* @param inMakeVisible true to show the caret, false to hide it
|
|
|
|
*/
|
2014-08-06 09:19:29 +04:00
|
|
|
void SetVisible(bool intMakeVisible);
|
|
|
|
/** IsVisible will get the visibility of the caret.
|
2014-08-06 09:19:29 +04:00
|
|
|
* This returns false if the caret is hidden because it was set
|
|
|
|
* to not be visible, or because the selection is not collapsed, or
|
|
|
|
* because an open popup is hiding the caret.
|
|
|
|
* It does not take account of blinking or the caret being hidden
|
|
|
|
* because we're in non-editable/disabled content.
|
2008-07-16 14:52:01 +04:00
|
|
|
*/
|
2018-05-08 20:52:42 +03:00
|
|
|
bool IsVisible(mozilla::dom::Selection* aSelection = nullptr) {
|
2017-08-15 22:12:11 +03:00
|
|
|
if (!mVisible || mHideCount) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mShowDuringSelection) {
|
|
|
|
mozilla::dom::Selection* selection;
|
|
|
|
if (aSelection) {
|
2018-05-08 20:52:42 +03:00
|
|
|
selection = aSelection;
|
2017-08-15 22:12:11 +03:00
|
|
|
} else {
|
2018-05-08 20:52:38 +03:00
|
|
|
selection = GetSelection();
|
2017-08-15 22:12:11 +03:00
|
|
|
}
|
|
|
|
if (!selection || !selection->IsCollapsed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-06 09:19:24 +04:00
|
|
|
if (IsMenuPopupHidingCaret()) {
|
2014-08-06 09:19:27 +04:00
|
|
|
return false;
|
2014-08-06 09:19:26 +04:00
|
|
|
}
|
2008-07-16 14:52:01 +04:00
|
|
|
|
2017-08-15 22:12:11 +03:00
|
|
|
return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2008-07-16 14:52:01 +04:00
|
|
|
/**
|
|
|
|
* AddForceHide() increases mHideCount and hide the caret even if
|
|
|
|
* SetVisible(true) has been or will be called. This is useful when the
|
|
|
|
* caller wants to hide caret temporarily and it needs to cancel later.
|
|
|
|
* Especially, in the latter case, it's too difficult to decide if the
|
|
|
|
* caret should be actually visible or not because caret visible state
|
|
|
|
* is set from a lot of event handlers. So, it's very stateful.
|
|
|
|
*/
|
2016-01-06 03:08:17 +03:00
|
|
|
void AddForceHide();
|
2018-11-30 13:46:48 +03:00
|
|
|
/**
|
2016-01-06 03:08:17 +03:00
|
|
|
* RemoveForceHide() decreases mHideCount if it's over 0.
|
2015-08-17 14:58:38 +03:00
|
|
|
* If the value becomes 0, this may show the caret if SetVisible(true)
|
|
|
|
* has been called.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2015-08-17 14:58:38 +03:00
|
|
|
void RemoveForceHide();
|
2016-01-06 03:08:17 +03:00
|
|
|
/** SetCaretReadOnly set the appearance of the caret
|
|
|
|
* @param inMakeReadonly true to show the caret in a 'read only' state,
|
2000-09-14 15:45:01 +04:00
|
|
|
* false to show the caret in normal, editing state
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2005-02-01 02:47:26 +03:00
|
|
|
void SetCaretReadOnly(bool inMakeReadonly);
|
2014-08-06 09:19:26 +04:00
|
|
|
/**
|
|
|
|
* @param aVisibility true if the caret should be visible even when the
|
2014-08-06 09:19:24 +04:00
|
|
|
* selection is not collapsed.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-08-06 09:19:24 +04:00
|
|
|
void SetVisibilityDuringSelection(bool aVisibility);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-08-06 09:19:26 +04:00
|
|
|
* Set the caret's position explicitly to the specified node and offset
|
|
|
|
* instead of tracking its selection.
|
|
|
|
* Passing null for aNode would set the caret to track its selection again.
|
|
|
|
**/
|
|
|
|
void SetCaretPosition(nsINode* aNode, int32_t aOffset);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-06 09:19:26 +04:00
|
|
|
/**
|
2014-08-06 09:19:26 +04:00
|
|
|
* Schedule a repaint for the frame where the caret would appear.
|
|
|
|
* Does not check visibility etc.
|
2014-08-06 09:19:26 +04:00
|
|
|
*/
|
2018-05-08 20:52:42 +03:00
|
|
|
void SchedulePaint(mozilla::dom::Selection* aSelection = nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-06 09:19:26 +04:00
|
|
|
/**
|
2014-08-06 09:19:24 +04:00
|
|
|
* Returns a frame to paint in, and the bounds of the painted caret
|
|
|
|
* relative to that frame.
|
|
|
|
* The rectangle includes bidi decorations.
|
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
|
|
|
* Returns null if the caret should not be drawn (including if it's blinked
|
2014-08-06 09:19:24 +04:00
|
|
|
* off).
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-11-12 00:54:00 +03:00
|
|
|
nsIFrame* GetPaintGeometry(nsRect* aRect);
|
2015-09-09 11:47:20 +03:00
|
|
|
/**
|
|
|
|
* A simple wrapper around GetGeometry. Does not take any caret state into
|
|
|
|
* account other than the current selection.
|
|
|
|
*/
|
|
|
|
nsIFrame* GetGeometry(nsRect* aRect) {
|
|
|
|
return GetGeometry(GetSelection(), aRect);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-09-09 11:47:20 +03:00
|
|
|
/** PaintCaret
|
|
|
|
* Actually paint the caret onto the given rendering context.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
Bug 1506547 - Align user-select behavior more with other UAs. r=mats
There's a few subtle behavior changes here, which I'll try to break down in the
commit message.
The biggest one is the EditableDescendantCount stuff going away. This
was added in bug 1181130, to prevent clicking on the non-editable div from
selecting the editable div inside. This is problematic for multiple reasons:
* First, I don't think non-editable regions of an editable element should
be user-select: all.
* Second, it just doesn't work in Shadow DOM (the editable descendant count is
not kept up-to-date when not in the uncomposed doc), so nested
contenteditables behave differently inside vs. outside a Shadow Tree.
* Third, I think it's user hostile to just entirely disable selection if you
have a contenteditable descendant as a child of a user-select: all thing.
WebKit behaves like this patch in the following test-case (though not Blink):
https://crisal.io/tmp/user-select-all-contenteditable-descendant.html
Edge doesn't seem to support user-select: all at all (no pun intended).
But we don't allow to select anything at all which looks wrong.
* Fourth, it's not tested at all (which explains how we broke it in Shadow DOM
and not even notice...).
In any case I've verified that this doesn't regress the editor from that bug. If
this regresses anything we can fix it as outlined in the first bullet point
above, which should also make us more compatible with other UAs in that
test-case.
The other change is `all` not overriding everything else. So, something like:
<div style="-webkit-user-select: all">All <div style="-webkit-user-select: none">None</div></div>
Totally ignores the -webkit-user-select: none declaration in Firefox before this
change. This doesn't match any other UA nor the spec, and this patch aligns us
with WebKit / Blink.
This in turn makes us not need -moz-text anymore, whose only purpose was to
avoid this.
This also fixes a variety of bugs uncovered by the previous changes, like the
SetIgnoreUserModify(false) call in editor being completely useless, since
presShell->SetCaretEnabled ended in nsCaret::SetVisible, which overrode it.
This in turn uncovered even more bugs, from bugs in the caret painting code,
like not checking -moz-user-modify on the right frame if you're the last frame
of a line, to even funnier bits where before this patch you show the caret but
can't write at all...
In any case, the new setup I came up with is that when you're editing (the
selection is focused on an editable node) moving the caret forces it to end up
in an editable node, thus jumping over non-editable ones.
This has the nice effect of not completely disabling selection of
-moz-user-select: all elements that have editable descendants (which was a very
ad-hoc hack for bug 1181130, and somewhat broken per the above), and also
not needing the -moz-user-select: all for non-editable bits in contenteditable.css
at all.
This also fixes issues with br-skipping like not being able to insert content in
the following test-case:
<div contenteditable="true"><span contenteditable="false">xyz </span><br>editable</div>
If you start moving to the left from the second line, for example.
I think this yields way better behavior in all the relevant test-cases from bug
1181130 / bug 1109968 / bug 1132768, shouldn't cause any regression, and the
complexity is significantly reduced in some places.
There's still some other broken bits that this patch doesn't fix, but I'll file
follow-ups for those.
Differential Revision: https://phabricator.services.mozilla.com/D12687
--HG--
extra : moz-landing-system : lando
2018-11-26 12:21:37 +03:00
|
|
|
void PaintCaret(DrawTarget& aDrawTarget, nsIFrame* aForFrame,
|
2014-08-06 09:19:24 +04:00
|
|
|
const nsPoint& aOffset);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
Bug 1506547 - Align user-select behavior more with other UAs. r=mats
There's a few subtle behavior changes here, which I'll try to break down in the
commit message.
The biggest one is the EditableDescendantCount stuff going away. This
was added in bug 1181130, to prevent clicking on the non-editable div from
selecting the editable div inside. This is problematic for multiple reasons:
* First, I don't think non-editable regions of an editable element should
be user-select: all.
* Second, it just doesn't work in Shadow DOM (the editable descendant count is
not kept up-to-date when not in the uncomposed doc), so nested
contenteditables behave differently inside vs. outside a Shadow Tree.
* Third, I think it's user hostile to just entirely disable selection if you
have a contenteditable descendant as a child of a user-select: all thing.
WebKit behaves like this patch in the following test-case (though not Blink):
https://crisal.io/tmp/user-select-all-contenteditable-descendant.html
Edge doesn't seem to support user-select: all at all (no pun intended).
But we don't allow to select anything at all which looks wrong.
* Fourth, it's not tested at all (which explains how we broke it in Shadow DOM
and not even notice...).
In any case I've verified that this doesn't regress the editor from that bug. If
this regresses anything we can fix it as outlined in the first bullet point
above, which should also make us more compatible with other UAs in that
test-case.
The other change is `all` not overriding everything else. So, something like:
<div style="-webkit-user-select: all">All <div style="-webkit-user-select: none">None</div></div>
Totally ignores the -webkit-user-select: none declaration in Firefox before this
change. This doesn't match any other UA nor the spec, and this patch aligns us
with WebKit / Blink.
This in turn makes us not need -moz-text anymore, whose only purpose was to
avoid this.
This also fixes a variety of bugs uncovered by the previous changes, like the
SetIgnoreUserModify(false) call in editor being completely useless, since
presShell->SetCaretEnabled ended in nsCaret::SetVisible, which overrode it.
This in turn uncovered even more bugs, from bugs in the caret painting code,
like not checking -moz-user-modify on the right frame if you're the last frame
of a line, to even funnier bits where before this patch you show the caret but
can't write at all...
In any case, the new setup I came up with is that when you're editing (the
selection is focused on an editable node) moving the caret forces it to end up
in an editable node, thus jumping over non-editable ones.
This has the nice effect of not completely disabling selection of
-moz-user-select: all elements that have editable descendants (which was a very
ad-hoc hack for bug 1181130, and somewhat broken per the above), and also
not needing the -moz-user-select: all for non-editable bits in contenteditable.css
at all.
This also fixes issues with br-skipping like not being able to insert content in
the following test-case:
<div contenteditable="true"><span contenteditable="false">xyz </span><br>editable</div>
If you start moving to the left from the second line, for example.
I think this yields way better behavior in all the relevant test-cases from bug
1181130 / bug 1109968 / bug 1132768, shouldn't cause any regression, and the
complexity is significantly reduced in some places.
There's still some other broken bits that this patch doesn't fix, but I'll file
follow-ups for those.
Differential Revision: https://phabricator.services.mozilla.com/D12687
--HG--
extra : moz-landing-system : lando
2018-11-26 12:21:37 +03:00
|
|
|
// nsISelectionListener interface
|
2005-02-01 02:47:26 +03:00
|
|
|
NS_DECL_NSISELECTIONLISTENER
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
Bug 1506547 - Align user-select behavior more with other UAs. r=mats
There's a few subtle behavior changes here, which I'll try to break down in the
commit message.
The biggest one is the EditableDescendantCount stuff going away. This
was added in bug 1181130, to prevent clicking on the non-editable div from
selecting the editable div inside. This is problematic for multiple reasons:
* First, I don't think non-editable regions of an editable element should
be user-select: all.
* Second, it just doesn't work in Shadow DOM (the editable descendant count is
not kept up-to-date when not in the uncomposed doc), so nested
contenteditables behave differently inside vs. outside a Shadow Tree.
* Third, I think it's user hostile to just entirely disable selection if you
have a contenteditable descendant as a child of a user-select: all thing.
WebKit behaves like this patch in the following test-case (though not Blink):
https://crisal.io/tmp/user-select-all-contenteditable-descendant.html
Edge doesn't seem to support user-select: all at all (no pun intended).
But we don't allow to select anything at all which looks wrong.
* Fourth, it's not tested at all (which explains how we broke it in Shadow DOM
and not even notice...).
In any case I've verified that this doesn't regress the editor from that bug. If
this regresses anything we can fix it as outlined in the first bullet point
above, which should also make us more compatible with other UAs in that
test-case.
The other change is `all` not overriding everything else. So, something like:
<div style="-webkit-user-select: all">All <div style="-webkit-user-select: none">None</div></div>
Totally ignores the -webkit-user-select: none declaration in Firefox before this
change. This doesn't match any other UA nor the spec, and this patch aligns us
with WebKit / Blink.
This in turn makes us not need -moz-text anymore, whose only purpose was to
avoid this.
This also fixes a variety of bugs uncovered by the previous changes, like the
SetIgnoreUserModify(false) call in editor being completely useless, since
presShell->SetCaretEnabled ended in nsCaret::SetVisible, which overrode it.
This in turn uncovered even more bugs, from bugs in the caret painting code,
like not checking -moz-user-modify on the right frame if you're the last frame
of a line, to even funnier bits where before this patch you show the caret but
can't write at all...
In any case, the new setup I came up with is that when you're editing (the
selection is focused on an editable node) moving the caret forces it to end up
in an editable node, thus jumping over non-editable ones.
This has the nice effect of not completely disabling selection of
-moz-user-select: all elements that have editable descendants (which was a very
ad-hoc hack for bug 1181130, and somewhat broken per the above), and also
not needing the -moz-user-select: all for non-editable bits in contenteditable.css
at all.
This also fixes issues with br-skipping like not being able to insert content in
the following test-case:
<div contenteditable="true"><span contenteditable="false">xyz </span><br>editable</div>
If you start moving to the left from the second line, for example.
I think this yields way better behavior in all the relevant test-cases from bug
1181130 / bug 1109968 / bug 1132768, shouldn't cause any regression, and the
complexity is significantly reduced in some places.
There's still some other broken bits that this patch doesn't fix, but I'll file
follow-ups for those.
Differential Revision: https://phabricator.services.mozilla.com/D12687
--HG--
extra : moz-landing-system : lando
2018-11-26 12:21:37 +03:00
|
|
|
* Gets the position and size of the caret that would be drawn for
|
|
|
|
* the focus node/offset of aSelection (assuming it would be drawn,
|
2015-09-09 11:47:20 +03:00
|
|
|
* i.e., disregarding blink status). The geometry is stored in aRect,
|
|
|
|
* and we return the frame aRect is relative to.
|
|
|
|
* Only looks at the focus node of aSelection, so you can call it even if
|
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
|
|
|
* aSelection is not collapsed.
|
2014-06-23 02:02:59 +04:00
|
|
|
* This rect does not include any extra decorations for bidi.
|
|
|
|
* @param aRect must be non-null
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-06-23 02:02:59 +04:00
|
|
|
static nsIFrame* GetGeometry(mozilla::dom::Selection* aSelection,
|
2017-02-15 00:49:27 +03:00
|
|
|
nsRect* aRect);
|
|
|
|
static nsresult GetCaretFrameForNodeOffset(
|
|
|
|
nsFrameSelection* aFrameSelection, nsIContent* aContentNode,
|
2014-08-06 09:19:27 +04:00
|
|
|
int32_t aOffset, CaretAssociationHint aFrameHint, uint8_t aBidiLevel,
|
2017-02-15 00:49:27 +03:00
|
|
|
nsIFrame** aReturnFrame, nsIFrame** aReturnUnadjustedFrame,
|
|
|
|
int32_t* aReturnOffset);
|
|
|
|
static nsRect GetGeometryForFrame(nsIFrame* aFrame, int32_t aFrameOffset,
|
2008-04-15 01:09:23 +04:00
|
|
|
nscoord* aBidiIndicatorSize);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-04-15 01:09:23 +04:00
|
|
|
// Get the frame and frame offset based on the focus node and focus offset
|
|
|
|
// of aSelection. If aOverrideNode and aOverride are provided, use them
|
|
|
|
// instead.
|
|
|
|
// @param aFrameOffset return the frame offset if non-null.
|
|
|
|
// @param aUnadjustedFrame return the original frame that the selection is
|
|
|
|
// targeting, without any adjustment for painting.
|
2015-09-09 11:47:20 +03:00
|
|
|
// @return the frame of the focus node.
|
2008-04-15 01:09:23 +04:00
|
|
|
static nsIFrame* GetFrameAndOffset(mozilla::dom::Selection* aSelection,
|
2015-09-09 11:47:20 +03:00
|
|
|
nsINode* aOverrideNode,
|
|
|
|
int32_t aOverrideOffset,
|
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
|
|
|
int32_t* aFrameOffset,
|
|
|
|
nsIFrame** aUnadjustedFrame = nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-04-15 01:09:23 +04:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-06 09:19:26 +04:00
|
|
|
nsIFrame* GetFrame(int32_t* aContentOffset);
|
|
|
|
void ComputeCaretRects(nsIFrame* aFrame, int32_t aFrameOffset,
|
|
|
|
nsRect* aCaretRect, nsRect* aHookRect);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-04-01 12:35:11 +04:00
|
|
|
protected:
|
|
|
|
static void CaretBlinkCallback(nsITimer* aTimer, void* aClosure);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-04-01 12:35:11 +04:00
|
|
|
void CheckSelectionLanguageChange();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-04-01 12:35:11 +04:00
|
|
|
void ResetBlinking();
|
|
|
|
void StopBlinking();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-04-01 12:35:11 +04:00
|
|
|
struct Metrics {
|
|
|
|
nscoord mBidiIndicatorSize; // width and height of bidi indicator
|
|
|
|
nscoord mCaretWidth; // full caret width including bidi indicator
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2008-04-01 12:35:11 +04:00
|
|
|
static Metrics ComputeMetrics(nsIFrame* aFrame, int32_t aOffset,
|
|
|
|
nscoord aCaretHeight);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
// Returns true if we should not draw the caret because of XUL menu popups.
|
2000-09-08 00:21:22 +04:00
|
|
|
// The caret should be hidden if:
|
2010-03-15 01:50:36 +03:00
|
|
|
// 1. An open popup contains the caret, but a menu popup exists before the
|
2014-08-06 09:19:30 +04:00
|
|
|
// caret-owning popup in the popup list (i.e. a menu is in front of the
|
|
|
|
// popup with the caret). If the menu itself contains the caret we don't
|
|
|
|
// hide it.
|
|
|
|
// 2. A menu popup is open, but there is no caret present in any popup.
|
2008-04-01 12:35:11 +04:00
|
|
|
// 3. The caret selection is empty.
|
2017-08-15 22:12:11 +03:00
|
|
|
bool IsMenuPopupHidingCaret();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2000-09-08 00:21:22 +04:00
|
|
|
nsWeakPtr mPresShell;
|
2014-08-06 09:19:30 +04:00
|
|
|
mozilla::WeakPtr<mozilla::dom::Selection> mDomSelectionWeak;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-06 09:19:30 +04:00
|
|
|
nsCOMPtr<nsITimer> mBlinkTimer;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-06 09:19:30 +04:00
|
|
|
/**
|
|
|
|
* The content to draw the caret at. If null, we use mDomSelectionWeak's
|
|
|
|
* focus node instead.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-08-06 09:19:30 +04:00
|
|
|
nsCOMPtr<nsINode> mOverrideContent;
|
2015-04-29 17:23:19 +03:00
|
|
|
/**
|
|
|
|
* The character offset to draw the caret at.
|
|
|
|
* Ignored if mOverrideContent is null.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2015-04-29 17:23:19 +03:00
|
|
|
int32_t mOverrideOffset;
|
2018-11-30 13:46:48 +03:00
|
|
|
/**
|
2015-04-29 17:23:19 +03:00
|
|
|
* mBlinkCount is used to control the number of times to blink the caret
|
|
|
|
* before stopping the blink. This is reset each time we reset the
|
|
|
|
* blinking.
|
|
|
|
*/
|
|
|
|
int32_t mBlinkCount;
|
2017-06-14 03:09:22 +03:00
|
|
|
/**
|
|
|
|
* mBlinkRate is the rate of the caret blinking the last time we read it.
|
|
|
|
* It is used as a way to optimize whether we need to reset the blinking
|
|
|
|
* timer.
|
|
|
|
*/
|
|
|
|
uint32_t mBlinkRate;
|
2015-08-17 14:58:38 +03:00
|
|
|
/**
|
|
|
|
* mHideCount is not 0, it means that somebody doesn't want the caret
|
|
|
|
* to be visible. See AddForceHide() and RemoveForceHide().
|
|
|
|
*/
|
|
|
|
uint32_t mHideCount;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-08-17 14:58:38 +03:00
|
|
|
/**
|
|
|
|
* mIsBlinkOn is true when we're in a blink cycle where the caret is on.
|
|
|
|
*/
|
|
|
|
bool mIsBlinkOn;
|
2014-08-06 09:19:29 +04:00
|
|
|
/**
|
|
|
|
* mIsVisible is true when SetVisible was last called with 'true'.
|
|
|
|
*/
|
|
|
|
bool mVisible;
|
2014-08-06 09:19:30 +04:00
|
|
|
/**
|
|
|
|
* mReadOnly is true when the caret is set to "read only" mode (i.e.,
|
|
|
|
* it doesn't blink).
|
|
|
|
*/
|
|
|
|
bool mReadOnly;
|
|
|
|
/**
|
|
|
|
* mShowDuringSelection is true when the caret should be shown even when
|
|
|
|
* the selection is not collapsed.
|
|
|
|
*/
|
|
|
|
bool mShowDuringSelection;
|
|
|
|
/**
|
|
|
|
* mIgnoreUserModify is true when the caret should be shown even when
|
|
|
|
* it's in non-user-modifiable content.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIgnoreUserModify;
|
1999-02-12 02:49:08 +03:00
|
|
|
};
|
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
#endif // nsCaret_h__
|