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

Side by Side Diff: content/renderer/pepper_plugin_delegate_impl.cc

Issue 8073021: Implement Pepper IME API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments from brettw, yzshen, and kochi. Created 9 years, 2 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 "content/renderer/pepper_plugin_delegate_impl.h" 5 #include "content/renderer/pepper_plugin_delegate_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 // saved pipe handle. 658 // saved pipe handle.
659 // Temporarily, just call back. 659 // Temporarily, just call back.
660 client->BrokerConnected(PlatformFileToInt(plugin_handle), result); 660 client->BrokerConnected(PlatformFileToInt(plugin_handle), result);
661 } 661 }
662 662
663 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) 663 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view)
664 : render_view_(render_view), 664 : render_view_(render_view),
665 has_saved_context_menu_action_(false), 665 has_saved_context_menu_action_(false),
666 saved_context_menu_action_(0), 666 saved_context_menu_action_(0),
667 id_generator_(0), 667 id_generator_(0),
668 is_pepper_plugin_focused_(false), 668 focused_plugin_(NULL),
669 mouse_lock_owner_(NULL), 669 mouse_lock_owner_(NULL),
670 mouse_locked_(false), 670 mouse_locked_(false),
671 pending_lock_request_(false), 671 pending_lock_request_(false),
672 pending_unlock_request_(false) { 672 pending_unlock_request_(false) {
673 } 673 }
674 674
675 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { 675 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() {
676 DCHECK(!mouse_lock_owner_); 676 DCHECK(!mouse_lock_owner_);
677 } 677 }
678 678
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 active_instances_.begin(); 841 active_instances_.begin();
842 i != active_instances_.end(); ++i) { 842 i != active_instances_.end(); ++i) {
843 webkit::ppapi::PluginInstance* instance = *i; 843 webkit::ppapi::PluginInstance* instance = *i;
844 if (instance->GetBitmapForOptimizedPluginPaint( 844 if (instance->GetBitmapForOptimizedPluginPaint(
845 paint_bounds, dib, location, clip)) 845 paint_bounds, dib, location, clip))
846 return *i; 846 return *i;
847 } 847 }
848 return NULL; 848 return NULL;
849 } 849 }
850 850
851 void PepperPluginDelegateImpl::PluginFocusChanged(bool focused) { 851 void PepperPluginDelegateImpl::PluginFocusChanged(
852 is_pepper_plugin_focused_ = focused; 852 webkit::ppapi::PluginInstance* instance,
853 bool focused) {
854 if (focused)
855 focused_plugin_ = instance;
856 else if (focused_plugin_ == instance)
857 focused_plugin_ = NULL;
853 if (render_view_) 858 if (render_view_)
854 render_view_->PpapiPluginFocusChanged(); 859 render_view_->PpapiPluginFocusChanged();
855 } 860 }
856 861
862 void PepperPluginDelegateImpl::PluginTextInputTypeChanged(
863 webkit::ppapi::PluginInstance* instance) {
864 if (focused_plugin_ == instance && render_view_)
865 render_view_->PpapiPluginTextInputTypeChanged();
866 }
867
868 void PepperPluginDelegateImpl::PluginRequestedCancelComposition(
869 webkit::ppapi::PluginInstance* instance) {
870 if (focused_plugin_ == instance && render_view_)
871 render_view_->PpapiPluginCancelComposition();
872 }
873
874 void PepperPluginDelegateImpl::OnImeSetComposition(
875 const string16& text,
876 const std::vector<WebKit::WebCompositionUnderline>& underlines,
877 int selection_start,
878 int selection_end) {
879 if (!IsPluginAcceptingCompositionEvents()) {
880 composition_text_ = text;
881 } else {
882 // TODO(kinaba) currently all composition events are sent directly to
883 // plugins. Use DOM event mechanism after WebKit is made aware about
884 // plugins that support composition.
885 // The code below mimics the behavior of WebCore::Editor::setComposition.
886
887 // Empty -> nonempty: composition started.
888 if (composition_text_.empty() && !text.empty())
889 focused_plugin_->HandleCompositionStart(string16());
890 // Nonempty -> empty: composition canceled.
891 if (!composition_text_.empty() && text.empty())
892 focused_plugin_->HandleCompositionEnd(string16());
893 composition_text_ = text;
894 // Nonempty: composition is ongoing.
895 if (!composition_text_.empty()) {
896 focused_plugin_->HandleCompositionUpdate(composition_text_, underlines,
897 selection_start, selection_end);
898 }
899 }
900 }
901
902 void PepperPluginDelegateImpl::OnImeConfirmComposition(const string16& text) {
903 if (!text.empty())
904 composition_text_ = text;
905 if (composition_text_.empty())
906 return;
907
908 if (!IsPluginAcceptingCompositionEvents()) {
909 for (size_t i = 0; i < text.size(); ++i) {
910 WebKit::WebKeyboardEvent char_event;
911 char_event.type = WebKit::WebInputEvent::Char;
912 char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
913 char_event.modifiers = 0;
914 char_event.windowsKeyCode = composition_text_[i];
915 char_event.nativeKeyCode = composition_text_[i];
916 char_event.text[0] = composition_text_[i];
917 char_event.unmodifiedText[0] = composition_text_[i];
918 if (render_view_->webwidget())
919 render_view_->webwidget()->handleInputEvent(char_event);
920 }
921 } else {
922 // Mimics the order of events sent by WebKit.
923 // See WebCore::Editor::setComposition() for the corresponding code.
924 focused_plugin_->HandleCompositionEnd(composition_text_);
925 focused_plugin_->HandleTextInput(composition_text_);
926 }
927 composition_text_.clear();
928 }
929
930 gfx::Rect PepperPluginDelegateImpl::GetCaretBounds() const {
931 if (!focused_plugin_)
932 return gfx::Rect(0, 0, 0, 0);
933 return focused_plugin_->GetCaretBounds();
934 }
935
936 ui::TextInputType PepperPluginDelegateImpl::GetTextInputType() const {
937 if (!focused_plugin_)
938 return ui::TEXT_INPUT_TYPE_NONE;
939 return focused_plugin_->text_input_type();
940 }
941
942 bool PepperPluginDelegateImpl::IsPluginAcceptingCompositionEvents() const {
943 if (!focused_plugin_)
944 return false;
945 return focused_plugin_->IsPluginAcceptingCompositionEvents();
946 }
947
948 bool PepperPluginDelegateImpl::CanComposeInline() const {
949 return IsPluginAcceptingCompositionEvents();
950 }
951
857 void PepperPluginDelegateImpl::PluginCrashed( 952 void PepperPluginDelegateImpl::PluginCrashed(
858 webkit::ppapi::PluginInstance* instance) { 953 webkit::ppapi::PluginInstance* instance) {
859 subscribed_to_policy_updates_.erase(instance); 954 subscribed_to_policy_updates_.erase(instance);
860 render_view_->PluginCrashed(instance->module()->path()); 955 render_view_->PluginCrashed(instance->module()->path());
861 956
862 UnlockMouse(instance); 957 UnlockMouse(instance);
863 } 958 }
864 959
865 void PepperPluginDelegateImpl::InstanceCreated( 960 void PepperPluginDelegateImpl::InstanceCreated(
866 webkit::ppapi::PluginInstance* instance) { 961 webkit::ppapi::PluginInstance* instance) {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 } 1138 }
1044 1139
1045 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) { 1140 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) {
1046 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = 1141 for (std::set<webkit::ppapi::PluginInstance*>::iterator i =
1047 active_instances_.begin(); 1142 active_instances_.begin();
1048 i != active_instances_.end(); ++i) 1143 i != active_instances_.end(); ++i)
1049 (*i)->SetContentAreaFocus(has_focus); 1144 (*i)->SetContentAreaFocus(has_focus);
1050 } 1145 }
1051 1146
1052 bool PepperPluginDelegateImpl::IsPluginFocused() const { 1147 bool PepperPluginDelegateImpl::IsPluginFocused() const {
1053 return is_pepper_plugin_focused_; 1148 return focused_plugin_ != NULL;
1054 } 1149 }
1055 1150
1056 void PepperPluginDelegateImpl::OnLockMouseACK(bool succeeded) { 1151 void PepperPluginDelegateImpl::OnLockMouseACK(bool succeeded) {
1057 DCHECK(!mouse_locked_ && pending_lock_request_); 1152 DCHECK(!mouse_locked_ && pending_lock_request_);
1058 1153
1059 mouse_locked_ = succeeded; 1154 mouse_locked_ = succeeded;
1060 pending_lock_request_ = false; 1155 pending_lock_request_ = false;
1061 if (pending_unlock_request_ && !succeeded) { 1156 if (pending_unlock_request_ && !succeeded) {
1062 // We have sent an unlock request after the lock request. However, since 1157 // We have sent an unlock request after the lock request. However, since
1063 // the lock request has failed, the unlock request will be ignored by the 1158 // the lock request has failed, the unlock request will be ignored by the
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 1710
1616 int PepperPluginDelegateImpl::GetRoutingId() const { 1711 int PepperPluginDelegateImpl::GetRoutingId() const {
1617 return render_view_->routing_id(); 1712 return render_view_->routing_id();
1618 } 1713 }
1619 1714
1620 void PepperPluginDelegateImpl::PublishInitialPolicy( 1715 void PepperPluginDelegateImpl::PublishInitialPolicy(
1621 scoped_refptr<webkit::ppapi::PluginInstance> instance, 1716 scoped_refptr<webkit::ppapi::PluginInstance> instance,
1622 const std::string& policy) { 1717 const std::string& policy) {
1623 instance->HandlePolicyUpdate(policy); 1718 instance->HandlePolicyUpdate(policy);
1624 } 1719 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698