OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 #import <QuartzCore/QuartzCore.h> | 6 #import <QuartzCore/QuartzCore.h> |
7 | 7 |
8 #include "webkit/glue/plugins/webplugin_delegate_impl.h" | 8 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/metrics/stats_counters.h" | 16 #include "base/metrics/stats_counters.h" |
17 #include "base/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "base/sys_string_conversions.h" |
20 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 21 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
21 #include "webkit/glue/plugins/plugin_instance.h" | 22 #include "webkit/glue/plugins/plugin_instance.h" |
22 #include "webkit/glue/plugins/plugin_lib.h" | 23 #include "webkit/glue/plugins/plugin_lib.h" |
23 #include "webkit/glue/plugins/plugin_list.h" | 24 #include "webkit/glue/plugins/plugin_list.h" |
24 #include "webkit/glue/plugins/plugin_stream_url.h" | 25 #include "webkit/glue/plugins/plugin_stream_url.h" |
25 #include "webkit/glue/plugins/plugin_web_event_converter_mac.h" | 26 #include "webkit/glue/plugins/plugin_web_event_converter_mac.h" |
26 #include "webkit/glue/plugins/webplugin.h" | 27 #include "webkit/glue/plugins/webplugin.h" |
27 #include "webkit/glue/plugins/webplugin_accelerated_surface_mac.h" | 28 #include "webkit/glue/plugins/webplugin_accelerated_surface_mac.h" |
28 #include "webkit/glue/webkit_glue.h" | 29 #include "webkit/glue/webkit_glue.h" |
29 | 30 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 parent_(containing_view), | 257 parent_(containing_view), |
257 quirks_(0), | 258 quirks_(0), |
258 buffer_context_(NULL), | 259 buffer_context_(NULL), |
259 layer_(nil), | 260 layer_(nil), |
260 surface_(NULL), | 261 surface_(NULL), |
261 renderer_(nil), | 262 renderer_(nil), |
262 containing_window_has_focus_(false), | 263 containing_window_has_focus_(false), |
263 initial_window_focus_(false), | 264 initial_window_focus_(false), |
264 container_is_visible_(false), | 265 container_is_visible_(false), |
265 have_called_set_window_(false), | 266 have_called_set_window_(false), |
| 267 ime_enabled_(false), |
266 external_drag_tracker_(new ExternalDragTracker()), | 268 external_drag_tracker_(new ExternalDragTracker()), |
267 handle_event_depth_(0), | 269 handle_event_depth_(0), |
268 first_set_window_call_(true), | 270 first_set_window_call_(true), |
269 plugin_has_focus_(false), | 271 plugin_has_focus_(false), |
270 has_webkit_focus_(false), | 272 has_webkit_focus_(false), |
271 containing_view_has_focus_(true) { | 273 containing_view_has_focus_(true) { |
272 memset(&window_, 0, sizeof(window_)); | 274 memset(&window_, 0, sizeof(window_)); |
273 #ifndef NP_NO_CARBON | 275 #ifndef NP_NO_CARBON |
274 memset(&np_cg_context_, 0, sizeof(np_cg_context_)); | 276 memset(&np_cg_context_, 0, sizeof(np_cg_context_)); |
275 #endif | 277 #endif |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 return false; | 568 return false; |
567 } | 569 } |
568 } | 570 } |
569 | 571 |
570 // Send the plugin the event. | 572 // Send the plugin the event. |
571 scoped_ptr<NPAPI::ScopedCurrentPluginEvent> event_scope(NULL); | 573 scoped_ptr<NPAPI::ScopedCurrentPluginEvent> event_scope(NULL); |
572 if (instance()->event_model() == NPEventModelCocoa) { | 574 if (instance()->event_model() == NPEventModelCocoa) { |
573 event_scope.reset(new NPAPI::ScopedCurrentPluginEvent( | 575 event_scope.reset(new NPAPI::ScopedCurrentPluginEvent( |
574 instance(), static_cast<NPCocoaEvent*>(plugin_event))); | 576 instance(), static_cast<NPCocoaEvent*>(plugin_event))); |
575 } | 577 } |
576 bool handled = instance()->NPP_HandleEvent(plugin_event) != 0; | 578 int16_t handle_response = instance()->NPP_HandleEvent(plugin_event); |
| 579 bool handled = handle_response != kNPEventNotHandled; |
| 580 |
| 581 if (handled && event.type == WebInputEvent::KeyDown) { |
| 582 // Update IME state as requested by the plugin. |
| 583 SetImeEnabled(handle_response == kNPEventStartIME); |
| 584 } |
577 | 585 |
578 // Plugins don't give accurate information about whether or not they handled | 586 // Plugins don't give accurate information about whether or not they handled |
579 // events, so browsers on the Mac ignore the return value. | 587 // events, so browsers on the Mac ignore the return value. |
580 // Scroll events are the exception, since the Cocoa spec defines a meaning | 588 // Scroll events are the exception, since the Cocoa spec defines a meaning |
581 // for the return value. | 589 // for the return value. |
582 if (WebInputEvent::isMouseEventType(event.type)) { | 590 if (WebInputEvent::isMouseEventType(event.type)) { |
583 handled = true; | 591 handled = true; |
584 } else if (WebInputEvent::isKeyboardEventType(event.type)) { | 592 } else if (WebInputEvent::isKeyboardEventType(event.type)) { |
585 // For Command-key events, trust the return value since eating all menu | 593 // For Command-key events, trust the return value since eating all menu |
586 // shortcuts is not ideal. | 594 // shortcuts is not ideal. |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 // states (WindowlessSetWindow will then send it on the first call). | 779 // states (WindowlessSetWindow will then send it on the first call). |
772 if (!have_called_set_window_) { | 780 if (!have_called_set_window_) { |
773 initial_window_focus_ = has_focus; | 781 initial_window_focus_ = has_focus; |
774 return; | 782 return; |
775 } | 783 } |
776 | 784 |
777 if (has_focus == containing_window_has_focus_) | 785 if (has_focus == containing_window_has_focus_) |
778 return; | 786 return; |
779 containing_window_has_focus_ = has_focus; | 787 containing_window_has_focus_ = has_focus; |
780 | 788 |
| 789 if (!has_focus) |
| 790 SetImeEnabled(false); |
| 791 |
781 #ifndef NP_NO_QUICKDRAW | 792 #ifndef NP_NO_QUICKDRAW |
782 // Make sure controls repaint with the correct look. | 793 // Make sure controls repaint with the correct look. |
783 if (quirks_ & PLUGIN_QUIRK_ALLOW_FASTER_QUICKDRAW_PATH) | 794 if (quirks_ & PLUGIN_QUIRK_ALLOW_FASTER_QUICKDRAW_PATH) |
784 SetQuickDrawFastPathEnabled(false); | 795 SetQuickDrawFastPathEnabled(false); |
785 #endif | 796 #endif |
786 | 797 |
787 ScopedActiveDelegate active_delegate(this); | 798 ScopedActiveDelegate active_delegate(this); |
788 switch (instance()->event_model()) { | 799 switch (instance()->event_model()) { |
789 #ifndef NP_NO_CARBON | 800 #ifndef NP_NO_CARBON |
790 case NPEventModelCarbon: { | 801 case NPEventModelCarbon: { |
(...skipping 16 matching lines...) Expand all Loading... |
807 instance()->NPP_HandleEvent(&focus_event); | 818 instance()->NPP_HandleEvent(&focus_event); |
808 break; | 819 break; |
809 } | 820 } |
810 } | 821 } |
811 } | 822 } |
812 | 823 |
813 bool WebPluginDelegateImpl::PlatformSetPluginHasFocus(bool focused) { | 824 bool WebPluginDelegateImpl::PlatformSetPluginHasFocus(bool focused) { |
814 if (!have_called_set_window_) | 825 if (!have_called_set_window_) |
815 return false; | 826 return false; |
816 | 827 |
| 828 if (!focused) |
| 829 SetImeEnabled(false); |
| 830 |
817 ScopedActiveDelegate active_delegate(this); | 831 ScopedActiveDelegate active_delegate(this); |
818 | 832 |
819 switch (instance()->event_model()) { | 833 switch (instance()->event_model()) { |
820 #ifndef NP_NO_CARBON | 834 #ifndef NP_NO_CARBON |
821 case NPEventModelCarbon: { | 835 case NPEventModelCarbon: { |
822 NPEvent focus_event = { 0 }; | 836 NPEvent focus_event = { 0 }; |
823 if (focused) | 837 if (focused) |
824 focus_event.what = NPEventType_GetFocusEvent; | 838 focus_event.what = NPEventType_GetFocusEvent; |
825 else | 839 else |
826 focus_event.what = NPEventType_LoseFocusEvent; | 840 focus_event.what = NPEventType_LoseFocusEvent; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 if (!clip_rect_.IsEmpty()) | 885 if (!clip_rect_.IsEmpty()) |
872 instance()->webplugin()->InvalidateRect(gfx::Rect()); | 886 instance()->webplugin()->InvalidateRect(gfx::Rect()); |
873 } | 887 } |
874 | 888 |
875 void WebPluginDelegateImpl::WindowFrameChanged(const gfx::Rect& window_frame, | 889 void WebPluginDelegateImpl::WindowFrameChanged(const gfx::Rect& window_frame, |
876 const gfx::Rect& view_frame) { | 890 const gfx::Rect& view_frame) { |
877 instance()->set_window_frame(window_frame); | 891 instance()->set_window_frame(window_frame); |
878 SetContentAreaOrigin(gfx::Point(view_frame.x(), view_frame.y())); | 892 SetContentAreaOrigin(gfx::Point(view_frame.x(), view_frame.y())); |
879 } | 893 } |
880 | 894 |
| 895 void WebPluginDelegateImpl::ImeCompositionConfirmed(const string16& text) { |
| 896 if (instance()->event_model() != NPEventModelCocoa) { |
| 897 DLOG(ERROR) << "IME text receieved in Carbon event model"; |
| 898 return; |
| 899 } |
| 900 |
| 901 NPCocoaEvent text_event; |
| 902 memset(&text_event, 0, sizeof(NPCocoaEvent)); |
| 903 text_event.type = NPCocoaEventTextInput; |
| 904 text_event.data.text.text = |
| 905 reinterpret_cast<NPNSString*>(base::SysUTF16ToNSString(text)); |
| 906 instance()->NPP_HandleEvent(&text_event); |
| 907 } |
| 908 |
881 void WebPluginDelegateImpl::SetThemeCursor(ThemeCursor cursor) { | 909 void WebPluginDelegateImpl::SetThemeCursor(ThemeCursor cursor) { |
882 current_windowless_cursor_.InitFromThemeCursor(cursor); | 910 current_windowless_cursor_.InitFromThemeCursor(cursor); |
883 } | 911 } |
884 | 912 |
885 void WebPluginDelegateImpl::SetCursor(const Cursor* cursor) { | 913 void WebPluginDelegateImpl::SetCursor(const Cursor* cursor) { |
886 current_windowless_cursor_.InitFromCursor(cursor); | 914 current_windowless_cursor_.InitFromCursor(cursor); |
887 } | 915 } |
888 | 916 |
889 void WebPluginDelegateImpl::SetNSCursor(NSCursor* cursor) { | 917 void WebPluginDelegateImpl::SetNSCursor(NSCursor* cursor) { |
890 current_windowless_cursor_.InitFromNSCursor(cursor); | 918 current_windowless_cursor_.InitFromNSCursor(cursor); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 if (plugin_visible && !redraw_timer_->IsRunning() && windowed_handle()) { | 957 if (plugin_visible && !redraw_timer_->IsRunning() && windowed_handle()) { |
930 redraw_timer_->Start( | 958 redraw_timer_->Start( |
931 base::TimeDelta::FromMilliseconds(kCoreAnimationRedrawPeriodMs), | 959 base::TimeDelta::FromMilliseconds(kCoreAnimationRedrawPeriodMs), |
932 this, &WebPluginDelegateImpl::DrawLayerInSurface); | 960 this, &WebPluginDelegateImpl::DrawLayerInSurface); |
933 } else if (!plugin_visible) { | 961 } else if (!plugin_visible) { |
934 redraw_timer_->Stop(); | 962 redraw_timer_->Stop(); |
935 } | 963 } |
936 } | 964 } |
937 } | 965 } |
938 | 966 |
| 967 void WebPluginDelegateImpl::SetImeEnabled(bool enabled) { |
| 968 if (instance()->event_model() != NPEventModelCocoa) |
| 969 return; |
| 970 if (enabled == ime_enabled_) |
| 971 return; |
| 972 ime_enabled_ = enabled; |
| 973 plugin_->SetImeEnabled(enabled); |
| 974 } |
| 975 |
939 #pragma mark - | 976 #pragma mark - |
940 #pragma mark Core Animation Support | 977 #pragma mark Core Animation Support |
941 | 978 |
942 void WebPluginDelegateImpl::DrawLayerInSurface() { | 979 void WebPluginDelegateImpl::DrawLayerInSurface() { |
943 // If we haven't plumbed up the surface yet, don't try to draw. | 980 // If we haven't plumbed up the surface yet, don't try to draw. |
944 if (!windowed_handle()) | 981 if (!windowed_handle()) |
945 return; | 982 return; |
946 | 983 |
947 surface_->StartDrawing(); | 984 surface_->StartDrawing(); |
948 | 985 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 return; | 1129 return; |
1093 } | 1130 } |
1094 | 1131 |
1095 qd_manager_->SetFastPathEnabled(enabled); | 1132 qd_manager_->SetFastPathEnabled(enabled); |
1096 qd_port_.port = qd_manager_->port(); | 1133 qd_port_.port = qd_manager_->port(); |
1097 WindowlessSetWindow(); | 1134 WindowlessSetWindow(); |
1098 // Send a paint event so that the new buffer gets updated immediately. | 1135 // Send a paint event so that the new buffer gets updated immediately. |
1099 WindowlessPaint(buffer_context_, clip_rect_); | 1136 WindowlessPaint(buffer_context_, clip_rect_); |
1100 } | 1137 } |
1101 #endif // !NP_NO_QUICKDRAW | 1138 #endif // !NP_NO_QUICKDRAW |
OLD | NEW |