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

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: Rebased after addition of touch_handle_orientation file Created 5 years, 9 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 2015 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/gfx/geometry/point_conversions.h"
15 #include "ui/strings/grit/ui_strings.h"
16
17 namespace content {
18
19 TouchSelectionControllerAuraClientImpl::TouchSelectionControllerAuraClientImpl(
20 RenderWidgetHostViewAura* rwhva) : rwhva_(rwhva) {
21 }
22
23 TouchSelectionControllerAuraClientImpl::
24 ~TouchSelectionControllerAuraClientImpl() {
25 }
26
27 void TouchSelectionControllerAuraClientImpl::MoveCaret(
28 const gfx::PointF& position) {
29 RenderWidgetHostImpl* host =
30 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost());
31 host->MoveCaret(gfx::ToRoundedPoint(position));
32 }
33
34 void TouchSelectionControllerAuraClientImpl::MoveRangeSelectionExtent(
35 const gfx::PointF& extent) {
36 RenderViewHost* rvh = RenderViewHost::From(rwhva_->GetRenderWidgetHost());
37 WebContentsImpl* wc =
38 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh));
39 wc->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent));
40 }
41
42 void TouchSelectionControllerAuraClientImpl::SelectBetweenCoordinates(
43 const gfx::PointF& base,
44 const gfx::PointF& extent) {
45 RenderViewHost* rvh = RenderViewHost::From(rwhva_->GetRenderWidgetHost());
46 WebContentsImpl* wc =
47 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh));
48 wc->SelectRange(gfx::ToRoundedPoint(base), gfx::ToRoundedPoint(extent));
49 }
50
51 aura::Window* TouchSelectionControllerAuraClientImpl::GetParentWindow() const {
52 return rwhva_->GetNativeView();
53 }
54
55 gfx::Rect TouchSelectionControllerAuraClientImpl::GetClientBounds() const {
56 return gfx::Rect(rwhva_->GetNativeView()->bounds().size());
57 }
58
59 bool TouchSelectionControllerAuraClientImpl::IsCommandIdEnabled(
60 int command_id) const {
61 bool editable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
62 bool readable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_PASSWORD;
63 gfx::Range selection_range;
64 rwhva_->GetSelectionRange(&selection_range);
65 bool has_selection = !selection_range.is_empty();
66 switch (command_id) {
67 case IDS_APP_CUT:
68 return editable && readable && has_selection;
69 case IDS_APP_COPY:
70 return readable && has_selection;
71 case IDS_APP_PASTE: {
72 base::string16 result;
73 ui::Clipboard::GetForCurrentThread()->ReadText(
74 ui::CLIPBOARD_TYPE_COPY_PASTE, &result);
75 return editable && !result.empty();
76 }
77 case IDS_APP_DELETE:
78 return editable && has_selection;
79 case IDS_APP_SELECT_ALL:
80 return true;
81 default:
82 return false;
83 }
84 }
85
86 void TouchSelectionControllerAuraClientImpl::ExecuteCommand(int command_id,
87 int event_flags) {
88 RenderViewHost* rvh = RenderViewHost::From(rwhva_->GetRenderWidgetHost());
89 WebContents* wc = WebContents::FromRenderViewHost(rvh);
90 switch (command_id) {
91 case IDS_APP_CUT:
92 wc->Cut();
93 break;
94 case IDS_APP_COPY:
95 wc->Copy();
96 break;
97 case IDS_APP_PASTE:
98 wc->Paste();
99 break;
100 case IDS_APP_DELETE:
101 wc->Delete();
102 break;
103 case IDS_APP_SELECT_ALL:
104 wc->SelectAll();
105 break;
106 default:
107 NOTREACHED();
108 break;
109 }
110 }
111
112 void TouchSelectionControllerAuraClientImpl::OpenContextMenu(
113 const gfx::PointF& point) {
114 RenderWidgetHostImpl* host =
115 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost());
116 host->Send(new ViewMsg_ShowContextMenu(host->GetRoutingID(),
117 ui::MENU_SOURCE_TOUCH_EDIT_MENU,
118 gfx::ToRoundedPoint(point)));
119 }
120
121 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698