Chromium Code Reviews| 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 2714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2725 } | 2725 } |
| 2726 | 2726 |
| 2727 void RenderViewImpl::SetFocus(bool enable) { | 2727 void RenderViewImpl::SetFocus(bool enable) { |
| 2728 RenderWidget::OnSetFocus(enable); | 2728 RenderWidget::OnSetFocus(enable); |
| 2729 | 2729 |
| 2730 // Notify all BrowserPlugins of the RenderView's focus state. | 2730 // Notify all BrowserPlugins of the RenderView's focus state. |
| 2731 if (BrowserPluginManager::Get()) | 2731 if (BrowserPluginManager::Get()) |
| 2732 BrowserPluginManager::Get()->UpdateFocusState(); | 2732 BrowserPluginManager::Get()->UpdateFocusState(); |
| 2733 } | 2733 } |
| 2734 | 2734 |
| 2735 void RenderViewImpl::OnImeSetComposition( | |
| 2736 const base::string16& text, | |
| 2737 const std::vector<blink::WebCompositionUnderline>& underlines, | |
| 2738 const gfx::Range& replacement_range, | |
| 2739 int selection_start, | |
| 2740 int selection_end) { | |
| 2741 #if defined(ENABLE_PLUGINS) | |
| 2742 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2743 if (focused_pepper_plugin) { | |
| 2744 focused_pepper_plugin->render_frame()->OnImeSetComposition( | |
| 2745 text, underlines, selection_start, selection_end); | |
| 2746 return; | |
| 2747 } | |
| 2748 #endif // ENABLE_PLUGINS | |
| 2749 if (replacement_range.IsValid() && webview()) { | |
| 2750 // Select the text in |replacement_range|, it will then be replaced by | |
| 2751 // text added by the call to RenderWidget::OnImeSetComposition(). | |
| 2752 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) { | |
| 2753 WebRange webrange = WebRange::fromDocumentRange( | |
| 2754 frame, replacement_range.start(), replacement_range.length()); | |
| 2755 if (!webrange.isNull()) | |
| 2756 frame->selectRange(webrange); | |
| 2757 } | |
| 2758 } | |
| 2759 RenderWidget::OnImeSetComposition(text, | |
| 2760 underlines, | |
| 2761 replacement_range, | |
| 2762 selection_start, | |
| 2763 selection_end); | |
| 2764 } | |
| 2765 | |
| 2766 void RenderViewImpl::OnImeConfirmComposition( | |
| 2767 const base::string16& text, | |
| 2768 const gfx::Range& replacement_range, | |
| 2769 bool keep_selection) { | |
| 2770 #if defined(ENABLE_PLUGINS) | |
| 2771 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2772 if (focused_pepper_plugin) { | |
| 2773 focused_pepper_plugin->render_frame()->OnImeConfirmComposition( | |
| 2774 text, replacement_range, keep_selection); | |
| 2775 return; | |
| 2776 } | |
| 2777 #endif // ENABLE_PLUGINS | |
| 2778 if (replacement_range.IsValid() && webview()) { | |
| 2779 // Select the text in |replacement_range|, it will then be replaced by | |
| 2780 // text added by the call to RenderWidget::OnImeConfirmComposition(). | |
| 2781 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) { | |
| 2782 WebRange webrange = WebRange::fromDocumentRange( | |
| 2783 frame, replacement_range.start(), replacement_range.length()); | |
| 2784 if (!webrange.isNull()) | |
| 2785 frame->selectRange(webrange); | |
| 2786 } | |
| 2787 } | |
| 2788 RenderWidget::OnImeConfirmComposition(text, | |
| 2789 replacement_range, | |
| 2790 keep_selection); | |
| 2791 } | |
| 2792 | |
| 2793 void RenderViewImpl::RenderWidgetDidSetColorProfile( | 2735 void RenderViewImpl::RenderWidgetDidSetColorProfile( |
| 2794 const std::vector<char>& profile) { | 2736 const std::vector<char>& profile) { |
| 2795 if (webview()) { | 2737 if (webview()) { |
| 2796 bool was_reset = (profile.size() == 1 && profile[0] == '0'); | 2738 bool was_reset = (profile.size() == 1 && profile[0] == '0'); |
| 2797 | 2739 |
| 2798 if (was_reset) { | 2740 if (was_reset) { |
| 2799 webview()->resetDeviceColorProfileForTesting(); | 2741 webview()->resetDeviceColorProfileForTesting(); |
| 2800 } else { | 2742 } else { |
| 2801 WebVector<char> colorProfile = profile; | 2743 WebVector<char> colorProfile = profile; |
| 2802 webview()->setDeviceColorProfile(colorProfile); | 2744 webview()->setDeviceColorProfile(colorProfile); |
| 2803 } | 2745 } |
| 2804 } | 2746 } |
| 2805 } | 2747 } |
| 2806 | 2748 |
| 2807 ui::TextInputType RenderViewImpl::GetTextInputType() { | |
| 2808 #if defined(ENABLE_PLUGINS) | |
| 2809 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2810 if (focused_pepper_plugin) | |
| 2811 return focused_pepper_plugin->text_input_type(); | |
| 2812 #endif | |
| 2813 return RenderWidget::GetTextInputType(); | |
| 2814 } | |
| 2815 | |
| 2816 void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { | |
| 2817 #if defined(ENABLE_PLUGINS) | |
| 2818 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2819 if (focused_pepper_plugin) { | |
| 2820 // TODO(kinaba) http://crbug.com/101101 | |
| 2821 // Current Pepper IME API does not handle selection bounds. So we simply | |
| 2822 // use the caret position as an empty range for now. It will be updated | |
| 2823 // after Pepper API equips features related to surrounding text retrieval. | |
| 2824 blink::WebRect caret(focused_pepper_plugin->GetCaretBounds()); | |
| 2825 ConvertViewportToWindowViaWidget(&caret); | |
| 2826 *start = caret; | |
| 2827 *end = caret; | |
| 2828 return; | |
| 2829 } | |
| 2830 #endif | |
| 2831 RenderWidget::GetSelectionBounds(start, end); | |
| 2832 } | |
| 2833 | |
| 2834 void RenderViewImpl::GetCompositionCharacterBounds( | |
| 2835 std::vector<gfx::Rect>* bounds_in_window) { | |
| 2836 DCHECK(bounds_in_window); | |
| 2837 bounds_in_window->clear(); | |
| 2838 | |
| 2839 #if defined(ENABLE_PLUGINS) | |
| 2840 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2841 if (focused_pepper_plugin) | |
| 2842 return; | |
| 2843 #endif | |
| 2844 | |
| 2845 if (!webview()) | |
| 2846 return; | |
| 2847 size_t start_offset = 0; | |
| 2848 size_t character_count = 0; | |
| 2849 if (!webview()->compositionRange(&start_offset, &character_count)) | |
| 2850 return; | |
| 2851 if (character_count == 0) | |
| 2852 return; | |
| 2853 | |
| 2854 blink::WebFrame* frame = webview()->focusedFrame(); | |
| 2855 if (!frame) | |
| 2856 return; | |
| 2857 | |
| 2858 bounds_in_window->reserve(character_count); | |
| 2859 blink::WebRect webrect; | |
| 2860 for (size_t i = 0; i < character_count; ++i) { | |
| 2861 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) { | |
| 2862 DLOG(ERROR) << "Could not retrieve character rectangle at " << i; | |
| 2863 bounds_in_window->clear(); | |
| 2864 return; | |
| 2865 } | |
| 2866 ConvertViewportToWindowViaWidget(&webrect); | |
| 2867 bounds_in_window->push_back(webrect); | |
| 2868 } | |
| 2869 } | |
| 2870 | |
| 2871 void RenderViewImpl::GetCompositionRange(gfx::Range* range) { | |
| 2872 #if defined(ENABLE_PLUGINS) | |
| 2873 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2874 if (focused_pepper_plugin) | |
| 2875 return; | |
| 2876 #endif | |
| 2877 RenderWidget::GetCompositionRange(range); | |
| 2878 } | |
| 2879 | |
| 2880 bool RenderViewImpl::CanComposeInline() { | |
| 2881 #if defined(ENABLE_PLUGINS) | |
| 2882 PepperPluginInstanceImpl* focused_pepper_plugin = GetFocusedPepperPlugin(); | |
| 2883 if (focused_pepper_plugin) | |
| 2884 return focused_pepper_plugin->IsPluginAcceptingCompositionEvents(); | |
| 2885 #endif | |
| 2886 return true; | |
| 2887 } | |
| 2888 | |
| 2889 void RenderViewImpl::DidCompletePageScaleAnimation() { | 2749 void RenderViewImpl::DidCompletePageScaleAnimation() { |
| 2890 GetWidget()->FocusChangeComplete(); | 2750 GetWidget()->FocusChangeComplete(); |
| 2891 } | 2751 } |
| 2892 | 2752 |
| 2893 void RenderViewImpl::OnDeviceScaleFactorChanged() { | 2753 void RenderViewImpl::OnDeviceScaleFactorChanged() { |
| 2894 RenderWidget::OnDeviceScaleFactorChanged(); | 2754 RenderWidget::OnDeviceScaleFactorChanged(); |
| 2895 UpdateWebViewWithDeviceScaleFactor(); | 2755 UpdateWebViewWithDeviceScaleFactor(); |
| 2896 if (auto_resize_mode_) | 2756 if (auto_resize_mode_) |
| 2897 AutoResizeCompositor(); | 2757 AutoResizeCompositor(); |
| 2898 } | 2758 } |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3249 if (IsUseZoomForDSFEnabled()) { | 3109 if (IsUseZoomForDSFEnabled()) { |
| 3250 webview()->setZoomFactorForDeviceScaleFactor(device_scale_factor_); | 3110 webview()->setZoomFactorForDeviceScaleFactor(device_scale_factor_); |
| 3251 } else { | 3111 } else { |
| 3252 webview()->setDeviceScaleFactor(device_scale_factor_); | 3112 webview()->setDeviceScaleFactor(device_scale_factor_); |
| 3253 } | 3113 } |
| 3254 webview()->settings()->setPreferCompositingToLCDTextEnabled( | 3114 webview()->settings()->setPreferCompositingToLCDTextEnabled( |
| 3255 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); | 3115 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); |
| 3256 } | 3116 } |
| 3257 | 3117 |
| 3258 #if defined(ENABLE_PLUGINS) | 3118 #if defined(ENABLE_PLUGINS) |
| 3259 PepperPluginInstanceImpl* RenderViewImpl::GetFocusedPepperPlugin() { | 3119 PepperPluginInstanceImpl* RenderViewImpl::GetFocusedPepperPlugin() { |
|
lfg
2016/07/05 18:30:46
Is this still needed?
EhsanK
2016/07/07 14:40:47
I think it will be really nice to not have this. B
| |
| 3260 blink::WebFrame* frame = GetWebView()->mainFrame(); | 3120 blink::WebFrame* frame = GetWebView()->mainFrame(); |
| 3261 | 3121 |
| 3262 while (frame) { | 3122 while (frame) { |
| 3263 if (frame->isWebLocalFrame()) { | 3123 if (frame->isWebLocalFrame()) { |
| 3264 RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(frame); | 3124 RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(frame); |
| 3265 if (render_frame->focused_pepper_plugin()) | 3125 if (render_frame->focused_pepper_plugin()) |
| 3266 return render_frame->focused_pepper_plugin(); | 3126 return render_frame->focused_pepper_plugin(); |
| 3267 } | 3127 } |
| 3268 frame = frame->traverseNext(false); | 3128 frame = frame->traverseNext(false); |
| 3269 } | 3129 } |
| 3270 | 3130 |
| 3271 return nullptr; | 3131 return nullptr; |
| 3272 } | 3132 } |
| 3273 #endif | 3133 #endif |
| 3274 | 3134 |
| 3275 } // namespace content | 3135 } // namespace content |
| OLD | NEW |