| 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..a457c10add736f166434fdcacf9590adf5d76fdc
|
| --- /dev/null
|
| +++ b/content/browser/web_contents/touch_selection_controller_aura_client_impl.cc
|
| @@ -0,0 +1,128 @@
|
| +// Copyright (c) 2013 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/strings/grit/ui_strings.h"
|
| +
|
| +namespace content {
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// TouchSelectionControllerAuraClientImpl, public:
|
| +
|
| +TouchSelectionControllerAuraClientImpl::TouchSelectionControllerAuraClientImpl(
|
| + RenderWidgetHostViewAura* rwhva) : rwhva_(rwhva) {
|
| +}
|
| +
|
| +TouchSelectionControllerAuraClientImpl::
|
| + ~TouchSelectionControllerAuraClientImpl() {
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// TouchSelectionControllerAuraClient implementation:
|
| +
|
| +void TouchSelectionControllerAuraClientImpl::MoveCaret(
|
| + const gfx::PointF& position) {
|
| + RenderWidgetHostImpl* host =
|
| + RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost());
|
| + host->MoveCaret(gfx::Point(position.x(), position.y()));
|
| +}
|
| +
|
| +void TouchSelectionControllerAuraClientImpl::MoveRangeSelectionExtent(
|
| + const gfx::PointF& extent) {
|
| + RenderViewHost* rvh = RenderViewHost::From(rwhva_->GetRenderWidgetHost());
|
| + WebContentsImpl* wc =
|
| + static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh));
|
| + wc->MoveRangeSelectionExtent(gfx::Point(extent.x(), extent.y()));
|
| +}
|
| +
|
| +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::Point(base.x(), base.y()),
|
| + gfx::Point(extent.x(), extent.y()));
|
| +}
|
| +
|
| +aura::Window* TouchSelectionControllerAuraClientImpl::GetParentWindow() const {
|
| + return rwhva_->GetNativeView();
|
| +}
|
| +
|
| +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::Point(point.x(), point.y())));
|
| +}
|
| +
|
| +gfx::Rect TouchSelectionControllerAuraClientImpl::ConvertRectToScreen(
|
| + const gfx::Rect& rect) const {
|
| + return rwhva_->ConvertRectToScreen(rect);
|
| +}
|
| +
|
| +} // namespace content
|
|
|