Commit 81209323 authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Move blink::WebSurroundingText out of the public API

This class is now only used from blink::SurroundingTextImpl, so we can
move it down into renderer/core/editing and remove it from the public API.

Also, make the most of this move to make the new blink::SurroundingText
class use internal Blink types (i.e. WTF::String, LocalFrame) instead of
the public Web* types (i.e. WebString, WebLocalFrame), which will allow
migrating blink::EditingImpl away from WebLocalFrame on a follow-up CL.

Bug: 980151, 919392
Change-Id: I2a6ba1aa9e00603d40b4ccb9acb69f46baf5931b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1699608
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680007}
parent 143f3a45
...@@ -498,7 +498,6 @@ source_set("blink_headers") { ...@@ -498,7 +498,6 @@ source_set("blink_headers") {
"web/web_settings.h", "web/web_settings.h",
"web/web_shared_worker.h", "web/web_shared_worker.h",
"web/web_shared_worker_client.h", "web/web_shared_worker_client.h",
"web/web_surrounding_text.h",
"web/web_testing_support.h", "web/web_testing_support.h",
"web/web_text_check_client.h", "web/web_text_check_client.h",
"web/web_text_checking_completion.h", "web/web_text_checking_completion.h",
......
...@@ -1165,7 +1165,6 @@ jumbo_source_set("unit_tests") { ...@@ -1165,7 +1165,6 @@ jumbo_source_set("unit_tests") {
"exported/web_scoped_window_focus_allowed_indicator_test.cc", "exported/web_scoped_window_focus_allowed_indicator_test.cc",
"exported/web_searchable_form_data_test.cc", "exported/web_searchable_form_data_test.cc",
"exported/web_selector_test.cc", "exported/web_selector_test.cc",
"exported/web_surrounding_text_test.cc",
"exported/web_user_gesture_token_test.cc", "exported/web_user_gesture_token_test.cc",
"exported/web_view_test.cc", "exported/web_view_test.cc",
"feature_policy/feature_policy_test.cc", "feature_policy/feature_policy_test.cc",
......
...@@ -299,6 +299,8 @@ blink_core_sources("editing") { ...@@ -299,6 +299,8 @@ blink_core_sources("editing") {
"suggestion/text_suggestion_controller.cc", "suggestion/text_suggestion_controller.cc",
"suggestion/text_suggestion_controller.h", "suggestion/text_suggestion_controller.h",
"suggestion/text_suggestion_info.h", "suggestion/text_suggestion_info.h",
"surrounding_text.cc",
"surrounding_text.h",
"text_affinity.cc", "text_affinity.cc",
"text_affinity.h", "text_affinity.h",
"text_granularity.h", "text_granularity.h",
...@@ -410,6 +412,7 @@ jumbo_source_set("unit_tests") { ...@@ -410,6 +412,7 @@ jumbo_source_set("unit_tests") {
"state_machines/state_machine_test_util.h", "state_machines/state_machine_test_util.h",
"state_machines/state_machine_util_test.cc", "state_machines/state_machine_util_test.cc",
"suggestion/text_suggestion_controller_test.cc", "suggestion/text_suggestion_controller_test.cc",
"surrounding_text_test.cc",
"testing/editing_test_base.cc", "testing/editing_test_base.cc",
"testing/editing_test_base.h", "testing/editing_test_base.h",
"testing/editing_test_base_test.cc", "testing/editing_test_base_test.cc",
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* DAMAGE. * DAMAGE.
*/ */
#include "third_party/blink/public/web/web_surrounding_text.h" #include "third_party/blink/renderer/core/editing/surrounding_text.h"
#include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/editing/editing_utilities.h" #include "third_party/blink/renderer/core/editing/editing_utilities.h"
...@@ -33,32 +33,28 @@ ...@@ -33,32 +33,28 @@
#include "third_party/blink/renderer/core/editing/iterators/character_iterator.h" #include "third_party/blink/renderer/core/editing/iterators/character_iterator.h"
#include "third_party/blink/renderer/core/editing/visible_selection.h" #include "third_party/blink/renderer/core/editing/visible_selection.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/html/forms/html_form_control_element.h" #include "third_party/blink/renderer/core/html/forms/html_form_control_element.h"
namespace blink { namespace blink {
namespace { namespace {
EphemeralRange ComputeRangeFromFrameSelection(WebLocalFrame* frame) { EphemeralRange ComputeRangeFromFrameSelection(LocalFrame* frame) {
LocalFrame* web_frame = To<WebLocalFrameImpl>(frame)->GetFrame();
// TODO(editing-dev): The use of UpdateStyleAndLayout // TODO(editing-dev): The use of UpdateStyleAndLayout
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
web_frame->GetDocument()->UpdateStyleAndLayout(); frame->GetDocument()->UpdateStyleAndLayout();
return web_frame->Selection() return frame->Selection()
.ComputeVisibleSelectionInDOMTree() .ComputeVisibleSelectionInDOMTree()
.ToNormalizedEphemeralRange(); .ToNormalizedEphemeralRange();
} }
} // namespace } // namespace
WebSurroundingText::WebSurroundingText(WebLocalFrame* frame, size_t max_length) SurroundingText::SurroundingText(LocalFrame* frame, size_t max_length)
: WebSurroundingText(ComputeRangeFromFrameSelection(frame), max_length) {} : SurroundingText(ComputeRangeFromFrameSelection(frame), max_length) {}
WebSurroundingText::WebSurroundingText(const EphemeralRange& range, SurroundingText::SurroundingText(const EphemeralRange& range, size_t max_length)
size_t max_length)
: start_offset_in_text_content_(0), end_offset_in_text_content_(0) { : start_offset_in_text_content_(0), end_offset_in_text_content_(0) {
const Position start_position = range.StartPosition(); const Position start_position = range.StartPosition();
const Position end_position = range.EndPosition(); const Position end_position = range.EndPosition();
...@@ -126,19 +122,19 @@ WebSurroundingText::WebSurroundingText(const EphemeralRange& range, ...@@ -126,19 +122,19 @@ WebSurroundingText::WebSurroundingText(const EphemeralRange& range,
TextIteratorBehavior::EmitsObjectReplacementCharacterBehavior()); TextIteratorBehavior::EmitsObjectReplacementCharacterBehavior());
} }
WebString WebSurroundingText::TextContent() const { String SurroundingText::TextContent() const {
return text_content_; return text_content_;
} }
size_t WebSurroundingText::StartOffsetInTextContent() const { size_t SurroundingText::StartOffsetInTextContent() const {
return start_offset_in_text_content_; return start_offset_in_text_content_;
} }
size_t WebSurroundingText::EndOffsetInTextContent() const { size_t SurroundingText::EndOffsetInTextContent() const {
return end_offset_in_text_content_; return end_offset_in_text_content_;
} }
bool WebSurroundingText::IsEmpty() const { bool SurroundingText::IsEmpty() const {
return text_content_.IsEmpty(); return text_content_.IsEmpty();
} }
......
...@@ -22,48 +22,50 @@ ...@@ -22,48 +22,50 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_SURROUNDING_TEXT_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_EDITING_SURROUNDING_TEXT_H_
#define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_SURROUNDING_TEXT_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_EDITING_SURROUNDING_TEXT_H_
#include "third_party/blink/renderer/core/core_export.h"
#if INSIDE_BLINK #if INSIDE_BLINK
#include "third_party/blink/renderer/core/editing/forward.h" // nogncheck #include "third_party/blink/renderer/core/editing/forward.h" // nogncheck
#endif #endif
#include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink { namespace blink {
class WebLocalFrame; class LocalFrame;
// WebSurroundingText is a Blink API that gives access to the SurroundingText // SurroundingText is a Blink API that gives access to the SurroundingText
// API. It allows caller to know the text surrounding a point or a range. // API. It allows caller to know the text surrounding a point or a range.
class WebSurroundingText { class CORE_EXPORT SurroundingText {
public: public:
// Initializes the object with the current selection in a given frame. // Initializes the object with the current selection in a given frame.
// The maximum length of the contents retrieved is defined by max_length. // The maximum length of the contents retrieved is defined by max_length.
// It does not include the text inside the range. // It does not include the text inside the range.
BLINK_EXPORT WebSurroundingText(WebLocalFrame*, size_t max_length); SurroundingText(LocalFrame*, size_t max_length);
#if INSIDE_BLINK #if INSIDE_BLINK
BLINK_EXPORT WebSurroundingText(const EphemeralRange&, size_t max_length); SurroundingText(const EphemeralRange&, size_t max_length);
#endif #endif
BLINK_EXPORT bool IsEmpty() const; bool IsEmpty() const;
// Surrounding text content retrieved. // Surrounding text content retrieved.
BLINK_EXPORT WebString TextContent() const; String TextContent() const;
// Start offset of the initial text in the text content. // Start offset of the initial text in the text content.
BLINK_EXPORT size_t StartOffsetInTextContent() const; size_t StartOffsetInTextContent() const;
// End offset of the initial text in the text content. // End offset of the initial text in the text content.
BLINK_EXPORT size_t EndOffsetInTextContent() const; size_t EndOffsetInTextContent() const;
private: private:
WebString text_content_; String text_content_;
size_t start_offset_in_text_content_; size_t start_offset_in_text_content_;
size_t end_offset_in_text_content_; size_t end_offset_in_text_content_;
}; };
} // namespace blink } // namespace blink
#endif #endif // THIRD_PARTY_BLINK_RENDERER_CORE_EDITING_SURROUNDING_TEXT_H_
...@@ -73,7 +73,6 @@ blink_core_sources("exported") { ...@@ -73,7 +73,6 @@ blink_core_sources("exported") {
"web_settings_impl.h", "web_settings_impl.h",
"web_shared_worker_impl.cc", "web_shared_worker_impl.cc",
"web_shared_worker_impl.h", "web_shared_worker_impl.h",
"web_surrounding_text.cc",
"web_text_checking_result.cc", "web_text_checking_result.cc",
"web_user_gesture_indicator.cc", "web_user_gesture_indicator.cc",
"web_user_gesture_token.cc", "web_user_gesture_token.cc",
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <utility> #include <utility>
#include "third_party/blink/public/platform/task_type.h" #include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/web/web_surrounding_text.h" #include "third_party/blink/renderer/core/editing/surrounding_text.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h" #include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/platform/heap/persistent.h" #include "third_party/blink/renderer/platform/heap/persistent.h"
...@@ -35,7 +35,7 @@ void SurroundingTextImpl::BindToReceiver( ...@@ -35,7 +35,7 @@ void SurroundingTextImpl::BindToReceiver(
void SurroundingTextImpl::GetTextSurroundingSelection( void SurroundingTextImpl::GetTextSurroundingSelection(
uint32_t max_length, uint32_t max_length,
GetTextSurroundingSelectionCallback callback) { GetTextSurroundingSelectionCallback callback) {
blink::WebSurroundingText surrounding_text(frame_, max_length); blink::SurroundingText surrounding_text(frame_->GetFrame(), max_length);
if (surrounding_text.IsEmpty()) { if (surrounding_text.IsEmpty()) {
// |surrounding_text| might not be correctly initialized, for example if // |surrounding_text| might not be correctly initialized, for example if
......
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