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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 3618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3629 | 3629 |
3630 Send(new ViewHostMsg_UpdateState( | 3630 Send(new ViewHostMsg_UpdateState( |
3631 routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); | 3631 routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
3632 } | 3632 } |
3633 | 3633 |
3634 void RenderViewImpl::SyncSelectionIfRequired() { | 3634 void RenderViewImpl::SyncSelectionIfRequired() { |
3635 WebFrame* frame = webview()->focusedFrame(); | 3635 WebFrame* frame = webview()->focusedFrame(); |
3636 if (!frame) | 3636 if (!frame) |
3637 return; | 3637 return; |
3638 | 3638 |
3639 size_t location, length; | |
3640 if (!webview()->caretOrSelectionRange(&location, &length)) | |
3641 return; | |
3642 | |
3643 string16 text; | 3639 string16 text; |
3644 size_t offset; | 3640 size_t offset; |
3645 ui::Range range(location, location + length); | 3641 ui::Range range; |
3646 | 3642 |
3647 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) { | 3643 if (pepper_delegate_.IsPluginFocused()) { |
3648 // If current focused element is editable, we will send 100 more chars | 3644 pepper_delegate_.GetSurroundingText(&text, &range); |
3649 // before and after selection. It is for input method surrounding text | 3645 offset = 0; // Pepper API does not support offset reporting. |
3650 // feature. | 3646 // TODO(kinaba): cut as needed. |
3651 if (location > kExtraCharsBeforeAndAfterSelection) | |
3652 offset = location - kExtraCharsBeforeAndAfterSelection; | |
3653 else | |
3654 offset = 0; | |
3655 length = location + length - offset + kExtraCharsBeforeAndAfterSelection; | |
3656 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length); | |
3657 if (!webrange.isNull()) | |
3658 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText(); | |
3659 } else { | 3647 } else { |
3660 offset = location; | 3648 size_t location, length; |
3661 text = frame->selectionAsText(); | 3649 if (!webview()->caretOrSelectionRange(&location, &length)) |
3662 // http://crbug.com/101435 | 3650 return; |
3663 // In some case, frame->selectionAsText() returned text's length is not | 3651 |
3664 // equal to the length returned from webview()->caretOrSelectionRange(). | 3652 range = ui::Range(location, location + length); |
3665 // So we have to set the range according to text.length(). | 3653 |
3666 range.set_end(range.start() + text.length()); | 3654 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) { |
| 3655 // If current focused element is editable, we will send 100 more chars |
| 3656 // before and after selection. It is for input method surrounding text |
| 3657 // feature. |
| 3658 if (location > kExtraCharsBeforeAndAfterSelection) |
| 3659 offset = location - kExtraCharsBeforeAndAfterSelection; |
| 3660 else |
| 3661 offset = 0; |
| 3662 length = location + length - offset + kExtraCharsBeforeAndAfterSelection; |
| 3663 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length); |
| 3664 if (!webrange.isNull()) |
| 3665 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText(); |
| 3666 } else { |
| 3667 offset = location; |
| 3668 text = frame->selectionAsText(); |
| 3669 // http://crbug.com/101435 |
| 3670 // In some case, frame->selectionAsText() returned text's length is not |
| 3671 // equal to the length returned from webview()->caretOrSelectionRange(). |
| 3672 // So we have to set the range according to text.length(). |
| 3673 range.set_end(range.start() + text.length()); |
| 3674 } |
3667 } | 3675 } |
3668 | 3676 |
3669 // Sometimes we get repeated didChangeSelection calls from webkit when | 3677 // Sometimes we get repeated didChangeSelection calls from webkit when |
3670 // the selection hasn't actually changed. We don't want to report these | 3678 // the selection hasn't actually changed. We don't want to report these |
3671 // because it will cause us to continually claim the X clipboard. | 3679 // because it will cause us to continually claim the X clipboard. |
3672 if (selection_text_offset_ != offset || | 3680 if (selection_text_offset_ != offset || |
3673 selection_range_ != range || | 3681 selection_range_ != range || |
3674 selection_text_ != text) { | 3682 selection_text_ != text) { |
3675 selection_text_ = text; | 3683 selection_text_ = text; |
3676 selection_text_offset_ = offset; | 3684 selection_text_offset_ = offset; |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4739 *rect = pepper_delegate_.GetCaretBounds(); | 4747 *rect = pepper_delegate_.GetCaretBounds(); |
4740 return true; | 4748 return true; |
4741 } | 4749 } |
4742 | 4750 |
4743 void RenderViewImpl::PpapiPluginCancelComposition() { | 4751 void RenderViewImpl::PpapiPluginCancelComposition() { |
4744 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); | 4752 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
4745 ui::Range range(ui::Range::InvalidRange()); | 4753 ui::Range range(ui::Range::InvalidRange()); |
4746 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range)); | 4754 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range)); |
4747 } | 4755 } |
4748 | 4756 |
| 4757 void RenderViewImpl::PpapiPluginSelectionChanged() { |
| 4758 SyncSelectionIfRequired(); |
| 4759 } |
| 4760 |
4749 void RenderViewImpl::OnImeSetComposition( | 4761 void RenderViewImpl::OnImeSetComposition( |
4750 const string16& text, | 4762 const string16& text, |
4751 const std::vector<WebKit::WebCompositionUnderline>& underlines, | 4763 const std::vector<WebKit::WebCompositionUnderline>& underlines, |
4752 int selection_start, | 4764 int selection_start, |
4753 int selection_end) { | 4765 int selection_end) { |
4754 if (pepper_delegate_.IsPluginFocused()) { | 4766 if (pepper_delegate_.IsPluginFocused()) { |
4755 // When a PPAPI plugin has focus, we bypass WebKit. | 4767 // When a PPAPI plugin has focus, we bypass WebKit. |
4756 pepper_delegate_.OnImeSetComposition(text, | 4768 pepper_delegate_.OnImeSetComposition(text, |
4757 underlines, | 4769 underlines, |
4758 selection_start, | 4770 selection_start, |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5144 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { | 5156 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
5145 return !!RenderThreadImpl::current()->compositor_thread(); | 5157 return !!RenderThreadImpl::current()->compositor_thread(); |
5146 } | 5158 } |
5147 | 5159 |
5148 void RenderViewImpl::OnJavaBridgeInit() { | 5160 void RenderViewImpl::OnJavaBridgeInit() { |
5149 DCHECK(!java_bridge_dispatcher_.get()); | 5161 DCHECK(!java_bridge_dispatcher_.get()); |
5150 #if defined(ENABLE_JAVA_BRIDGE) | 5162 #if defined(ENABLE_JAVA_BRIDGE) |
5151 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); | 5163 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); |
5152 #endif | 5164 #endif |
5153 } | 5165 } |
OLD | NEW |