| 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 3032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3043 GetInputMethod()->OnCaretBoundsChanged(this); | 3043 GetInputMethod()->OnCaretBoundsChanged(this); |
| 3044 } | 3044 } |
| 3045 | 3045 |
| 3046 void RenderWidgetHostViewAura::OnTextSelectionChanged( | 3046 void RenderWidgetHostViewAura::OnTextSelectionChanged( |
| 3047 TextInputManager* text_input_manager, | 3047 TextInputManager* text_input_manager, |
| 3048 RenderWidgetHostViewBase* updated_view) { | 3048 RenderWidgetHostViewBase* updated_view) { |
| 3049 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 3049 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| 3050 if (!GetTextInputManager()) | 3050 if (!GetTextInputManager()) |
| 3051 return; | 3051 return; |
| 3052 | 3052 |
| 3053 const TextInputManager::TextSelection* text_selection = nullptr; | 3053 RenderWidgetHostViewBase* focused_view = nullptr; |
| 3054 if (is_guest_view_hack_) { | 3054 if (is_guest_view_hack_) { |
| 3055 // We obtain the TextSelection from focused RWH which is obtained from the | 3055 // We obtain the TextSelection from focused RWH which is obtained from the |
| 3056 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree | 3056 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree |
| 3057 // and the focused RWH will be that of the embedder which is incorrect. In | 3057 // and the focused RWH will be that of the embedder which is incorrect. In |
| 3058 // this case we should use TextSelection for |this| since RWHV for guest | 3058 // this case we should use TextSelection for |this| since RWHV for guest |
| 3059 // forwards text selection information to its platform view. | 3059 // forwards text selection information to its platform view. |
| 3060 text_selection = GetTextInputManager()->GetTextSelection(this); | 3060 focused_view = this; |
| 3061 } else { | 3061 } else { |
| 3062 RenderWidgetHostImpl* focused_widget = | 3062 RenderWidgetHostImpl* focused_widget = |
| 3063 host_->delegate()->GetFocusedRenderWidgetHost(host_); | 3063 host_->delegate()->GetFocusedRenderWidgetHost(host_); |
| 3064 if (!!focused_widget && !!focused_widget->GetView()) { | 3064 if (focused_widget) |
| 3065 text_selection = GetTextInputManager()->GetTextSelection( | 3065 focused_view = focused_widget->GetView(); |
| 3066 focused_widget->GetView()); | |
| 3067 } | |
| 3068 } | 3066 } |
| 3069 | 3067 |
| 3070 if (!text_selection) | 3068 if (!focused_view) |
| 3071 return; | 3069 return; |
| 3072 | 3070 |
| 3073 if (text_selection->text.empty() || text_selection->range.is_empty()) | 3071 base::string16 selected_text; |
| 3074 return; | 3072 if (GetTextInputManager()->GetSelectedText(focused_view, &selected_text)) { |
| 3075 size_t pos = text_selection->range.GetMin() - text_selection->offset; | 3073 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. |
| 3076 size_t n = text_selection->range.length(); | 3074 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); |
| 3077 | 3075 clipboard_writer.WriteText(selected_text); |
| 3078 DCHECK(pos + n <= text_selection->text.length()) | |
| 3079 << "The text can not fully cover range."; | |
| 3080 if (pos >= text_selection->text.length()) { | |
| 3081 NOTREACHED() << "The text can not cover range."; | |
| 3082 return; | |
| 3083 } | 3076 } |
| 3084 | |
| 3085 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. | |
| 3086 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); | |
| 3087 clipboard_writer.WriteText(text_selection->text.substr(pos, n)); | |
| 3088 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) | 3077 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) |
| 3089 } | 3078 } |
| 3090 | 3079 |
| 3091 //////////////////////////////////////////////////////////////////////////////// | 3080 //////////////////////////////////////////////////////////////////////////////// |
| 3092 // RenderWidgetHostViewBase, public: | 3081 // RenderWidgetHostViewBase, public: |
| 3093 | 3082 |
| 3094 // static | 3083 // static |
| 3095 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 3084 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 3096 GetScreenInfoForWindow(results, NULL); | 3085 GetScreenInfoForWindow(results, NULL); |
| 3097 } | 3086 } |
| 3098 | 3087 |
| 3099 } // namespace content | 3088 } // namespace content |
| OLD | NEW |