| OLD | NEW |
| 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 Loading... |
| 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 RenderWidgetHostImpl* focused_widget = |
| 3039 host_->delegate()->GetFocusedRenderWidgetHost(host_); |
| 3040 if (!!focused_widget && !!focused_widget->GetView()) { |
| 3041 text_selection = GetTextInputManager()->GetTextSelection( |
| 3042 focused_widget->GetView()); |
| 3043 } |
| 3044 } |
| 3045 |
| 3046 if (!text_selection) |
| 3047 return; |
| 3031 | 3048 |
| 3032 if (text_selection->text.empty() || text_selection->range.is_empty()) | 3049 if (text_selection->text.empty() || text_selection->range.is_empty()) |
| 3033 return; | 3050 return; |
| 3034 size_t pos = text_selection->range.GetMin() - text_selection->offset; | 3051 size_t pos = text_selection->range.GetMin() - text_selection->offset; |
| 3035 size_t n = text_selection->range.length(); | 3052 size_t n = text_selection->range.length(); |
| 3036 | 3053 |
| 3037 DCHECK(pos + n <= text_selection->text.length()) | 3054 DCHECK(pos + n <= text_selection->text.length()) |
| 3038 << "The text can not fully cover range."; | 3055 << "The text can not fully cover range."; |
| 3039 if (pos >= text_selection->text.length()) { | 3056 if (pos >= text_selection->text.length()) { |
| 3040 NOTREACHED() << "The text can not cover range."; | 3057 NOTREACHED() << "The text can not cover range."; |
| 3041 return; | 3058 return; |
| 3042 } | 3059 } |
| 3043 | 3060 |
| 3044 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. | 3061 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. |
| 3045 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); | 3062 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); |
| 3046 clipboard_writer.WriteText(text_selection->text.substr(pos, n)); | 3063 clipboard_writer.WriteText(text_selection->text.substr(pos, n)); |
| 3047 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) | 3064 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) |
| 3048 } | 3065 } |
| 3049 | 3066 |
| 3050 //////////////////////////////////////////////////////////////////////////////// | 3067 //////////////////////////////////////////////////////////////////////////////// |
| 3051 // RenderWidgetHostViewBase, public: | 3068 // RenderWidgetHostViewBase, public: |
| 3052 | 3069 |
| 3053 // static | 3070 // static |
| 3054 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 3071 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 3055 GetScreenInfoForWindow(results, NULL); | 3072 GetScreenInfoForWindow(results, NULL); |
| 3056 } | 3073 } |
| 3057 | 3074 |
| 3058 } // namespace content | 3075 } // namespace content |
| OLD | NEW |