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

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

Powered by Google App Engine
This is Rietveld 408576698