summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authordonnd@chromium.org <donnd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-20 13:09:08 +0000
committerdonnd@chromium.org <donnd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-20 13:09:08 +0000
commitda33fadc8038764bddab8bde0b76963e81ebfe98 (patch)
treef5fb312498454319c1506a19734ba1e7d901c70f /content
parentc18663d9903160b5355b0a09d187800496b0fd7c (diff)
downloadchromium_src-da33fadc8038764bddab8bde0b76963e81ebfe98.zip
chromium_src-da33fadc8038764bddab8bde0b76963e81ebfe98.tar.gz
chromium_src-da33fadc8038764bddab8bde0b76963e81ebfe98.tar.bz2
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
Diffstat (limited to 'content')
-rw-r--r--content/browser/android/content_view_core_impl.cc18
-rw-r--r--content/browser/android/content_view_core_impl.h6
-rw-r--r--content/browser/renderer_host/render_widget_host_view_android.cc11
-rw-r--r--content/browser/renderer_host/render_widget_host_view_android.h9
-rw-r--r--content/public/browser/android/content_view_core.h7
5 files changed, 49 insertions, 2 deletions
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc
index 2335d0a..4bb56aae 100644
--- a/content/browser/android/content_view_core_impl.cc
+++ b/content/browser/android/content_view_core_impl.cc
@@ -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();
diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h
index 6c003df..3036705 100644
--- a/content/browser/android/content_view_core_impl.h
+++ b/content/browser/android/content_view_core_impl.h
@@ -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
diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc
index 120161d..f421735 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.cc
+++ b/content/browser/renderer_host/render_widget_host_view_android.cc
@@ -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() {
diff --git a/content/browser/renderer_host/render_widget_host_view_android.h b/content/browser/renderer_host/render_widget_host_view_android.h
index 267b410..4707734 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.h
+++ b/content/browser/renderer_host/render_widget_host_view_android.h
@@ -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);
};
diff --git a/content/public/browser/android/content_view_core.h b/content/public/browser/android/content_view_core.h
index 1501985..cf620c0 100644
--- a/content/public/browser/android/content_view_core.h
+++ b/content/public/browser/android/content_view_core.h
@@ -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() {};
};