Commit 6119fb2c authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Commit Bot

Remove Invisible DOM parts of find-in-page

Removing since we're not pursuing Invisible DOM anymore.

Bug: 873057
Change-Id: I466b161bb997624704ae866b0f59741d32391784
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1633870Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664167}
parent 7add3421
...@@ -1945,7 +1945,6 @@ jumbo_source_set("unit_tests") { ...@@ -1945,7 +1945,6 @@ jumbo_source_set("unit_tests") {
"inspector/protocol_parser_test.cc", "inspector/protocol_parser_test.cc",
"inspector/protocol_unittest.cc", "inspector/protocol_unittest.cc",
"intersection_observer/intersection_observer_test.cc", "intersection_observer/intersection_observer_test.cc",
"invisible_dom/find_invisible_test.cc",
"layout/api/selection_state_test.cc", "layout/api/selection_state_test.cc",
"layout/collapsed_border_value_test.cc", "layout/collapsed_border_value_test.cc",
"layout/custom/layout_worklet_test.cc", "layout/custom/layout_worklet_test.cc",
......
...@@ -97,46 +97,6 @@ unsigned FindBuffer::Results::CountForTesting() { ...@@ -97,46 +97,6 @@ unsigned FindBuffer::Results::CountForTesting() {
return result; return result;
} }
void FindBuffer::InvisibleLayoutScope::EnsureRecalc(Node& block_root) {
if (!RuntimeEnabledFeatures::InvisibleDOMEnabled())
return;
if (did_recalc_)
return;
did_recalc_ = true;
DCHECK(block_root.GetDocument().Lifecycle().GetState() >=
DocumentLifecycle::kStyleClean);
// If we're in an invisible subtree, we should recalc style from the invisible
// root/the highest ancestor of |block_root| with the invisible attribute,
// otherwise we should recalc from |block_root|.
// InvisibleRoot is always non-null when IsInsideInvisibleSubtree is true.
if (InvisibleDOM::IsInsideInvisibleSubtree(block_root))
invisible_root_ = InvisibleDOM::InvisibleRoot(block_root);
else
invisible_root_ = &ToElement(block_root);
DCHECK(invisible_root_);
invisible_root_->GetDocument().SetFindInPageRoot(invisible_root_);
invisible_root_->SetNeedsStyleRecalc(
kSubtreeStyleChange,
StyleChangeReasonForTracing::Create(style_change_reason::kFindInvisible));
// TODO(rakina): This currently does layout too and might be expensive. In the
// future, we might to figure out a way to make NGOffsetMapping work with only
// style & layout tree so that we don't have to do layout here.
invisible_root_->GetDocument().UpdateStyleAndLayout();
}
FindBuffer::InvisibleLayoutScope::~InvisibleLayoutScope() {
if (!RuntimeEnabledFeatures::InvisibleDOMEnabled())
return;
if (!did_recalc_)
return;
invisible_root_->GetDocument().SetFindInPageRoot(nullptr);
invisible_root_->SetNeedsStyleRecalc(
kSubtreeStyleChange,
StyleChangeReasonForTracing::Create(style_change_reason::kFindInvisible));
invisible_root_->GetDocument().UpdateStyleAndLayout();
}
bool ShouldIgnoreContents(const Node& node) { bool ShouldIgnoreContents(const Node& node) {
const auto* element = DynamicTo<HTMLElement>(node); const auto* element = DynamicTo<HTMLElement>(node);
if (!element) if (!element)
...@@ -333,12 +293,6 @@ void FindBuffer::CollectTextUntilBlockBoundary( ...@@ -333,12 +293,6 @@ void FindBuffer::CollectTextUntilBlockBoundary(
FlatTreeTraversal::LastWithinOrSelf(block_ancestor)); FlatTreeTraversal::LastWithinOrSelf(block_ancestor));
const LayoutBlockFlow* last_block_flow = nullptr; const LayoutBlockFlow* last_block_flow = nullptr;
// Calculate layout tree and style for invisible nodes inside the whole
// subtree of |block_ancestor|.
if (RuntimeEnabledFeatures::InvisibleDOMEnabled() && node &&
InvisibleDOM::IsInsideInvisibleSubtree(*node))
invisible_layout_scope_.EnsureRecalc(block_ancestor);
// Collect all text under |block_ancestor| to |buffer_|, // Collect all text under |block_ancestor| to |buffer_|,
// unless we meet another block on the way. If so, we should split. // unless we meet another block on the way. If so, we should split.
// Example: <div id="outer">a<span>b</span>c<div>d</div></div> // Example: <div id="outer">a<span>b</span>c<div>d</div></div>
...@@ -369,19 +323,6 @@ void FindBuffer::CollectTextUntilBlockBoundary( ...@@ -369,19 +323,6 @@ void FindBuffer::CollectTextUntilBlockBoundary(
node = FlatTreeTraversal::NextSkippingChildren(*node); node = FlatTreeTraversal::NextSkippingChildren(*node);
continue; continue;
} }
if (RuntimeEnabledFeatures::InvisibleDOMEnabled() &&
node->IsElementNode() && ToElement(node)->HasInvisibleAttribute() &&
!invisible_layout_scope_.DidRecalc()) {
// We found and invisible node. Calculate the layout & style for the whole
// block at once, and we need to recalculate the NGOffsetMapping and start
// from the beginning again because the layout tree had changed.
mapping_needs_recalc_ = true;
node = first_traversed_node;
last_block_flow = nullptr;
buffer_.clear();
invisible_layout_scope_.EnsureRecalc(block_ancestor);
continue;
}
const ComputedStyle* style = node->EnsureComputedStyle(); const ComputedStyle* style = node->EnsureComputedStyle();
if (style->Display() == EDisplay::kNone) { if (style->Display() == EDisplay::kNone) {
// This element and its descendants are not visible, skip it. // This element and its descendants are not visible, skip it.
...@@ -473,10 +414,8 @@ PositionInFlatTree FindBuffer::PositionAtEndOfCharacterAtIndex( ...@@ -473,10 +414,8 @@ PositionInFlatTree FindBuffer::PositionAtEndOfCharacterAtIndex(
void FindBuffer::AddTextToBuffer(const Text& text_node, void FindBuffer::AddTextToBuffer(const Text& text_node,
LayoutBlockFlow& block_flow, LayoutBlockFlow& block_flow,
const EphemeralRangeInFlatTree& range) { const EphemeralRangeInFlatTree& range) {
if (!offset_mapping_ || mapping_needs_recalc_) { if (!offset_mapping_)
offset_mapping_ = NGInlineNode::GetOffsetMapping(&block_flow); offset_mapping_ = NGInlineNode::GetOffsetMapping(&block_flow);
mapping_needs_recalc_ = false;
}
Position node_start = Position node_start =
(&text_node == range.StartPosition().ComputeContainerNode()) (&text_node == range.StartPosition().ComputeContainerNode())
......
...@@ -134,21 +134,6 @@ class CORE_EXPORT FindBuffer { ...@@ -134,21 +134,6 @@ class CORE_EXPORT FindBuffer {
const Node* search_range_end_node, const Node* search_range_end_node,
const Node* node_after_block); const Node* node_after_block);
class CORE_EXPORT InvisibleLayoutScope {
STACK_ALLOCATED();
public:
InvisibleLayoutScope() {}
~InvisibleLayoutScope();
void EnsureRecalc(Node& block_root);
bool DidRecalc() { return did_recalc_; }
private:
bool did_recalc_ = false;
Member<Element> invisible_root_;
};
// Mapping for position in buffer -> actual node where the text came from, // Mapping for position in buffer -> actual node where the text came from,
// along with the offset in the NGOffsetMapping of this find_buffer. // along with the offset in the NGOffsetMapping of this find_buffer.
// This is needed because when we find a match in the buffer, we want to know // This is needed because when we find a match in the buffer, we want to know
...@@ -190,14 +175,12 @@ class CORE_EXPORT FindBuffer { ...@@ -190,14 +175,12 @@ class CORE_EXPORT FindBuffer {
LayoutBlockFlow& block_flow, LayoutBlockFlow& block_flow,
const EphemeralRangeInFlatTree& range); const EphemeralRangeInFlatTree& range);
InvisibleLayoutScope invisible_layout_scope_;
Member<Node> node_after_block_; Member<Node> node_after_block_;
Vector<UChar> buffer_; Vector<UChar> buffer_;
Vector<BufferNodeMapping> buffer_node_mappings_; Vector<BufferNodeMapping> buffer_node_mappings_;
Vector<DisplayLockContext::ScopedForcedUpdate> scoped_forced_update_list_; Vector<DisplayLockContext::ScopedForcedUpdate> scoped_forced_update_list_;
const NGOffsetMapping* offset_mapping_ = nullptr; const NGOffsetMapping* offset_mapping_ = nullptr;
bool mapping_needs_recalc_ = false;
}; };
} // namespace blink } // namespace blink
......
...@@ -266,8 +266,7 @@ TEST_F(FindBufferTest, FindBetweenPositionsSkippedNodes) { ...@@ -266,8 +266,7 @@ TEST_F(FindBufferTest, FindBetweenPositionsSkippedNodes) {
} }
TEST_F(FindBufferTest, FindMatchInRange) { TEST_F(FindBufferTest, FindMatchInRange) {
SetBodyContent( SetBodyContent("<div id='div'>foo<a id='a'>foof</a><b id='b'>oo</b></div>");
"<div id='div' invisible>foo<a id='a'>foof</a><b id='b'>oo</b></div>");
Element* div = GetElementById("div"); Element* div = GetElementById("div");
Element* a = GetElementById("a"); Element* a = GetElementById("a");
Element* b = GetElementById("b"); Element* b = GetElementById("b");
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/core/editing/finder/text_finder.h"
#include "third_party/blink/renderer/core/frame/find_in_page.h"
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
namespace blink {
class InvisibleFindInPageClient : public mojom::blink::FindInPageClient {
public:
InvisibleFindInPageClient()
: binding_(this),
active_index_(-1),
count_(-1),
find_results_are_ready_(false) {}
~InvisibleFindInPageClient() override = default;
void SetFrame(WebLocalFrameImpl* frame) {
mojom::blink::FindInPageClientPtr client;
binding_.Bind(MakeRequest(&client));
frame->GetFindInPage()->SetClient(std::move(client));
}
void SetNumberOfMatches(
int request_id,
unsigned int current_number_of_matches,
mojom::blink::FindMatchUpdateType final_update) final {
count_ = current_number_of_matches;
find_results_are_ready_ =
(final_update == mojom::blink::FindMatchUpdateType::kFinalUpdate);
}
void SetActiveMatch(int request_id,
const WebRect& active_match_rect,
int active_match_ordinal,
mojom::blink::FindMatchUpdateType final_update) final {
active_index_ = active_match_ordinal;
find_results_are_ready_ =
(final_update == mojom::blink::FindMatchUpdateType::kFinalUpdate);
}
bool FindResultsAreReady() const { return find_results_are_ready_; }
int Count() const { return count_; }
int ActiveIndex() const { return active_index_; }
void Reset() {
find_results_are_ready_ = false;
count_ = -1;
active_index_ = -1;
}
private:
mojo::Binding<mojom::blink::FindInPageClient> binding_;
int active_index_;
int count_;
bool find_results_are_ready_;
};
class FindInvisibleTest : public ::testing::WithParamInterface<bool>,
public testing::Test,
private ScopedLayoutNGForTest {
protected:
FindInvisibleTest() : ScopedLayoutNGForTest(GetParam()) {}
bool LayoutNGEnabled() const { return GetParam(); }
void SetUp() override { web_view_helper_.Initialize(); }
void TearDown() override { web_view_helper_.Reset(); }
Document& GetDocument() {
return *static_cast<Document*>(
web_view_helper_.LocalMainFrame()->GetDocument());
}
FindInPage* GetFindInPage() {
return web_view_helper_.LocalMainFrame()->GetFindInPage();
}
WebLocalFrameImpl* LocalMainFrame() {
return web_view_helper_.LocalMainFrame();
}
void UpdateAllLifecyclePhasesForTest() {
GetDocument().View()->UpdateAllLifecyclePhases(
DocumentLifecycle::LifecycleUpdateReason::kTest);
}
void SetInnerHTML(const char* content) {
GetDocument().documentElement()->SetInnerHTMLFromString(
String::FromUTF8(content));
UpdateAllLifecyclePhasesForTest();
}
void ResizeAndFocus() {
web_view_helper_.Resize(WebSize(640, 480));
web_view_helper_.GetWebView()->MainFrameWidget()->SetFocus(true);
test::RunPendingTasks();
}
private:
frame_test_helpers::WebViewHelper web_view_helper_;
};
INSTANTIATE_TEST_SUITE_P(All, FindInvisibleTest, ::testing::Bool());
TEST_P(FindInvisibleTest, FindingInvisibleTextHasCorrectCount) {
ResizeAndFocus();
SetInnerHTML(
"<div invisible>"
" foo1"
" <div>foo2</div>"
" foo3"
"</div>"
"<div>"
" bar"
" <span invisible>foo4</span>"
"</div>");
auto* find_in_page = GetFindInPage();
InvisibleFindInPageClient client;
client.SetFrame(LocalMainFrame());
auto find_options = mojom::blink::FindOptions::New();
find_options->run_synchronously_for_testing = true;
find_options->find_next = false;
find_options->forward = true;
int current_id = 0;
find_in_page->Find(current_id++, "foo", find_options->Clone());
EXPECT_FALSE(client.FindResultsAreReady());
test::RunPendingTasks();
EXPECT_TRUE(client.FindResultsAreReady());
EXPECT_EQ(4, client.Count());
EXPECT_EQ(1, client.ActiveIndex());
}
TEST_P(FindInvisibleTest, FindingInvisibleTextHasCorrectActiveMatch) {
ResizeAndFocus();
SetInnerHTML(
"<div id='div'>1foo<div invisible>22foo</div>333foo</div>"
"<div invisible><input id='input' value='4444foo'></div>55555foo");
auto* find_in_page = GetFindInPage();
InvisibleFindInPageClient client;
client.SetFrame(LocalMainFrame());
auto find_options = mojom::blink::FindOptions::New();
find_options->run_synchronously_for_testing = true;
find_options->find_next = false;
find_options->forward = true;
int current_id = 0;
find_in_page->Find(current_id++, "foo", find_options->Clone());
test::RunPendingTasks();
find_in_page->StopFinding(
mojom::blink::StopFindAction::kStopFindActionKeepSelection);
EXPECT_TRUE(client.FindResultsAreReady());
EXPECT_EQ(5, client.Count());
// Finding next focuses on "1foo".
WebRange range = LocalMainFrame()->SelectionRange();
ASSERT_FALSE(range.IsNull());
EXPECT_EQ(1, client.ActiveIndex());
EXPECT_EQ(1, range.StartOffset());
EXPECT_EQ(4, range.EndOffset());
find_options->find_next = true;
find_in_page->Find(current_id++, "foo", find_options->Clone());
test::RunPendingTasks();
find_in_page->StopFinding(
mojom::blink::StopFindAction::kStopFindActionKeepSelection);
// Finding next focuses on "22foo".
range = LocalMainFrame()->SelectionRange();
ASSERT_FALSE(range.IsNull());
EXPECT_EQ(2, client.ActiveIndex());
EXPECT_EQ(2, range.StartOffset());
EXPECT_EQ(5, range.EndOffset());
find_options->find_next = true;
find_in_page->Find(current_id++, "foo", find_options->Clone());
test::RunPendingTasks();
find_in_page->StopFinding(
mojom::blink::StopFindAction::kStopFindActionKeepSelection);
// Finding next focuses on "333foo".
range = LocalMainFrame()->SelectionRange();
ASSERT_FALSE(range.IsNull());
EXPECT_EQ(3, client.ActiveIndex());
EXPECT_EQ(3, range.StartOffset());
EXPECT_EQ(6, range.EndOffset());
find_options->find_next = true;
find_in_page->Find(current_id++, "foo", find_options->Clone());
test::RunPendingTasks();
find_in_page->StopFinding(
mojom::blink::StopFindAction::kStopFindActionKeepSelection);
// Finding next focuses on "4444foo".
range = LocalMainFrame()->SelectionRange();
ASSERT_FALSE(range.IsNull());
EXPECT_EQ(4, client.ActiveIndex());
EXPECT_EQ(4, range.StartOffset());
EXPECT_EQ(7, range.EndOffset());
find_options->find_next = true;
find_in_page->Find(current_id++, "foo", find_options->Clone());
test::RunPendingTasks();
find_in_page->StopFinding(
mojom::blink::StopFindAction::kStopFindActionKeepSelection);
// Finding next focuses on "55555foo".
range = LocalMainFrame()->SelectionRange();
ASSERT_FALSE(range.IsNull());
EXPECT_EQ(5, client.ActiveIndex());
EXPECT_EQ(5, range.StartOffset());
EXPECT_EQ(8, range.EndOffset());
}
} // namespace blink
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