Skip to content
Snippets Groups Projects
Commit 83e6cf07 authored by Masayuki Nakano's avatar Masayuki Nakano
Browse files

Bug 1885822 - part 1: Make `WSScanResult` created with...

Bug 1885822 - part 1: Make `WSScanResult` created with `WSType::InUncomposedDoc` if the scan is tried in uncomposed tree r=m_kato

This case should never happen because nobody can check proper editable state
in uncomposed tree unless the uncomposed tree has its own editing host.
Therefore, this patch adds assertions into the scanning methods too.

Differential Revision: https://phabricator.services.mozilla.com/D207681
parent a205245a
No related branches found
No related tags found
No related merge requests found
......@@ -1721,6 +1721,16 @@ template <typename PT, typename CT>
WSScanResult WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundaryFrom(
const EditorDOMPointBase<PT, CT>& aPoint) const {
MOZ_ASSERT(aPoint.IsSet());
MOZ_ASSERT(aPoint.IsInComposedDoc());
// We may not be able to check editable state in uncomposed tree as expected.
// For example, only some descendants in an editing host is temporarily
// removed from the tree, they are not editable unless nested contenteditable
// attribute is set to "true".
if (MOZ_UNLIKELY(!aPoint.IsInComposedDoc())) {
return WSScanResult(aPoint.template ContainerAs<nsIContent>(),
WSType::InUncomposedDoc, mBlockInlineCheck);
}
if (!TextFragmentDataAtStartRef().IsInitialized()) {
return WSScanResult(nullptr, WSType::UnexpectedError, mBlockInlineCheck);
......@@ -1770,6 +1780,16 @@ template <typename PT, typename CT>
WSScanResult WSRunScanner::ScanNextVisibleNodeOrBlockBoundaryFrom(
const EditorDOMPointBase<PT, CT>& aPoint) const {
MOZ_ASSERT(aPoint.IsSet());
MOZ_ASSERT(aPoint.IsInComposedDoc());
// We may not be able to check editable state in uncomposed tree as expected.
// For example, only some descendants in an editing host is temporarily
// removed from the tree, they are not editable unless nested contenteditable
// attribute is set to "true".
if (MOZ_UNLIKELY(!aPoint.IsInComposedDoc())) {
return WSScanResult(aPoint.template ContainerAs<nsIContent>(),
WSType::InUncomposedDoc, mBlockInlineCheck);
}
if (!TextFragmentDataAtStartRef().IsInitialized()) {
return WSScanResult(nullptr, WSType::UnexpectedError, mBlockInlineCheck);
......
......@@ -41,6 +41,8 @@ class MOZ_STACK_CLASS WSScanResult final {
NotInitialized,
// Could be the DOM tree is broken as like crash tests.
UnexpectedError,
// The scanner cannot work in uncomposed tree, but tried to scan in it.
InUncomposedDoc,
// The run is maybe collapsible white-spaces at start of a hard line.
LeadingWhiteSpaces,
// The run is maybe collapsible white-spaces at end of a hard line.
......@@ -67,6 +69,8 @@ class MOZ_STACK_CLASS WSScanResult final {
return aStream << "WSType::NotInitialized";
case WSType::UnexpectedError:
return aStream << "WSType::UnexpectedError";
case WSType::InUncomposedDoc:
return aStream << "WSType::InUncomposedDoc";
case WSType::LeadingWhiteSpaces:
return aStream << "WSType::LeadingWhiteSpaces";
case WSType::TrailingWhiteSpaces:
......@@ -111,6 +115,7 @@ class MOZ_STACK_CLASS WSScanResult final {
BlockInlineCheck aBlockInlineCheck) const {
#ifdef DEBUG
MOZ_ASSERT(mReason == WSType::UnexpectedError ||
mReason == WSType::InUncomposedDoc ||
mReason == WSType::NonCollapsibleCharacters ||
mReason == WSType::CollapsibleWhiteSpaces ||
mReason == WSType::BRElement ||
......@@ -119,6 +124,10 @@ class MOZ_STACK_CLASS WSScanResult final {
mReason == WSType::CurrentBlockBoundary ||
mReason == WSType::OtherBlockBoundary);
MOZ_ASSERT_IF(mReason == WSType::UnexpectedError, !mContent);
MOZ_ASSERT_IF(mReason == WSType::InUncomposedDoc,
mContent && !mContent->IsInComposedDoc());
MOZ_ASSERT_IF(mContent && !mContent->IsInComposedDoc(),
mReason == WSType::InUncomposedDoc);
MOZ_ASSERT_IF(mReason == WSType::NonCollapsibleCharacters ||
mReason == WSType::CollapsibleWhiteSpaces,
mContent && mContent->IsText());
......@@ -143,9 +152,6 @@ class MOZ_STACK_CLASS WSScanResult final {
// container start of scanner and is not editable.
if (mReason == WSType::CurrentBlockBoundary) {
if (!mContent ||
// Although not expected that scanning in orphan document fragment,
// it's okay.
!mContent->IsInComposedDoc() ||
// This is what the most preferred result is mContent itself is a
// block.
HTMLEditUtils::IsBlockElement(*mContent, aBlockInlineCheck) ||
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment