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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 2240553003: Track text selection on the browser side (Mac) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added #ifdef Created 4 years, 4 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 (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/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 3002 matching lines...) Expand 10 before | Expand all | Expand 10 after
3013 GetInputMethod()->OnCaretBoundsChanged(this); 3013 GetInputMethod()->OnCaretBoundsChanged(this);
3014 } 3014 }
3015 3015
3016 void RenderWidgetHostViewAura::OnTextSelectionChanged( 3016 void RenderWidgetHostViewAura::OnTextSelectionChanged(
3017 TextInputManager* text_input_manager, 3017 TextInputManager* text_input_manager,
3018 RenderWidgetHostViewBase* updated_view) { 3018 RenderWidgetHostViewBase* updated_view) {
3019 #if defined(USE_X11) && !defined(OS_CHROMEOS) 3019 #if defined(USE_X11) && !defined(OS_CHROMEOS)
3020 if (!GetTextInputManager()) 3020 if (!GetTextInputManager())
3021 return; 3021 return;
3022 3022
3023 const TextInputManager::TextSelection* text_selection = nullptr; 3023 // We obtain the TextSelection from focused RWH which is obtained from the
3024 if (is_guest_view_hack_) { 3024 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree
3025 // We obtain the TextSelection from focused RWH which is obtained from the 3025 // and the focused RWH will be that of the embedder which is incorrect. In
3026 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree 3026 // this case we should use TextSelection for |this| since RWHV for guest
3027 // and the focused RWH will be that of the embedder which is incorrect. In 3027 // forwards text selection information to its platform view.
3028 // this case we should use TextSelection for |this| since RWHV for guest 3028 RenderWidgetHostViewBase* focused_view =
3029 // forwards text selection information to its platform view. 3029 is_guest_view_hack_ ? this : GetFocusedWidget()
3030 text_selection = GetTextInputManager()->GetTextSelection(this); 3030 ? GetFocusedWidget()->GetView()
3031 } else { 3031 : nullptr;
3032 RenderWidgetHostImpl* focused_widget =
3033 host_->delegate()->GetFocusedRenderWidgetHost(host_);
3034 if (!!focused_widget && !!focused_widget->GetView()) {
3035 text_selection = GetTextInputManager()->GetTextSelection(
3036 focused_widget->GetView());
3037 }
3038 }
3039 3032
3040 if (!text_selection) 3033 if (!focused_view)
3041 return; 3034 return;
3042 3035
3043 if (text_selection->text.empty() || text_selection->range.is_empty()) 3036 base::string16 selected_text;
3044 return; 3037 if (GetTextInputManager()
3045 size_t pos = text_selection->range.GetMin() - text_selection->offset; 3038 ->GetTextSelection(focused_view)
3046 size_t n = text_selection->range.length(); 3039 ->GetSelectedText(&selected_text)) {
3047 3040 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
3048 DCHECK(pos + n <= text_selection->text.length()) 3041 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION);
3049 << "The text can not fully cover range."; 3042 clipboard_writer.WriteText(selected_text);
3050 if (pos >= text_selection->text.length()) {
3051 NOTREACHED() << "The text can not cover range.";
3052 return;
3053 } 3043 }
3054
3055 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
3056 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION);
3057 clipboard_writer.WriteText(text_selection->text.substr(pos, n));
3058 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) 3044 #endif // defined(USE_X11) && !defined(OS_CHROMEOS)
3059 } 3045 }
3060 3046
3061 } // namespace content 3047 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698