SelectionChangeListener is too generic name but it just dispatches
selectionchange event when it's necessary. So, it should be renamed to
SelectionChangeEventDispatcher. Additionally, it's in mozilla::dom namespace
but it does not represent any DOM object. So, it should be in mozilla namespace
instead.
Differential Revision: https://phabricator.services.mozilla.com/D4913
--HG--
rename : dom/base/SelectionChangeListener.cpp => dom/base/SelectionChangeEventDispatcher.cpp
rename : dom/base/SelectionChangeListener.h => dom/base/SelectionChangeEventDispatcher.h
extra : moz-landing-system : lando
SelectionChangeListener is an nsISelectionListener class. This is added only
to Selection for "normal" and added by nsFrameSelection::Init() after
AccessibleCaretEventHub. So, we can make Selection directly treat
SelectionChangeListener.
Differential Revision: https://phabricator.services.mozilla.com/D4757
--HG--
extra : moz-landing-system : lando
AccessibleCaretEventHub is an nsISelectionListener of Selection whose type is
"normal". This is added only when nsFrameSelection::Init() is called and
accessible caret is enabled. Additionally, nsFrameSelection::Init() is
always called immediately after creating nsFrameSelection.
Therefore, when AccessibleCaretEventHub is installed to Selection, this is
always second selection listener and won't be installed multiple times. So,
Selection can store pointer of AccessibleCaretEventHub directly only when
it's enabled and the Selection needs to notify it of selection change.
This patch makes Selection stores AccessibleCaretEventHub with RefPtr, then,
makes Selection::NotifySelectionListeners() call its OnSelectionChange()
immediately after AutoCopyListener.
Unfortunately, this patch includes making of MOZ_CAN_RUN_SCRIPT_BOUNDARY and
MOZ_CAN_RUN_SCRIPT a lot since some methods of AccessibleCaretEventHub are
marked as MOZ_CAN_RUN_SCRIPT and including AccessibleCaretEventHub.h into
Selection.h causes compile the compile errors.
Differential Revision: https://phabricator.services.mozilla.com/D4733
--HG--
extra : moz-landing-system : lando
This is a regression of bug 1486370.
Unlink of Selection removes all nsISelectionListener first, then, it removes
all its ranges since it does not want to notify the changes anymore.
After bug 1486370, Selection starts to store only bool flag whether it should
notify AutoCopyListener of selection changes. So, unless it sets the bool flag
to false in Unlink, it'll notify selection change caused by Unlink.
Differential Revision: https://phabricator.services.mozilla.com/D4690
--HG--
extra : moz-landing-system : lando
nsAutoCopyListener is a singleton class but refcountable and a selection
listener. nsFrameSelection adds it to only normal Selection when it's on
macOS or it's enabled by the pref. Additionally, it's always first selection
listener since it's added immediately after Selection instance is created.
So, we can make it a static class, and normal Selection instance should have
a bool to decide whether it should notify nsAutoCopyListener of its changes.
Then, we can save the cost of grabbing it with local RefPtr and the virtual
call.
Additionally, this patch renames nsAutoCopyListener to mozilla::AutoCopyListener
and optimizes constructor of nsFrameSelection (using bool var cache to retrieve
the pref, avoid retrieving the pref on macOS).
Differential Revision: https://phabricator.services.mozilla.com/D4504
--HG--
rename : layout/generic/nsAutoCopyListener.h => layout/generic/AutoCopyListener.h
extra : moz-landing-system : lando
mozInlineSpellChecker::ReplaceWord() is used for replacing misspelled word
with a word. So, this is necessary to be distinguished from insertText
command when we implement InputEvent.inputType. So, we should make it
use TextEditor::ReplaceTextAsAction() instead (same as autocomplete).
This patch makes TextEditor::ReplaceTextAsAction() take optional argument
to make callers can specify replace range. Then, the range is a spellchecker
selection range if the caller is mozInlineSpellChecker::ReplaceWord().
Prior to this patch, it clones the range for normal selection, but it's
expensive and we may be able to reuse cached range of Selection in this case.
So, this patch makes Selection::AddRangeInternal() checks if given range is
in another Selection and use mCachedRange as far as possible.
MozReview-Commit-ID: JIOTTsxlj4Q
--HG--
extra : rebase_source : 7c26b0255f08608ebe8c7045c9bcdca1dc70cadf
Selection caches an nsRange instance for saving re-allocation cost and AddMutationObserver() and RemoveMutationObserver()'s cost when its RemoveAllRangesTemporarily() is called.
Then, the instance is detached from the Selection but still referring editing point. E.g., the only text node in TextEditor when its value is set. Therefore, it'll receive character data change notification and need to check whether the point is still valid with new text. However, the range will be always set new position later, i.e., immediately before going back to a part of Selection. Therefore, even if the point becomes invalid, nobody must not have any problems.
This patch makes Selection make the cached range not positioned, and makes nsRange ignore any mutations when it's not positioned.
Differential Revision: https://phabricator.services.mozilla.com/D2587
--HG--
extra : moz-landing-system : lando
This was done automatically replacing:
s/mozilla::Move/std::move/
s/ Move(/ std::move(/
s/(Move(/(std::move(/
Removing the 'using mozilla::Move;' lines.
And then with a few manual fixups, see the bug for the split series..
MozReview-Commit-ID: Jxze3adipUh
None of the C++ callers of RemoveSelectionListener care about whether the
listener was already-added, and the only JS caller is in a test and knows the
listener was added. So the behavior change to no-op instead of throwing when
trying to remove a nonexistent listener is OK. Furthermore, the removal is
null-safe, so there's no point to explicitly failing if null is passed (which
it never is).
Since content can't directly add selection listeners, we can just use an
infallible append instead of returning errors callers don't check for anyway.
Also, no one passes null to AddSelectionListener, so we don't have to worry
about that part.
I think it's harmless security-wise, since Text and char data are both
nsIContent, so the vtable offset should be the same.
I could also just do AsContent(), which may be cleaner but involve a virtual
call, or add AsCharacterData(), just let me know.
MozReview-Commit-ID: 79I9CuCmioF
--HG--
extra : rebase_source : 59bcd64ee4ae4d444a4dbeed9b5ecf97455c4422
This method is not a virtual call, and also looks nicer.
This patch was mostly generated by a Python script, but I manually
cleaned up the code in a few places where statements didn't need to be
split across multiple lines any more.
MozReview-Commit-ID: 8JExxqSRc59
--HG--
extra : rebase_source : df6330a89e8d65dfe7a6fda0c8cb9f9732302efc
Most of them just want GetRootFrame(), and there's no need to explicitly go
through the frame manager for that, we have a handy alias in the shell.
MozReview-Commit-ID: GriEqkasidY