Commit e88ba434 authored by Gayane Petrosyan's avatar Gayane Petrosyan Committed by Commit Bot

[Sh-Blink] Return invalid selector when no match found.

When TextFragmentFinder finds no match for the provided selector,
TextFragmentSelectorGenerator should be notified so that it notifies the
user that generation failed.
As selector provided by TextFragmentSelectorGenerator is constructed for
the selection from the user, this can happen only if selector is
incorrectly constructed.

Bug: 1129649
Change-Id: I10b5a49602128b532166a66354faa905493fb7f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426464
Commit-Queue: Gayane Petrosyan <gayane@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811006}
parent 1a8fc80a
...@@ -84,6 +84,8 @@ class CORE_EXPORT TextFragmentAnchor final : public FragmentAnchor, ...@@ -84,6 +84,8 @@ class CORE_EXPORT TextFragmentAnchor final : public FragmentAnchor,
const TextFragmentAnchorMetrics::Match match_metrics, const TextFragmentAnchorMetrics::Match match_metrics,
bool is_unique) override; bool is_unique) override;
void NoMatchFound() override {}
private: private:
// Called when the search is finished. Reports metrics and activates the // Called when the search is finished. Reports metrics and activates the
// element fragment anchor if we didn't find a match. // element fragment anchor if we didn't find a match.
......
...@@ -240,6 +240,8 @@ void TextFragmentFinder::FindMatch(Document& document) { ...@@ -240,6 +240,8 @@ void TextFragmentFinder::FindMatch(Document& document) {
EphemeralRangeInFlatTree ambiguous_match = EphemeralRangeInFlatTree ambiguous_match =
FindMatchFromPosition(document, match.EndPosition()); FindMatchFromPosition(document, match.EndPosition());
client_.DidFindMatch(match, match_metrics, ambiguous_match.IsNull()); client_.DidFindMatch(match, match_metrics, ambiguous_match.IsNull());
} else {
client_.NoMatchFound();
} }
} }
......
...@@ -26,6 +26,7 @@ class CORE_EXPORT TextFragmentFinder final { ...@@ -26,6 +26,7 @@ class CORE_EXPORT TextFragmentFinder final {
const EphemeralRangeInFlatTree& range, const EphemeralRangeInFlatTree& range,
const TextFragmentAnchorMetrics::Match match_metrics, const TextFragmentAnchorMetrics::Match match_metrics,
bool is_unique) = 0; bool is_unique) = 0;
virtual void NoMatchFound() = 0;
}; };
// Client must outlive the finder. // Client must outlive the finder.
......
...@@ -289,6 +289,11 @@ void TextFragmentSelectorGenerator::DidFindMatch( ...@@ -289,6 +289,11 @@ void TextFragmentSelectorGenerator::DidFindMatch(
} }
} }
void TextFragmentSelectorGenerator::NoMatchFound() {
NotifySelectorReady(
TextFragmentSelector(TextFragmentSelector::SelectorType::kInvalid));
}
void TextFragmentSelectorGenerator::NotifySelectorReady( void TextFragmentSelectorGenerator::NotifySelectorReady(
const TextFragmentSelector& selector) { const TextFragmentSelector& selector) {
DCHECK(pending_generate_selector_callback_); DCHECK(pending_generate_selector_callback_);
......
...@@ -53,6 +53,8 @@ class CORE_EXPORT TextFragmentSelectorGenerator final ...@@ -53,6 +53,8 @@ class CORE_EXPORT TextFragmentSelectorGenerator final
const TextFragmentAnchorMetrics::Match match_metrics, const TextFragmentAnchorMetrics::Match match_metrics,
bool is_unique) override; bool is_unique) override;
void NoMatchFound() override;
// Notifies the results of |GenerateSelector|. // Notifies the results of |GenerateSelector|.
void NotifySelectorReady(const TextFragmentSelector& selector); void NotifySelectorReady(const TextFragmentSelector& selector);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment