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

Side by Side Diff: content/renderer/render_view_impl.cc

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

Powered by Google App Engine
This is Rietveld 408576698