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