- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / android / tab_contents / chrome_web_contents_view_delegate_android.cc
1 // Copyright (c) 2012 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 "chrome/browser/ui/android/tab_contents/chrome_web_contents_view_delegate_android.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/android/tab_android.h"
9 #include "content/public/browser/android/content_view_core.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_view.h"
12 #include "content/public/browser/web_contents_view_delegate.h"
13 #include "content/public/common/context_menu_params.h"
14
15 ChromeWebContentsViewDelegateAndroid::ChromeWebContentsViewDelegateAndroid(
16     content::WebContents* web_contents)
17     : web_contents_(web_contents) {
18 }
19
20 ChromeWebContentsViewDelegateAndroid::~ChromeWebContentsViewDelegateAndroid() {
21 }
22
23 content::WebDragDestDelegate*
24 ChromeWebContentsViewDelegateAndroid::GetDragDestDelegate() {
25   // GetDragDestDelegate is a pure virtual method from WebContentsViewDelegate
26   // and must have an implementation although android doesn't use it.
27   NOTREACHED();
28   return NULL;
29 }
30
31 void ChromeWebContentsViewDelegateAndroid::ShowContextMenu(
32     const content::ContextMenuParams& params) {
33   // Display paste pop-up only when selection is empty and editable.
34   if (params.is_editable && params.selection_text.empty()) {
35     content::ContentViewCore* content_view_core =
36         content::ContentViewCore::FromWebContents(web_contents_);
37     if (content_view_core) {
38       content_view_core->ShowPastePopup(params.selection_start.x(),
39                                         params.selection_start.y());
40       return;
41     }
42   }
43
44   TabAndroid* tab = TabAndroid::FromWebContents(web_contents_);
45   // We may not have a Tab if we're running in Android WebView mode.
46   // TODO: The long term plan is to factor out the context menu code into
47   // a shared class and have WebView use a separate delegate.
48   if (tab)
49     tab->ShowContextMenu(params);
50 }
51
52 namespace chrome {
53
54 content::WebContentsViewDelegate* CreateWebContentsViewDelegate(
55     content::WebContents* web_contents) {
56   return new ChromeWebContentsViewDelegateAndroid(web_contents);
57 }
58
59 }  // namespace chrome