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

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

Issue 7977017: Never submit: tentative Pepper IME. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/utf_offset_string_conversions.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "ppapi/c/dev/ppb_console_dev.h" 13 #include "ppapi/c/dev/ppb_console_dev.h"
13 #include "ppapi/c/dev/ppb_find_dev.h" 14 #include "ppapi/c/dev/ppb_find_dev.h"
14 #include "ppapi/c/dev/ppb_memory_dev.h" 15 #include "ppapi/c/dev/ppb_memory_dev.h"
15 #include "ppapi/c/dev/ppb_zoom_dev.h" 16 #include "ppapi/c/dev/ppb_zoom_dev.h"
16 #include "ppapi/c/dev/ppp_find_dev.h" 17 #include "ppapi/c/dev/ppp_find_dev.h"
17 #include "ppapi/c/dev/ppp_mouse_lock_dev.h" 18 #include "ppapi/c/dev/ppp_mouse_lock_dev.h"
18 #include "ppapi/c/dev/ppp_policy_update_dev.h" 19 #include "ppapi/c/dev/ppp_policy_update_dev.h"
19 #include "ppapi/c/dev/ppp_selection_dev.h" 20 #include "ppapi/c/dev/ppp_selection_dev.h"
20 #include "ppapi/c/dev/ppp_zoom_dev.h" 21 #include "ppapi/c/dev/ppp_zoom_dev.h"
21 #include "ppapi/c/pp_input_event.h" 22 #include "ppapi/c/pp_input_event.h"
22 #include "ppapi/c/pp_instance.h" 23 #include "ppapi/c/pp_instance.h"
23 #include "ppapi/c/pp_rect.h" 24 #include "ppapi/c/pp_rect.h"
24 #include "ppapi/c/pp_resource.h" 25 #include "ppapi/c/pp_resource.h"
25 #include "ppapi/c/pp_var.h" 26 #include "ppapi/c/pp_var.h"
26 #include "ppapi/c/ppb_core.h" 27 #include "ppapi/c/ppb_core.h"
27 #include "ppapi/c/ppb_instance.h" 28 #include "ppapi/c/ppb_instance.h"
28 #include "ppapi/c/ppp_input_event.h" 29 #include "ppapi/c/ppp_input_event.h"
29 #include "ppapi/c/ppp_instance.h" 30 #include "ppapi/c/ppp_instance.h"
30 #include "ppapi/c/ppp_messaging.h" 31 #include "ppapi/c/ppp_messaging.h"
31 #include "ppapi/c/private/ppb_instance_private.h" 32 #include "ppapi/c/private/ppb_instance_private.h"
32 #include "ppapi/c/private/ppp_instance_private.h" 33 #include "ppapi/c/private/ppp_instance_private.h"
33 #include "ppapi/shared_impl/input_event_impl.h" 34 #include "ppapi/shared_impl/input_event_impl.h"
34 #include "ppapi/shared_impl/resource.h" 35 #include "ppapi/shared_impl/resource.h"
36 #include "ppapi/shared_impl/time_conversion.h"
35 #include "ppapi/shared_impl/var.h" 37 #include "ppapi/shared_impl/var.h"
36 #include "ppapi/thunk/enter.h" 38 #include "ppapi/thunk/enter.h"
37 #include "ppapi/thunk/ppb_buffer_api.h" 39 #include "ppapi/thunk/ppb_buffer_api.h"
38 #include "printing/units.h" 40 #include "printing/units.h"
39 #include "skia/ext/platform_canvas.h" 41 #include "skia/ext/platform_canvas.h"
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 checked_for_plugin_messaging_interface_(false), 239 checked_for_plugin_messaging_interface_(false),
238 plugin_print_interface_(NULL), 240 plugin_print_interface_(NULL),
239 plugin_graphics_3d_interface_(NULL), 241 plugin_graphics_3d_interface_(NULL),
240 always_on_top_(false), 242 always_on_top_(false),
241 fullscreen_container_(NULL), 243 fullscreen_container_(NULL),
242 fullscreen_(false), 244 fullscreen_(false),
243 message_channel_(NULL), 245 message_channel_(NULL),
244 sad_plugin_(NULL), 246 sad_plugin_(NULL),
245 input_event_mask_(0), 247 input_event_mask_(0),
246 filtered_input_event_mask_(0), 248 filtered_input_event_mask_(0),
249 text_input_type_(WebKit::WebTextInputTypeText),
250 text_input_caret_set_(false),
247 lock_mouse_callback_(PP_BlockUntilComplete()) { 251 lock_mouse_callback_(PP_BlockUntilComplete()) {
252 memset(&text_input_caret_, 0, sizeof(text_input_caret_));
253 memset(&text_input_caret_bounds_, 0, sizeof(text_input_caret_bounds_));
248 pp_instance_ = ResourceTracker::Get()->AddInstance(this); 254 pp_instance_ = ResourceTracker::Get()->AddInstance(this);
249 255
250 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 256 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
251 DCHECK(delegate); 257 DCHECK(delegate);
252 module_->InstanceCreated(this); 258 module_->InstanceCreated(this);
253 delegate_->InstanceCreated(this); 259 delegate_->InstanceCreated(this);
254 message_channel_.reset(new MessageChannel(this)); 260 message_channel_.reset(new MessageChannel(this));
255 } 261 }
256 262
257 PluginInstance::~PluginInstance() { 263 PluginInstance::~PluginInstance() {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 argc, 446 argc,
441 argn.get(), 447 argn.get(),
442 argv.get())); 448 argv.get()));
443 } 449 }
444 450
445 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { 451 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) {
446 return PP_ToBool(instance_interface_->HandleDocumentLoad( 452 return PP_ToBool(instance_interface_->HandleDocumentLoad(
447 pp_instance(), loader->pp_resource())); 453 pp_instance(), loader->pp_resource()));
448 } 454 }
449 455
456 bool PluginInstance::SendCompositionEventToPlugin(PP_InputEvent_Type type,
457 const string16& text) {
458 std::vector<WebKit::WebCompositionUnderline> empty;
459 return SendCompositionEventWithUnderlineInformationToPlugin(
460 type, text, empty, static_cast<int>(text.size()),
461 static_cast<int>(text.size()));
462 }
463
464 bool PluginInstance::SendCompositionEventWithUnderlineInformationToPlugin(
465 PP_InputEvent_Type type,
466 const string16& text,
467 const std::vector<WebKit::WebCompositionUnderline>& underlines,
468 int selection_start,
469 int selection_end) {
470 // Keep a reference on the stack. See NOTE above.
471 scoped_refptr<PluginInstance> ref(this);
472
473 if (!LoadInputEventInterface())
474 return false;
475
476 PP_InputEvent_Class event_class = PP_INPUTEVENT_CLASS_IME;
477 if (!(filtered_input_event_mask_ & event_class) &&
478 !(input_event_mask_ & event_class))
479 return false;
480
481 ::ppapi::InputEventData event;
482 event.event_type = type;
483 event.event_time_stamp = ::ppapi::TimeTicksToPPTimeTicks(
484 base::TimeTicks::Now());
485
486 // Convert UTF16 text to UTF8 with offset conversion.
487 std::vector<size_t> utf16_offsets;
488 utf16_offsets.push_back(selection_start);
489 utf16_offsets.push_back(selection_end);
490 for (size_t i=0; i<underlines.size(); ++i) {
491 utf16_offsets.push_back(underlines[i].startOffset);
492 utf16_offsets.push_back(underlines[i].endOffset);
493 }
494 std::vector<size_t> utf8_offsets(utf16_offsets);
495 event.character_text = UTF16ToUTF8AndAdjustOffsets(text, &utf8_offsets);
496
497 // Set the converted selection range.
498 event.composition_selection_start = (utf8_offsets[0]==std::string::npos ?
499 event.character_text.size() : utf8_offsets[0]);
500 event.composition_selection_end = (utf8_offsets[1]==std::string::npos ?
501 event.character_text.size() : utf8_offsets[1]);
502
503 // Set the converted segmentation points.
504 // Be sure to add 0 and size(), and remove duplication or errors.
505 std::set<size_t> offset_set(utf8_offsets.begin()+2, utf8_offsets.end());
506 offset_set.insert(0);
507 offset_set.insert(event.character_text.size());
508 offset_set.erase(std::string::npos);
509 event.composition_segments.assign(offset_set.begin(), offset_set.end());
510
511 // Set the composition target.
512 for (size_t i=0; i<underlines.size(); ++i) {
513 if (underlines[i].thick) {
514 std::vector<uint32_t>::iterator it =
515 std::find(event.composition_segments.begin(),
516 event.composition_segments.end(),
517 utf8_offsets[2*i+2]);
518 if (it != event.composition_segments.end()) {
519 event.composition_target_segment =
520 it - event.composition_segments.begin();
521 break;
522 }
523 }
524 }
525
526 // Send the event.
527 if (filtered_input_event_mask_ & event_class)
528 event.is_filtered = true;
529 scoped_refptr<InputEventImpl> event_resource(
530 new InputEventImpl(InputEventImpl::InitAsImpl(),
531 pp_instance(), event));
532 return PP_ToBool(plugin_input_event_interface_->HandleInputEvent(
533 pp_instance(), event_resource->pp_resource()));
534 }
535
536 bool PluginInstance::HandleCompositionStart(const string16& text) {
537 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_COMPOSITION_START,
538 text);
539 }
540
541 bool PluginInstance::HandleCompositionUpdate(
542 const string16& text,
543 const std::vector<WebKit::WebCompositionUnderline>& underlines,
544 int selection_start,
545 int selection_end) {
546 return SendCompositionEventWithUnderlineInformationToPlugin(
547 PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE,
548 text, underlines, selection_start, selection_end);
549 }
550
551 bool PluginInstance::HandleCompositionEnd(const string16& text) {
552 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_COMPOSITION_END,
553 text);
554 }
555
556 bool PluginInstance::HandleTextInput(const string16& text) {
557 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_TEXT,
558 text);
559 }
560
561 void PluginInstance::UpdateCaretPosition(const PP_Rect& caret,
562 const PP_Rect& boundingBox) {
563 text_input_caret_ = caret;
564 text_input_caret_bounds_ = boundingBox;
565 text_input_caret_set_ = true;
566 }
567
568 void PluginInstance::SetTextInputType(WebKit::WebTextInputType type) {
569 text_input_type_ = type;
570 }
571
572 bool PluginInstance::CanComposeInline() const {
573 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) ||
574 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME);
575 }
576
577 WebKit::WebRect PluginInstance::GetCaretBounds() const {
578 if (!text_input_caret_set_) {
579 // If it is never set by the plugin, use the bottom left corner.
580 WebKit::WebRect caret(position().x(),
581 position().y(),
582 0,
583 position().height());
584 return caret;
585 }
586
587 // TODO(kinaba) take bounds into account
588 // TODO(kinaba) take CSS transformation into accont
589 WebKit::WebRect caret(text_input_caret_.point.x,
590 text_input_caret_.point.y,
591 text_input_caret_.size.width,
592 text_input_caret_.size.height);
593 caret.x += position().x();
594 caret.y += position().y();
595 return caret;
596 }
597
450 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, 598 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event,
451 WebCursorInfo* cursor_info) { 599 WebCursorInfo* cursor_info) {
452 // Don't dispatch input events to crashed plugins. 600 // Don't dispatch input events to crashed plugins.
453 if (module()->is_crashed()) 601 if (module()->is_crashed())
454 return false; 602 return false;
455 603
456 // Keep a reference on the stack. See NOTE above. 604 // Keep a reference on the stack. See NOTE above.
457 scoped_refptr<PluginInstance> ref(this); 605 scoped_refptr<PluginInstance> ref(this);
458 606
459 bool rv = false; 607 bool rv = false;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 instance_interface_->DidChangeView(pp_instance(), &pp_position, &pp_clip); 689 instance_interface_->DidChangeView(pp_instance(), &pp_position, &pp_clip);
542 } 690 }
543 691
544 void PluginInstance::SetWebKitFocus(bool has_focus) { 692 void PluginInstance::SetWebKitFocus(bool has_focus) {
545 if (has_webkit_focus_ == has_focus) 693 if (has_webkit_focus_ == has_focus)
546 return; 694 return;
547 695
548 bool old_plugin_focus = PluginHasFocus(); 696 bool old_plugin_focus = PluginHasFocus();
549 has_webkit_focus_ = has_focus; 697 has_webkit_focus_ = has_focus;
550 if (PluginHasFocus() != old_plugin_focus) { 698 if (PluginHasFocus() != old_plugin_focus) {
551 delegate()->PluginFocusChanged(PluginHasFocus()); 699 delegate()->PluginFocusChanged(this, PluginHasFocus());
552 instance_interface_->DidChangeFocus(pp_instance(), 700 instance_interface_->DidChangeFocus(pp_instance(),
553 PP_FromBool(PluginHasFocus())); 701 PP_FromBool(PluginHasFocus()));
554 } 702 }
555 } 703 }
556 704
557 void PluginInstance::SetContentAreaFocus(bool has_focus) { 705 void PluginInstance::SetContentAreaFocus(bool has_focus) {
558 if (has_content_area_focus_ == has_focus) 706 if (has_content_area_focus_ == has_focus)
559 return; 707 return;
560 708
561 bool old_plugin_focus = PluginHasFocus(); 709 bool old_plugin_focus = PluginHasFocus();
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 } 1753 }
1606 1754
1607 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { 1755 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) {
1608 cursor_.reset(cursor); 1756 cursor_.reset(cursor);
1609 if (fullscreen_container_) 1757 if (fullscreen_container_)
1610 fullscreen_container_->DidChangeCursor(*cursor); 1758 fullscreen_container_->DidChangeCursor(*cursor);
1611 } 1759 }
1612 1760
1613 } // namespace ppapi 1761 } // namespace ppapi
1614 } // namespace webkit 1762 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698