Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 10391101: Test for Pepper IME events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments from kochi & merge master. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
(...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 HandleInputEvent(event, &cursor_info); 1604 HandleInputEvent(event, &cursor_info);
1605 } 1605 }
1606 1606
1607 void PluginInstance::SimulateInputEvent(const InputEventData& input_event) { 1607 void PluginInstance::SimulateInputEvent(const InputEventData& input_event) {
1608 WebView* web_view = container()->element().document().frame()->view(); 1608 WebView* web_view = container()->element().document().frame()->view();
1609 if (!web_view) { 1609 if (!web_view) {
1610 NOTREACHED(); 1610 NOTREACHED();
1611 return; 1611 return;
1612 } 1612 }
1613 1613
1614 bool handled = SimulateIMEEvent(input_event);
1615 if (handled)
1616 return;
1617
1614 std::vector<linked_ptr<WebInputEvent> > events = 1618 std::vector<linked_ptr<WebInputEvent> > events =
1615 CreateSimulatedWebInputEvents( 1619 CreateSimulatedWebInputEvents(
1616 input_event, 1620 input_event,
1617 view_data_.rect.point.x + view_data_.rect.size.width / 2, 1621 view_data_.rect.point.x + view_data_.rect.size.width / 2,
1618 view_data_.rect.point.y + view_data_.rect.size.height / 2); 1622 view_data_.rect.point.y + view_data_.rect.size.height / 2);
1619 for (std::vector<linked_ptr<WebInputEvent> >::iterator it = events.begin(); 1623 for (std::vector<linked_ptr<WebInputEvent> >::iterator it = events.begin();
1620 it != events.end(); ++it) { 1624 it != events.end(); ++it) {
1621 web_view->handleInputEvent(*it->get()); 1625 web_view->handleInputEvent(*it->get());
1622 } 1626 }
1623 } 1627 }
1624 1628
1629 bool PluginInstance::SimulateIMEEvent(const InputEventData& input_event) {
1630 switch (input_event.event_type) {
1631 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_START:
1632 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE:
1633 SimulateImeSetCompositionEvent(input_event);
1634 break;
1635 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END:
1636 DCHECK(input_event.character_text.empty());
1637 SimulateImeSetCompositionEvent(input_event);
1638 break;
1639 case PP_INPUTEVENT_TYPE_IME_TEXT:
1640 delegate()->SimulateImeConfirmComposition(
1641 UTF8ToUTF16(input_event.character_text));
1642 break;
1643 default:
1644 return false;
1645 }
1646 return true;
1647 }
1648
1649 void PluginInstance::SimulateImeSetCompositionEvent(
1650 const InputEventData& input_event) {
1651 std::vector<size_t> offsets;
1652 offsets.push_back(input_event.composition_selection_start);
1653 offsets.push_back(input_event.composition_selection_end);
1654 offsets.insert(offsets.end(),
1655 input_event.composition_segment_offsets.begin(),
1656 input_event.composition_segment_offsets.end());
1657
1658 string16 utf16_text =
1659 UTF8ToUTF16AndAdjustOffsets(input_event.character_text, &offsets);
1660
1661 std::vector<WebKit::WebCompositionUnderline> underlines;
1662 for (size_t i = 2; i + 1 < offsets.size(); ++i) {
1663 WebKit::WebCompositionUnderline underline;
1664 underline.startOffset = offsets[i];
1665 underline.endOffset = offsets[i + 1];
1666 if (input_event.composition_target_segment == static_cast<int32_t>(i - 2))
1667 underline.thick = true;
1668 underlines.push_back(underline);
1669 }
1670
1671 delegate()->SimulateImeSetComposition(
1672 utf16_text, underlines, offsets[0], offsets[1]);
1673 }
1674
1625 void PluginInstance::ClosePendingUserGesture(PP_Instance instance, 1675 void PluginInstance::ClosePendingUserGesture(PP_Instance instance,
1626 PP_TimeTicks timestamp) { 1676 PP_TimeTicks timestamp) {
1627 // Close the pending user gesture if the plugin had a chance to respond. 1677 // Close the pending user gesture if the plugin had a chance to respond.
1628 // Don't close the pending user gesture if the timestamps are equal since 1678 // Don't close the pending user gesture if the timestamps are equal since
1629 // there may be multiple input events with the same timestamp. 1679 // there may be multiple input events with the same timestamp.
1630 if (timestamp > pending_user_gesture_) 1680 if (timestamp > pending_user_gesture_)
1631 pending_user_gesture_ = 0.0; 1681 pending_user_gesture_ = 0.0;
1632 } 1682 }
1633 1683
1634 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, 1684 PP_Bool PluginInstance::BindGraphics(PP_Instance instance,
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2087 screen_size_for_fullscreen_ = gfx::Size(); 2137 screen_size_for_fullscreen_ = gfx::Size();
2088 WebElement element = container_->element(); 2138 WebElement element = container_->element();
2089 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2139 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2090 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2140 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2091 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2141 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2092 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2142 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2093 } 2143 }
2094 2144
2095 } // namespace ppapi 2145 } // namespace ppapi
2096 } // namespace webkit 2146 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | webkit/plugins/ppapi/resource_creation_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698