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

Side by Side Diff: webkit/plugins/npapi/webplugin_delegate_impl_mac.mm

Issue 6259013: Update Mac plugin IME handling to match updated spec (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to trunk Created 9 years, 11 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
« no previous file with comments | « webkit/plugins/npapi/webplugin_delegate_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/plugins/npapi/webplugin_delegate_impl.h" 8 #include "webkit/plugins/npapi/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_info.h"
20 #include "base/sys_string_conversions.h" 21 #include "base/sys_string_conversions.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
22 #include "webkit/glue/webkit_glue.h" 23 #include "webkit/glue/webkit_glue.h"
23 #include "webkit/plugins/npapi/plugin_instance.h" 24 #include "webkit/plugins/npapi/plugin_instance.h"
24 #include "webkit/plugins/npapi/plugin_lib.h" 25 #include "webkit/plugins/npapi/plugin_lib.h"
25 #include "webkit/plugins/npapi/plugin_list.h" 26 #include "webkit/plugins/npapi/plugin_list.h"
26 #include "webkit/plugins/npapi/plugin_stream_url.h" 27 #include "webkit/plugins/npapi/plugin_stream_url.h"
27 #include "webkit/plugins/npapi/plugin_web_event_converter_mac.h" 28 #include "webkit/plugins/npapi/plugin_web_event_converter_mac.h"
28 #include "webkit/plugins/npapi/webplugin.h" 29 #include "webkit/plugins/npapi/webplugin.h"
29 #include "webkit/plugins/npapi/webplugin_accelerated_surface_mac.h" 30 #include "webkit/plugins/npapi/webplugin_accelerated_surface_mac.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 quirks_(0), 260 quirks_(0),
260 buffer_context_(NULL), 261 buffer_context_(NULL),
261 layer_(nil), 262 layer_(nil),
262 surface_(NULL), 263 surface_(NULL),
263 renderer_(nil), 264 renderer_(nil),
264 containing_window_has_focus_(false), 265 containing_window_has_focus_(false),
265 initial_window_focus_(false), 266 initial_window_focus_(false),
266 container_is_visible_(false), 267 container_is_visible_(false),
267 have_called_set_window_(false), 268 have_called_set_window_(false),
268 ime_enabled_(false), 269 ime_enabled_(false),
270 keyup_ignore_count_(0),
269 external_drag_tracker_(new ExternalDragTracker()), 271 external_drag_tracker_(new ExternalDragTracker()),
270 handle_event_depth_(0), 272 handle_event_depth_(0),
271 first_set_window_call_(true), 273 first_set_window_call_(true),
272 plugin_has_focus_(false), 274 plugin_has_focus_(false),
273 has_webkit_focus_(false), 275 has_webkit_focus_(false),
274 containing_view_has_focus_(true), 276 containing_view_has_focus_(true),
275 creation_succeeded_(false) { 277 creation_succeeded_(false) {
276 memset(&window_, 0, sizeof(window_)); 278 memset(&window_, 0, sizeof(window_));
277 #ifndef NP_NO_CARBON 279 #ifndef NP_NO_CARBON
278 memset(&np_cg_context_, 0, sizeof(np_cg_context_)); 280 memset(&np_cg_context_, 0, sizeof(np_cg_context_));
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 content_origin.y() != content_area_origin_.y()) { 500 content_origin.y() != content_area_origin_.y()) {
499 DLOG(WARNING) << "Stale plugin content area location: " 501 DLOG(WARNING) << "Stale plugin content area location: "
500 << content_area_origin_ << " instead of " 502 << content_area_origin_ << " instead of "
501 << content_origin; 503 << content_origin;
502 SetContentAreaOrigin(content_origin); 504 SetContentAreaOrigin(content_origin);
503 } 505 }
504 506
505 current_windowless_cursor_.GetCursorInfo(cursor_info); 507 current_windowless_cursor_.GetCursorInfo(cursor_info);
506 } 508 }
507 509
510 // Per the Cocoa Plugin IME spec, plugins shoudn't receive keydown or keyup
511 // events while composition is in progress. Treat them as handled, however,
512 // since IME is consuming them on behalf of the plugin.
513 if ((event.type == WebInputEvent::KeyDown && ime_enabled_) ||
514 (event.type == WebInputEvent::KeyUp && keyup_ignore_count_)) {
515 // Composition ends on a keydown, so ime_enabled_ will be false at keyup;
516 // because the keydown wasn't sent to the plugin, the keyup shouldn't be
517 // either (per the spec).
518 if (event.type == WebInputEvent::KeyDown)
519 ++keyup_ignore_count_;
520 else
521 --keyup_ignore_count_;
522 return true;
523 }
524
508 #ifndef NP_NO_CARBON 525 #ifndef NP_NO_CARBON
509 if (instance()->event_model() == NPEventModelCarbon) { 526 if (instance()->event_model() == NPEventModelCarbon) {
510 #ifndef NP_NO_QUICKDRAW 527 #ifndef NP_NO_QUICKDRAW
511 if (instance()->drawing_model() == NPDrawingModelQuickDraw) { 528 if (instance()->drawing_model() == NPDrawingModelQuickDraw) {
512 if (quirks_ & PLUGIN_QUIRK_ALLOW_FASTER_QUICKDRAW_PATH) { 529 if (quirks_ & PLUGIN_QUIRK_ALLOW_FASTER_QUICKDRAW_PATH) {
513 // Mouse event handling doesn't work correctly in the fast path mode, 530 // Mouse event handling doesn't work correctly in the fast path mode,
514 // so any time we get a mouse event turn the fast path off, but set a 531 // so any time we get a mouse event turn the fast path off, but set a
515 // time to switch it on again (we don't rely just on MouseLeave because 532 // time to switch it on again (we don't rely just on MouseLeave because
516 // we don't want poor performance in the case of clicking the play 533 // we don't want poor performance in the case of clicking the play
517 // button and then leaving the mouse there). 534 // button and then leaving the mouse there).
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 595
579 // Send the plugin the event. 596 // Send the plugin the event.
580 scoped_ptr<ScopedCurrentPluginEvent> event_scope(NULL); 597 scoped_ptr<ScopedCurrentPluginEvent> event_scope(NULL);
581 if (instance()->event_model() == NPEventModelCocoa) { 598 if (instance()->event_model() == NPEventModelCocoa) {
582 event_scope.reset(new ScopedCurrentPluginEvent( 599 event_scope.reset(new ScopedCurrentPluginEvent(
583 instance(), static_cast<NPCocoaEvent*>(plugin_event))); 600 instance(), static_cast<NPCocoaEvent*>(plugin_event)));
584 } 601 }
585 int16_t handle_response = instance()->NPP_HandleEvent(plugin_event); 602 int16_t handle_response = instance()->NPP_HandleEvent(plugin_event);
586 bool handled = handle_response != kNPEventNotHandled; 603 bool handled = handle_response != kNPEventNotHandled;
587 604
588 if (handled && event.type == WebInputEvent::KeyDown) { 605 // Start IME if requested by the plugin.
589 // Update IME state as requested by the plugin. 606 if (handled && handle_response == kNPEventStartIME &&
590 SetImeEnabled(handle_response == kNPEventStartIME); 607 event.type == WebInputEvent::KeyDown) {
608 StartIme();
609 ++keyup_ignore_count_;
591 } 610 }
592 611
593 // Plugins don't give accurate information about whether or not they handled 612 // Plugins don't give accurate information about whether or not they handled
594 // events, so browsers on the Mac ignore the return value. 613 // events, so browsers on the Mac ignore the return value.
595 // Scroll events are the exception, since the Cocoa spec defines a meaning 614 // Scroll events are the exception, since the Cocoa spec defines a meaning
596 // for the return value. 615 // for the return value.
597 if (WebInputEvent::isMouseEventType(event.type)) { 616 if (WebInputEvent::isMouseEventType(event.type)) {
598 handled = true; 617 handled = true;
599 } else if (WebInputEvent::isKeyboardEventType(event.type)) { 618 } else if (WebInputEvent::isKeyboardEventType(event.type)) {
600 // For Command-key events, trust the return value since eating all menu 619 // For Command-key events, trust the return value since eating all menu
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 // states (WindowlessSetWindow will then send it on the first call). 805 // states (WindowlessSetWindow will then send it on the first call).
787 if (!have_called_set_window_) { 806 if (!have_called_set_window_) {
788 initial_window_focus_ = has_focus; 807 initial_window_focus_ = has_focus;
789 return; 808 return;
790 } 809 }
791 810
792 if (has_focus == containing_window_has_focus_) 811 if (has_focus == containing_window_has_focus_)
793 return; 812 return;
794 containing_window_has_focus_ = has_focus; 813 containing_window_has_focus_ = has_focus;
795 814
796 if (!has_focus)
797 SetImeEnabled(false);
798
799 #ifndef NP_NO_QUICKDRAW 815 #ifndef NP_NO_QUICKDRAW
800 // Make sure controls repaint with the correct look. 816 // Make sure controls repaint with the correct look.
801 if (quirks_ & PLUGIN_QUIRK_ALLOW_FASTER_QUICKDRAW_PATH) 817 if (quirks_ & PLUGIN_QUIRK_ALLOW_FASTER_QUICKDRAW_PATH)
802 SetQuickDrawFastPathEnabled(false); 818 SetQuickDrawFastPathEnabled(false);
803 #endif 819 #endif
804 820
805 ScopedActiveDelegate active_delegate(this); 821 ScopedActiveDelegate active_delegate(this);
806 switch (instance()->event_model()) { 822 switch (instance()->event_model()) {
807 #ifndef NP_NO_CARBON 823 #ifndef NP_NO_CARBON
808 case NPEventModelCarbon: { 824 case NPEventModelCarbon: {
(...skipping 16 matching lines...) Expand all
825 instance()->NPP_HandleEvent(&focus_event); 841 instance()->NPP_HandleEvent(&focus_event);
826 break; 842 break;
827 } 843 }
828 } 844 }
829 } 845 }
830 846
831 bool WebPluginDelegateImpl::PlatformSetPluginHasFocus(bool focused) { 847 bool WebPluginDelegateImpl::PlatformSetPluginHasFocus(bool focused) {
832 if (!have_called_set_window_) 848 if (!have_called_set_window_)
833 return false; 849 return false;
834 850
835 if (!focused) 851 plugin_->FocusChanged(focused);
836 SetImeEnabled(false);
837 852
838 ScopedActiveDelegate active_delegate(this); 853 ScopedActiveDelegate active_delegate(this);
839 854
840 switch (instance()->event_model()) { 855 switch (instance()->event_model()) {
841 #ifndef NP_NO_CARBON 856 #ifndef NP_NO_CARBON
842 case NPEventModelCarbon: { 857 case NPEventModelCarbon: {
843 NPEvent focus_event = { 0 }; 858 NPEvent focus_event = { 0 };
844 if (focused) 859 if (focused)
845 focus_event.what = NPEventType_GetFocusEvent; 860 focus_event.what = NPEventType_GetFocusEvent;
846 else 861 else
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 if (!clip_rect_.IsEmpty()) 907 if (!clip_rect_.IsEmpty())
893 instance()->webplugin()->InvalidateRect(gfx::Rect()); 908 instance()->webplugin()->InvalidateRect(gfx::Rect());
894 } 909 }
895 910
896 void WebPluginDelegateImpl::WindowFrameChanged(const gfx::Rect& window_frame, 911 void WebPluginDelegateImpl::WindowFrameChanged(const gfx::Rect& window_frame,
897 const gfx::Rect& view_frame) { 912 const gfx::Rect& view_frame) {
898 instance()->set_window_frame(window_frame); 913 instance()->set_window_frame(window_frame);
899 SetContentAreaOrigin(gfx::Point(view_frame.x(), view_frame.y())); 914 SetContentAreaOrigin(gfx::Point(view_frame.x(), view_frame.y()));
900 } 915 }
901 916
902 void WebPluginDelegateImpl::ImeCompositionConfirmed(const string16& text) { 917 void WebPluginDelegateImpl::ImeCompositionCompleted(const string16& text) {
903 if (instance()->event_model() != NPEventModelCocoa) { 918 if (instance()->event_model() != NPEventModelCocoa) {
904 DLOG(ERROR) << "IME text receieved in Carbon event model"; 919 DLOG(ERROR) << "IME notification receieved in Carbon event model";
905 return; 920 return;
906 } 921 }
907 922
908 NPCocoaEvent text_event; 923 ime_enabled_ = false;
909 memset(&text_event, 0, sizeof(NPCocoaEvent)); 924
910 text_event.type = NPCocoaEventTextInput; 925 // If |text| is empty this was just called to tell us composition was
911 text_event.data.text.text = 926 // cancelled externally (e.g., the user pressed esc).
912 reinterpret_cast<NPNSString*>(base::SysUTF16ToNSString(text)); 927 if (!text.empty()) {
913 instance()->NPP_HandleEvent(&text_event); 928 NPCocoaEvent text_event;
929 memset(&text_event, 0, sizeof(NPCocoaEvent));
930 text_event.type = NPCocoaEventTextInput;
931 text_event.data.text.text =
932 reinterpret_cast<NPNSString*>(base::SysUTF16ToNSString(text));
933 instance()->NPP_HandleEvent(&text_event);
934 }
914 } 935 }
915 936
916 void WebPluginDelegateImpl::SetThemeCursor(ThemeCursor cursor) { 937 void WebPluginDelegateImpl::SetThemeCursor(ThemeCursor cursor) {
917 current_windowless_cursor_.InitFromThemeCursor(cursor); 938 current_windowless_cursor_.InitFromThemeCursor(cursor);
918 } 939 }
919 940
920 void WebPluginDelegateImpl::SetCursor(const Cursor* cursor) { 941 void WebPluginDelegateImpl::SetCursor(const Cursor* cursor) {
921 current_windowless_cursor_.InitFromCursor(cursor); 942 current_windowless_cursor_.InitFromCursor(cursor);
922 } 943 }
923 944
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 if (plugin_visible && !redraw_timer_->IsRunning() && windowed_handle()) { 985 if (plugin_visible && !redraw_timer_->IsRunning() && windowed_handle()) {
965 redraw_timer_->Start( 986 redraw_timer_->Start(
966 base::TimeDelta::FromMilliseconds(kCoreAnimationRedrawPeriodMs), 987 base::TimeDelta::FromMilliseconds(kCoreAnimationRedrawPeriodMs),
967 this, &WebPluginDelegateImpl::DrawLayerInSurface); 988 this, &WebPluginDelegateImpl::DrawLayerInSurface);
968 } else if (!plugin_visible) { 989 } else if (!plugin_visible) {
969 redraw_timer_->Stop(); 990 redraw_timer_->Stop();
970 } 991 }
971 } 992 }
972 } 993 }
973 994
974 void WebPluginDelegateImpl::SetImeEnabled(bool enabled) { 995 void WebPluginDelegateImpl::StartIme() {
975 if (instance()->event_model() != NPEventModelCocoa) 996 if (instance()->event_model() != NPEventModelCocoa ||
997 !IsImeSupported()) {
976 return; 998 return;
977 if (enabled == ime_enabled_) 999 }
1000 if (ime_enabled_)
978 return; 1001 return;
979 ime_enabled_ = enabled; 1002 ime_enabled_ = true;
980 plugin_->SetImeEnabled(enabled); 1003 plugin_->StartIme();
1004 }
1005
1006 bool WebPluginDelegateImpl::IsImeSupported() {
1007 // Currently the plugin IME implementation only works on 10.6.
1008 static BOOL sImeSupported = NO;
1009 static BOOL sHaveCheckedSupport = NO;
1010 if (!sHaveCheckedSupport) {
1011 int32 major, minor, bugfix;
1012 base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugfix);
1013 sImeSupported = major > 10 || (major == 10 && minor > 5);
1014 sHaveCheckedSupport = YES;
1015 }
1016 return sImeSupported;
981 } 1017 }
982 1018
983 #pragma mark - 1019 #pragma mark -
984 #pragma mark Core Animation Support 1020 #pragma mark Core Animation Support
985 1021
986 void WebPluginDelegateImpl::DrawLayerInSurface() { 1022 void WebPluginDelegateImpl::DrawLayerInSurface() {
987 // If we haven't plumbed up the surface yet, don't try to draw. 1023 // If we haven't plumbed up the surface yet, don't try to draw.
988 if (!windowed_handle() || !renderer_) 1024 if (!windowed_handle() || !renderer_)
989 return; 1025 return;
990 1026
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 qd_manager_->SetFastPathEnabled(enabled); 1176 qd_manager_->SetFastPathEnabled(enabled);
1141 qd_port_.port = qd_manager_->port(); 1177 qd_port_.port = qd_manager_->port();
1142 WindowlessSetWindow(); 1178 WindowlessSetWindow();
1143 // Send a paint event so that the new buffer gets updated immediately. 1179 // Send a paint event so that the new buffer gets updated immediately.
1144 WindowlessPaint(buffer_context_, clip_rect_); 1180 WindowlessPaint(buffer_context_, clip_rect_);
1145 } 1181 }
1146 #endif // !NP_NO_QUICKDRAW 1182 #endif // !NP_NO_QUICKDRAW
1147 1183
1148 } // namespace npapi 1184 } // namespace npapi
1149 } // namespace webkit 1185 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/webplugin_delegate_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698