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

Side by Side Diff: content/browser/web_contents/touch_selection_controller_aura_client_impl.cc

Issue 698253004: Reland: Implement Aura side of unified touch text selection for contents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed overrides in TouchHandleDrawableAura Created 5 years, 11 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/web_contents/touch_selection_controller_aura_client_im pl.h"
6
7 #include "content/browser/renderer_host/render_widget_host_impl.h"
8 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/common/view_messages.h"
11 #include "content/public/browser/render_view_host.h"
12 #include "ui/aura/window.h"
13 #include "ui/base/clipboard/clipboard.h"
14 #include "ui/strings/grit/ui_strings.h"
15
16 namespace content {
17
18 ////////////////////////////////////////////////////////////////////////////////
19 // TouchSelectionControllerAuraClientImpl, public:
20
21 TouchSelectionControllerAuraClientImpl::TouchSelectionControllerAuraClientImpl(
22 RenderWidgetHostViewAura* rwhva) : rwhva_(rwhva) {
23 }
24
25 TouchSelectionControllerAuraClientImpl::
26 ~TouchSelectionControllerAuraClientImpl() {
27 }
28
29 ////////////////////////////////////////////////////////////////////////////////
30 // TouchSelectionControllerAuraClient implementation:
31
32 void TouchSelectionControllerAuraClientImpl::MoveCaret(
33 const gfx::PointF& position) {
34 RenderWidgetHostImpl* host =
35 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost());
36 host->MoveCaret(gfx::Point(position.x(), position.y()));
37 }
38
39 void TouchSelectionControllerAuraClientImpl::MoveRangeSelectionExtent(
40 const gfx::PointF& extent) {
41 RenderViewHost* rvh = RenderViewHost::From(rwhva_->GetRenderWidgetHost());
42 WebContentsImpl* wc =
43 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh));
44 wc->MoveRangeSelectionExtent(gfx::Point(extent.x(), extent.y()));
45 }
46
47 void TouchSelectionControllerAuraClientImpl::SelectBetweenCoordinates(
48 const gfx::PointF& base,
49 const gfx::PointF& extent) {
50 RenderViewHost* rvh = RenderViewHost::From(rwhva_->GetRenderWidgetHost());
51 WebContentsImpl* wc =
52 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh));
53 wc->SelectRange(gfx::Point(base.x(), base.y()),
54 gfx::Point(extent.x(), extent.y()));
55 }
56
57 aura::Window* TouchSelectionControllerAuraClientImpl::GetParentWindow() const {
58 return rwhva_->GetNativeView();
59 }
60
61 bool TouchSelectionControllerAuraClientImpl::IsCommandIdEnabled(
62 int command_id) const {
63 bool editable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
64 bool readable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_PASSWORD;
65 gfx::Range selection_range;
66 rwhva_->GetSelectionRange(&selection_range);
67 bool has_selection = !selection_range.is_empty();
68 switch (command_id) {
69 case IDS_APP_CUT:
70 return editable && readable && has_selection;
71 case IDS_APP_COPY:
72 return readable && has_selection;
73 case IDS_APP_PASTE: {
74 base::string16 result;
75 ui::Clipboard::GetForCurrentThread()->ReadText(
76 ui::CLIPBOARD_TYPE_COPY_PASTE, &result);
77 return editable && !result.empty();
78 }
79 case IDS_APP_DELETE:
80 return editable && has_selection;
81 case IDS_APP_SELECT_ALL:
82 return true;
83 default:
84 return false;
85 }
86 }
87
88 void TouchSelectionControllerAuraClientImpl::ExecuteCommand(int command_id,
89 int event_flags) {
90 RenderViewHost* rvh = RenderViewHost::From(rwhva_->GetRenderWidgetHost());
91 WebContents* wc = WebContents::FromRenderViewHost(rvh);
92 switch (command_id) {
93 case IDS_APP_CUT:
94 wc->Cut();
95 break;
96 case IDS_APP_COPY:
97 wc->Copy();
98 break;
99 case IDS_APP_PASTE:
100 wc->Paste();
101 break;
102 case IDS_APP_DELETE:
103 wc->Delete();
104 break;
105 case IDS_APP_SELECT_ALL:
106 wc->SelectAll();
107 break;
108 default:
109 NOTREACHED();
110 break;
111 }
112 }
113
114 void TouchSelectionControllerAuraClientImpl::OpenContextMenu(
115 const gfx::PointF& point) {
116 RenderWidgetHostImpl* host =
117 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost());
118 host->Send(new ViewMsg_ShowContextMenu(host->GetRoutingID(),
119 ui::MENU_SOURCE_TOUCH_EDIT_MENU,
120 gfx::Point(point.x(), point.y())));
121 }
122
123 gfx::Rect TouchSelectionControllerAuraClientImpl::ConvertRectToScreen(
124 const gfx::Rect& rect) const {
125 return rwhva_->ConvertRectToScreen(rect);
126 }
127
128 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698