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

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

Issue 2208093004: Use focused RenderWidgetHostImpl instead of TextInputManager::GetActiveWidget() to obtain TextSelec… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a test 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 3005 matching lines...) Expand 10 before | Expand all | Expand 10 after
3016 TextInputManager* text_input_manager, 3016 TextInputManager* text_input_manager,
3017 RenderWidgetHostViewBase* updated_view) { 3017 RenderWidgetHostViewBase* updated_view) {
3018 if (GetInputMethod()) 3018 if (GetInputMethod())
3019 GetInputMethod()->OnCaretBoundsChanged(this); 3019 GetInputMethod()->OnCaretBoundsChanged(this);
3020 } 3020 }
3021 3021
3022 void RenderWidgetHostViewAura::OnTextSelectionChanged( 3022 void RenderWidgetHostViewAura::OnTextSelectionChanged(
3023 TextInputManager* text_input_manager, 3023 TextInputManager* text_input_manager,
3024 RenderWidgetHostViewBase* updated_view) { 3024 RenderWidgetHostViewBase* updated_view) {
3025 #if defined(USE_X11) && !defined(OS_CHROMEOS) 3025 #if defined(USE_X11) && !defined(OS_CHROMEOS)
3026 if (!GetTextInputManager() || !GetTextInputManager()->GetActiveWidget()) 3026 if (!GetTextInputManager())
3027 return; 3027 return;
3028 3028
3029 const TextInputManager::TextSelection* text_selection = 3029 const TextInputManager::TextSelection* text_selection = nullptr;
3030 GetTextInputManager()->GetTextSelection(); 3030 if (is_guest_view_hack_) {
3031 // We obtain the TextSelection from focused RWH which is obtained from the
3032 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree
3033 // and the focused RWH will be that of the embedder which is incorrect. In
3034 // this case we should use TextSelection for |this| since RWHV for guest
3035 // forwards text selection information to its platform view.
3036 text_selection = GetTextInputManager()->GetTextSelection(this);
3037 } else {
3038 RenderWidgetHostViewBase* focused =
3039 host_->delegate()->GetFocusedRenderWidgetHost(host_)->GetView();
kenrb 2016/08/08 20:45:03 It looks like GetFocusedRenderWidgetHost can retur
EhsanK 2016/08/08 21:15:52 Acknowledged. And Done. Thanks for spotting this.
3040 if (focused)
3041 text_selection = GetTextInputManager()->GetTextSelection(focused);
3042 }
3043
3044 if (!text_selection)
3045 return;
3031 3046
3032 if (text_selection->text.empty() || text_selection->range.is_empty()) 3047 if (text_selection->text.empty() || text_selection->range.is_empty())
3033 return; 3048 return;
3034 size_t pos = text_selection->range.GetMin() - text_selection->offset; 3049 size_t pos = text_selection->range.GetMin() - text_selection->offset;
3035 size_t n = text_selection->range.length(); 3050 size_t n = text_selection->range.length();
3036 3051
3037 DCHECK(pos + n <= text_selection->text.length()) 3052 DCHECK(pos + n <= text_selection->text.length())
3038 << "The text can not fully cover range."; 3053 << "The text can not fully cover range.";
3039 if (pos >= text_selection->text.length()) { 3054 if (pos >= text_selection->text.length()) {
3040 NOTREACHED() << "The text can not cover range."; 3055 NOTREACHED() << "The text can not cover range.";
3041 return; 3056 return;
3042 } 3057 }
3043 3058
3044 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. 3059 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
3045 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); 3060 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION);
3046 clipboard_writer.WriteText(text_selection->text.substr(pos, n)); 3061 clipboard_writer.WriteText(text_selection->text.substr(pos, n));
3047 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) 3062 #endif // defined(USE_X11) && !defined(OS_CHROMEOS)
3048 } 3063 }
3049 3064
3050 //////////////////////////////////////////////////////////////////////////////// 3065 ////////////////////////////////////////////////////////////////////////////////
3051 // RenderWidgetHostViewBase, public: 3066 // RenderWidgetHostViewBase, public:
3052 3067
3053 // static 3068 // static
3054 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 3069 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
3055 GetScreenInfoForWindow(results, NULL); 3070 GetScreenInfoForWindow(results, NULL);
3056 } 3071 }
3057 3072
3058 } // namespace content 3073 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698