summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorkinaba@google.com <kinaba@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-30 07:05:57 +0000
committerkinaba@google.com <kinaba@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-30 07:05:57 +0000
commit56ea1a632a03756008dcc5b608f87704c231d735 (patch)
tree8a7c4784c2d42a94c8def3f9028b8c5d898f8d5b /content
parent9522abfe553ccbe114e94e13aceaa82b0a8e4bf7 (diff)
downloadchromium_src-56ea1a632a03756008dcc5b608f87704c231d735.zip
chromium_src-56ea1a632a03756008dcc5b608f87704c231d735.tar.gz
chromium_src-56ea1a632a03756008dcc5b608f87704c231d735.tar.bz2
The first step for enabling off-the-spot IME on Pepper on ChromeOS/Linux.
BUG=83684 TEST=Go to http://weathernews.jp with pepper flash plug in enabled. Focus the text input field and type something with IME on. Verify that the candidate window is shown somewhere on the screen and commited text is entered in the text field. This patch is the first step toward off-the-spot IME on Pepper plugins hosted on RenderWidgetHostViewGtk. This patch: - Makes it possible to turn on/off IME when a plugin is focused. - Makes it possible for the plugin to receive committed results from IME. What are NOT IN this patch (and what I hope to improve in forthcoming separate patches) are: - Proper placement of the candidate window. - Showing preedit texts. Review URL: http://codereview.chromium.org/6990072 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87215 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/renderer/pepper_plugin_delegate_impl.cc13
-rw-r--r--content/renderer/pepper_plugin_delegate_impl.h7
-rw-r--r--content/renderer/render_view.cc55
-rw-r--r--content/renderer/render_view.h10
-rw-r--r--content/renderer/render_widget.cc14
-rw-r--r--content/renderer/render_widget.h8
6 files changed, 99 insertions, 8 deletions
diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc
index 74f091c..b20c2b9 100644
--- a/content/renderer/pepper_plugin_delegate_impl.cc
+++ b/content/renderer/pepper_plugin_delegate_impl.cc
@@ -564,7 +564,8 @@ PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view)
: render_view_(render_view),
has_saved_context_menu_action_(false),
saved_context_menu_action_(0),
- id_generator_(0) {
+ id_generator_(0),
+ is_pepper_plugin_focused_(false) {
}
PepperPluginDelegateImpl::~PepperPluginDelegateImpl() {
@@ -740,6 +741,12 @@ PepperPluginDelegateImpl::GetBitmapForOptimizedPluginPaint(
return NULL;
}
+void PepperPluginDelegateImpl::PluginFocusChanged(bool focused) {
+ is_pepper_plugin_focused_ = focused;
+ if (render_view_)
+ render_view_->PpapiPluginFocusChanged();
+}
+
void PepperPluginDelegateImpl::PluginCrashed(
webkit::ppapi::PluginInstance* instance) {
render_view_->PluginCrashed(instance->module()->path());
@@ -911,6 +918,10 @@ void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) {
(*i)->SetContentAreaFocus(has_focus);
}
+bool PepperPluginDelegateImpl::IsPluginFocused() const {
+ return is_pepper_plugin_focused_;
+}
+
bool PepperPluginDelegateImpl::OpenFileSystem(
const GURL& url,
fileapi::FileSystemType type,
diff --git a/content/renderer/pepper_plugin_delegate_impl.h b/content/renderer/pepper_plugin_delegate_impl.h
index f75121d..8f66680 100644
--- a/content/renderer/pepper_plugin_delegate_impl.h
+++ b/content/renderer/pepper_plugin_delegate_impl.h
@@ -161,7 +161,11 @@ class PepperPluginDelegateImpl
// notifies all of the plugins.
void OnSetFocus(bool has_focus);
+ // Returns whether or not a Pepper plugin is focused.
+ bool IsPluginFocused() const;
+
// PluginDelegate implementation.
+ virtual void PluginFocusChanged(bool focused) OVERRIDE;
virtual void PluginCrashed(webkit::ppapi::PluginInstance* instance);
virtual void InstanceCreated(
webkit::ppapi::PluginInstance* instance);
@@ -303,6 +307,9 @@ class PepperPluginDelegateImpl
typedef IDMap<scoped_refptr<PpapiBrokerImpl>, IDMapOwnPointer> BrokerMap;
BrokerMap pending_connect_broker_;
+ // Whether or not the focus is on a PPAPI plugin
+ bool is_pepper_plugin_focused_;
+
DISALLOW_COPY_AND_ASSIGN(PepperPluginDelegateImpl);
};
diff --git a/content/renderer/render_view.cc b/content/renderer/render_view.cc
index 7f22503..d38f52b 100644
--- a/content/renderer/render_view.cc
+++ b/content/renderer/render_view.cc
@@ -89,6 +89,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
@@ -3941,6 +3942,60 @@ void RenderView::OnSetFocus(bool enable) {
}
}
+void RenderView::PpapiPluginFocusChanged() {
+ UpdateInputMethod();
+}
+
+void RenderView::OnImeSetComposition(
+ const string16& text,
+ const std::vector<WebKit::WebCompositionUnderline>& underlines,
+ int selection_start,
+ int selection_end) {
+ // Until PPAPI has an interface for handling IME events, we skip sending
+ // OnImeSetComposition. Otherwise the composition is canceled when a
+ // non-editable DOM element is focused.
+ //
+ // TODO(kinaba) This temporal remedy can be removed after PPAPI is extended
+ // with an IME handling interface.
+ if (!pepper_delegate_.IsPluginFocused()) {
+ RenderWidget::OnImeSetComposition(text,
+ underlines,
+ selection_start,
+ selection_end);
+ }
+}
+
+void RenderView::OnImeConfirmComposition(const string16& text) {
+ if (pepper_delegate_.IsPluginFocused()) {
+ // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
+ // send character events.
+ for (size_t i = 0; i < text.size(); ++i) {
+ WebKit::WebKeyboardEvent char_event;
+ char_event.type = WebKit::WebInputEvent::Char;
+ char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
+ char_event.modifiers = 0;
+ char_event.windowsKeyCode = text[i];
+ char_event.nativeKeyCode = text[i];
+ char_event.text[0] = text[i];
+ char_event.unmodifiedText[0] = text[i];
+ if (webwidget_)
+ webwidget_->handleInputEvent(char_event);
+ }
+ } else {
+ RenderWidget::OnImeConfirmComposition(text);
+ }
+}
+
+WebKit::WebTextInputType RenderView::GetTextInputType() {
+ if (pepper_delegate_.IsPluginFocused()) {
+ // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
+ // consider all the parts of PPAPI plugins are accepting text inputs.
+ return WebKit::WebTextInputTypeText;
+ } else {
+ return RenderWidget::GetTextInputType();
+ }
+}
+
#if defined(OS_MACOSX)
void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
diff --git a/content/renderer/render_view.h b/content/renderer/render_view.h
index 157955c..1b56068 100644
--- a/content/renderer/render_view.h
+++ b/content/renderer/render_view.h
@@ -306,6 +306,9 @@ class RenderView : public RenderWidget,
WebKit::WebPlugin* CreatePluginNoCheck(WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params);
+ // Informs the render view that a PPAPI plugin has gained or lost focus.
+ void PpapiPluginFocusChanged();
+
#if defined(OS_MACOSX)
// Informs the render view that the given plugin has gained or lost focus.
void PluginFocusChanged(bool focused, int plugin_id);
@@ -610,6 +613,13 @@ class RenderView : public RenderWidget,
virtual void OnWasHidden();
virtual void OnWasRestored(bool needs_repainting);
virtual bool SupportsAsynchronousSwapBuffers() OVERRIDE;
+ virtual void OnImeSetComposition(
+ const string16& text,
+ const std::vector<WebKit::WebCompositionUnderline>& underlines,
+ int selection_start,
+ int selection_end) OVERRIDE;
+ virtual void OnImeConfirmComposition(const string16& text) OVERRIDE;
+ virtual WebKit::WebTextInputType GetTextInputType() OVERRIDE;
private:
// For unit tests.
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index 4e7ad0d..17c70d0 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -1252,13 +1252,11 @@ void RenderWidget::UpdateInputMethod() {
if (!input_method_is_active_)
return;
- WebTextInputType new_type = WebKit::WebTextInputTypeNone;
+ WebTextInputType new_type = GetTextInputType();
WebRect new_caret_bounds;
- if (webwidget_) {
- new_type = webwidget_->textInputType();
- new_caret_bounds = webwidget_->caretOrSelectionBounds();
- }
+ if (webwidget_)
+ new_caret_bounds = webwidget_->caretOrSelectionBounds();
// Only sends text input type and caret bounds to the browser process if they
// are changed.
@@ -1270,6 +1268,12 @@ void RenderWidget::UpdateInputMethod() {
}
}
+WebKit::WebTextInputType RenderWidget::GetTextInputType() {
+ if (webwidget_)
+ return webwidget_->textInputType();
+ return WebKit::WebTextInputTypeNone;
+}
+
WebScreenInfo RenderWidget::screenInfo() {
WebScreenInfo results;
Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results));
diff --git a/content/renderer/render_widget.h b/content/renderer/render_widget.h
index ce9df19..f4a1c93 100644
--- a/content/renderer/render_widget.h
+++ b/content/renderer/render_widget.h
@@ -199,12 +199,12 @@ class RenderWidget : public IPC::Channel::Listener,
void OnMouseCaptureLost();
virtual void OnSetFocus(bool enable);
void OnSetInputMethodActive(bool is_active);
- void OnImeSetComposition(
+ virtual void OnImeSetComposition(
const string16& text,
const std::vector<WebKit::WebCompositionUnderline>& underlines,
int selection_start,
int selection_end);
- void OnImeConfirmComposition(const string16& text);
+ virtual void OnImeConfirmComposition(const string16& text);
void OnMsgPaintAtSize(const TransportDIB::Handle& dib_id,
int tag,
const gfx::Size& page_size,
@@ -273,6 +273,10 @@ class RenderWidget : public IPC::Channel::Listener,
// If they are changed, the new value will be sent to the browser process.
void UpdateInputMethod();
+ // Override point to obtain that the current input method state and caret
+ // position.
+ virtual WebKit::WebTextInputType GetTextInputType();
+
// Tells the renderer it does not have focus. Used to prevent us from getting
// the focus on our own when the browser did not focus us.
void ClearFocus();