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

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, static_cast<int>(text.size()),
459 static_cast<int>(text.size()));
460 }
461
462 bool PluginInstance::SendCompositionEventWithUnderlineInformationToPlugin(
463 PP_InputEvent_Type type,
464 const string16& text,
465 const std::vector<WebKit::WebCompositionUnderline>& underlines,
466 int selection_start,
467 int selection_end) {
468 // Keep a reference on the stack. See NOTE above.
469 scoped_refptr<PluginInstance> ref(this);
470
471 if (!LoadInputEventInterface())
472 return false;
473
474 PP_InputEvent_Class event_class = PP_INPUTEVENT_CLASS_IME;
475 if (!(filtered_input_event_mask_ & event_class) &&
476 !(input_event_mask_ & event_class))
477 return false;
478
479 ::ppapi::InputEventData event;
480 event.event_type = type;
481 event.event_time_stamp = ::ppapi::TimeTicksToPPTimeTicks(
482 base::TimeTicks::Now());
483
484 // Convert UTF16 text to UTF8 with offset conversion.
485 std::vector<size_t> offsets;
486 for (size_t i=0; i<underlines.size(); ++i) {
487 offsets.push_back(underlines[i].startOffset);
488 offsets.push_back(underlines[i].endOffset);
489 }
490 offsets.push_back(selection_start);
491 offsets.push_back(selection_end);
492 event.character_text = UTF16ToUTF8AndAdjustOffsets(text, &offsets);
493
494 size_t len = event.character_text.size();
495 for (size_t i=0; i<underlines.size(); ++i) {
496 // UTF16ToUTF8AndAdjustOffsets does not convert end-of-string offsets.
497 size_t left = underlines[i].startOffset==text.size() ? len : offsets[2*i];
498 size_t right = underlines[i].endOffset==text.size() ? len : offsets[2*i+1];
499 if (left != string16::npos && right != string16::npos) {
500 if (underlines[i].thick)
501 event.composition_target_segment = event.composition_segments.size()/2;
502 event.composition_segments.push_back(left);
503 event.composition_segments.push_back(right);
504 }
505 }
506 size_t left = selection_start==static_cast<int>(text.size()) ? len :
507 offsets[offsets.size()-2];
508 size_t right = selection_end==static_cast<int>(text.size()) ? len :
509 offsets[offsets.size()-1];
510 if (left != string16::npos && right != string16::npos) {
511 event.composition_selection_start = left;
512 event.composition_selection_end = right;
513 } else {
514 event.composition_selection_start = len;
515 event.composition_selection_end = len;
516 }
517
518 if (filtered_input_event_mask_ & event_class)
519 event.is_filtered = true;
520 scoped_refptr<InputEventImpl> event_resource(
521 new InputEventImpl(InputEventImpl::InitAsImpl(),
522 pp_instance(), event));
523
524 return PP_ToBool(plugin_input_event_interface_->HandleInputEvent(
525 pp_instance(), event_resource->pp_resource()));
526 }
527
528 bool PluginInstance::HandleCompositionStart(const string16& text) {
529 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_COMPOSITION_START,
530 text);
531 }
532
533 bool PluginInstance::HandleCompositionUpdate(
534 const string16& text,
535 const std::vector<WebKit::WebCompositionUnderline>& underlines,
536 int selection_start,
537 int selection_end) {
538 return SendCompositionEventWithUnderlineInformationToPlugin(
539 PP_INPUTEVENT_TYPE_COMPOSITION_UPDATE,
540 text, underlines, selection_start, selection_end);
541 }
542
543 bool PluginInstance::HandleCompositionEnd(const string16& text) {
544 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_COMPOSITION_END,
545 text);
546 }
547
548 bool PluginInstance::HandleTextInput(const string16& text) {
549 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_TEXT,
550 text);
551 }
552
553 void PluginInstance::UpdateCaretPosition(const PP_Rect& caret,
554 const PP_Rect& boundingBox) {
555 text_input_caret_ = caret;
556 text_input_caret_bounds_ = boundingBox;
557 text_input_caret_set_ = true;
558 }
559
560 void PluginInstance::SetTextInputType(WebKit::WebTextInputType type) {
561 text_input_type_ = type;
562 }
563
564 bool PluginInstance::CanComposeInline() const {
565 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) ||
566 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME);
567 }
568
569 WebKit::WebRect PluginInstance::GetCaretBounds() const {
570 if (!text_input_caret_set_) {
571 // If it is never set by the plugin, use the bottom left corner.
572 WebKit::WebRect caret(position().x(),
573 position().y(),
574 0,
575 position().height());
576 return caret;
577 }
578
579 // TODO(kinaba) take bounds into account
580 // TODO(kinaba) take CSS transformation into accont
581 WebKit::WebRect caret(text_input_caret_.point.x,
582 text_input_caret_.point.y,
583 text_input_caret_.size.width,
584 text_input_caret_.size.height);
585 caret.x += position().x();
586 caret.y += position().y();
587 return caret;
588 }
589
448 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, 590 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event,
449 WebCursorInfo* cursor_info) { 591 WebCursorInfo* cursor_info) {
450 // Keep a reference on the stack. See NOTE above. 592 // Keep a reference on the stack. See NOTE above.
451 scoped_refptr<PluginInstance> ref(this); 593 scoped_refptr<PluginInstance> ref(this);
452 594
453 bool rv = false; 595 bool rv = false;
454 if (LoadInputEventInterface()) { 596 if (LoadInputEventInterface()) {
455 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); 597 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type);
456 if (!event_class) 598 if (!event_class)
457 return false; 599 return false;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 instance_interface_->DidChangeView(pp_instance(), &pp_position, &pp_clip); 677 instance_interface_->DidChangeView(pp_instance(), &pp_position, &pp_clip);
536 } 678 }
537 679
538 void PluginInstance::SetWebKitFocus(bool has_focus) { 680 void PluginInstance::SetWebKitFocus(bool has_focus) {
539 if (has_webkit_focus_ == has_focus) 681 if (has_webkit_focus_ == has_focus)
540 return; 682 return;
541 683
542 bool old_plugin_focus = PluginHasFocus(); 684 bool old_plugin_focus = PluginHasFocus();
543 has_webkit_focus_ = has_focus; 685 has_webkit_focus_ = has_focus;
544 if (PluginHasFocus() != old_plugin_focus) { 686 if (PluginHasFocus() != old_plugin_focus) {
545 delegate()->PluginFocusChanged(PluginHasFocus()); 687 delegate()->PluginFocusChanged(this, PluginHasFocus());
546 instance_interface_->DidChangeFocus(pp_instance(), 688 instance_interface_->DidChangeFocus(pp_instance(),
547 PP_FromBool(PluginHasFocus())); 689 PP_FromBool(PluginHasFocus()));
548 } 690 }
549 } 691 }
550 692
551 void PluginInstance::SetContentAreaFocus(bool has_focus) { 693 void PluginInstance::SetContentAreaFocus(bool has_focus) {
552 if (has_content_area_focus_ == has_focus) 694 if (has_content_area_focus_ == has_focus)
553 return; 695 return;
554 696
555 bool old_plugin_focus = PluginHasFocus(); 697 bool old_plugin_focus = PluginHasFocus();
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 } 1683 }
1542 1684
1543 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { 1685 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) {
1544 cursor_.reset(cursor); 1686 cursor_.reset(cursor);
1545 if (fullscreen_container_) 1687 if (fullscreen_container_)
1546 fullscreen_container_->DidChangeCursor(*cursor); 1688 fullscreen_container_->DidChangeCursor(*cursor);
1547 } 1689 }
1548 1690
1549 } // namespace ppapi 1691 } // namespace ppapi
1550 } // namespace webkit 1692 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | webkit/plugins/ppapi/ppb_text_input_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698