Bug 1490974 Part 1: For find-in-page, prevent invisible nodes and option nodes from being included in find results. r=mikedeboer

Differential Revision: https://phabricator.services.mozilla.com/D10631

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brad Werth 2019-02-27 21:23:55 +00:00
parent 7ef4f21bc7
commit 5afd6194db

View File

@ -27,6 +27,8 @@
#include "mozilla/dom/ChildIterator.h"
#include "mozilla/dom/TreeIterator.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/HTMLOptionElement.h"
#include "mozilla/dom/HTMLSelectElement.h"
#include "mozilla/dom/Text.h"
using namespace mozilla;
@ -153,7 +155,7 @@ static bool IsTextFormControl(nsIContent& aContent) {
static bool SkipNode(const nsIContent* aContent) {
const nsIContent* content = aContent;
while (content) {
if (!IsDisplayedNode(content) || content->IsComment() ||
if (!IsVisibleNode(content) || content->IsComment() ||
content->IsAnyOfHTMLElements(nsGkAtoms::script, nsGkAtoms::noframes,
nsGkAtoms::select)) {
DEBUG_FIND_PRINTF("Skipping node: ");
@ -161,6 +163,21 @@ static bool SkipNode(const nsIContent* aContent) {
return true;
}
// Skip option nodes if their select is a combo box, or if they
// have no select (somehow).
if (content->IsHTMLElement(nsGkAtoms::option)) {
const HTMLOptionElement* option = HTMLOptionElement::FromNode(content);
if (option) {
HTMLSelectElement* select =
HTMLSelectElement::FromNodeOrNull(option->GetParent());
if (!select || select->IsCombobox()) {
DEBUG_FIND_PRINTF("Skipping node: ");
DumpNode(content);
return true;
}
}
}
// Skip NAC in non-form-control.
if (content->IsInNativeAnonymousSubtree() &&
!IsTextFormControl(AnonymousSubtreeRootParent(*content))) {