mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-27 01:27:30 +09:00
Issue #2388 - Part 1: Mark Selection as "called by JS" when caused by a JS call to the selection API
This commit is contained in:
parent
a2c28b4268
commit
a83e4b6a34
6 changed files with 239 additions and 34 deletions
|
|
@ -269,6 +269,7 @@ nsRange::nsRange(nsINode* aNode)
|
||||||
, mStartOffsetWasIncremented(false)
|
, mStartOffsetWasIncremented(false)
|
||||||
, mEndOffsetWasIncremented(false)
|
, mEndOffsetWasIncremented(false)
|
||||||
, mEnableGravitationOnElementRemoval(true)
|
, mEnableGravitationOnElementRemoval(true)
|
||||||
|
, mCalledByJS(false)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
, mAssertNextInsertOrAppendIndex(-1)
|
, mAssertNextInsertOrAppendIndex(-1)
|
||||||
, mAssertNextInsertOrAppendNode(nullptr)
|
, mAssertNextInsertOrAppendNode(nullptr)
|
||||||
|
|
@ -997,7 +998,7 @@ nsRange::DoSetRange(nsINode* aStartN, uint32_t aStartOffset,
|
||||||
// Notify any selection listeners. This has to occur last because otherwise the world
|
// Notify any selection listeners. This has to occur last because otherwise the world
|
||||||
// could be observed by a selection listener while the range was in an invalid state.
|
// could be observed by a selection listener while the range was in an invalid state.
|
||||||
if (mSelection) {
|
if (mSelection) {
|
||||||
mSelection->NotifySelectionListeners();
|
mSelection->NotifySelectionListeners(mCalledByJS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1224,6 +1225,13 @@ nsRange::IsValidBoundary(nsINode* aNode)
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsRange::SetStartJS(nsINode& aNode, uint32_t aOffset, ErrorResult& aErr)
|
||||||
|
{
|
||||||
|
AutoCalledByJSSetter markAsCalledByJS(*this);
|
||||||
|
SetStart(aNode, aOffset, aErr);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsRange::SetStart(nsINode& aNode, uint32_t aOffset, ErrorResult& aRv)
|
nsRange::SetStart(nsINode& aNode, uint32_t aOffset, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
@ -1279,6 +1287,13 @@ nsRange::SetStart(nsINode* aParent, uint32_t aOffset)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsRange::SetStartBeforeJS(nsINode& aNode, ErrorResult& aErr)
|
||||||
|
{
|
||||||
|
AutoCalledByJSSetter markAsCalledByJS(*this);
|
||||||
|
SetStartBefore(aNode, aErr);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsRange::SetStartBefore(nsINode& aNode, ErrorResult& aRv)
|
nsRange::SetStartBefore(nsINode& aNode, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
@ -1310,6 +1325,13 @@ nsRange::SetStartBefore(nsIDOMNode* aSibling)
|
||||||
return rv.StealNSResult();
|
return rv.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsRange::SetStartAfterJS(nsINode& aNode, ErrorResult& aErr)
|
||||||
|
{
|
||||||
|
AutoCalledByJSSetter markAsCalledByJS(*this);
|
||||||
|
SetStartAfter(aNode, aErr);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsRange::SetStartAfter(nsINode& aNode, ErrorResult& aRv)
|
nsRange::SetStartAfter(nsINode& aNode, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
@ -1341,6 +1363,13 @@ nsRange::SetStartAfter(nsIDOMNode* aSibling)
|
||||||
return rv.StealNSResult();
|
return rv.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsRange::SetEndJS(nsINode& aNode, uint32_t aOffset, ErrorResult& aErr)
|
||||||
|
{
|
||||||
|
AutoCalledByJSSetter markAsCalledByJS(*this);
|
||||||
|
SetEnd(aNode, aOffset, aErr);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsRange::SetEnd(nsINode& aNode, uint32_t aOffset, ErrorResult& aRv)
|
nsRange::SetEnd(nsINode& aNode, uint32_t aOffset, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
@ -1455,6 +1484,13 @@ nsRange::SetStartAndEnd(nsINode* aStartParent, uint32_t aStartOffset,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsRange::SetEndBeforeJS(nsINode& aNode, ErrorResult& aErr)
|
||||||
|
{
|
||||||
|
AutoCalledByJSSetter markAsCalledByJS(*this);
|
||||||
|
SetEndBefore(aNode, aErr);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsRange::SetEndBefore(nsINode& aNode, ErrorResult& aRv)
|
nsRange::SetEndBefore(nsINode& aNode, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
@ -1486,6 +1522,13 @@ nsRange::SetEndBefore(nsIDOMNode* aSibling)
|
||||||
return rv.StealNSResult();
|
return rv.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsRange::SetEndAfterJS(nsINode& aNode, ErrorResult& aErr)
|
||||||
|
{
|
||||||
|
AutoCalledByJSSetter markAsCalledByJS(*this);
|
||||||
|
SetEndAfter(aNode, aErr);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsRange::SetEndAfter(nsINode& aNode, ErrorResult& aRv)
|
nsRange::SetEndAfter(nsINode& aNode, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
@ -1532,6 +1575,13 @@ nsRange::Collapse(bool aToStart)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsRange::CollapseJS(bool aToStart)
|
||||||
|
{
|
||||||
|
AutoCalledByJSSetter markAsCalledByJS(*this);
|
||||||
|
Unused << Collapse(aToStart);
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsRange::SelectNode(nsIDOMNode* aN)
|
nsRange::SelectNode(nsIDOMNode* aN)
|
||||||
{
|
{
|
||||||
|
|
@ -1543,6 +1593,13 @@ nsRange::SelectNode(nsIDOMNode* aN)
|
||||||
return rv.StealNSResult();
|
return rv.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsRange::SelectNodeJS(nsINode& aNode, ErrorResult& aErr)
|
||||||
|
{
|
||||||
|
AutoCalledByJSSetter markAsCalledByJS(*this);
|
||||||
|
SelectNode(aNode, aErr);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsRange::SelectNode(nsINode& aNode, ErrorResult& aRv)
|
nsRange::SelectNode(nsINode& aNode, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
@ -1582,6 +1639,13 @@ nsRange::SelectNodeContents(nsIDOMNode* aN)
|
||||||
return rv.StealNSResult();
|
return rv.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsRange::SelectNodeContentsJS(nsINode& aNode, ErrorResult& aErr)
|
||||||
|
{
|
||||||
|
AutoCalledByJSSetter markAsCalledByJS(*this);
|
||||||
|
SelectNodeContents(aNode, aErr);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsRange::SelectNodeContents(nsINode& aNode, ErrorResult& aRv)
|
nsRange::SelectNodeContents(nsINode& aNode, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
#include "nsStubMutationObserver.h"
|
#include "nsStubMutationObserver.h"
|
||||||
#include "nsWrapperCache.h"
|
#include "nsWrapperCache.h"
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
|
#include "mozilla/GuardObjects.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
class ErrorResult;
|
class ErrorResult;
|
||||||
|
|
@ -256,14 +257,20 @@ public:
|
||||||
void InsertNode(nsINode& aNode, ErrorResult& aErr);
|
void InsertNode(nsINode& aNode, ErrorResult& aErr);
|
||||||
bool IntersectsNode(nsINode& aNode, ErrorResult& aRv);
|
bool IntersectsNode(nsINode& aNode, ErrorResult& aRv);
|
||||||
bool IsPointInRange(nsINode& aParent, uint32_t aOffset, ErrorResult& aErr);
|
bool IsPointInRange(nsINode& aParent, uint32_t aOffset, ErrorResult& aErr);
|
||||||
void SelectNode(nsINode& aNode, ErrorResult& aErr);
|
|
||||||
void SelectNodeContents(nsINode& aNode, ErrorResult& aErr);
|
// *JS() methods are mapped to Range.*() of DOM.
|
||||||
void SetEnd(nsINode& aNode, uint32_t aOffset, ErrorResult& aErr);
|
// They may move focus only when the range represents normal selection.
|
||||||
void SetEndAfter(nsINode& aNode, ErrorResult& aErr);
|
// These methods shouldn't be used from internal.
|
||||||
void SetEndBefore(nsINode& aNode, ErrorResult& aErr);
|
void CollapseJS(bool aToStart);
|
||||||
void SetStart(nsINode& aNode, uint32_t aOffset, ErrorResult& aErr);
|
void SelectNodeJS(nsINode& aNode, ErrorResult& aErr);
|
||||||
void SetStartAfter(nsINode& aNode, ErrorResult& aErr);
|
void SelectNodeContentsJS(nsINode& aNode, ErrorResult& aErr);
|
||||||
void SetStartBefore(nsINode& aNode, ErrorResult& aErr);
|
void SetEndJS(nsINode& aNode, uint32_t aOffset, ErrorResult& aErr);
|
||||||
|
void SetEndAfterJS(nsINode& aNode, ErrorResult& aErr);
|
||||||
|
void SetEndBeforeJS(nsINode& aNode, ErrorResult& aErr);
|
||||||
|
void SetStartJS(nsINode& aNode, uint32_t aOffset, ErrorResult& aErr);
|
||||||
|
void SetStartAfterJS(nsINode& aNode, ErrorResult& aErr);
|
||||||
|
void SetStartBeforeJS(nsINode& aNode, ErrorResult& aErr);
|
||||||
|
|
||||||
void SurroundContents(nsINode& aNode, ErrorResult& aErr);
|
void SurroundContents(nsINode& aNode, ErrorResult& aErr);
|
||||||
already_AddRefed<DOMRect> GetBoundingClientRect(bool aClampToEdge = true,
|
already_AddRefed<DOMRect> GetBoundingClientRect(bool aClampToEdge = true,
|
||||||
bool aFlushLayout = true);
|
bool aFlushLayout = true);
|
||||||
|
|
@ -272,6 +279,17 @@ public:
|
||||||
void GetClientRectsAndTexts(
|
void GetClientRectsAndTexts(
|
||||||
mozilla::dom::ClientRectsAndTexts& aResult,
|
mozilla::dom::ClientRectsAndTexts& aResult,
|
||||||
ErrorResult& aErr);
|
ErrorResult& aErr);
|
||||||
|
|
||||||
|
// Following methods should be used for internal use instead of *JS().
|
||||||
|
void SelectNode(nsINode& aNode, ErrorResult& aErr);
|
||||||
|
void SelectNodeContents(nsINode& aNode, ErrorResult& aErr);
|
||||||
|
void SetEnd(nsINode& aNode, uint32_t aOffset, ErrorResult& aErr);
|
||||||
|
void SetEndAfter(nsINode& aNode, ErrorResult& aErr);
|
||||||
|
void SetEndBefore(nsINode& aNode, ErrorResult& aErr);
|
||||||
|
void SetStart(nsINode& aNode, uint32_t aOffset, ErrorResult& aErr);
|
||||||
|
void SetStartAfter(nsINode& aNode, ErrorResult& aErr);
|
||||||
|
void SetStartBefore(nsINode& aNode, ErrorResult& aErr);
|
||||||
|
|
||||||
static void GetInnerTextNoFlush(mozilla::dom::DOMString& aValue,
|
static void GetInnerTextNoFlush(mozilla::dom::DOMString& aValue,
|
||||||
mozilla::ErrorResult& aError,
|
mozilla::ErrorResult& aError,
|
||||||
nsIContent* aStartParent,
|
nsIContent* aStartParent,
|
||||||
|
|
@ -392,6 +410,31 @@ protected:
|
||||||
size_t aRangeStart,
|
size_t aRangeStart,
|
||||||
size_t aRangeEnd);
|
size_t aRangeEnd);
|
||||||
|
|
||||||
|
// Assume that this is guaranteed that this is held by the caller when
|
||||||
|
// this is used. (Note that we cannot use AutoRestore for mCalledByJS
|
||||||
|
// due to a bit field.)
|
||||||
|
class MOZ_RAII AutoCalledByJSSetter final
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
nsRange& mRange;
|
||||||
|
bool mOldValue;
|
||||||
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AutoCalledByJSSetter(nsRange& aRange
|
||||||
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||||
|
: mRange(aRange)
|
||||||
|
, mOldValue(aRange.mCalledByJS)
|
||||||
|
{
|
||||||
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||||
|
mRange.mCalledByJS = true;
|
||||||
|
}
|
||||||
|
~AutoCalledByJSSetter()
|
||||||
|
{
|
||||||
|
mRange.mCalledByJS = mOldValue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct MOZ_STACK_CLASS AutoInvalidateSelection
|
struct MOZ_STACK_CLASS AutoInvalidateSelection
|
||||||
{
|
{
|
||||||
explicit AutoInvalidateSelection(nsRange* aRange) : mRange(aRange)
|
explicit AutoInvalidateSelection(nsRange* aRange) : mRange(aRange)
|
||||||
|
|
@ -428,6 +471,7 @@ protected:
|
||||||
bool mStartOffsetWasIncremented : 1;
|
bool mStartOffsetWasIncremented : 1;
|
||||||
bool mEndOffsetWasIncremented : 1;
|
bool mEndOffsetWasIncremented : 1;
|
||||||
bool mEnableGravitationOnElementRemoval : 1;
|
bool mEnableGravitationOnElementRemoval : 1;
|
||||||
|
bool mCalledByJS : 1;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
int32_t mAssertNextInsertOrAppendIndex;
|
int32_t mAssertNextInsertOrAppendIndex;
|
||||||
nsINode* mAssertNextInsertOrAppendNode;
|
nsINode* mAssertNextInsertOrAppendNode;
|
||||||
|
|
|
||||||
|
|
@ -26,22 +26,23 @@ interface Range {
|
||||||
[Throws]
|
[Throws]
|
||||||
readonly attribute Node commonAncestorContainer;
|
readonly attribute Node commonAncestorContainer;
|
||||||
|
|
||||||
[Throws]
|
[Throws, BinaryName="setStartJS"]
|
||||||
void setStart(Node refNode, unsigned long offset);
|
void setStart(Node refNode, unsigned long offset);
|
||||||
[Throws]
|
[Throws, BinaryName="setEndJS"]
|
||||||
void setEnd(Node refNode, unsigned long offset);
|
void setEnd(Node refNode, unsigned long offset);
|
||||||
[Throws]
|
[Throws, BinaryName="setStartBeforeJS"]
|
||||||
void setStartBefore(Node refNode);
|
void setStartBefore(Node refNode);
|
||||||
[Throws]
|
[Throws, BinaryName="setStartAfterJS"]
|
||||||
void setStartAfter(Node refNode);
|
void setStartAfter(Node refNode);
|
||||||
[Throws]
|
[Throws, BinaryName="setEndBeforeJS"]
|
||||||
void setEndBefore(Node refNode);
|
void setEndBefore(Node refNode);
|
||||||
[Throws]
|
[Throws, BinaryName="setEndAfterJS"]
|
||||||
void setEndAfter(Node refNode);
|
void setEndAfter(Node refNode);
|
||||||
|
[BinaryName="collapseJS"]
|
||||||
void collapse(optional boolean toStart = false);
|
void collapse(optional boolean toStart = false);
|
||||||
[Throws]
|
[Throws, BinaryName="selectNodeJS"]
|
||||||
void selectNode(Node refNode);
|
void selectNode(Node refNode);
|
||||||
[Throws]
|
[Throws, BinaryName="selectNodeContentsJS"]
|
||||||
void selectNodeContents(Node refNode);
|
void selectNodeContents(Node refNode);
|
||||||
|
|
||||||
const unsigned short START_TO_START = 0;
|
const unsigned short START_TO_START = 0;
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,17 @@ interface Selection {
|
||||||
readonly attribute unsigned long focusOffset;
|
readonly attribute unsigned long focusOffset;
|
||||||
|
|
||||||
readonly attribute boolean isCollapsed;
|
readonly attribute boolean isCollapsed;
|
||||||
[Throws]
|
[Throws, BinaryName="collapseJS"]
|
||||||
void collapse(Node node, unsigned long offset);
|
void collapse(Node node, unsigned long offset);
|
||||||
[Throws]
|
[Throws, BinaryName="collapseToStartJS"]
|
||||||
void collapseToStart();
|
void collapseToStart();
|
||||||
[Throws]
|
[Throws, BinaryName="collapseToEndJS"]
|
||||||
void collapseToEnd();
|
void collapseToEnd();
|
||||||
|
|
||||||
[Throws]
|
[Throws, BinaryName="extendJS"]
|
||||||
void extend(Node node, unsigned long offset);
|
void extend(Node node, unsigned long offset);
|
||||||
|
|
||||||
[Throws]
|
[Throws, BinaryName="selectAllChildrenJS"]
|
||||||
void selectAllChildren(Node node);
|
void selectAllChildren(Node node);
|
||||||
[Throws]
|
[Throws]
|
||||||
void deleteFromDocument();
|
void deleteFromDocument();
|
||||||
|
|
@ -36,7 +36,7 @@ interface Selection {
|
||||||
readonly attribute DOMString type;
|
readonly attribute DOMString type;
|
||||||
[Throws]
|
[Throws]
|
||||||
Range getRangeAt(unsigned long index);
|
Range getRangeAt(unsigned long index);
|
||||||
[Throws]
|
[Throws, BinaryName="addRangeJS"]
|
||||||
void addRange(Range range);
|
void addRange(Range range);
|
||||||
[Throws]
|
[Throws]
|
||||||
void removeRange(Range range);
|
void removeRange(Range range);
|
||||||
|
|
@ -46,7 +46,7 @@ interface Selection {
|
||||||
[Throws]
|
[Throws]
|
||||||
boolean containsNode(Node node, boolean allowPartialContainment);
|
boolean containsNode(Node node, boolean allowPartialContainment);
|
||||||
|
|
||||||
[Throws]
|
[Throws, BinaryName="setBaseAndExtentJS"]
|
||||||
void setBaseAndExtent(Node anchorNode,
|
void setBaseAndExtent(Node anchorNode,
|
||||||
unsigned long anchorOffset,
|
unsigned long anchorOffset,
|
||||||
Node focusNode,
|
Node focusNode,
|
||||||
|
|
|
||||||
|
|
@ -170,13 +170,19 @@ public:
|
||||||
uint32_t FocusOffset();
|
uint32_t FocusOffset();
|
||||||
|
|
||||||
bool IsCollapsed() const;
|
bool IsCollapsed() const;
|
||||||
void Collapse(nsINode& aNode, uint32_t aOffset, mozilla::ErrorResult& aRv);
|
// *JS() methods are mapped to Selection.*().
|
||||||
void CollapseToStart(mozilla::ErrorResult& aRv);
|
// They may move focus only when the range represents normal selection.
|
||||||
void CollapseToEnd(mozilla::ErrorResult& aRv);
|
// These methods shouldn't be used by non-JS callers.
|
||||||
|
void CollapseJS(nsINode& aNode, uint32_t aOffset,
|
||||||
|
mozilla::ErrorResult& aRv);
|
||||||
|
void CollapseToStartJS(mozilla::ErrorResult& aRv);
|
||||||
|
void CollapseToEndJS(mozilla::ErrorResult& aRv);
|
||||||
|
|
||||||
void Extend(nsINode& aNode, uint32_t aOffset, mozilla::ErrorResult& aRv);
|
void ExtendJS(nsINode& aNode, uint32_t aOffset,
|
||||||
|
mozilla::ErrorResult& aRv);
|
||||||
|
|
||||||
|
void SelectAllChildrenJS(nsINode& aNode, mozilla::ErrorResult& aRv);
|
||||||
|
|
||||||
void SelectAllChildren(nsINode& aNode, mozilla::ErrorResult& aRv);
|
|
||||||
void DeleteFromDocument(mozilla::ErrorResult& aRv);
|
void DeleteFromDocument(mozilla::ErrorResult& aRv);
|
||||||
|
|
||||||
uint32_t RangeCount() const
|
uint32_t RangeCount() const
|
||||||
|
|
@ -187,7 +193,7 @@ public:
|
||||||
void GetType(nsAString& aOutType) const;
|
void GetType(nsAString& aOutType) const;
|
||||||
|
|
||||||
nsRange* GetRangeAt(uint32_t aIndex, mozilla::ErrorResult& aRv);
|
nsRange* GetRangeAt(uint32_t aIndex, mozilla::ErrorResult& aRv);
|
||||||
void AddRange(nsRange& aRange, mozilla::ErrorResult& aRv);
|
void AddRangeJS(nsRange& aRange, mozilla::ErrorResult& aRv);
|
||||||
void RemoveRange(nsRange& aRange, mozilla::ErrorResult& aRv);
|
void RemoveRange(nsRange& aRange, mozilla::ErrorResult& aRv);
|
||||||
void RemoveAllRanges(mozilla::ErrorResult& aRv);
|
void RemoveAllRanges(mozilla::ErrorResult& aRv);
|
||||||
|
|
||||||
|
|
@ -207,9 +213,9 @@ public:
|
||||||
void Modify(const nsAString& aAlter, const nsAString& aDirection,
|
void Modify(const nsAString& aAlter, const nsAString& aDirection,
|
||||||
const nsAString& aGranularity, mozilla::ErrorResult& aRv);
|
const nsAString& aGranularity, mozilla::ErrorResult& aRv);
|
||||||
|
|
||||||
void SetBaseAndExtent(nsINode& aAnchorNode, uint32_t aAnchorOffset,
|
void SetBaseAndExtentJS(nsINode& aAnchorNode, uint32_t aAnchorOffset,
|
||||||
nsINode& aFocusNode, uint32_t aFocusOffset,
|
nsINode& aFocusNode, uint32_t aFocusOffset,
|
||||||
mozilla::ErrorResult& aRv);
|
mozilla::ErrorResult& aRv);
|
||||||
|
|
||||||
bool GetInterlinePosition(mozilla::ErrorResult& aRv);
|
bool GetInterlinePosition(mozilla::ErrorResult& aRv);
|
||||||
void SetInterlinePosition(bool aValue, mozilla::ErrorResult& aRv);
|
void SetInterlinePosition(bool aValue, mozilla::ErrorResult& aRv);
|
||||||
|
|
@ -243,6 +249,17 @@ public:
|
||||||
int16_t aVPercent, int16_t aHPercent,
|
int16_t aVPercent, int16_t aHPercent,
|
||||||
mozilla::ErrorResult& aRv);
|
mozilla::ErrorResult& aRv);
|
||||||
|
|
||||||
|
// Non-JS callers should use the following methods.
|
||||||
|
void Collapse(nsINode& aNode, uint32_t aOffset, mozilla::ErrorResult& aRv);
|
||||||
|
void CollapseToStart(mozilla::ErrorResult& aRv);
|
||||||
|
void CollapseToEnd(mozilla::ErrorResult& aRv);
|
||||||
|
void Extend(nsINode& aNode, uint32_t aOffset, mozilla::ErrorResult& aRv);
|
||||||
|
void AddRange(nsRange& aRange, mozilla::ErrorResult& aRv);
|
||||||
|
void SelectAllChildren(nsINode& aNode, mozilla::ErrorResult& aRv);
|
||||||
|
void SetBaseAndExtent(nsINode& aAnchorNode, uint32_t aAnchorOffset,
|
||||||
|
nsINode& aFocusNode, uint32_t aFocusOffset,
|
||||||
|
mozilla::ErrorResult& aRv);
|
||||||
|
|
||||||
void AddSelectionChangeBlocker();
|
void AddSelectionChangeBlocker();
|
||||||
void RemoveSelectionChangeBlocker();
|
void RemoveSelectionChangeBlocker();
|
||||||
bool IsBlockingSelectionChangeEvents() const;
|
bool IsBlockingSelectionChangeEvents() const;
|
||||||
|
|
@ -265,7 +282,8 @@ public:
|
||||||
mSelectionType = aSelectionType;
|
mSelectionType = aSelectionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult NotifySelectionListeners();
|
nsresult NotifySelectionListeners(bool aCalledByJS);
|
||||||
|
nsresult NotifySelectionListeners();
|
||||||
|
|
||||||
friend struct AutoUserInitiated;
|
friend struct AutoUserInitiated;
|
||||||
struct MOZ_RAII AutoUserInitiated
|
struct MOZ_RAII AutoUserInitiated
|
||||||
|
|
@ -371,6 +389,12 @@ private:
|
||||||
*/
|
*/
|
||||||
bool mUserInitiated;
|
bool mUserInitiated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the selection change is caused by a call of Selection API,
|
||||||
|
* mCalledByJS is true. Otherwise, false.
|
||||||
|
*/
|
||||||
|
bool mCalledByJS;
|
||||||
|
|
||||||
// Non-zero if we don't want any changes we make to the selection to be
|
// Non-zero if we don't want any changes we make to the selection to be
|
||||||
// visible to content. If non-zero, content won't be notified about changes.
|
// visible to content. If non-zero, content won't be notified about changes.
|
||||||
uint32_t mSelectionChangeBlockerCount;
|
uint32_t mSelectionChangeBlockerCount;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include "mozilla/dom/Selection.h"
|
#include "mozilla/dom/Selection.h"
|
||||||
|
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
|
#include "mozilla/AutoRestore.h"
|
||||||
#include "mozilla/EventStates.h"
|
#include "mozilla/EventStates.h"
|
||||||
|
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
|
|
@ -3473,6 +3474,7 @@ Selection::Selection()
|
||||||
, mDirection(eDirNext)
|
, mDirection(eDirNext)
|
||||||
, mSelectionType(SelectionType::eNormal)
|
, mSelectionType(SelectionType::eNormal)
|
||||||
, mUserInitiated(false)
|
, mUserInitiated(false)
|
||||||
|
, mCalledByJS(false)
|
||||||
, mSelectionChangeBlockerCount(0)
|
, mSelectionChangeBlockerCount(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -3483,6 +3485,7 @@ Selection::Selection(nsFrameSelection* aList)
|
||||||
, mDirection(eDirNext)
|
, mDirection(eDirNext)
|
||||||
, mSelectionType(SelectionType::eNormal)
|
, mSelectionType(SelectionType::eNormal)
|
||||||
, mUserInitiated(false)
|
, mUserInitiated(false)
|
||||||
|
, mCalledByJS(false)
|
||||||
, mSelectionChangeBlockerCount(0)
|
, mSelectionChangeBlockerCount(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -4966,6 +4969,14 @@ Selection::AddRange(nsIDOMRange* aDOMRange)
|
||||||
return result.StealNSResult();
|
return result.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Selection::AddRangeJS(nsRange& aRange, ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
AutoRestore<bool> calledFromJSRestorer(mCalledByJS);
|
||||||
|
mCalledByJS = true;
|
||||||
|
AddRange(aRange, aRv);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Selection::AddRange(nsRange& aRange, ErrorResult& aRv)
|
Selection::AddRange(nsRange& aRange, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
@ -5140,6 +5151,14 @@ Selection::CollapseNative(nsINode* aParentNode, int32_t aOffset)
|
||||||
return Collapse(aParentNode, aOffset);
|
return Collapse(aParentNode, aOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Selection::CollapseJS(nsINode& aNode, uint32_t aOffset, ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
AutoRestore<bool> calledFromJSRestorer(mCalledByJS);
|
||||||
|
mCalledByJS = true;
|
||||||
|
Collapse(aNode, aOffset, aRv);
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
Selection::Collapse(nsINode* aParentNode, int32_t aOffset)
|
Selection::Collapse(nsINode* aParentNode, int32_t aOffset)
|
||||||
{
|
{
|
||||||
|
|
@ -5240,6 +5259,14 @@ Selection::CollapseToStart()
|
||||||
return result.StealNSResult();
|
return result.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Selection::CollapseToStartJS(ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
AutoRestore<bool> calledFromJSRestorer(mCalledByJS);
|
||||||
|
mCalledByJS = true;
|
||||||
|
CollapseToStart(aRv);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Selection::CollapseToStart(ErrorResult& aRv)
|
Selection::CollapseToStart(ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
@ -5281,6 +5308,14 @@ Selection::CollapseToEnd()
|
||||||
return result.StealNSResult();
|
return result.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Selection::CollapseToEndJS(ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
AutoRestore<bool> calledFromJSRestorer(mCalledByJS);
|
||||||
|
mCalledByJS = true;
|
||||||
|
CollapseToEnd(aRv);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Selection::CollapseToEnd(ErrorResult& aRv)
|
Selection::CollapseToEnd(ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
@ -5495,6 +5530,14 @@ Selection::ExtendNative(nsINode* aParentNode, int32_t aOffset)
|
||||||
return Extend(aParentNode, aOffset);
|
return Extend(aParentNode, aOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Selection::ExtendJS(nsINode& aNode, uint32_t aOffset, ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
AutoRestore<bool> calledFromJSRestorer(mCalledByJS);
|
||||||
|
mCalledByJS = true;
|
||||||
|
Extend(aNode, aOffset, aRv);
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
Selection::Extend(nsINode* aParentNode, int32_t aOffset)
|
Selection::Extend(nsINode* aParentNode, int32_t aOffset)
|
||||||
{
|
{
|
||||||
|
|
@ -5790,6 +5833,14 @@ Selection::SelectAllChildren(nsIDOMNode* aParentNode)
|
||||||
return result.StealNSResult();
|
return result.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Selection::SelectAllChildrenJS(nsINode& aNode, ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
AutoRestore<bool> calledFromJSRestorer(mCalledByJS);
|
||||||
|
mCalledByJS = true;
|
||||||
|
SelectAllChildren(aNode, aRv);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Selection::SelectAllChildren(nsINode& aNode, ErrorResult& aRv)
|
Selection::SelectAllChildren(nsINode& aNode, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
|
|
@ -6239,6 +6290,14 @@ Selection::RemoveSelectionListener(nsISelectionListener* aListenerToRemove,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
Selection::NotifySelectionListeners(bool aCalledByJS)
|
||||||
|
{
|
||||||
|
AutoRestore<bool> calledFromJSRestorer(mCalledByJS);
|
||||||
|
mCalledByJS = aCalledByJS;
|
||||||
|
return NotifySelectionListeners();
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
Selection::NotifySelectionListeners()
|
Selection::NotifySelectionListeners()
|
||||||
{
|
{
|
||||||
|
|
@ -6454,6 +6513,19 @@ Selection::Modify(const nsAString& aAlter, const nsAString& aDirection,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Selection::SetBaseAndExtentJS(nsINode& aAnchorNode,
|
||||||
|
uint32_t aAnchorOffset,
|
||||||
|
nsINode& aFocusNode,
|
||||||
|
uint32_t aFocusOffset,
|
||||||
|
ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
AutoRestore<bool> calledFromJSRestorer(mCalledByJS);
|
||||||
|
mCalledByJS = true;
|
||||||
|
SetBaseAndExtent(aAnchorNode, aAnchorOffset,
|
||||||
|
aFocusNode, aFocusOffset, aRv);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Selection::SetBaseAndExtent(nsINode& aAnchorNode, uint32_t aAnchorOffset,
|
Selection::SetBaseAndExtent(nsINode& aAnchorNode, uint32_t aAnchorOffset,
|
||||||
nsINode& aFocusNode, uint32_t aFocusOffset,
|
nsINode& aFocusNode, uint32_t aFocusOffset,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue