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

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

Issue 7621010: Never submit: tentative Pepper IME. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: snapshot 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_find_dev.h" 13 #include "ppapi/c/dev/ppb_find_dev.h"
13 #include "ppapi/c/dev/ppb_fullscreen_dev.h" 14 #include "ppapi/c/dev/ppb_fullscreen_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/WebCursorInfo.h" 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 checked_for_plugin_messaging_interface_(false), 237 checked_for_plugin_messaging_interface_(false),
236 plugin_print_interface_(NULL), 238 plugin_print_interface_(NULL),
237 plugin_graphics_3d_interface_(NULL), 239 plugin_graphics_3d_interface_(NULL),
238 always_on_top_(false), 240 always_on_top_(false),
239 fullscreen_container_(NULL), 241 fullscreen_container_(NULL),
240 fullscreen_(false), 242 fullscreen_(false),
241 message_channel_(NULL), 243 message_channel_(NULL),
242 sad_plugin_(NULL), 244 sad_plugin_(NULL),
243 input_event_mask_(0), 245 input_event_mask_(0),
244 filtered_input_event_mask_(0), 246 filtered_input_event_mask_(0),
247 text_input_type_(WebKit::WebTextInputTypeText),
248 text_input_caret_set_(false),
245 lock_mouse_callback_(PP_BlockUntilComplete()) { 249 lock_mouse_callback_(PP_BlockUntilComplete()) {
250 memset(&text_input_caret_, 0, sizeof(text_input_caret_));
251 memset(&text_input_caret_bounds_, 0, sizeof(text_input_caret_bounds_));
246 pp_instance_ = ResourceTracker::Get()->AddInstance(this); 252 pp_instance_ = ResourceTracker::Get()->AddInstance(this);
247 253
248 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 254 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
249 DCHECK(delegate); 255 DCHECK(delegate);
250 module_->InstanceCreated(this); 256 module_->InstanceCreated(this);
251 delegate_->InstanceCreated(this); 257 delegate_->InstanceCreated(this);
252 message_channel_.reset(new MessageChannel(this)); 258 message_channel_.reset(new MessageChannel(this));
253 } 259 }
254 260
255 PluginInstance::~PluginInstance() { 261 PluginInstance::~PluginInstance() {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 argc, 444 argc,
439 argn.get(), 445 argn.get(),
440 argv.get())); 446 argv.get()));
441 } 447 }
442 448
443 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { 449 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) {
444 return PP_ToBool(instance_interface_->HandleDocumentLoad( 450 return PP_ToBool(instance_interface_->HandleDocumentLoad(
445 pp_instance(), loader->pp_resource())); 451 pp_instance(), loader->pp_resource()));
446 } 452 }
447 453
454 bool PluginInstance::SendCompositionEventToPlugin(PP_InputEvent_Type type,
455 const string16& text) {
456 std::vector<WebKit::WebCompositionUnderline> empty;
457 return SendCompositionEventWithUnderlineInformationToPlugin(
458 type, text, empty, 0, 0);
459 }
460
461 bool PluginInstance::SendCompositionEventWithUnderlineInformationToPlugin(
462 PP_InputEvent_Type type,
463 const string16& text,
464 const std::vector<WebKit::WebCompositionUnderline>& underlines,
465 int selection_start,
466 int selection_end) {
467 // Keep a reference on the stack. See NOTE above.
468 scoped_refptr<PluginInstance> ref(this);
469
470 if (LoadInputEventInterface()) {
471 PP_InputEvent_Class event_class = PP_INPUTEVENT_CLASS_IME;
472
473 if ((filtered_input_event_mask_ & event_class) ||
474 (input_event_mask_ & event_class)) {
475 ::ppapi::InputEventData event;
476 event.event_type = type;
477 event.event_time_stamp = ::ppapi::TimeTicksToPPTimeTicks(
478 base::TimeTicks::Now());
479
480 // Convert std::vector<WebCompositionUnderline> to segment information.
481 std::set<size_t> utf16_index_set;
482 utf16_index_set.insert(0);
483 for (size_t i=0; i<underlines.size(); ++i) {
484 utf16_index_set.insert(underlines[i].startOffset);
485 utf16_index_set.insert(underlines[i].endOffset);
486 }
487 // UTF16ToUTF8AndAdjustOffsets converts end-of-string to string::npos,
488 // So treat it separately.
489 utf16_index_set.erase(text.size());
490
491 std::vector<size_t> segments(utf16_index_set.begin(),
492 utf16_index_set.end());
493 event.composition_target_segment = segments.size() - 1;
494 for (size_t i=0; i<underlines.size(); ++i) {
495 if (underlines[i].thick) {
496 event.composition_target_segment =
497 std::find( segments.begin(),
498 segments.end(),
499 underlines[i].startOffset ) -
500 segments.begin();
501 break;
502 }
503 }
504 event.character_text = UTF16ToUTF8AndAdjustOffsets(text, &segments);
505 segments.push_back(event.character_text.size());
506 for (size_t i=0; i<segments.size(); ++i)
507 if (segments[i] != std::string::npos)
508 event.composition_segments.push_back(segments[i]);
509
510 if (filtered_input_event_mask_ & event_class)
511 event.is_filtered = true;
512 scoped_refptr<InputEventImpl> event_resource(
513 new InputEventImpl(InputEventImpl::InitAsImpl(),
514 pp_instance(), event));
515
516 return PP_ToBool(plugin_input_event_interface_->HandleInputEvent(
517 pp_instance(), event_resource->pp_resource()));
518 }
519 }
520 return false;
521 }
522
523 bool PluginInstance::HandleCompositionStart(const string16& text) {
524 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_COMPOSITION_START,
525 text);
526 }
527
528 bool PluginInstance::HandleCompositionUpdate(
529 const string16& text,
530 const std::vector<WebKit::WebCompositionUnderline>& underlines,
531 int selection_start,
532 int selection_end) {
533 return SendCompositionEventWithUnderlineInformationToPlugin(
534 PP_INPUTEVENT_TYPE_COMPOSITION_UPDATE,
535 text, underlines, selection_start, selection_end);
536 }
537
538 bool PluginInstance::HandleCompositionEnd(const string16& text) {
539 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_COMPOSITION_END,
540 text);
541 }
542
543 bool PluginInstance::HandleTextInput(const string16& text) {
544 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_TEXT,
545 text);
546 }
547
548 void PluginInstance::UpdateCaretPosition(const PP_Rect& caret,
549 const PP_Rect& boundingBox) {
550 text_input_caret_ = caret;
551 text_input_caret_bounds_ = boundingBox;
552 text_input_caret_set_ = true;
553 }
554
555 void PluginInstance::SetTextInputType(WebKit::WebTextInputType type) {
556 text_input_type_ = type;
557 }
558
559 bool PluginInstance::CanComposeInline() const {
560 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) ||
561 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME);
562 }
563
564 WebKit::WebRect PluginInstance::GetCaretBounds() const {
565 if (!text_input_caret_set_) {
566 // If it is never set by the plugin, use the bottom left corner.
567 WebKit::WebRect caret(position().x(),
568 position().y(),
569 0,
570 position().height());
571 return caret;
572 }
573
574 // TODO(kinaba) take bounds into account
575 // TODO(kinaba) take CSS transformation into accont
576 WebKit::WebRect caret(text_input_caret_.point.x,
577 text_input_caret_.point.y,
578 text_input_caret_.size.width,
579 text_input_caret_.size.height);
580 caret.x += position().x();
581 caret.y += position().y();
582 return caret;
583 }
584
448 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, 585 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event,
449 WebCursorInfo* cursor_info) { 586 WebCursorInfo* cursor_info) {
450 // Keep a reference on the stack. See NOTE above. 587 // Keep a reference on the stack. See NOTE above.
451 scoped_refptr<PluginInstance> ref(this); 588 scoped_refptr<PluginInstance> ref(this);
452 589
453 bool rv = false; 590 bool rv = false;
454 if (LoadInputEventInterface()) { 591 if (LoadInputEventInterface()) {
455 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); 592 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type);
456 if (!event_class) 593 if (!event_class)
457 return false; 594 return false;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 instance_interface_->DidChangeView(pp_instance(), &pp_position, &pp_clip); 672 instance_interface_->DidChangeView(pp_instance(), &pp_position, &pp_clip);
536 } 673 }
537 674
538 void PluginInstance::SetWebKitFocus(bool has_focus) { 675 void PluginInstance::SetWebKitFocus(bool has_focus) {
539 if (has_webkit_focus_ == has_focus) 676 if (has_webkit_focus_ == has_focus)
540 return; 677 return;
541 678
542 bool old_plugin_focus = PluginHasFocus(); 679 bool old_plugin_focus = PluginHasFocus();
543 has_webkit_focus_ = has_focus; 680 has_webkit_focus_ = has_focus;
544 if (PluginHasFocus() != old_plugin_focus) { 681 if (PluginHasFocus() != old_plugin_focus) {
545 delegate()->PluginFocusChanged(PluginHasFocus()); 682 delegate()->PluginFocusChanged(this, PluginHasFocus());
546 instance_interface_->DidChangeFocus(pp_instance(), 683 instance_interface_->DidChangeFocus(pp_instance(),
547 PP_FromBool(PluginHasFocus())); 684 PP_FromBool(PluginHasFocus()));
548 } 685 }
549 } 686 }
550 687
551 void PluginInstance::SetContentAreaFocus(bool has_focus) { 688 void PluginInstance::SetContentAreaFocus(bool has_focus) {
552 if (has_content_area_focus_ == has_focus) 689 if (has_content_area_focus_ == has_focus)
553 return; 690 return;
554 691
555 bool old_plugin_focus = PluginHasFocus(); 692 bool old_plugin_focus = PluginHasFocus();
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 } 1678 }
1542 1679
1543 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { 1680 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) {
1544 cursor_.reset(cursor); 1681 cursor_.reset(cursor);
1545 if (fullscreen_container_) 1682 if (fullscreen_container_)
1546 fullscreen_container_->DidChangeCursor(*cursor); 1683 fullscreen_container_->DidChangeCursor(*cursor);
1547 } 1684 }
1548 1685
1549 } // namespace ppapi 1686 } // namespace ppapi
1550 } // namespace webkit 1687 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698