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

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: Addressing erikchen@'s comments 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 2731 matching lines...) Expand 10 before | Expand all | Expand 10 after
2742 selection_controller_->OnSelectionEmpty(is_empty_text_form_control); 2742 selection_controller_->OnSelectionEmpty(is_empty_text_form_control);
2743 selection_controller_->OnSelectionBoundsChanged(start, end); 2743 selection_controller_->OnSelectionBoundsChanged(start, end);
2744 } 2744 }
2745 2745
2746 void RenderWidgetHostViewAura::CreateSelectionController() { 2746 void RenderWidgetHostViewAura::CreateSelectionController() {
2747 ui::TouchSelectionController::Config tsc_config; 2747 ui::TouchSelectionController::Config tsc_config;
2748 tsc_config.max_tap_duration = base::TimeDelta::FromMilliseconds( 2748 tsc_config.max_tap_duration = base::TimeDelta::FromMilliseconds(
2749 ui::GestureConfiguration::GetInstance()->long_press_time_in_ms()); 2749 ui::GestureConfiguration::GetInstance()->long_press_time_in_ms());
2750 tsc_config.tap_slop = ui::GestureConfiguration::GetInstance() 2750 tsc_config.tap_slop = ui::GestureConfiguration::GetInstance()
2751 ->max_touch_move_in_pixels_for_click(); 2751 ->max_touch_move_in_pixels_for_click();
2752 tsc_config.show_on_tap_for_empty_editable = false; 2752 tsc_config.show_on_tap_for_empty_editable = false;
EhsanK 2016/08/17 06:22:33 Sorry about the rebase + change together.
2753 tsc_config.enable_longpress_drag_selection = false; 2753 tsc_config.enable_longpress_drag_selection = false;
2754 selection_controller_.reset(new ui::TouchSelectionController( 2754 selection_controller_.reset(new ui::TouchSelectionController(
2755 selection_controller_client_.get(), tsc_config)); 2755 selection_controller_client_.get(), tsc_config));
2756 } 2756 }
2757 2757
2758 void RenderWidgetHostViewAura::HandleGestureForTouchSelection( 2758 void RenderWidgetHostViewAura::HandleGestureForTouchSelection(
2759 ui::GestureEvent* event) { 2759 ui::GestureEvent* event) {
2760 switch (event->type()) { 2760 switch (event->type()) {
2761 case ui::ET_GESTURE_LONG_PRESS: 2761 case ui::ET_GESTURE_LONG_PRESS:
2762 if (selection_controller_->WillHandleLongPressEvent( 2762 if (selection_controller_->WillHandleLongPressEvent(
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
3014 GetInputMethod()->OnCaretBoundsChanged(this); 3014 GetInputMethod()->OnCaretBoundsChanged(this);
3015 } 3015 }
3016 3016
3017 void RenderWidgetHostViewAura::OnTextSelectionChanged( 3017 void RenderWidgetHostViewAura::OnTextSelectionChanged(
3018 TextInputManager* text_input_manager, 3018 TextInputManager* text_input_manager,
3019 RenderWidgetHostViewBase* updated_view) { 3019 RenderWidgetHostViewBase* updated_view) {
3020 #if defined(USE_X11) && !defined(OS_CHROMEOS) 3020 #if defined(USE_X11) && !defined(OS_CHROMEOS)
3021 if (!GetTextInputManager()) 3021 if (!GetTextInputManager())
3022 return; 3022 return;
3023 3023
3024 const TextInputManager::TextSelection* text_selection = nullptr; 3024 // We obtain the TextSelection from focused RWH which is obtained from the
3025 if (is_guest_view_hack_) { 3025 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree
3026 // We obtain the TextSelection from focused RWH which is obtained from the 3026 // and the focused RWH will be that of the embedder which is incorrect. In
3027 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree 3027 // this case we should use TextSelection for |this| since RWHV for guest
3028 // and the focused RWH will be that of the embedder which is incorrect. In 3028 // forwards text selection information to its platform view.
3029 // this case we should use TextSelection for |this| since RWHV for guest 3029 RenderWidgetHostViewBase* focused_view =
3030 // forwards text selection information to its platform view. 3030 is_guest_view_hack_ ? this : GetFocusedSubView(this);
3031 text_selection = GetTextInputManager()->GetTextSelection(this);
3032 } else {
3033 RenderWidgetHostImpl* focused_widget =
3034 host_->delegate()->GetFocusedRenderWidgetHost(host_);
3035 if (!!focused_widget && !!focused_widget->GetView()) {
3036 text_selection = GetTextInputManager()->GetTextSelection(
3037 focused_widget->GetView());
3038 }
3039 }
3040 3031
3041 if (!text_selection) 3032 if (!focused_view)
3042 return; 3033 return;
3043 3034
3044 if (text_selection->text.empty() || text_selection->range.is_empty()) 3035 base::string16 selected_text;
3045 return; 3036 if (GetTextInputManager()
3046 size_t pos = text_selection->range.GetMin() - text_selection->offset; 3037 ->GetTextSelection(focused_view)
3047 size_t n = text_selection->range.length(); 3038 ->GetSelectedText(&selected_text)) {
3048 3039 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
3049 DCHECK(pos + n <= text_selection->text.length()) 3040 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION);
3050 << "The text can not fully cover range."; 3041 clipboard_writer.WriteText(selected_text);
3051 if (pos >= text_selection->text.length()) {
3052 NOTREACHED() << "The text can not cover range.";
3053 return;
3054 } 3042 }
3055
3056 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
3057 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION);
3058 clipboard_writer.WriteText(text_selection->text.substr(pos, n));
3059 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) 3043 #endif // defined(USE_X11) && !defined(OS_CHROMEOS)
3060 } 3044 }
3061 3045
3062 } // namespace content 3046 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698