diff options
author | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-21 07:09:32 +0000 |
---|---|---|
committer | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-21 07:09:32 +0000 |
commit | 397c2396865ba5bd314827141f647a47d1cbb3fb (patch) | |
tree | a6b3972a4d3904940df315b8385aa77b625d4541 /webkit | |
parent | 455258051a2cb4591155cd099e959ce593340736 (diff) | |
download | chromium_src-397c2396865ba5bd314827141f647a47d1cbb3fb.zip chromium_src-397c2396865ba5bd314827141f647a47d1cbb3fb.tar.gz chromium_src-397c2396865ba5bd314827141f647a47d1cbb3fb.tar.bz2 |
Test for Pepper IME events.
This patch adds a way to simulate IME composition events
inside the renderer process, and tests that IME events are
properly passed between the renderer and plugins.
ppapi/tests/test_ime_input_event.cc:
is the actual test case
ppapi/{api,c,cpp}/dev/*ime_input_event_dev*:
implements an API to create IME events from plugins for testing.
other files:
wire necessary stuff for simulating IME events.
Since Pepper IME events are not delivered through WebKit/DOM layer
but rather directly sent from renderer to plugins,
the simulation part also follows the similar code path.
BUG=126714
TEST=browser_tests PPAPITest.ImeInputEvent
Review URL: https://chromiumcodereview.appspot.com/10391101
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138080 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.cc | 10 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.h | 6 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 8 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 50 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 6 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_creation_impl.cc | 72 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_creation_impl.h | 9 |
7 files changed, 113 insertions, 48 deletions
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index 971754c..7c7329f 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -37,6 +37,16 @@ void MockPluginDelegate::PluginRequestedCancelComposition( void MockPluginDelegate::PluginSelectionChanged(PluginInstance* instance) { } +void MockPluginDelegate::SimulateImeSetComposition( + const string16& text, + const std::vector<WebKit::WebCompositionUnderline>& underlines, + int selection_start, + int selection_end) { +} + +void MockPluginDelegate::SimulateImeConfirmComposition(const string16& text) { +} + void MockPluginDelegate::PluginCrashed(PluginInstance* instance) { } diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index 91c62e0..3136847 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -24,6 +24,12 @@ class MockPluginDelegate : public PluginDelegate { virtual void PluginCaretPositionChanged(PluginInstance* instance); virtual void PluginRequestedCancelComposition(PluginInstance* instance); virtual void PluginSelectionChanged(PluginInstance* instance); + virtual void SimulateImeSetComposition( + const string16& text, + const std::vector<WebKit::WebCompositionUnderline>& underlines, + int selection_start, + int selection_end); + virtual void SimulateImeConfirmComposition(const string16& text); virtual void PluginCrashed(PluginInstance* instance); virtual void InstanceCreated(PluginInstance* instance); virtual void InstanceDeleted(PluginInstance* instance); diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index 304cb09..9229143 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -70,6 +70,7 @@ namespace WebKit { class WebFileChooserCompletion; class WebGamepads; class WebPlugin; +struct WebCompositionUnderline; struct WebCursorInfo; struct WebFileChooserParams; } @@ -316,6 +317,13 @@ class PluginDelegate { // Notification that the text selection in the given plugin is changed. virtual void PluginSelectionChanged( webkit::ppapi::PluginInstance* instance) = 0; + // Requests simulating IME events for testing purpose. + virtual void SimulateImeSetComposition( + const string16& text, + const std::vector<WebKit::WebCompositionUnderline>& underlines, + int selection_start, + int selection_end) = 0; + virtual void SimulateImeConfirmComposition(const string16& text) = 0; // Notification that the given plugin has crashed. When a plugin crashes, all // instances associated with that plugin will notify that they've crashed via diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 390f8dc..429dd03 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -1611,6 +1611,10 @@ void PluginInstance::SimulateInputEvent(const InputEventData& input_event) { return; } + bool handled = SimulateIMEEvent(input_event); + if (handled) + return; + std::vector<linked_ptr<WebInputEvent> > events = CreateSimulatedWebInputEvents( input_event, @@ -1622,6 +1626,52 @@ void PluginInstance::SimulateInputEvent(const InputEventData& input_event) { } } +bool PluginInstance::SimulateIMEEvent(const InputEventData& input_event) { + switch (input_event.event_type) { + case PP_INPUTEVENT_TYPE_IME_COMPOSITION_START: + case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE: + SimulateImeSetCompositionEvent(input_event); + break; + case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END: + DCHECK(input_event.character_text.empty()); + SimulateImeSetCompositionEvent(input_event); + break; + case PP_INPUTEVENT_TYPE_IME_TEXT: + delegate()->SimulateImeConfirmComposition( + UTF8ToUTF16(input_event.character_text)); + break; + default: + return false; + } + return true; +} + +void PluginInstance::SimulateImeSetCompositionEvent( + const InputEventData& input_event) { + std::vector<size_t> offsets; + offsets.push_back(input_event.composition_selection_start); + offsets.push_back(input_event.composition_selection_end); + offsets.insert(offsets.end(), + input_event.composition_segment_offsets.begin(), + input_event.composition_segment_offsets.end()); + + string16 utf16_text = + UTF8ToUTF16AndAdjustOffsets(input_event.character_text, &offsets); + + std::vector<WebKit::WebCompositionUnderline> underlines; + for (size_t i = 2; i + 1 < offsets.size(); ++i) { + WebKit::WebCompositionUnderline underline; + underline.startOffset = offsets[i]; + underline.endOffset = offsets[i + 1]; + if (input_event.composition_target_segment == static_cast<int32_t>(i - 2)) + underline.thick = true; + underlines.push_back(underline); + } + + delegate()->SimulateImeSetComposition( + utf16_text, underlines, offsets[0], offsets[1]); +} + void PluginInstance::ClosePendingUserGesture(PP_Instance instance, PP_TimeTicks timestamp) { // Close the pending user gesture if the plugin had a chance to respond. diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 63b742f..ffd184b 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -326,6 +326,12 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : // which sends it back up to the plugin as if it came from the user. void SimulateInputEvent(const ::ppapi::InputEventData& input_event); + // Simulates an IME event at the level of RenderView which sends it back up to + // the plugin as if it came from the user. + bool SimulateIMEEvent(const ::ppapi::InputEventData& input_event); + void SimulateImeSetCompositionEvent( + const ::ppapi::InputEventData& input_event); + // PPB_Instance_API implementation. virtual PP_Bool BindGraphics(PP_Instance instance, PP_Resource device) OVERRIDE; diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index 17ef13b..077e247 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -182,6 +182,21 @@ PP_Resource ResourceCreationImpl::CreateImageData(PP_Instance instance, return PPB_ImageData_Impl::Create(instance, format, size, init_to_zero); } +PP_Resource ResourceCreationImpl::CreateIMEInputEvent( + PP_Instance instance, + PP_InputEvent_Type type, + PP_TimeTicks time_stamp, + struct PP_Var text, + uint32_t segment_number, + const uint32_t* segment_offsets, + int32_t target_segment, + uint32_t selection_start, + uint32_t selection_end) { + return PPB_InputEvent_Shared::CreateIMEInputEvent( + ::ppapi::OBJECT_IS_IMPL, instance, type, time_stamp, text, segment_number, + segment_offsets, target_segment, selection_start, selection_end); +} + PP_Resource ResourceCreationImpl::CreateKeyboardInputEvent( PP_Instance instance, PP_InputEvent_Type type, @@ -189,26 +204,9 @@ PP_Resource ResourceCreationImpl::CreateKeyboardInputEvent( uint32_t modifiers, uint32_t key_code, struct PP_Var character_text) { - if (type != PP_INPUTEVENT_TYPE_RAWKEYDOWN && - type != PP_INPUTEVENT_TYPE_KEYDOWN && - type != PP_INPUTEVENT_TYPE_KEYUP && - type != PP_INPUTEVENT_TYPE_CHAR) - return 0; - - InputEventData data; - data.event_type = type; - data.event_time_stamp = time_stamp; - data.event_modifiers = modifiers; - data.key_code = key_code; - if (character_text.type == PP_VARTYPE_STRING) { - StringVar* string_var = StringVar::FromPPVar(character_text); - if (!string_var) - return 0; - data.character_text = string_var->value(); - } - - return (new PPB_InputEvent_Shared(::ppapi::OBJECT_IS_IMPL, - instance, data))->GetReference(); + return PPB_InputEvent_Shared::CreateKeyboardInputEvent( + ::ppapi::OBJECT_IS_IMPL, instance, type, time_stamp, modifiers, key_code, + character_text); } PP_Resource ResourceCreationImpl::CreateMouseInputEvent( @@ -220,24 +218,9 @@ PP_Resource ResourceCreationImpl::CreateMouseInputEvent( const PP_Point* mouse_position, int32_t click_count, const PP_Point* mouse_movement) { - if (type != PP_INPUTEVENT_TYPE_MOUSEDOWN && - type != PP_INPUTEVENT_TYPE_MOUSEUP && - type != PP_INPUTEVENT_TYPE_MOUSEMOVE && - type != PP_INPUTEVENT_TYPE_MOUSEENTER && - type != PP_INPUTEVENT_TYPE_MOUSELEAVE) - return 0; - - InputEventData data; - data.event_type = type; - data.event_time_stamp = time_stamp; - data.event_modifiers = modifiers; - data.mouse_button = mouse_button; - data.mouse_position = *mouse_position; - data.mouse_click_count = click_count; - data.mouse_movement = *mouse_movement; - - return (new PPB_InputEvent_Shared(::ppapi::OBJECT_IS_IMPL, - instance, data))->GetReference(); + return PPB_InputEvent_Shared::CreateMouseInputEvent( + ::ppapi::OBJECT_IS_IMPL, instance, type, time_stamp, modifiers, + mouse_button, mouse_position, click_count, mouse_movement); } PP_Resource ResourceCreationImpl::CreateNetworkMonitor( @@ -330,16 +313,9 @@ PP_Resource ResourceCreationImpl::CreateWheelInputEvent( const PP_FloatPoint* wheel_delta, const PP_FloatPoint* wheel_ticks, PP_Bool scroll_by_page) { - InputEventData data; - data.event_type = PP_INPUTEVENT_TYPE_WHEEL; - data.event_time_stamp = time_stamp; - data.event_modifiers = modifiers; - data.wheel_delta = *wheel_delta; - data.wheel_ticks = *wheel_ticks; - data.wheel_scroll_by_page = PP_ToBool(scroll_by_page); - - return (new PPB_InputEvent_Shared(::ppapi::OBJECT_IS_IMPL, - instance, data))->GetReference(); + return PPB_InputEvent_Shared::CreateWheelInputEvent( + ::ppapi::OBJECT_IS_IMPL, instance, time_stamp, modifiers, + wheel_delta, wheel_ticks, scroll_by_page); } PP_Resource ResourceCreationImpl::CreateX509CertificatePrivate( diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h index 44dae8e..ca8bb54 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.h +++ b/webkit/plugins/ppapi/resource_creation_impl.h @@ -67,6 +67,15 @@ class ResourceCreationImpl : public ::ppapi::thunk::ResourceCreationAPI { PP_ImageDataFormat format, const PP_Size& size, PP_Bool init_to_zero) OVERRIDE; + virtual PP_Resource CreateIMEInputEvent(PP_Instance instance, + PP_InputEvent_Type type, + PP_TimeTicks time_stamp, + struct PP_Var text, + uint32_t segment_number, + const uint32_t* segment_offsets, + int32_t target_segment, + uint32_t selection_start, + uint32_t selection_end) OVERRIDE; virtual PP_Resource CreateKeyboardInputEvent( PP_Instance instance, PP_InputEvent_Type type, |