Commit da33fadc authored by donnd@chromium.org's avatar donnd@chromium.org

Add an interface to gather text surrounding the selection.

This CL is dependent on 292113008 and its dependencies.

BUG=371596, 355154

Review URL: https://codereview.chromium.org/322203002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278693 0039d316-1c4b-4281-b951-d872f2087c98
parent c18663d9
......@@ -37,6 +37,7 @@
#include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h"
#include "content/browser/ssl/ssl_host_state.h"
#include "content/browser/web_contents/web_contents_view_android.h"
#include "content/common/frame_messages.h"
#include "content/common/input/web_input_event_traits.h"
#include "content/common/input_messages.h"
#include "content/common/view_messages.h"
......@@ -1572,6 +1573,23 @@ void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env, jobject jobj,
GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque);
}
void ContentViewCoreImpl::RequestTextSurroundingSelection(
int max_length,
const base::Callback<
void(const base::string16& content, int start_offset, int end_offset)>&
callback) {
DCHECK(!callback.is_null());
RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame();
if (!focused_frame)
return;
if (GetRenderWidgetHostViewAndroid()) {
GetRenderWidgetHostViewAndroid()->SetTextSurroundingSelectionCallback(
callback);
focused_frame->Send(new FrameMsg_TextSurroundingSelectionRequest(
focused_frame->GetRoutingID(), max_length));
}
}
void ContentViewCoreImpl::OnSmartClipDataExtracted(
const base::string16& result) {
JNIEnv* env = AttachCurrentThread();
......
......@@ -9,7 +9,6 @@
#include "base/android/jni_android.h"
#include "base/android/jni_weak_ref.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/i18n/rtl.h"
#include "base/memory/scoped_ptr.h"
......@@ -62,6 +61,11 @@ class ContentViewCoreImpl : public ContentViewCore,
virtual float GetDpiScale() const OVERRIDE;
virtual void PauseVideo() OVERRIDE;
virtual void PauseOrResumeGeolocation(bool should_pause) OVERRIDE;
virtual void RequestTextSurroundingSelection(
int max_length,
const base::Callback<void(const base::string16& content,
int start_offset,
int end_offset)>& callback) OVERRIDE;
// --------------------------------------------------------------------------
// Methods called from Java via JNI
......
......@@ -433,10 +433,21 @@ void RenderWidgetHostViewAndroid::UnlockCompositingSurface() {
}
}
void RenderWidgetHostViewAndroid::SetTextSurroundingSelectionCallback(
const TextSurroundingSelectionCallback& callback) {
// Only one outstanding request is allowed at any given time.
DCHECK(!callback.is_null());
text_surrounding_selection_callback_ = callback;
}
void RenderWidgetHostViewAndroid::OnTextSurroundingSelectionResponse(
const base::string16& content,
size_t start_offset,
size_t end_offset) {
if (text_surrounding_selection_callback_.is_null())
return;
text_surrounding_selection_callback_.Run(content, start_offset, end_offset);
text_surrounding_selection_callback_.Reset();
}
void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() {
......
......@@ -224,6 +224,12 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid
void SetOverlayVideoMode(bool enabled);
typedef base::Callback<
void(const base::string16& content, int start_offset, int end_offset)>
TextSurroundingSelectionCallback;
void SetTextSurroundingSelectionCallback(
const TextSurroundingSelectionCallback& callback);
private:
void RunAckCallbacks();
......@@ -283,7 +289,6 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid
void SetNeedsAnimate();
bool Animate(base::TimeTicks frame_time);
// The model object.
RenderWidgetHostImpl* host_;
......@@ -353,6 +358,8 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid
scoped_ptr<LastFrameInfo> last_frame_info_;
TextSurroundingSelectionCallback text_surrounding_selection_callback_;
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAndroid);
};
......
......@@ -68,6 +68,13 @@ class CONTENT_EXPORT ContentViewCore {
const gfx::Vector2dF& scroll_offset,
float page_scale_factor)> UpdateFrameInfoCallback;
// Text surrounding selection.
virtual void RequestTextSurroundingSelection(
int max_length,
const base::Callback<void(const base::string16& content,
int start_offset,
int end_offset)>& callback) = 0;
protected:
virtual ~ContentViewCore() {};
};
......
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