Index: content/browser/web_contents/touch_selection_controller_aura_client_impl.cc |
diff --git a/content/browser/web_contents/touch_selection_controller_aura_client_impl.cc b/content/browser/web_contents/touch_selection_controller_aura_client_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a1e9850bb24266dea434c99bc5b52387c99292e0 |
--- /dev/null |
+++ b/content/browser/web_contents/touch_selection_controller_aura_client_impl.cc |
@@ -0,0 +1,121 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/web_contents/touch_selection_controller_aura_client_impl.h" |
+ |
+#include "content/browser/renderer_host/render_widget_host_impl.h" |
+#include "content/browser/renderer_host/render_widget_host_view_aura.h" |
+#include "content/browser/web_contents/web_contents_impl.h" |
+#include "content/common/view_messages.h" |
+#include "content/public/browser/render_view_host.h" |
+#include "ui/aura/window.h" |
+#include "ui/base/clipboard/clipboard.h" |
+#include "ui/gfx/geometry/point_conversions.h" |
+#include "ui/strings/grit/ui_strings.h" |
+ |
+namespace content { |
+ |
+TouchSelectionControllerAuraClientImpl::TouchSelectionControllerAuraClientImpl( |
+ RenderWidgetHostViewAura* rwhva) : rwhva_(rwhva) { |
+} |
+ |
+TouchSelectionControllerAuraClientImpl:: |
+ ~TouchSelectionControllerAuraClientImpl() { |
+} |
+ |
+void TouchSelectionControllerAuraClientImpl::MoveCaret( |
+ const gfx::PointF& position) { |
+ RenderWidgetHostImpl* host = |
+ RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost()); |
+ host->MoveCaret(gfx::ToRoundedPoint(position)); |
+} |
+ |
+void TouchSelectionControllerAuraClientImpl::MoveRangeSelectionExtent( |
+ const gfx::PointF& extent) { |
+ RenderViewHost* rvh = RenderViewHost::From(rwhva_->GetRenderWidgetHost()); |
+ WebContentsImpl* wc = |
+ static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); |
+ wc->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); |
+} |
+ |
+void TouchSelectionControllerAuraClientImpl::SelectBetweenCoordinates( |
+ const gfx::PointF& base, |
+ const gfx::PointF& extent) { |
+ RenderViewHost* rvh = RenderViewHost::From(rwhva_->GetRenderWidgetHost()); |
+ WebContentsImpl* wc = |
+ static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); |
+ wc->SelectRange(gfx::ToRoundedPoint(base), gfx::ToRoundedPoint(extent)); |
+} |
+ |
+aura::Window* TouchSelectionControllerAuraClientImpl::GetParentWindow() const { |
+ return rwhva_->GetNativeView(); |
+} |
+ |
+gfx::Rect TouchSelectionControllerAuraClientImpl::GetClientBounds() const { |
+ return gfx::Rect(rwhva_->GetNativeView()->bounds().size()); |
+} |
+ |
+bool TouchSelectionControllerAuraClientImpl::IsCommandIdEnabled( |
+ int command_id) const { |
+ bool editable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; |
+ bool readable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_PASSWORD; |
+ gfx::Range selection_range; |
+ rwhva_->GetSelectionRange(&selection_range); |
+ bool has_selection = !selection_range.is_empty(); |
+ switch (command_id) { |
+ case IDS_APP_CUT: |
+ return editable && readable && has_selection; |
+ case IDS_APP_COPY: |
+ return readable && has_selection; |
+ case IDS_APP_PASTE: { |
+ base::string16 result; |
+ ui::Clipboard::GetForCurrentThread()->ReadText( |
+ ui::CLIPBOARD_TYPE_COPY_PASTE, &result); |
+ return editable && !result.empty(); |
+ } |
+ case IDS_APP_DELETE: |
+ return editable && has_selection; |
+ case IDS_APP_SELECT_ALL: |
+ return true; |
+ default: |
+ return false; |
+ } |
+} |
+ |
+void TouchSelectionControllerAuraClientImpl::ExecuteCommand(int command_id, |
+ int event_flags) { |
+ RenderViewHost* rvh = RenderViewHost::From(rwhva_->GetRenderWidgetHost()); |
+ WebContents* wc = WebContents::FromRenderViewHost(rvh); |
+ switch (command_id) { |
+ case IDS_APP_CUT: |
+ wc->Cut(); |
+ break; |
+ case IDS_APP_COPY: |
+ wc->Copy(); |
+ break; |
+ case IDS_APP_PASTE: |
+ wc->Paste(); |
+ break; |
+ case IDS_APP_DELETE: |
+ wc->Delete(); |
+ break; |
+ case IDS_APP_SELECT_ALL: |
+ wc->SelectAll(); |
+ break; |
+ default: |
+ NOTREACHED(); |
+ break; |
+ } |
+} |
+ |
+void TouchSelectionControllerAuraClientImpl::OpenContextMenu( |
+ const gfx::PointF& point) { |
+ RenderWidgetHostImpl* host = |
+ RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost()); |
+ host->Send(new ViewMsg_ShowContextMenu(host->GetRoutingID(), |
+ ui::MENU_SOURCE_TOUCH_EDIT_MENU, |
+ gfx::ToRoundedPoint(point))); |
+} |
+ |
+} // namespace content |