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

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

Issue 2856093003: Update TextSelection for non-user initiated events (Closed)
Patch Set: Created 3 years, 7 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 <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 #if defined(OS_MACOSX) || defined(USE_AURA) 1374 #if defined(OS_MACOSX) || defined(USE_AURA)
1375 GetRenderWidget()->UpdateCompositionInfo( 1375 GetRenderWidget()->UpdateCompositionInfo(
1376 false /* not an immediate request */); 1376 false /* not an immediate request */);
1377 #endif 1377 #endif
1378 } 1378 }
1379 1379
1380 void RenderFrameImpl::PepperSelectionChanged( 1380 void RenderFrameImpl::PepperSelectionChanged(
1381 PepperPluginInstanceImpl* instance) { 1381 PepperPluginInstanceImpl* instance) {
1382 if (instance != focused_pepper_plugin_) 1382 if (instance != focused_pepper_plugin_)
1383 return; 1383 return;
1384 SyncSelectionIfRequired(); 1384 SyncSelectionIfRequired(true);
nasko 2017/05/04 16:10:24 Can we put some small comments in cases where we p
Peter Varga 2017/05/04 16:33:45 I can't say this is correct. The only reason that
1385 } 1385 }
1386 1386
1387 RenderWidgetFullscreenPepper* RenderFrameImpl::CreatePepperFullscreenContainer( 1387 RenderWidgetFullscreenPepper* RenderFrameImpl::CreatePepperFullscreenContainer(
1388 PepperPluginInstanceImpl* plugin) { 1388 PepperPluginInstanceImpl* plugin) {
1389 GURL active_url; 1389 GURL active_url;
1390 if (render_view()->webview()) 1390 if (render_view()->webview())
1391 active_url = render_view()->GetURLForGraphicsContext3D(); 1391 active_url = render_view()->GetURLForGraphicsContext3D();
1392 1392
1393 // Synchronous IPC to obtain a routing id for the fullscreen widget. 1393 // Synchronous IPC to obtain a routing id for the fullscreen widget.
1394 int32_t fullscreen_widget_routing_id = MSG_ROUTING_NONE; 1394 int32_t fullscreen_widget_routing_id = MSG_ROUTING_NONE;
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1964 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1965 frame_->MoveRangeSelectionExtent( 1965 frame_->MoveRangeSelectionExtent(
1966 render_view_->ConvertWindowPointToViewport(point)); 1966 render_view_->ConvertWindowPointToViewport(point));
1967 } 1967 }
1968 1968
1969 void RenderFrameImpl::OnReplace(const base::string16& text) { 1969 void RenderFrameImpl::OnReplace(const base::string16& text) {
1970 if (!frame_->HasSelection()) 1970 if (!frame_->HasSelection())
1971 frame_->SelectWordAroundCaret(); 1971 frame_->SelectWordAroundCaret();
1972 1972
1973 frame_->ReplaceSelection(WebString::FromUTF16(text)); 1973 frame_->ReplaceSelection(WebString::FromUTF16(text));
1974 SyncSelectionIfRequired(); 1974 SyncSelectionIfRequired(true);
1975 } 1975 }
1976 1976
1977 void RenderFrameImpl::OnReplaceMisspelling(const base::string16& text) { 1977 void RenderFrameImpl::OnReplaceMisspelling(const base::string16& text) {
1978 if (!frame_->HasSelection()) 1978 if (!frame_->HasSelection())
1979 return; 1979 return;
1980 1980
1981 frame_->ReplaceMisspelledRange(WebString::FromUTF16(text)); 1981 frame_->ReplaceMisspelledRange(WebString::FromUTF16(text));
1982 } 1982 }
1983 1983
1984 void RenderFrameImpl::OnCopyImageAt(int x, int y) { 1984 void RenderFrameImpl::OnCopyImageAt(int x, int y) {
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
2645 void RenderFrameImpl::AttachGuest(int element_instance_id) { 2645 void RenderFrameImpl::AttachGuest(int element_instance_id) {
2646 BrowserPluginManager::Get()->Attach(element_instance_id); 2646 BrowserPluginManager::Get()->Attach(element_instance_id);
2647 } 2647 }
2648 2648
2649 void RenderFrameImpl::DetachGuest(int element_instance_id) { 2649 void RenderFrameImpl::DetachGuest(int element_instance_id) {
2650 BrowserPluginManager::Get()->Detach(element_instance_id); 2650 BrowserPluginManager::Get()->Detach(element_instance_id);
2651 } 2651 }
2652 2652
2653 void RenderFrameImpl::SetSelectedText(const base::string16& selection_text, 2653 void RenderFrameImpl::SetSelectedText(const base::string16& selection_text,
2654 size_t offset, 2654 size_t offset,
2655 const gfx::Range& range) { 2655 const gfx::Range& range,
2656 bool user_initiated) {
2656 Send(new FrameHostMsg_SelectionChanged(routing_id_, selection_text, 2657 Send(new FrameHostMsg_SelectionChanged(routing_id_, selection_text,
2657 static_cast<uint32_t>(offset), range)); 2658 static_cast<uint32_t>(offset), range,
2659 user_initiated));
2658 } 2660 }
2659 2661
2660 void RenderFrameImpl::EnsureMojoBuiltinsAreAvailable( 2662 void RenderFrameImpl::EnsureMojoBuiltinsAreAvailable(
2661 v8::Isolate* isolate, 2663 v8::Isolate* isolate,
2662 v8::Local<v8::Context> context) { 2664 v8::Local<v8::Context> context) {
2663 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(context); 2665 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(context);
2664 if (registry->available_modules().count(mojo::edk::js::Core::kModuleName)) 2666 if (registry->available_modules().count(mojo::edk::js::Core::kModuleName))
2665 return; 2667 return;
2666 2668
2667 v8::HandleScope handle_scope(isolate); 2669 v8::HandleScope handle_scope(isolate);
(...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after
4172 blink::WebEffectiveConnectionType 4174 blink::WebEffectiveConnectionType
4173 RenderFrameImpl::GetEffectiveConnectionType() { 4175 RenderFrameImpl::GetEffectiveConnectionType() {
4174 return effective_connection_type_; 4176 return effective_connection_type_;
4175 } 4177 }
4176 4178
4177 void RenderFrameImpl::AbortClientNavigation() { 4179 void RenderFrameImpl::AbortClientNavigation() {
4178 Send(new FrameHostMsg_AbortNavigation(routing_id_)); 4180 Send(new FrameHostMsg_AbortNavigation(routing_id_));
4179 } 4181 }
4180 4182
4181 void RenderFrameImpl::DidChangeSelection(bool is_empty_selection) { 4183 void RenderFrameImpl::DidChangeSelection(bool is_empty_selection) {
4182 if (!GetRenderWidget()->input_handler().handling_input_event() && 4184 bool user_initiated =
4183 !handling_select_range_) 4185 GetRenderWidget()->input_handler().handling_input_event() ||
4184 return; 4186 handling_select_range_;
4185 4187
4186 if (is_empty_selection) 4188 if (is_empty_selection)
4187 selection_text_.clear(); 4189 selection_text_.clear();
4188 4190
4189 // UpdateTextInputState should be called before SyncSelectionIfRequired. 4191 // UpdateTextInputState should be called before SyncSelectionIfRequired.
4190 // UpdateTextInputState may send TextInputStateChanged to notify the focus 4192 // UpdateTextInputState may send TextInputStateChanged to notify the focus
4191 // was changed, and SyncSelectionIfRequired may send SelectionChanged 4193 // was changed, and SyncSelectionIfRequired may send SelectionChanged
4192 // to notify the selection was changed. Focus change should be notified 4194 // to notify the selection was changed. Focus change should be notified
4193 // before selection change. 4195 // before selection change.
4194 GetRenderWidget()->UpdateTextInputState(); 4196 GetRenderWidget()->UpdateTextInputState();
4195 SyncSelectionIfRequired(); 4197 SyncSelectionIfRequired(user_initiated);
4196 } 4198 }
4197 4199
4198 bool RenderFrameImpl::HandleCurrentKeyboardEvent() { 4200 bool RenderFrameImpl::HandleCurrentKeyboardEvent() {
4199 bool did_execute_command = false; 4201 bool did_execute_command = false;
4200 for (auto command : GetRenderWidget()->edit_commands()) { 4202 for (auto command : GetRenderWidget()->edit_commands()) {
4201 // In gtk and cocoa, it's possible to bind multiple edit commands to one 4203 // In gtk and cocoa, it's possible to bind multiple edit commands to one
4202 // key (but it's the exception). Once one edit command is not executed, it 4204 // key (but it's the exception). Once one edit command is not executed, it
4203 // seems safest to not execute the rest. 4205 // seems safest to not execute the rest.
4204 if (!frame_->ExecuteCommand(blink::WebString::FromUTF8(command.name), 4206 if (!frame_->ExecuteCommand(blink::WebString::FromUTF8(command.name),
4205 blink::WebString::FromUTF8(command.value))) 4207 blink::WebString::FromUTF8(command.value)))
(...skipping 2078 matching lines...) Expand 10 before | Expand all | Expand 10 after
6284 } 6286 }
6285 } 6287 }
6286 6288
6287 void RenderFrameImpl::UpdateEncoding(WebFrame* frame, 6289 void RenderFrameImpl::UpdateEncoding(WebFrame* frame,
6288 const std::string& encoding_name) { 6290 const std::string& encoding_name) {
6289 // Only update main frame's encoding_name. 6291 // Only update main frame's encoding_name.
6290 if (!frame->Parent()) 6292 if (!frame->Parent())
6291 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name)); 6293 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name));
6292 } 6294 }
6293 6295
6294 void RenderFrameImpl::SyncSelectionIfRequired() { 6296 void RenderFrameImpl::SyncSelectionIfRequired(bool user_initiated) {
6295 base::string16 text; 6297 base::string16 text;
6296 size_t offset; 6298 size_t offset = 0;
6297 gfx::Range range; 6299 gfx::Range range = gfx::Range::InvalidRange();
6298 #if BUILDFLAG(ENABLE_PLUGINS) 6300 #if BUILDFLAG(ENABLE_PLUGINS)
6299 if (focused_pepper_plugin_) { 6301 if (focused_pepper_plugin_) {
6300 focused_pepper_plugin_->GetSurroundingText(&text, &range); 6302 focused_pepper_plugin_->GetSurroundingText(&text, &range);
6301 offset = 0; // Pepper API does not support offset reporting. 6303 offset = 0; // Pepper API does not support offset reporting.
6302 // TODO(kinaba): cut as needed. 6304 // TODO(kinaba): cut as needed.
6303 } else 6305 } else
6304 #endif 6306 #endif
6305 { 6307 {
6306 WebRange selection = 6308 WebRange selection =
6307 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); 6309 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange();
6308 if (selection.IsNull()) 6310 if (!selection.IsNull()) {
nasko 2017/05/04 16:10:24 This looks like a change in behavior as the block
Peter Varga 2017/05/04 16:33:45 Yes it is intentional. I haven't found any test re
Peter Varga 2017/05/05 13:09:11 While working on the new test I've found a case wh
6309 return; 6311 range = gfx::Range(selection.StartOffset(), selection.EndOffset());
6310 6312
6311 range = gfx::Range(selection.StartOffset(), selection.EndOffset()); 6313 if (frame_->GetInputMethodController()->TextInputType() !=
6312 6314 blink::kWebTextInputTypeNone) {
6313 if (frame_->GetInputMethodController()->TextInputType() != 6315 // If current focused element is editable, we will send 100 more chars
6314 blink::kWebTextInputTypeNone) { 6316 // before and after selection. It is for input method surrounding text
6315 // If current focused element is editable, we will send 100 more chars 6317 // feature.
6316 // before and after selection. It is for input method surrounding text 6318 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection)
6317 // feature. 6319 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection;
6318 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection) 6320 else
6319 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection; 6321 offset = 0;
6320 else 6322 size_t length =
6321 offset = 0; 6323 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection;
6322 size_t length = 6324 text = frame_->RangeAsText(WebRange(offset, length)).Utf16();
6323 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection; 6325 } else {
6324 text = frame_->RangeAsText(WebRange(offset, length)).Utf16(); 6326 offset = selection.StartOffset();
6325 } else { 6327 text = frame_->SelectionAsText().Utf16();
6326 offset = selection.StartOffset(); 6328 // http://crbug.com/101435
6327 text = frame_->SelectionAsText().Utf16(); 6329 // In some case, frame->selectionAsText() returned text's length is not
6328 // http://crbug.com/101435 6330 // equal to the length returned from
6329 // In some case, frame->selectionAsText() returned text's length is not 6331 // GetWebWidget()->caretOrSelectionRange().
6330 // equal to the length returned from 6332 // So we have to set the range according to text.length().
6331 // GetWebWidget()->caretOrSelectionRange(). 6333 range.set_end(range.start() + text.length());
6332 // So we have to set the range according to text.length(). 6334 }
6333 range.set_end(range.start() + text.length());
6334 } 6335 }
6335 } 6336 }
6336 6337
6337 // TODO(dglazkov): Investigate if and why this would be happening, 6338 // TODO(dglazkov): Investigate if and why this would be happening,
6338 // and resolve this. We shouldn't be carrying selection text here. 6339 // and resolve this. We shouldn't be carrying selection text here.
6339 // http://crbug.com/632920. 6340 // http://crbug.com/632920.
6340 // Sometimes we get repeated didChangeSelection calls from webkit when 6341 // Sometimes we get repeated didChangeSelection calls from webkit when
6341 // the selection hasn't actually changed. We don't want to report these 6342 // the selection hasn't actually changed. We don't want to report these
6342 // because it will cause us to continually claim the X clipboard. 6343 // because it will cause us to continually claim the X clipboard.
6343 if (selection_text_offset_ != offset || 6344 if (selection_text_offset_ != offset ||
6344 selection_range_ != range || 6345 selection_range_ != range ||
6345 selection_text_ != text) { 6346 selection_text_ != text) {
6346 selection_text_ = text; 6347 selection_text_ = text;
6347 selection_text_offset_ = offset; 6348 selection_text_offset_ = offset;
6348 selection_range_ = range; 6349 selection_range_ = range;
6349 SetSelectedText(text, offset, range); 6350 SetSelectedText(text, offset, range, user_initiated);
6350 } 6351 }
6351 GetRenderWidget()->UpdateSelectionBounds(); 6352 GetRenderWidget()->UpdateSelectionBounds();
6352 } 6353 }
6353 6354
6354 void RenderFrameImpl::InitializeUserMediaClient() { 6355 void RenderFrameImpl::InitializeUserMediaClient() {
6355 RenderThreadImpl* render_thread = RenderThreadImpl::current(); 6356 RenderThreadImpl* render_thread = RenderThreadImpl::current();
6356 if (!render_thread) // Will be NULL during unit tests. 6357 if (!render_thread) // Will be NULL during unit tests.
6357 return; 6358 return;
6358 6359
6359 #if BUILDFLAG(ENABLE_WEBRTC) 6360 #if BUILDFLAG(ENABLE_WEBRTC)
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
7069 policy(info.default_policy), 7070 policy(info.default_policy),
7070 replaces_current_history_item(info.replaces_current_history_item), 7071 replaces_current_history_item(info.replaces_current_history_item),
7071 history_navigation_in_new_child_frame( 7072 history_navigation_in_new_child_frame(
7072 info.is_history_navigation_in_new_child_frame), 7073 info.is_history_navigation_in_new_child_frame),
7073 client_redirect(info.is_client_redirect), 7074 client_redirect(info.is_client_redirect),
7074 cache_disabled(info.is_cache_disabled), 7075 cache_disabled(info.is_cache_disabled),
7075 form(info.form), 7076 form(info.form),
7076 source_location(info.source_location) {} 7077 source_location(info.source_location) {}
7077 7078
7078 } // namespace content 7079 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698