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

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: . 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 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 HandleInputEvent(event, &cursor_info); 1585 HandleInputEvent(event, &cursor_info);
1586 } 1586 }
1587 1587
1588 void PluginInstance::SimulateInputEvent(const InputEventData& input_event) { 1588 void PluginInstance::SimulateInputEvent(const InputEventData& input_event) {
1589 WebView* web_view = container()->element().document().frame()->view(); 1589 WebView* web_view = container()->element().document().frame()->view();
1590 if (!web_view) { 1590 if (!web_view) {
1591 NOTREACHED(); 1591 NOTREACHED();
1592 return; 1592 return;
1593 } 1593 }
1594 1594
1595 bool handled = SimulateIMEEvent(input_event);
1596 if (handled)
1597 return;
1598
1595 std::vector<linked_ptr<WebInputEvent> > events = 1599 std::vector<linked_ptr<WebInputEvent> > events =
1596 CreateSimulatedWebInputEvents( 1600 CreateSimulatedWebInputEvents(
1597 input_event, 1601 input_event,
1598 view_data_.rect.point.x + view_data_.rect.size.width / 2, 1602 view_data_.rect.point.x + view_data_.rect.size.width / 2,
1599 view_data_.rect.point.y + view_data_.rect.size.height / 2); 1603 view_data_.rect.point.y + view_data_.rect.size.height / 2);
1600 for (std::vector<linked_ptr<WebInputEvent> >::iterator it = events.begin(); 1604 for (std::vector<linked_ptr<WebInputEvent> >::iterator it = events.begin();
1601 it != events.end(); ++it) { 1605 it != events.end(); ++it) {
1602 web_view->handleInputEvent(*it->get()); 1606 web_view->handleInputEvent(*it->get());
1603 } 1607 }
1604 } 1608 }
1605 1609
1610 bool PluginInstance::SimulateIMEEvent(const InputEventData& input_event) {
1611 switch (input_event.event_type) {
1612 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_START:
1613 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE:
1614 SimulateImeSetCompositionEvent(input_event);
1615 break;
1616 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END:
1617 DCHECK(input_event.character_text.empty());
1618 SimulateImeSetCompositionEvent(input_event);
1619 break;
1620 case PP_INPUTEVENT_TYPE_IME_TEXT:
1621 delegate()->SimulateImeConfirmComposition(
1622 UTF8ToUTF16(input_event.character_text));
1623 break;
1624 default:
1625 return false;
1626 }
1627 return true;
1628 }
1629
1630 void PluginInstance::SimulateImeSetCompositionEvent(
1631 const InputEventData& input_event) {
1632 std::vector<size_t> offsets;
1633 offsets.push_back(input_event.composition_selection_start);
1634 offsets.push_back(input_event.composition_selection_end);
1635 offsets.insert(offsets.end(),
1636 input_event.composition_segment_offsets.begin(),
1637 input_event.composition_segment_offsets.end());
1638
1639 string16 utf16_text =
1640 UTF8ToUTF16AndAdjustOffsets(input_event.character_text, &offsets);
1641
1642 std::vector<WebKit::WebCompositionUnderline> underlines;
1643 for (size_t i = 2; i + 1 < offsets.size(); ++i) {
1644 WebKit::WebCompositionUnderline underline;
1645 underline.startOffset = offsets[i];
1646 underline.endOffset = offsets[i+1];
yzshen1 2012/05/15 18:03:48 spaces around '+', please.
kinaba 2012/05/16 10:13:57 Done.
1647 if (input_event.composition_target_segment == static_cast<int32_t>(i - 2))
1648 underline.thick = true;
1649 underlines.push_back(underline);
1650 }
1651
1652 delegate()->SimulateImeSetComposition(
1653 utf16_text, underlines, offsets[0], offsets[1]);
1654 }
1655
1606 void PluginInstance::ClosePendingUserGesture(PP_Instance instance, 1656 void PluginInstance::ClosePendingUserGesture(PP_Instance instance,
1607 PP_TimeTicks timestamp) { 1657 PP_TimeTicks timestamp) {
1608 // Close the pending user gesture if the plugin had a chance to respond. 1658 // Close the pending user gesture if the plugin had a chance to respond.
1609 // Don't close the pending user gesture if the timestamps are equal since 1659 // Don't close the pending user gesture if the timestamps are equal since
1610 // there may be multiple input events with the same timestamp. 1660 // there may be multiple input events with the same timestamp.
1611 if (timestamp > pending_user_gesture_) 1661 if (timestamp > pending_user_gesture_)
1612 pending_user_gesture_ = 0.0; 1662 pending_user_gesture_ = 0.0;
1613 } 1663 }
1614 1664
1615 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, 1665 PP_Bool PluginInstance::BindGraphics(PP_Instance instance,
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2068 screen_size_for_fullscreen_ = gfx::Size(); 2118 screen_size_for_fullscreen_ = gfx::Size();
2069 WebElement element = container_->element(); 2119 WebElement element = container_->element();
2070 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2120 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2071 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2121 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2072 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2122 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2073 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2123 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2074 } 2124 }
2075 2125
2076 } // namespace ppapi 2126 } // namespace ppapi
2077 } // namespace webkit 2127 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698