Chromium Code Reviews| Index: content/browser/renderer_host/render_widget_host_view_aura.cc |
| diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc |
| index 3362aecf01defdbf2d288f7b99bfb11d20ade97f..a8ae5f468409abb9d93a3ae12381b88fdae4e1a1 100644 |
| --- a/content/browser/renderer_host/render_widget_host_view_aura.cc |
| +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc |
| @@ -1535,11 +1535,19 @@ bool RenderWidgetHostViewAura::GetTextRange(gfx::Range* range) const { |
| if (!text_input_manager_) |
| return false; |
| - const TextInputManager::TextSelection* selection = |
| - text_input_manager_->GetTextSelection(); |
| - if (!selection) |
| +RenderWidgetHostViewBase* view = nullptr; |
|
Charlie Reis
2016/08/04 19:56:50
nit: Wrong indent.
Also, this block needs a comme
EhsanK
2016/08/04 22:29:55
Acknowledged.
|
| + if (is_guest_view_hack_) |
|
Charlie Reis
2016/08/04 19:56:50
Wow. I can't wait till we switch from BrowserPlugi
EhsanK
2016/08/04 22:29:54
Me too. Although this could take a while since Mim
|
| + view = const_cast<RenderWidgetHostViewAura*>(this); |
|
Charlie Reis
2016/08/04 19:56:50
Using const_cast here doesn't seem ok.
EhsanK
2016/08/04 22:29:55
This is similar to the issue we had with RWHV::Get
|
| + else { |
|
Charlie Reis
2016/08/04 19:56:50
Style nit: If the else branch needs braces, so doe
EhsanK
2016/08/04 22:29:54
Acknowledged.
|
| + RenderWidgetHostImpl* host = ActiveOrFocusedWidget(); |
| + if (host) |
| + view = host->GetView(); |
| + } |
| + if (!view) |
| return false; |
| + const TextInputManager::TextSelection* selection = |
| + text_input_manager_->GetTextSelection(view); |
| range->set_start(selection->offset); |
| range->set_end(selection->offset + selection->text.length()); |
| return true; |
| @@ -1556,11 +1564,19 @@ bool RenderWidgetHostViewAura::GetSelectionRange(gfx::Range* range) const { |
| if (!text_input_manager_) |
| return false; |
| - const TextInputManager::TextSelection* selection = |
| - text_input_manager_->GetTextSelection(); |
| - if (!selection) |
| + RenderWidgetHostViewBase* view = nullptr; |
| + if (is_guest_view_hack_) |
| + view = const_cast<RenderWidgetHostViewAura*>(this); |
| + else { |
| + RenderWidgetHostImpl* host = ActiveOrFocusedWidget(); |
| + if (host) |
| + view = host->GetView(); |
| + } |
| + if (!view) |
| return false; |
| + const TextInputManager::TextSelection* selection = |
| + text_input_manager_->GetTextSelection(view); |
| range->set_start(selection->range.start()); |
| range->set_end(selection->range.end()); |
| return true; |
| @@ -1584,11 +1600,19 @@ bool RenderWidgetHostViewAura::GetTextFromRange( |
| if (!text_input_manager_) |
| return false; |
| - const TextInputManager::TextSelection* selection = |
| - text_input_manager_->GetTextSelection(); |
| - if (!selection) |
| + RenderWidgetHostViewBase* view = nullptr; |
|
Charlie Reis
2016/08/04 19:56:50
We shouldn't be copy/pasting this pattern.
EhsanK
2016/08/04 22:29:54
Now I am using (something similar) this pattern on
|
| + if (is_guest_view_hack_) |
| + view = const_cast<RenderWidgetHostViewAura*>(this); |
| + else { |
| + RenderWidgetHostImpl* host = ActiveOrFocusedWidget(); |
| + if (host) |
| + view = host->GetView(); |
| + } |
| + if (!view) |
| return false; |
| + const TextInputManager::TextSelection* selection = |
| + text_input_manager_->GetTextSelection(view); |
| gfx::Range selection_text_range(selection->offset, |
| selection->offset + selection->text.length()); |
| @@ -3038,27 +3062,38 @@ void RenderWidgetHostViewAura::OnTextSelectionChanged( |
| TextInputManager* text_input_manager, |
| RenderWidgetHostViewBase* updated_view) { |
| #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| - if (!GetTextInputManager() || !GetTextInputManager()->GetActiveWidget()) |
| + if (!text_input_manager_) |
| + return; |
| + |
| + RenderWidgetHostViewBase* view = nullptr; |
| + if (is_guest_view_hack_) |
| + view = this; |
| + else { |
| + RenderWidgetHostImpl* host = ActiveOrFocusedWidget(); |
| + if (host) |
| + view = host->GetView(); |
| + } |
| + if (!view) |
| return; |
| - const TextInputManager::TextSelection* text_selection = |
| - GetTextInputManager()->GetTextSelection(); |
| + const TextInputManager::TextSelection* selection = |
| + text_input_manager_->GetTextSelection(view); |
| - if (text_selection->text.empty() || text_selection->range.is_empty()) |
| + if (selection->text.empty() || selection->range.is_empty()) |
| return; |
| - size_t pos = text_selection->range.GetMin() - text_selection->offset; |
| - size_t n = text_selection->range.length(); |
| + size_t pos = selection->range.GetMin() - selection->offset; |
| + size_t n = selection->range.length(); |
| - DCHECK(pos + n <= text_selection->text.length()) |
| + DCHECK(pos + n <= selection->text.length()) |
| << "The text can not fully cover range."; |
| - if (pos >= text_selection->text.length()) { |
| + if (pos >= selection->text.length()) { |
| NOTREACHED() << "The text can not cover range."; |
| return; |
| } |
| // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. |
| ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); |
| - clipboard_writer.WriteText(text_selection->text.substr(pos, n)); |
| + clipboard_writer.WriteText(selection->text.substr(pos, n)); |
| #endif // defined(USE_X11) && !defined(OS_CHROMEOS) |
| } |