Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 2910223003: [refactor] - Rename and Move WebWidget::CaretOrSelectionRange to WebInputMethodController::GetSelec… (Closed)
Patch Set: Rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 1959 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 // This IPC is dispatched by RenderWidgetHost, so use its routing id. 1970 // This IPC is dispatched by RenderWidgetHost, so use its routing id.
1971 Send(new InputHostMsg_SelectRange_ACK(GetRenderWidget()->routing_id())); 1971 Send(new InputHostMsg_SelectRange_ACK(GetRenderWidget()->routing_id()));
1972 1972
1973 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1973 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1974 frame_->SelectRange(render_view_->ConvertWindowPointToViewport(base), 1974 frame_->SelectRange(render_view_->ConvertWindowPointToViewport(base),
1975 render_view_->ConvertWindowPointToViewport(extent)); 1975 render_view_->ConvertWindowPointToViewport(extent));
1976 } 1976 }
1977 1977
1978 void RenderFrameImpl::OnAdjustSelectionByCharacterOffset(int start_adjust, 1978 void RenderFrameImpl::OnAdjustSelectionByCharacterOffset(int start_adjust,
1979 int end_adjust) { 1979 int end_adjust) {
1980 WebRange range = GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); 1980 WebRange range = frame_->GetInputMethodController()->GetSelectionOffsets();
1981 if (range.IsNull()) 1981 if (range.IsNull())
1982 return; 1982 return;
1983 1983
1984 // Sanity checks to disallow empty and out of range selections. 1984 // Sanity checks to disallow empty and out of range selections.
1985 if (start_adjust - end_adjust > range.length() || 1985 if (start_adjust - end_adjust > range.length() ||
1986 range.StartOffset() + start_adjust < 0) 1986 range.StartOffset() + start_adjust < 0)
1987 return; 1987 return;
1988 1988
1989 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1989 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1990 1990
1991 // A negative adjust amount moves the selection towards the beginning of 1991 // A negative adjust amount moves the selection towards the beginning of
1992 // the document, a positive amount moves the selection towards the end of 1992 // the document, a positive amount moves the selection towards the end of
1993 // the document. 1993 // the document.
1994 frame_->SelectRange(WebRange(range.StartOffset() + start_adjust, 1994 frame_->SelectRange(WebRange(range.StartOffset() + start_adjust,
1995 range.length() + end_adjust - start_adjust), 1995 range.length() + end_adjust - start_adjust),
1996 WebLocalFrame::kPreserveHandleVisibility); 1996 WebLocalFrame::kPreserveHandleVisibility);
1997 } 1997 }
1998 1998
1999 void RenderFrameImpl::OnCollapseSelection() { 1999 void RenderFrameImpl::OnCollapseSelection() {
2000 const WebRange& range = 2000 const WebRange& range =
2001 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); 2001 frame_->GetInputMethodController()->GetSelectionOffsets();
2002 if (range.IsNull()) 2002 if (range.IsNull())
2003 return; 2003 return;
2004 2004
2005 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 2005 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
2006 frame_->SelectRange(WebRange(range.EndOffset(), 0)); 2006 frame_->SelectRange(WebRange(range.EndOffset(), 0));
2007 } 2007 }
2008 2008
2009 void RenderFrameImpl::OnMoveRangeSelectionExtent(const gfx::Point& point) { 2009 void RenderFrameImpl::OnMoveRangeSelectionExtent(const gfx::Point& point) {
2010 // This IPC is dispatched by RenderWidgetHost, so use its routing id. 2010 // This IPC is dispatched by RenderWidgetHost, so use its routing id.
2011 Send(new InputHostMsg_MoveRangeSelectionExtent_ACK( 2011 Send(new InputHostMsg_MoveRangeSelectionExtent_ACK(
(...skipping 4203 matching lines...) Expand 10 before | Expand all | Expand 10 after
6215 gfx::Range range; 6215 gfx::Range range;
6216 #if BUILDFLAG(ENABLE_PLUGINS) 6216 #if BUILDFLAG(ENABLE_PLUGINS)
6217 if (focused_pepper_plugin_) { 6217 if (focused_pepper_plugin_) {
6218 focused_pepper_plugin_->GetSurroundingText(&text, &range); 6218 focused_pepper_plugin_->GetSurroundingText(&text, &range);
6219 offset = 0; // Pepper API does not support offset reporting. 6219 offset = 0; // Pepper API does not support offset reporting.
6220 // TODO(kinaba): cut as needed. 6220 // TODO(kinaba): cut as needed.
6221 } else 6221 } else
6222 #endif 6222 #endif
6223 { 6223 {
6224 WebRange selection = 6224 WebRange selection =
6225 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); 6225 frame_->GetInputMethodController()->GetSelectionOffsets();
6226 if (selection.IsNull()) 6226 if (selection.IsNull())
6227 return; 6227 return;
6228 6228
6229 range = gfx::Range(selection.StartOffset(), selection.EndOffset()); 6229 range = gfx::Range(selection.StartOffset(), selection.EndOffset());
6230 6230
6231 if (frame_->GetInputMethodController()->TextInputType() != 6231 if (frame_->GetInputMethodController()->TextInputType() !=
6232 blink::kWebTextInputTypeNone) { 6232 blink::kWebTextInputTypeNone) {
6233 // If current focused element is editable, we will send 100 more chars 6233 // If current focused element is editable, we will send 100 more chars
6234 // before and after selection. It is for input method surrounding text 6234 // before and after selection. It is for input method surrounding text
6235 // feature. 6235 // feature.
6236 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection) 6236 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection)
6237 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection; 6237 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection;
6238 else 6238 else
6239 offset = 0; 6239 offset = 0;
6240 size_t length = 6240 size_t length =
6241 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection; 6241 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection;
6242 text = frame_->RangeAsText(WebRange(offset, length)).Utf16(); 6242 text = frame_->RangeAsText(WebRange(offset, length)).Utf16();
6243 } else { 6243 } else {
6244 offset = selection.StartOffset(); 6244 offset = selection.StartOffset();
6245 text = frame_->SelectionAsText().Utf16(); 6245 text = frame_->SelectionAsText().Utf16();
6246 // http://crbug.com/101435 6246 // http://crbug.com/101435
6247 // In some case, frame->selectionAsText() returned text's length is not 6247 // In some case, frame->selectionAsText() returned text's length is not
6248 // equal to the length returned from 6248 // equal to the length returned from frame_->GetSelectionOffsets(). So we
6249 // GetWebWidget()->caretOrSelectionRange(). 6249 // have to set the range according to text.length().
6250 // So we have to set the range according to text.length().
6251 range.set_end(range.start() + text.length()); 6250 range.set_end(range.start() + text.length());
6252 } 6251 }
6253 } 6252 }
6254 6253
6255 // TODO(dglazkov): Investigate if and why this would be happening, 6254 // TODO(dglazkov): Investigate if and why this would be happening,
6256 // and resolve this. We shouldn't be carrying selection text here. 6255 // and resolve this. We shouldn't be carrying selection text here.
6257 // http://crbug.com/632920. 6256 // http://crbug.com/632920.
6258 // Sometimes we get repeated didChangeSelection calls from webkit when 6257 // Sometimes we get repeated didChangeSelection calls from webkit when
6259 // the selection hasn't actually changed. We don't want to report these 6258 // the selection hasn't actually changed. We don't want to report these
6260 // because it will cause us to continually claim the X clipboard. 6259 // because it will cause us to continually claim the X clipboard.
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
6910 replaces_current_history_item(info.replaces_current_history_item), 6909 replaces_current_history_item(info.replaces_current_history_item),
6911 history_navigation_in_new_child_frame( 6910 history_navigation_in_new_child_frame(
6912 info.is_history_navigation_in_new_child_frame), 6911 info.is_history_navigation_in_new_child_frame),
6913 client_redirect(info.is_client_redirect), 6912 client_redirect(info.is_client_redirect),
6914 triggering_event_info(info.triggering_event_info), 6913 triggering_event_info(info.triggering_event_info),
6915 cache_disabled(info.is_cache_disabled), 6914 cache_disabled(info.is_cache_disabled),
6916 form(info.form), 6915 form(info.form),
6917 source_location(info.source_location) {} 6916 source_location(info.source_location) {}
6918 6917
6919 } // namespace content 6918 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698