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