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

Side by Side Diff: content/browser/renderer_host/input/touch_selection_controller_client_child_frame.cc

Issue 2883653002: Implement TouchSelectionEditing controls for OOPIF. (Closed)
Patch Set: ChildFrame client uses root view's animation defaults. Created 3 years, 7 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 2017 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/renderer_host/input/touch_selection_controller_client_ child_frame.h"
6
7 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
8 #include "content/browser/renderer_host/input/touch_selection_controller_client_ manager.h"
9 #include "content/browser/renderer_host/render_widget_host_delegate.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h"
11 #include "content/common/content_switches_internal.h"
12 #include "content/common/view_messages.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 TouchSelectionControllerClientChildFrame::
20 TouchSelectionControllerClientChildFrame(
21 RenderWidgetHostViewChildFrame* rwhv,
22 TouchSelectionControllerClientManager* manager)
23 : rwhv_(rwhv), manager_(manager) {
24 DCHECK(rwhv);
25 DCHECK(manager_);
26 }
27
28 TouchSelectionControllerClientChildFrame::
29 ~TouchSelectionControllerClientChildFrame() {
30 // If the manager doesn't outlive us, our owning view sill detach us.
31 manager_->InvalidateClient(this);
32 }
33
34 void TouchSelectionControllerClientChildFrame::UpdateSelectionBoundsIfNeeded(
35 const cc::Selection<gfx::SelectionBound>& selection,
36 float device_scale_factor) {
37 gfx::PointF start_edge_top = selection.start.edge_top();
38 gfx::PointF start_edge_bottom = selection.start.edge_bottom();
39 gfx::PointF end_edge_top = selection.end.edge_top();
40 gfx::PointF end_edge_bottom = selection.end.edge_bottom();
41
42 if (IsUseZoomForDSFEnabled()) {
43 float viewportToDIPScale = 1.0f / device_scale_factor;
44
45 start_edge_top.Scale(viewportToDIPScale);
46 start_edge_bottom.Scale(viewportToDIPScale);
47 end_edge_top.Scale(viewportToDIPScale);
48 end_edge_bottom.Scale(viewportToDIPScale);
49 }
50
51 gfx::Point origin = rwhv_->GetViewOriginInRoot();
52 gfx::Vector2dF offset_v(origin.x(), origin.y());
53 start_edge_top += offset_v;
54 start_edge_bottom += offset_v;
55 end_edge_top += offset_v;
56 end_edge_bottom += offset_v;
57
58 cc::Selection<gfx::SelectionBound> transformed_selection(selection);
59 transformed_selection.start.SetEdge(start_edge_top, start_edge_bottom);
60 transformed_selection.end.SetEdge(end_edge_top, end_edge_bottom);
61
62 if (transformed_selection.start != selection_start_ ||
63 transformed_selection.end != selection_end_) {
64 selection_start_ = transformed_selection.start;
65 selection_end_ = transformed_selection.end;
66 manager_->UpdateClientSelectionBounds(selection_start_, selection_end_,
67 this, this);
68 }
69 }
70
71 gfx::Point TouchSelectionControllerClientChildFrame::ConvertFromRoot(
72 const gfx::PointF& point_f) const {
73 gfx::Point origin = rwhv_->GetViewOriginInRoot();
74 return gfx::ToRoundedPoint(
75 gfx::PointF(point_f.x() - origin.x(), point_f.y() - origin.y()));
76 }
77
78 bool TouchSelectionControllerClientChildFrame::SupportsAnimation() const {
79 NOTREACHED();
80 return false;
81 }
82
83 void TouchSelectionControllerClientChildFrame::SetNeedsAnimate() {
84 NOTREACHED();
85 }
86
87 void TouchSelectionControllerClientChildFrame::MoveCaret(
88 const gfx::PointF& position) {
89 RenderWidgetHostImpl* host =
90 RenderWidgetHostImpl::From(rwhv_->GetRenderWidgetHost());
91 host->MoveCaret(ConvertFromRoot(position));
92 }
93
94 void TouchSelectionControllerClientChildFrame::MoveRangeSelectionExtent(
95 const gfx::PointF& extent) {
96 RenderWidgetHostDelegate* host_delegate =
97 RenderWidgetHostImpl::From(rwhv_->GetRenderWidgetHost())->delegate();
98 if (host_delegate)
99 host_delegate->MoveRangeSelectionExtent(ConvertFromRoot(extent));
100 }
101
102 void TouchSelectionControllerClientChildFrame::SelectBetweenCoordinates(
103 const gfx::PointF& base,
104 const gfx::PointF& extent) {
105 RenderWidgetHostDelegate* host_delegate =
106 RenderWidgetHostImpl::From(rwhv_->GetRenderWidgetHost())->delegate();
107 if (host_delegate) {
108 host_delegate->SelectRange(ConvertFromRoot(base), ConvertFromRoot(extent));
109 }
110 }
111
112 void TouchSelectionControllerClientChildFrame::OnSelectionEvent(
113 ui::SelectionEventType event) {
114 NOTREACHED();
115 }
116
117 std::unique_ptr<ui::TouchHandleDrawable>
118 TouchSelectionControllerClientChildFrame::CreateDrawable() {
119 NOTREACHED();
120 return std::unique_ptr<ui::TouchHandleDrawable>();
121 }
122
123 bool TouchSelectionControllerClientChildFrame::IsCommandIdEnabled(
124 int command_id) const {
125 bool editable = rwhv_->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
126 bool readable = rwhv_->GetTextInputType() != ui::TEXT_INPUT_TYPE_PASSWORD;
127 // TODO(wjmaclean): The test for has_selection should be changed to
128 //
129 // rwhv_->GetSelectionRange(&selection_range);
130 // bool has_selection = !selection_range.is_empty();
131 //
132 // like in TouchSelectionControllerClientAura. Unfortunately this fails here
133 // due to https://crbug.com/723790, which means that the first text
134 // selected in an oopif subframe when it acquires focus will fail to send
135 // a FrameHostMsg_SelectionChanged, meaning the TextInputManager won't
136 // know about the new selection.
137 bool has_selection = selection_start_.type() != gfx::SelectionBound::EMPTY &&
138 selection_end_.type() != gfx::SelectionBound::EMPTY &&
139 selection_start_ != selection_end_;
140 switch (command_id) {
141 case IDS_APP_CUT:
142 return editable && readable && has_selection;
143 case IDS_APP_COPY:
144 return readable && has_selection;
145 case IDS_APP_PASTE: {
146 base::string16 result;
147 ui::Clipboard::GetForCurrentThread()->ReadText(
148 ui::CLIPBOARD_TYPE_COPY_PASTE, &result);
149 return editable && !result.empty();
150 }
151 default:
152 return false;
153 }
154 }
155
156 void TouchSelectionControllerClientChildFrame::ExecuteCommand(int command_id,
157 int event_flags) {
158 manager_->GetTouchSelectionController()
159 ->HideAndDisallowShowingAutomatically();
160 RenderWidgetHostDelegate* host_delegate =
161 RenderWidgetHostImpl::From(rwhv_->GetRenderWidgetHost())->delegate();
162 if (!host_delegate)
163 return;
164
165 switch (command_id) {
166 case IDS_APP_CUT:
167 host_delegate->Cut();
168 break;
169 case IDS_APP_COPY:
170 host_delegate->Copy();
171 break;
172 case IDS_APP_PASTE:
173 host_delegate->Paste();
174 break;
175 default:
176 NOTREACHED();
177 break;
178 }
179 }
180
181 void TouchSelectionControllerClientChildFrame::RunContextMenu() {
182 gfx::RectF anchor_rect =
183 manager_->GetTouchSelectionController()->GetRectBetweenBounds();
184 gfx::PointF anchor_point =
185 gfx::PointF(anchor_rect.CenterPoint().x(), anchor_rect.y());
186 gfx::Point origin = rwhv_->GetViewOriginInRoot();
187 anchor_point.Offset(-origin.x(), -origin.y());
188 RenderWidgetHostImpl* host =
189 RenderWidgetHostImpl::From(rwhv_->GetRenderWidgetHost());
190 // TODO(wjmaclean): Probably this ViewMsg should be converted to a FrameMsg
191 // since it will need to go to a RenderFrame once the Blink-side plumbing for
192 // this is hooked up.
193 host->Send(new ViewMsg_ShowContextMenu(host->GetRoutingID(),
194 ui::MENU_SOURCE_TOUCH_EDIT_MENU,
195 gfx::ToRoundedPoint(anchor_point)));
196
197 // Hide selection handles after getting rect-between-bounds from touch
198 // selection controller; otherwise, rect would be empty and the above
199 // calculations would be invalid.
200 manager_->GetTouchSelectionController()
201 ->HideAndDisallowShowingAutomatically();
202 }
203
204 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698