| 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 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 2818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2829 } | 2829 } |
| 2830 | 2830 |
| 2831 void RenderViewImpl::SetFocus(bool enable) { | 2831 void RenderViewImpl::SetFocus(bool enable) { |
| 2832 RenderWidget::OnSetFocus(enable); | 2832 RenderWidget::OnSetFocus(enable); |
| 2833 | 2833 |
| 2834 // Notify all BrowserPlugins of the RenderView's focus state. | 2834 // Notify all BrowserPlugins of the RenderView's focus state. |
| 2835 if (BrowserPluginManager::Get()) | 2835 if (BrowserPluginManager::Get()) |
| 2836 BrowserPluginManager::Get()->UpdateFocusState(); | 2836 BrowserPluginManager::Get()->UpdateFocusState(); |
| 2837 } | 2837 } |
| 2838 | 2838 |
| 2839 void RenderViewImpl::OnImeSetComposition( | |
| 2840 const base::string16& text, | |
| 2841 const std::vector<blink::WebCompositionUnderline>& underlines, | |
| 2842 const gfx::Range& replacement_range, | |
| 2843 int selection_start, | |
| 2844 int selection_end) { | |
| 2845 #if defined(ENABLE_PLUGINS) | |
| 2846 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2847 if (focused_pepper_plugin) { | |
| 2848 focused_pepper_plugin->render_frame()->OnImeSetComposition( | |
| 2849 text, underlines, selection_start, selection_end); | |
| 2850 return; | |
| 2851 } | |
| 2852 #endif // ENABLE_PLUGINS | |
| 2853 if (replacement_range.IsValid() && webview()) { | |
| 2854 // Select the text in |replacement_range|, it will then be replaced by | |
| 2855 // text added by the call to RenderWidget::OnImeSetComposition(). | |
| 2856 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) { | |
| 2857 WebRange webrange = WebRange::fromDocumentRange( | |
| 2858 frame, replacement_range.start(), replacement_range.length()); | |
| 2859 if (!webrange.isNull()) | |
| 2860 frame->selectRange(webrange); | |
| 2861 } | |
| 2862 } | |
| 2863 RenderWidget::OnImeSetComposition(text, | |
| 2864 underlines, | |
| 2865 replacement_range, | |
| 2866 selection_start, | |
| 2867 selection_end); | |
| 2868 } | |
| 2869 | |
| 2870 void RenderViewImpl::OnImeConfirmComposition( | |
| 2871 const base::string16& text, | |
| 2872 const gfx::Range& replacement_range, | |
| 2873 bool keep_selection) { | |
| 2874 #if defined(ENABLE_PLUGINS) | |
| 2875 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2876 if (focused_pepper_plugin) { | |
| 2877 focused_pepper_plugin->render_frame()->OnImeConfirmComposition( | |
| 2878 text, replacement_range, keep_selection); | |
| 2879 return; | |
| 2880 } | |
| 2881 #endif // ENABLE_PLUGINS | |
| 2882 if (replacement_range.IsValid() && webview()) { | |
| 2883 // Select the text in |replacement_range|, it will then be replaced by | |
| 2884 // text added by the call to RenderWidget::OnImeConfirmComposition(). | |
| 2885 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) { | |
| 2886 WebRange webrange = WebRange::fromDocumentRange( | |
| 2887 frame, replacement_range.start(), replacement_range.length()); | |
| 2888 if (!webrange.isNull()) | |
| 2889 frame->selectRange(webrange); | |
| 2890 } | |
| 2891 } | |
| 2892 RenderWidget::OnImeConfirmComposition(text, | |
| 2893 replacement_range, | |
| 2894 keep_selection); | |
| 2895 } | |
| 2896 | |
| 2897 void RenderViewImpl::RenderWidgetDidSetColorProfile( | 2839 void RenderViewImpl::RenderWidgetDidSetColorProfile( |
| 2898 const std::vector<char>& profile) { | 2840 const std::vector<char>& profile) { |
| 2899 if (webview()) { | 2841 if (webview()) { |
| 2900 bool was_reset = (profile.size() == 1 && profile[0] == '0'); | 2842 bool was_reset = (profile.size() == 1 && profile[0] == '0'); |
| 2901 | 2843 |
| 2902 if (was_reset) { | 2844 if (was_reset) { |
| 2903 webview()->resetDeviceColorProfileForTesting(); | 2845 webview()->resetDeviceColorProfileForTesting(); |
| 2904 } else { | 2846 } else { |
| 2905 WebVector<char> colorProfile = profile; | 2847 WebVector<char> colorProfile = profile; |
| 2906 webview()->setDeviceColorProfile(colorProfile); | 2848 webview()->setDeviceColorProfile(colorProfile); |
| 2907 } | 2849 } |
| 2908 } | 2850 } |
| 2909 } | 2851 } |
| 2910 | 2852 |
| 2911 ui::TextInputType RenderViewImpl::GetTextInputType() { | |
| 2912 #if defined(ENABLE_PLUGINS) | |
| 2913 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2914 if (focused_pepper_plugin) | |
| 2915 return focused_pepper_plugin->text_input_type(); | |
| 2916 #endif | |
| 2917 return RenderWidget::GetTextInputType(); | |
| 2918 } | |
| 2919 | |
| 2920 void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { | |
| 2921 #if defined(ENABLE_PLUGINS) | |
| 2922 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2923 if (focused_pepper_plugin) { | |
| 2924 // TODO(kinaba) http://crbug.com/101101 | |
| 2925 // Current Pepper IME API does not handle selection bounds. So we simply | |
| 2926 // use the caret position as an empty range for now. It will be updated | |
| 2927 // after Pepper API equips features related to surrounding text retrieval. | |
| 2928 blink::WebRect caret(focused_pepper_plugin->GetCaretBounds()); | |
| 2929 ConvertViewportToWindowViaWidget(&caret); | |
| 2930 *start = caret; | |
| 2931 *end = caret; | |
| 2932 return; | |
| 2933 } | |
| 2934 #endif | |
| 2935 RenderWidget::GetSelectionBounds(start, end); | |
| 2936 } | |
| 2937 | |
| 2938 void RenderViewImpl::GetCompositionCharacterBounds( | |
| 2939 std::vector<gfx::Rect>* bounds_in_window) { | |
| 2940 DCHECK(bounds_in_window); | |
| 2941 bounds_in_window->clear(); | |
| 2942 | |
| 2943 #if defined(ENABLE_PLUGINS) | |
| 2944 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2945 if (focused_pepper_plugin) | |
| 2946 return; | |
| 2947 #endif | |
| 2948 | |
| 2949 if (!webview()) | |
| 2950 return; | |
| 2951 size_t start_offset = 0; | |
| 2952 size_t character_count = 0; | |
| 2953 if (!webview()->compositionRange(&start_offset, &character_count)) | |
| 2954 return; | |
| 2955 if (character_count == 0) | |
| 2956 return; | |
| 2957 | |
| 2958 blink::WebFrame* frame = webview()->focusedFrame(); | |
| 2959 if (!frame) | |
| 2960 return; | |
| 2961 | |
| 2962 bounds_in_window->reserve(character_count); | |
| 2963 blink::WebRect webrect; | |
| 2964 for (size_t i = 0; i < character_count; ++i) { | |
| 2965 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) { | |
| 2966 DLOG(ERROR) << "Could not retrieve character rectangle at " << i; | |
| 2967 bounds_in_window->clear(); | |
| 2968 return; | |
| 2969 } | |
| 2970 ConvertViewportToWindowViaWidget(&webrect); | |
| 2971 bounds_in_window->push_back(webrect); | |
| 2972 } | |
| 2973 } | |
| 2974 | |
| 2975 void RenderViewImpl::GetCompositionRange(gfx::Range* range) { | |
| 2976 #if defined(ENABLE_PLUGINS) | |
| 2977 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2978 if (focused_pepper_plugin) | |
| 2979 return; | |
| 2980 #endif | |
| 2981 RenderWidget::GetCompositionRange(range); | |
| 2982 } | |
| 2983 | |
| 2984 bool RenderViewImpl::CanComposeInline() { | |
| 2985 #if defined(ENABLE_PLUGINS) | |
| 2986 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2987 if (focused_pepper_plugin) | |
| 2988 return focused_pepper_plugin->IsPluginAcceptingCompositionEvents(); | |
| 2989 #endif | |
| 2990 return true; | |
| 2991 } | |
| 2992 | |
| 2993 void RenderViewImpl::DidCompletePageScaleAnimation() { | 2853 void RenderViewImpl::DidCompletePageScaleAnimation() { |
| 2994 GetWidget()->FocusChangeComplete(); | 2854 GetWidget()->FocusChangeComplete(); |
| 2995 } | 2855 } |
| 2996 | 2856 |
| 2997 void RenderViewImpl::OnDeviceScaleFactorChanged() { | 2857 void RenderViewImpl::OnDeviceScaleFactorChanged() { |
| 2998 RenderWidget::OnDeviceScaleFactorChanged(); | 2858 RenderWidget::OnDeviceScaleFactorChanged(); |
| 2999 UpdateWebViewWithDeviceScaleFactor(); | 2859 UpdateWebViewWithDeviceScaleFactor(); |
| 3000 if (auto_resize_mode_) | 2860 if (auto_resize_mode_) |
| 3001 AutoResizeCompositor(); | 2861 AutoResizeCompositor(); |
| 3002 } | 2862 } |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3395 return render_frame->focused_pepper_plugin(); | 3255 return render_frame->focused_pepper_plugin(); |
| 3396 } | 3256 } |
| 3397 frame = frame->traverseNext(false); | 3257 frame = frame->traverseNext(false); |
| 3398 } | 3258 } |
| 3399 | 3259 |
| 3400 return nullptr; | 3260 return nullptr; |
| 3401 } | 3261 } |
| 3402 #endif | 3262 #endif |
| 3403 | 3263 |
| 3404 } // namespace content | 3264 } // namespace content |
| OLD | NEW |