| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 2005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2016 // This IPC is dispatched by RenderWidgetHost, so use its routing id. | 2016 // This IPC is dispatched by RenderWidgetHost, so use its routing id. |
| 2017 Send(new InputHostMsg_SelectRange_ACK(GetRenderWidget()->routing_id())); | 2017 Send(new InputHostMsg_SelectRange_ACK(GetRenderWidget()->routing_id())); |
| 2018 | 2018 |
| 2019 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 2019 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 2020 frame_->SelectRange(render_view_->ConvertWindowPointToViewport(base), | 2020 frame_->SelectRange(render_view_->ConvertWindowPointToViewport(base), |
| 2021 render_view_->ConvertWindowPointToViewport(extent)); | 2021 render_view_->ConvertWindowPointToViewport(extent)); |
| 2022 } | 2022 } |
| 2023 | 2023 |
| 2024 void RenderFrameImpl::OnAdjustSelectionByCharacterOffset(int start_adjust, | 2024 void RenderFrameImpl::OnAdjustSelectionByCharacterOffset(int start_adjust, |
| 2025 int end_adjust) { | 2025 int end_adjust) { |
| 2026 WebRange range = GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); | 2026 WebRange range = frame_->GetInputMethodController()->GetSelectionOffsets(); |
| 2027 if (range.IsNull()) | 2027 if (range.IsNull()) |
| 2028 return; | 2028 return; |
| 2029 | 2029 |
| 2030 // Sanity checks to disallow empty and out of range selections. | 2030 // Sanity checks to disallow empty and out of range selections. |
| 2031 if (start_adjust - end_adjust > range.length() || | 2031 if (start_adjust - end_adjust > range.length() || |
| 2032 range.StartOffset() + start_adjust < 0) | 2032 range.StartOffset() + start_adjust < 0) |
| 2033 return; | 2033 return; |
| 2034 | 2034 |
| 2035 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 2035 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 2036 | 2036 |
| 2037 // A negative adjust amount moves the selection towards the beginning of | 2037 // A negative adjust amount moves the selection towards the beginning of |
| 2038 // the document, a positive amount moves the selection towards the end of | 2038 // the document, a positive amount moves the selection towards the end of |
| 2039 // the document. | 2039 // the document. |
| 2040 frame_->SelectRange(WebRange(range.StartOffset() + start_adjust, | 2040 frame_->SelectRange(WebRange(range.StartOffset() + start_adjust, |
| 2041 range.length() + end_adjust - start_adjust), | 2041 range.length() + end_adjust - start_adjust), |
| 2042 WebLocalFrame::kPreserveHandleVisibility); | 2042 WebLocalFrame::kPreserveHandleVisibility); |
| 2043 } | 2043 } |
| 2044 | 2044 |
| 2045 void RenderFrameImpl::OnCollapseSelection() { | 2045 void RenderFrameImpl::OnCollapseSelection() { |
| 2046 const WebRange& range = | 2046 const WebRange& range = |
| 2047 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); | 2047 frame_->GetInputMethodController()->GetSelectionOffsets(); |
| 2048 if (range.IsNull()) | 2048 if (range.IsNull()) |
| 2049 return; | 2049 return; |
| 2050 | 2050 |
| 2051 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 2051 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 2052 frame_->SelectRange(WebRange(range.EndOffset(), 0)); | 2052 frame_->SelectRange(WebRange(range.EndOffset(), 0)); |
| 2053 } | 2053 } |
| 2054 | 2054 |
| 2055 void RenderFrameImpl::OnMoveRangeSelectionExtent(const gfx::Point& point) { | 2055 void RenderFrameImpl::OnMoveRangeSelectionExtent(const gfx::Point& point) { |
| 2056 // This IPC is dispatched by RenderWidgetHost, so use its routing id. | 2056 // This IPC is dispatched by RenderWidgetHost, so use its routing id. |
| 2057 Send(new InputHostMsg_MoveRangeSelectionExtent_ACK( | 2057 Send(new InputHostMsg_MoveRangeSelectionExtent_ACK( |
| (...skipping 4330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6388 gfx::Range range; | 6388 gfx::Range range; |
| 6389 #if BUILDFLAG(ENABLE_PLUGINS) | 6389 #if BUILDFLAG(ENABLE_PLUGINS) |
| 6390 if (focused_pepper_plugin_) { | 6390 if (focused_pepper_plugin_) { |
| 6391 focused_pepper_plugin_->GetSurroundingText(&text, &range); | 6391 focused_pepper_plugin_->GetSurroundingText(&text, &range); |
| 6392 offset = 0; // Pepper API does not support offset reporting. | 6392 offset = 0; // Pepper API does not support offset reporting. |
| 6393 // TODO(kinaba): cut as needed. | 6393 // TODO(kinaba): cut as needed. |
| 6394 } else | 6394 } else |
| 6395 #endif | 6395 #endif |
| 6396 { | 6396 { |
| 6397 WebRange selection = | 6397 WebRange selection = |
| 6398 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); | 6398 frame_->GetInputMethodController()->GetSelectionOffsets(); |
| 6399 if (selection.IsNull()) | 6399 if (selection.IsNull()) |
| 6400 return; | 6400 return; |
| 6401 | 6401 |
| 6402 range = gfx::Range(selection.StartOffset(), selection.EndOffset()); | 6402 range = gfx::Range(selection.StartOffset(), selection.EndOffset()); |
| 6403 | 6403 |
| 6404 if (frame_->GetInputMethodController()->TextInputType() != | 6404 if (frame_->GetInputMethodController()->TextInputType() != |
| 6405 blink::kWebTextInputTypeNone) { | 6405 blink::kWebTextInputTypeNone) { |
| 6406 // If current focused element is editable, we will send 100 more chars | 6406 // If current focused element is editable, we will send 100 more chars |
| 6407 // before and after selection. It is for input method surrounding text | 6407 // before and after selection. It is for input method surrounding text |
| 6408 // feature. | 6408 // feature. |
| 6409 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection) | 6409 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection) |
| 6410 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection; | 6410 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection; |
| 6411 else | 6411 else |
| 6412 offset = 0; | 6412 offset = 0; |
| 6413 size_t length = | 6413 size_t length = |
| 6414 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection; | 6414 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection; |
| 6415 text = frame_->RangeAsText(WebRange(offset, length)).Utf16(); | 6415 text = frame_->RangeAsText(WebRange(offset, length)).Utf16(); |
| 6416 } else { | 6416 } else { |
| 6417 offset = selection.StartOffset(); | 6417 offset = selection.StartOffset(); |
| 6418 text = frame_->SelectionAsText().Utf16(); | 6418 text = frame_->SelectionAsText().Utf16(); |
| 6419 // http://crbug.com/101435 | 6419 // http://crbug.com/101435 |
| 6420 // In some case, frame->selectionAsText() returned text's length is not | 6420 // In some case, frame->selectionAsText() returned text's length is not |
| 6421 // equal to the length returned from | 6421 // equal to the length returned from frame_->GetSelectionOffsets(). So we |
| 6422 // GetWebWidget()->caretOrSelectionRange(). | 6422 // have to set the range according to text.length(). |
| 6423 // So we have to set the range according to text.length(). | |
| 6424 range.set_end(range.start() + text.length()); | 6423 range.set_end(range.start() + text.length()); |
| 6425 } | 6424 } |
| 6426 } | 6425 } |
| 6427 | 6426 |
| 6428 // TODO(dglazkov): Investigate if and why this would be happening, | 6427 // TODO(dglazkov): Investigate if and why this would be happening, |
| 6429 // and resolve this. We shouldn't be carrying selection text here. | 6428 // and resolve this. We shouldn't be carrying selection text here. |
| 6430 // http://crbug.com/632920. | 6429 // http://crbug.com/632920. |
| 6431 // Sometimes we get repeated didChangeSelection calls from webkit when | 6430 // Sometimes we get repeated didChangeSelection calls from webkit when |
| 6432 // the selection hasn't actually changed. We don't want to report these | 6431 // the selection hasn't actually changed. We don't want to report these |
| 6433 // because it will cause us to continually claim the X clipboard. | 6432 // because it will cause us to continually claim the X clipboard. |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7173 policy(info.default_policy), | 7172 policy(info.default_policy), |
| 7174 replaces_current_history_item(info.replaces_current_history_item), | 7173 replaces_current_history_item(info.replaces_current_history_item), |
| 7175 history_navigation_in_new_child_frame( | 7174 history_navigation_in_new_child_frame( |
| 7176 info.is_history_navigation_in_new_child_frame), | 7175 info.is_history_navigation_in_new_child_frame), |
| 7177 client_redirect(info.is_client_redirect), | 7176 client_redirect(info.is_client_redirect), |
| 7178 cache_disabled(info.is_cache_disabled), | 7177 cache_disabled(info.is_cache_disabled), |
| 7179 form(info.form), | 7178 form(info.form), |
| 7180 source_location(info.source_location) {} | 7179 source_location(info.source_location) {} |
| 7181 | 7180 |
| 7182 } // namespace content | 7181 } // namespace content |
| OLD | NEW |