Bug 1797148: Simplify checkVisibility API (on nsISelectionController and nsIFrame) into a single nsTextFrame::HasVisibleText method. r=masayuki

Before this patch, we had two `checkVisibilty` methods on the
nsISelectionController interface, backed by several layers of implementation,
ultimately backed by a single function on nsTextFrame (which didn't actually
do anything meaningful with any of the parameters).

As it turns out, this API only had one caller, in HTMLEditUtils.cpp.

This patch converts that caller to directly query nsTextFrame (if the given
node's primary frame is indeed a nsTextFrame).  The direct function-call is
renamed to HasVisibleText(), to be a bit clearer about it being text-specific
and also to avoid confusion with the (unrelated) recently-specified HTML
checkVisibility() API.

With these changes, we can remove the API from the nsISelectionController
interface and its implementations.

This patch also updates the HTMLEditUtils::IsInVisibleTextFrames documentation
(with s/all/any/) to reflect the reality of what the nsTextFrame impl actually
does.

Differential Revision: https://phabricator.services.mozilla.com/D160563
This commit is contained in:
Daniel Holbert
2022-10-28 17:56:04 +00:00
parent 2aed64e73d
commit dbc431214c
10 changed files with 18 additions and 166 deletions

View File

@@ -2507,50 +2507,6 @@ PresShell::CompleteMove(bool aForward, bool aExtend) {
nsISelectionController::SCROLL_FOR_CARET_MOVE);
}
static void DoCheckVisibility(nsPresContext* aPresContext, nsIContent* aNode,
int16_t aStartOffset, int16_t aEndOffset,
bool* aRetval) {
nsIFrame* frame = aNode->GetPrimaryFrame();
if (!frame) {
// No frame to look at so it must not be visible.
return;
}
// Start process now to go through all frames to find startOffset. Then check
// chars after that to see if anything until EndOffset is visible.
bool finished = false;
frame->CheckVisibility(aPresContext, aStartOffset, aEndOffset, true,
&finished, aRetval);
// Don't worry about other return value.
}
NS_IMETHODIMP
PresShell::CheckVisibility(nsINode* node, int16_t startOffset,
int16_t EndOffset, bool* _retval) {
if (!node || startOffset > EndOffset || !_retval || startOffset < 0 ||
EndOffset < 0)
return NS_ERROR_INVALID_ARG;
*_retval = false; // initialize return parameter
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
if (!content) return NS_ERROR_FAILURE;
DoCheckVisibility(mPresContext, content, startOffset, EndOffset, _retval);
return NS_OK;
}
nsresult PresShell::CheckVisibilityContent(nsIContent* aNode,
int16_t aStartOffset,
int16_t aEndOffset, bool* aRetval) {
if (!aNode || aStartOffset > aEndOffset || !aRetval || aStartOffset < 0 ||
aEndOffset < 0) {
return NS_ERROR_INVALID_ARG;
}
*aRetval = false;
DoCheckVisibility(mPresContext, aNode, aStartOffset, aEndOffset, aRetval);
return NS_OK;
}
// end implementations nsISelectionController
nsIFrame* PresShell::GetRootScrollFrame() const {