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