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 3588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3599 | 3599 |
3600 Send(new ViewHostMsg_UpdateState( | 3600 Send(new ViewHostMsg_UpdateState( |
3601 routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); | 3601 routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
3602 } | 3602 } |
3603 | 3603 |
3604 void RenderViewImpl::SyncSelectionIfRequired() { | 3604 void RenderViewImpl::SyncSelectionIfRequired() { |
3605 WebFrame* frame = webview()->focusedFrame(); | 3605 WebFrame* frame = webview()->focusedFrame(); |
3606 if (!frame) | 3606 if (!frame) |
3607 return; | 3607 return; |
3608 | 3608 |
3609 size_t location, length; | |
3610 if (!webview()->caretOrSelectionRange(&location, &length)) | |
3611 return; | |
3612 | |
3613 string16 text; | 3609 string16 text; |
3614 size_t offset; | 3610 size_t offset; |
3615 ui::Range range(location, location + length); | 3611 ui::Range range; |
3616 | 3612 |
3617 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) { | 3613 if (pepper_delegate_.IsPluginFocused()) { |
3618 // If current focused element is editable, we will send 100 more chars | 3614 pepper_delegate_.GetSurroundingText(&text, &range); |
3619 // before and after selection. It is for input method surrounding text | 3615 offset = 0; // Pepper API does not support offset reporting. |
3620 // feature. | 3616 // TODO(kinaba): cut as needed. |
3621 if (location > kExtraCharsBeforeAndAfterSelection) | |
3622 offset = location - kExtraCharsBeforeAndAfterSelection; | |
3623 else | |
3624 offset = 0; | |
3625 length = location + length - offset + kExtraCharsBeforeAndAfterSelection; | |
3626 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length); | |
3627 if (!webrange.isNull()) | |
3628 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText(); | |
3629 } else { | 3617 } else { |
3630 offset = location; | 3618 size_t location, length; |
3631 text = frame->selectionAsText(); | 3619 if (!webview()->caretOrSelectionRange(&location, &length)) |
3632 // http://crbug.com/101435 | 3620 return; |
3633 // In some case, frame->selectionAsText() returned text's length is not | 3621 |
3634 // equal to the length returned from webview()->caretOrSelectionRange(). | 3622 range = ui::Range(location, location + length); |
3635 // So we have to set the range according to text.length(). | 3623 |
3636 range.set_end(range.start() + text.length()); | 3624 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) { |
| 3625 // If current focused element is editable, we will send 100 more chars |
| 3626 // before and after selection. It is for input method surrounding text |
| 3627 // feature. |
| 3628 if (location > kExtraCharsBeforeAndAfterSelection) |
| 3629 offset = location - kExtraCharsBeforeAndAfterSelection; |
| 3630 else |
| 3631 offset = 0; |
| 3632 length = location + length - offset + kExtraCharsBeforeAndAfterSelection; |
| 3633 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length); |
| 3634 if (!webrange.isNull()) |
| 3635 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText(); |
| 3636 } else { |
| 3637 offset = location; |
| 3638 text = frame->selectionAsText(); |
| 3639 // http://crbug.com/101435 |
| 3640 // In some case, frame->selectionAsText() returned text's length is not |
| 3641 // equal to the length returned from webview()->caretOrSelectionRange(). |
| 3642 // So we have to set the range according to text.length(). |
| 3643 range.set_end(range.start() + text.length()); |
| 3644 } |
3637 } | 3645 } |
3638 | 3646 |
3639 // Sometimes we get repeated didChangeSelection calls from webkit when | 3647 // Sometimes we get repeated didChangeSelection calls from webkit when |
3640 // the selection hasn't actually changed. We don't want to report these | 3648 // the selection hasn't actually changed. We don't want to report these |
3641 // because it will cause us to continually claim the X clipboard. | 3649 // because it will cause us to continually claim the X clipboard. |
3642 if (selection_text_offset_ != offset || | 3650 if (selection_text_offset_ != offset || |
3643 selection_range_ != range || | 3651 selection_range_ != range || |
3644 selection_text_ != text) { | 3652 selection_text_ != text) { |
3645 selection_text_ = text; | 3653 selection_text_ = text; |
3646 selection_text_offset_ = offset; | 3654 selection_text_offset_ = offset; |
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4682 *rect = pepper_delegate_.GetCaretBounds(); | 4690 *rect = pepper_delegate_.GetCaretBounds(); |
4683 return true; | 4691 return true; |
4684 } | 4692 } |
4685 | 4693 |
4686 void RenderViewImpl::PpapiPluginCancelComposition() { | 4694 void RenderViewImpl::PpapiPluginCancelComposition() { |
4687 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); | 4695 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
4688 ui::Range range(ui::Range::InvalidRange()); | 4696 ui::Range range(ui::Range::InvalidRange()); |
4689 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range)); | 4697 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range)); |
4690 } | 4698 } |
4691 | 4699 |
| 4700 void RenderViewImpl::PpapiPluginSelectionChanged() { |
| 4701 SyncSelectionIfRequired(); |
| 4702 } |
| 4703 |
4692 void RenderViewImpl::OnImeSetComposition( | 4704 void RenderViewImpl::OnImeSetComposition( |
4693 const string16& text, | 4705 const string16& text, |
4694 const std::vector<WebKit::WebCompositionUnderline>& underlines, | 4706 const std::vector<WebKit::WebCompositionUnderline>& underlines, |
4695 int selection_start, | 4707 int selection_start, |
4696 int selection_end) { | 4708 int selection_end) { |
4697 if (pepper_delegate_.IsPluginFocused()) { | 4709 if (pepper_delegate_.IsPluginFocused()) { |
4698 // When a PPAPI plugin has focus, we bypass WebKit. | 4710 // When a PPAPI plugin has focus, we bypass WebKit. |
4699 pepper_delegate_.OnImeSetComposition(text, | 4711 pepper_delegate_.OnImeSetComposition(text, |
4700 underlines, | 4712 underlines, |
4701 selection_start, | 4713 selection_start, |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5086 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { | 5098 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
5087 return !!RenderThreadImpl::current()->compositor_thread(); | 5099 return !!RenderThreadImpl::current()->compositor_thread(); |
5088 } | 5100 } |
5089 | 5101 |
5090 void RenderViewImpl::OnJavaBridgeInit() { | 5102 void RenderViewImpl::OnJavaBridgeInit() { |
5091 DCHECK(!java_bridge_dispatcher_.get()); | 5103 DCHECK(!java_bridge_dispatcher_.get()); |
5092 #if defined(ENABLE_JAVA_BRIDGE) | 5104 #if defined(ENABLE_JAVA_BRIDGE) |
5093 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); | 5105 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); |
5094 #endif | 5106 #endif |
5095 } | 5107 } |
OLD | NEW |