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

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

Issue 2901093003: Revert of Update TextSelection for non-user initiated events (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 #if defined(OS_MACOSX) || defined(USE_AURA) 1370 #if defined(OS_MACOSX) || defined(USE_AURA)
1371 GetRenderWidget()->UpdateCompositionInfo( 1371 GetRenderWidget()->UpdateCompositionInfo(
1372 false /* not an immediate request */); 1372 false /* not an immediate request */);
1373 #endif 1373 #endif
1374 } 1374 }
1375 1375
1376 void RenderFrameImpl::PepperSelectionChanged( 1376 void RenderFrameImpl::PepperSelectionChanged(
1377 PepperPluginInstanceImpl* instance) { 1377 PepperPluginInstanceImpl* instance) {
1378 if (instance != focused_pepper_plugin_) 1378 if (instance != focused_pepper_plugin_)
1379 return; 1379 return;
1380 // Keep the original behavior for pepper plugins and handle all selection 1380 SyncSelectionIfRequired();
1381 // change as user initiated.
1382 SyncSelectionIfRequired(true);
1383 } 1381 }
1384 1382
1385 RenderWidgetFullscreenPepper* RenderFrameImpl::CreatePepperFullscreenContainer( 1383 RenderWidgetFullscreenPepper* RenderFrameImpl::CreatePepperFullscreenContainer(
1386 PepperPluginInstanceImpl* plugin) { 1384 PepperPluginInstanceImpl* plugin) {
1387 GURL active_url; 1385 GURL active_url;
1388 if (render_view()->webview()) 1386 if (render_view()->webview())
1389 active_url = render_view()->GetURLForGraphicsContext3D(); 1387 active_url = render_view()->GetURLForGraphicsContext3D();
1390 1388
1391 // Synchronous IPC to obtain a routing id for the fullscreen widget. 1389 // Synchronous IPC to obtain a routing id for the fullscreen widget.
1392 int32_t fullscreen_widget_routing_id = MSG_ROUTING_NONE; 1390 int32_t fullscreen_widget_routing_id = MSG_ROUTING_NONE;
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1954 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1957 frame_->MoveRangeSelectionExtent( 1955 frame_->MoveRangeSelectionExtent(
1958 render_view_->ConvertWindowPointToViewport(point)); 1956 render_view_->ConvertWindowPointToViewport(point));
1959 } 1957 }
1960 1958
1961 void RenderFrameImpl::OnReplace(const base::string16& text) { 1959 void RenderFrameImpl::OnReplace(const base::string16& text) {
1962 if (!frame_->HasSelection()) 1960 if (!frame_->HasSelection())
1963 frame_->SelectWordAroundCaret(); 1961 frame_->SelectWordAroundCaret();
1964 1962
1965 frame_->ReplaceSelection(WebString::FromUTF16(text)); 1963 frame_->ReplaceSelection(WebString::FromUTF16(text));
1966 // Handle this selection change as user initiated since typically triggered 1964 SyncSelectionIfRequired();
1967 // from context menu.
1968 SyncSelectionIfRequired(true);
1969 } 1965 }
1970 1966
1971 void RenderFrameImpl::OnReplaceMisspelling(const base::string16& text) { 1967 void RenderFrameImpl::OnReplaceMisspelling(const base::string16& text) {
1972 if (!frame_->HasSelection()) 1968 if (!frame_->HasSelection())
1973 return; 1969 return;
1974 1970
1975 frame_->ReplaceMisspelledRange(WebString::FromUTF16(text)); 1971 frame_->ReplaceMisspelledRange(WebString::FromUTF16(text));
1976 } 1972 }
1977 1973
1978 void RenderFrameImpl::OnCopyImageAt(int x, int y) { 1974 void RenderFrameImpl::OnCopyImageAt(int x, int y) {
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 void RenderFrameImpl::AttachGuest(int element_instance_id) { 2633 void RenderFrameImpl::AttachGuest(int element_instance_id) {
2638 BrowserPluginManager::Get()->Attach(element_instance_id); 2634 BrowserPluginManager::Get()->Attach(element_instance_id);
2639 } 2635 }
2640 2636
2641 void RenderFrameImpl::DetachGuest(int element_instance_id) { 2637 void RenderFrameImpl::DetachGuest(int element_instance_id) {
2642 BrowserPluginManager::Get()->Detach(element_instance_id); 2638 BrowserPluginManager::Get()->Detach(element_instance_id);
2643 } 2639 }
2644 2640
2645 void RenderFrameImpl::SetSelectedText(const base::string16& selection_text, 2641 void RenderFrameImpl::SetSelectedText(const base::string16& selection_text,
2646 size_t offset, 2642 size_t offset,
2647 const gfx::Range& range, 2643 const gfx::Range& range) {
2648 bool user_initiated) {
2649 Send(new FrameHostMsg_SelectionChanged(routing_id_, selection_text, 2644 Send(new FrameHostMsg_SelectionChanged(routing_id_, selection_text,
2650 static_cast<uint32_t>(offset), range, 2645 static_cast<uint32_t>(offset), range));
2651 user_initiated));
2652 } 2646 }
2653 2647
2654 void RenderFrameImpl::EnsureMojoBuiltinsAreAvailable( 2648 void RenderFrameImpl::EnsureMojoBuiltinsAreAvailable(
2655 v8::Isolate* isolate, 2649 v8::Isolate* isolate,
2656 v8::Local<v8::Context> context) { 2650 v8::Local<v8::Context> context) {
2657 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(context); 2651 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(context);
2658 if (registry->available_modules().count(mojo::edk::js::Core::kModuleName)) 2652 if (registry->available_modules().count(mojo::edk::js::Core::kModuleName))
2659 return; 2653 return;
2660 2654
2661 v8::HandleScope handle_scope(isolate); 2655 v8::HandleScope handle_scope(isolate);
(...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after
4172 if (previews_state_ & SERVER_LOFI_ON) 4166 if (previews_state_ & SERVER_LOFI_ON)
4173 return request.Url().ProtocolIs("https"); 4167 return request.Url().ProtocolIs("https");
4174 return true; 4168 return true;
4175 } 4169 }
4176 4170
4177 void RenderFrameImpl::AbortClientNavigation() { 4171 void RenderFrameImpl::AbortClientNavigation() {
4178 Send(new FrameHostMsg_AbortNavigation(routing_id_)); 4172 Send(new FrameHostMsg_AbortNavigation(routing_id_));
4179 } 4173 }
4180 4174
4181 void RenderFrameImpl::DidChangeSelection(bool is_empty_selection) { 4175 void RenderFrameImpl::DidChangeSelection(bool is_empty_selection) {
4182 bool user_initiated = 4176 if (!GetRenderWidget()->input_handler().handling_input_event() &&
4183 GetRenderWidget()->input_handler().handling_input_event() || 4177 !handling_select_range_)
4184 handling_select_range_; 4178 return;
4185 4179
4186 if (is_empty_selection) 4180 if (is_empty_selection)
4187 selection_text_.clear(); 4181 selection_text_.clear();
4188 4182
4189 // UpdateTextInputState should be called before SyncSelectionIfRequired. 4183 // UpdateTextInputState should be called before SyncSelectionIfRequired.
4190 // UpdateTextInputState may send TextInputStateChanged to notify the focus 4184 // UpdateTextInputState may send TextInputStateChanged to notify the focus
4191 // was changed, and SyncSelectionIfRequired may send SelectionChanged 4185 // was changed, and SyncSelectionIfRequired may send SelectionChanged
4192 // to notify the selection was changed. Focus change should be notified 4186 // to notify the selection was changed. Focus change should be notified
4193 // before selection change. 4187 // before selection change.
4194 GetRenderWidget()->UpdateTextInputState(); 4188 GetRenderWidget()->UpdateTextInputState();
4195 SyncSelectionIfRequired(user_initiated); 4189 SyncSelectionIfRequired();
4196 } 4190 }
4197 4191
4198 bool RenderFrameImpl::HandleCurrentKeyboardEvent() { 4192 bool RenderFrameImpl::HandleCurrentKeyboardEvent() {
4199 bool did_execute_command = false; 4193 bool did_execute_command = false;
4200 for (auto command : GetRenderWidget()->edit_commands()) { 4194 for (auto command : GetRenderWidget()->edit_commands()) {
4201 // In gtk and cocoa, it's possible to bind multiple edit commands to one 4195 // 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 4196 // key (but it's the exception). Once one edit command is not executed, it
4203 // seems safest to not execute the rest. 4197 // seems safest to not execute the rest.
4204 if (!frame_->ExecuteCommand(blink::WebString::FromUTF8(command.name), 4198 if (!frame_->ExecuteCommand(blink::WebString::FromUTF8(command.name),
4205 blink::WebString::FromUTF8(command.value))) 4199 blink::WebString::FromUTF8(command.value)))
(...skipping 2070 matching lines...) Expand 10 before | Expand all | Expand 10 after
6276 } 6270 }
6277 } 6271 }
6278 6272
6279 void RenderFrameImpl::UpdateEncoding(WebFrame* frame, 6273 void RenderFrameImpl::UpdateEncoding(WebFrame* frame,
6280 const std::string& encoding_name) { 6274 const std::string& encoding_name) {
6281 // Only update main frame's encoding_name. 6275 // Only update main frame's encoding_name.
6282 if (!frame->Parent()) 6276 if (!frame->Parent())
6283 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name)); 6277 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name));
6284 } 6278 }
6285 6279
6286 void RenderFrameImpl::SyncSelectionIfRequired(bool user_initiated) { 6280 void RenderFrameImpl::SyncSelectionIfRequired() {
6287 base::string16 text; 6281 base::string16 text;
6288 size_t offset = 0; 6282 size_t offset;
6289 gfx::Range range = gfx::Range::InvalidRange(); 6283 gfx::Range range;
6290 #if BUILDFLAG(ENABLE_PLUGINS) 6284 #if BUILDFLAG(ENABLE_PLUGINS)
6291 if (focused_pepper_plugin_) { 6285 if (focused_pepper_plugin_) {
6292 focused_pepper_plugin_->GetSurroundingText(&text, &range); 6286 focused_pepper_plugin_->GetSurroundingText(&text, &range);
6293 offset = 0; // Pepper API does not support offset reporting. 6287 offset = 0; // Pepper API does not support offset reporting.
6294 // TODO(kinaba): cut as needed. 6288 // TODO(kinaba): cut as needed.
6295 } else 6289 } else
6296 #endif 6290 #endif
6297 { 6291 {
6298 WebRange selection = 6292 WebRange selection =
6299 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); 6293 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange();
6294 if (selection.IsNull())
6295 return;
6300 6296
6301 // When clearing text selection from JavaScript the selection range 6297 range = gfx::Range(selection.StartOffset(), selection.EndOffset());
6302 // might be null but the selected text still have to be updated.
6303 // Do not cancel sync selection if the clear was not user initiated.
6304 if (!selection.IsNull()) {
6305 range = gfx::Range(selection.StartOffset(), selection.EndOffset());
6306 6298
6307 if (frame_->GetInputMethodController()->TextInputType() != 6299 if (frame_->GetInputMethodController()->TextInputType() !=
6308 blink::kWebTextInputTypeNone) { 6300 blink::kWebTextInputTypeNone) {
6309 // If current focused element is editable, we will send 100 more chars 6301 // If current focused element is editable, we will send 100 more chars
6310 // before and after selection. It is for input method surrounding text 6302 // before and after selection. It is for input method surrounding text
6311 // feature. 6303 // feature.
6312 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection) 6304 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection)
6313 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection; 6305 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection;
6314 else 6306 else
6315 offset = 0; 6307 offset = 0;
6316 size_t length = 6308 size_t length =
6317 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection; 6309 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection;
6318 text = frame_->RangeAsText(WebRange(offset, length)).Utf16(); 6310 text = frame_->RangeAsText(WebRange(offset, length)).Utf16();
6319 } else { 6311 } else {
6320 offset = selection.StartOffset(); 6312 offset = selection.StartOffset();
6321 text = frame_->SelectionAsText().Utf16(); 6313 text = frame_->SelectionAsText().Utf16();
6322 // http://crbug.com/101435 6314 // http://crbug.com/101435
6323 // In some case, frame->selectionAsText() returned text's length is not 6315 // In some case, frame->selectionAsText() returned text's length is not
6324 // equal to the length returned from 6316 // equal to the length returned from
6325 // GetWebWidget()->caretOrSelectionRange(). 6317 // GetWebWidget()->caretOrSelectionRange().
6326 // So we have to set the range according to text.length(). 6318 // So we have to set the range according to text.length().
6327 range.set_end(range.start() + text.length()); 6319 range.set_end(range.start() + text.length());
6328 }
6329 } else if (user_initiated) {
6330 return;
6331 } 6320 }
6332 } 6321 }
6333 6322
6334 // TODO(dglazkov): Investigate if and why this would be happening, 6323 // TODO(dglazkov): Investigate if and why this would be happening,
6335 // and resolve this. We shouldn't be carrying selection text here. 6324 // and resolve this. We shouldn't be carrying selection text here.
6336 // http://crbug.com/632920. 6325 // http://crbug.com/632920.
6337 // Sometimes we get repeated didChangeSelection calls from webkit when 6326 // Sometimes we get repeated didChangeSelection calls from webkit when
6338 // the selection hasn't actually changed. We don't want to report these 6327 // the selection hasn't actually changed. We don't want to report these
6339 // because it will cause us to continually claim the X clipboard. 6328 // because it will cause us to continually claim the X clipboard.
6340 if (selection_text_offset_ != offset || 6329 if (selection_text_offset_ != offset ||
6341 selection_range_ != range || 6330 selection_range_ != range ||
6342 selection_text_ != text) { 6331 selection_text_ != text) {
6343 selection_text_ = text; 6332 selection_text_ = text;
6344 selection_text_offset_ = offset; 6333 selection_text_offset_ = offset;
6345 selection_range_ = range; 6334 selection_range_ = range;
6346 SetSelectedText(text, offset, range, user_initiated); 6335 SetSelectedText(text, offset, range);
6347 } 6336 }
6348 GetRenderWidget()->UpdateSelectionBounds(); 6337 GetRenderWidget()->UpdateSelectionBounds();
6349 } 6338 }
6350 6339
6351 void RenderFrameImpl::InitializeUserMediaClient() { 6340 void RenderFrameImpl::InitializeUserMediaClient() {
6352 RenderThreadImpl* render_thread = RenderThreadImpl::current(); 6341 RenderThreadImpl* render_thread = RenderThreadImpl::current();
6353 if (!render_thread) // Will be NULL during unit tests. 6342 if (!render_thread) // Will be NULL during unit tests.
6354 return; 6343 return;
6355 6344
6356 #if BUILDFLAG(ENABLE_WEBRTC) 6345 #if BUILDFLAG(ENABLE_WEBRTC)
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
7066 policy(info.default_policy), 7055 policy(info.default_policy),
7067 replaces_current_history_item(info.replaces_current_history_item), 7056 replaces_current_history_item(info.replaces_current_history_item),
7068 history_navigation_in_new_child_frame( 7057 history_navigation_in_new_child_frame(
7069 info.is_history_navigation_in_new_child_frame), 7058 info.is_history_navigation_in_new_child_frame),
7070 client_redirect(info.is_client_redirect), 7059 client_redirect(info.is_client_redirect),
7071 cache_disabled(info.is_cache_disabled), 7060 cache_disabled(info.is_cache_disabled),
7072 form(info.form), 7061 form(info.form),
7073 source_location(info.source_location) {} 7062 source_location(info.source_location) {}
7074 7063
7075 } // namespace content 7064 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698