| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/render_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 #endif | 631 #endif |
| 632 has_focus_(false), | 632 has_focus_(false), |
| 633 has_scrolled_focused_editable_node_into_rect_(false), | 633 has_scrolled_focused_editable_node_into_rect_(false), |
| 634 main_render_frame_(nullptr), | 634 main_render_frame_(nullptr), |
| 635 frame_widget_(nullptr), | 635 frame_widget_(nullptr), |
| 636 speech_recognition_dispatcher_(NULL), | 636 speech_recognition_dispatcher_(NULL), |
| 637 mouse_lock_dispatcher_(NULL), | 637 mouse_lock_dispatcher_(NULL), |
| 638 #if defined(OS_ANDROID) | 638 #if defined(OS_ANDROID) |
| 639 expected_content_intent_id_(0), | 639 expected_content_intent_id_(0), |
| 640 #endif | 640 #endif |
| 641 #if defined(OS_WIN) |
| 642 focused_plugin_id_(-1), |
| 643 #endif |
| 641 #if defined(ENABLE_PLUGINS) | 644 #if defined(ENABLE_PLUGINS) |
| 642 focused_pepper_plugin_(NULL), | 645 focused_pepper_plugin_(NULL), |
| 643 pepper_last_mouse_event_target_(NULL), | 646 pepper_last_mouse_event_target_(NULL), |
| 644 #endif | 647 #endif |
| 645 enumeration_completion_id_(0), | 648 enumeration_completion_id_(0), |
| 646 session_storage_namespace_id_(params.session_storage_namespace_id) { | 649 session_storage_namespace_id_(params.session_storage_namespace_id) { |
| 647 GetWidget()->set_owner_delegate(this); | 650 GetWidget()->set_owner_delegate(this); |
| 648 } | 651 } |
| 649 | 652 |
| 650 void RenderViewImpl::Initialize(const ViewMsg_New_Params& params, | 653 void RenderViewImpl::Initialize(const ViewMsg_New_Params& params, |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1201 // environments where RenderView isn't hosting them), so we always have to | 1204 // environments where RenderView isn't hosting them), so we always have to |
| 1202 // set the initial state. See webplugin_delegate_impl.h for details. | 1205 // set the initial state. See webplugin_delegate_impl.h for details. |
| 1203 delegate->SetContentAreaFocus(has_focus()); | 1206 delegate->SetContentAreaFocus(has_focus()); |
| 1204 } | 1207 } |
| 1205 | 1208 |
| 1206 void RenderViewImpl::UnregisterPluginDelegate( | 1209 void RenderViewImpl::UnregisterPluginDelegate( |
| 1207 WebPluginDelegateProxy* delegate) { | 1210 WebPluginDelegateProxy* delegate) { |
| 1208 plugin_delegates_.erase(delegate); | 1211 plugin_delegates_.erase(delegate); |
| 1209 } | 1212 } |
| 1210 | 1213 |
| 1214 #if defined(OS_WIN) |
| 1215 void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
| 1216 if (focused) |
| 1217 focused_plugin_id_ = plugin_id; |
| 1218 else |
| 1219 focused_plugin_id_ = -1; |
| 1220 } |
| 1221 #endif |
| 1222 |
| 1211 #if defined(OS_MACOSX) | 1223 #if defined(OS_MACOSX) |
| 1212 void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { | 1224 void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
| 1213 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id)); | 1225 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id)); |
| 1214 } | 1226 } |
| 1215 | 1227 |
| 1216 void RenderViewImpl::OnGetRenderedText() { | 1228 void RenderViewImpl::OnGetRenderedText() { |
| 1217 if (!webview()) | 1229 if (!webview()) |
| 1218 return; | 1230 return; |
| 1219 | 1231 |
| 1220 if (!webview()->mainFrame()->isWebLocalFrame()) | 1232 if (!webview()->mainFrame()->isWebLocalFrame()) |
| (...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2908 const std::vector<blink::WebCompositionUnderline>& underlines, | 2920 const std::vector<blink::WebCompositionUnderline>& underlines, |
| 2909 const gfx::Range& replacement_range, | 2921 const gfx::Range& replacement_range, |
| 2910 int selection_start, | 2922 int selection_start, |
| 2911 int selection_end) { | 2923 int selection_end) { |
| 2912 #if defined(ENABLE_PLUGINS) | 2924 #if defined(ENABLE_PLUGINS) |
| 2913 if (focused_pepper_plugin_) { | 2925 if (focused_pepper_plugin_) { |
| 2914 focused_pepper_plugin_->render_frame()->OnImeSetComposition( | 2926 focused_pepper_plugin_->render_frame()->OnImeSetComposition( |
| 2915 text, underlines, selection_start, selection_end); | 2927 text, underlines, selection_start, selection_end); |
| 2916 return; | 2928 return; |
| 2917 } | 2929 } |
| 2930 |
| 2931 #if defined(OS_WIN) |
| 2932 // When a plugin has focus, we create platform-specific IME data used by |
| 2933 // our IME emulator and send it directly to the focused plugin, i.e. we |
| 2934 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its |
| 2935 // instance ID is the same one as the specified ID.) |
| 2936 if (focused_plugin_id_ >= 0) { |
| 2937 std::vector<int> clauses; |
| 2938 std::vector<int> target; |
| 2939 for (size_t i = 0; i < underlines.size(); ++i) { |
| 2940 clauses.push_back(underlines[i].startOffset); |
| 2941 clauses.push_back(underlines[i].endOffset); |
| 2942 if (underlines[i].thick) { |
| 2943 target.clear(); |
| 2944 target.push_back(underlines[i].startOffset); |
| 2945 target.push_back(underlines[i].endOffset); |
| 2946 } |
| 2947 } |
| 2948 std::set<WebPluginDelegateProxy*>::iterator it; |
| 2949 for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) { |
| 2950 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end, |
| 2951 focused_plugin_id_); |
| 2952 } |
| 2953 return; |
| 2954 } |
| 2955 #endif // OS_WIN |
| 2918 #endif // ENABLE_PLUGINS | 2956 #endif // ENABLE_PLUGINS |
| 2919 if (replacement_range.IsValid() && webview()) { | 2957 if (replacement_range.IsValid() && webview()) { |
| 2920 // Select the text in |replacement_range|, it will then be replaced by | 2958 // Select the text in |replacement_range|, it will then be replaced by |
| 2921 // text added by the call to RenderWidget::OnImeSetComposition(). | 2959 // text added by the call to RenderWidget::OnImeSetComposition(). |
| 2922 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) { | 2960 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) { |
| 2923 WebRange webrange = WebRange::fromDocumentRange( | 2961 WebRange webrange = WebRange::fromDocumentRange( |
| 2924 frame, replacement_range.start(), replacement_range.length()); | 2962 frame, replacement_range.start(), replacement_range.length()); |
| 2925 if (!webrange.isNull()) | 2963 if (!webrange.isNull()) |
| 2926 frame->selectRange(webrange); | 2964 frame->selectRange(webrange); |
| 2927 } | 2965 } |
| 2928 } | 2966 } |
| 2929 RenderWidget::OnImeSetComposition(text, | 2967 RenderWidget::OnImeSetComposition(text, |
| 2930 underlines, | 2968 underlines, |
| 2931 replacement_range, | 2969 replacement_range, |
| 2932 selection_start, | 2970 selection_start, |
| 2933 selection_end); | 2971 selection_end); |
| 2934 } | 2972 } |
| 2935 | 2973 |
| 2936 void RenderViewImpl::OnImeConfirmComposition( | 2974 void RenderViewImpl::OnImeConfirmComposition( |
| 2937 const base::string16& text, | 2975 const base::string16& text, |
| 2938 const gfx::Range& replacement_range, | 2976 const gfx::Range& replacement_range, |
| 2939 bool keep_selection) { | 2977 bool keep_selection) { |
| 2940 #if defined(ENABLE_PLUGINS) | 2978 #if defined(ENABLE_PLUGINS) |
| 2941 if (focused_pepper_plugin_) { | 2979 if (focused_pepper_plugin_) { |
| 2942 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( | 2980 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( |
| 2943 text, replacement_range, keep_selection); | 2981 text, replacement_range, keep_selection); |
| 2944 return; | 2982 return; |
| 2945 } | 2983 } |
| 2984 #if defined(OS_WIN) |
| 2985 // Same as OnImeSetComposition(), we send the text from IMEs directly to |
| 2986 // plugins. When we send IME text directly to plugins, we should not send |
| 2987 // it to WebKit to prevent WebKit from controlling IMEs. |
| 2988 // TODO(thakis): Honor |replacement_range| for plugins? |
| 2989 if (focused_plugin_id_ >= 0) { |
| 2990 std::set<WebPluginDelegateProxy*>::iterator it; |
| 2991 for (it = plugin_delegates_.begin(); |
| 2992 it != plugin_delegates_.end(); ++it) { |
| 2993 (*it)->ImeCompositionCompleted(text, focused_plugin_id_); |
| 2994 } |
| 2995 return; |
| 2996 } |
| 2997 #endif // OS_WIN |
| 2946 #endif // ENABLE_PLUGINS | 2998 #endif // ENABLE_PLUGINS |
| 2947 if (replacement_range.IsValid() && webview()) { | 2999 if (replacement_range.IsValid() && webview()) { |
| 2948 // Select the text in |replacement_range|, it will then be replaced by | 3000 // Select the text in |replacement_range|, it will then be replaced by |
| 2949 // text added by the call to RenderWidget::OnImeConfirmComposition(). | 3001 // text added by the call to RenderWidget::OnImeConfirmComposition(). |
| 2950 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) { | 3002 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) { |
| 2951 WebRange webrange = WebRange::fromDocumentRange( | 3003 WebRange webrange = WebRange::fromDocumentRange( |
| 2952 frame, replacement_range.start(), replacement_range.length()); | 3004 frame, replacement_range.start(), replacement_range.length()); |
| 2953 if (!webrange.isNull()) | 3005 if (!webrange.isNull()) |
| 2954 frame->selectRange(webrange); | 3006 frame->selectRange(webrange); |
| 2955 } | 3007 } |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3453 if (IsUseZoomForDSFEnabled()) { | 3505 if (IsUseZoomForDSFEnabled()) { |
| 3454 webview()->setZoomFactorForDeviceScaleFactor(device_scale_factor_); | 3506 webview()->setZoomFactorForDeviceScaleFactor(device_scale_factor_); |
| 3455 } else { | 3507 } else { |
| 3456 webview()->setDeviceScaleFactor(device_scale_factor_); | 3508 webview()->setDeviceScaleFactor(device_scale_factor_); |
| 3457 } | 3509 } |
| 3458 webview()->settings()->setPreferCompositingToLCDTextEnabled( | 3510 webview()->settings()->setPreferCompositingToLCDTextEnabled( |
| 3459 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); | 3511 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); |
| 3460 } | 3512 } |
| 3461 | 3513 |
| 3462 } // namespace content | 3514 } // namespace content |
| OLD | NEW |