15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/android/tab_contents/chrome_web_contents_view_delegate_android.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/ui/android/context_menu_helper.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/android/content_view_core.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents_view_delegate.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/context_menu_params.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ChromeWebContentsViewDelegateAndroid::ChromeWebContentsViewDelegateAndroid( 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* web_contents) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : web_contents_(web_contents) { 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ChromeWebContentsViewDelegateAndroid::~ChromeWebContentsViewDelegateAndroid() { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)content::WebDragDestDelegate* 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ChromeWebContentsViewDelegateAndroid::GetDragDestDelegate() { 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // GetDragDestDelegate is a pure virtual method from WebContentsViewDelegate 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and must have an implementation although android doesn't use it. 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED(); 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return NULL; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ChromeWebContentsViewDelegateAndroid::ShowContextMenu( 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::RenderFrameHost* render_frame_host, 327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const content::ContextMenuParams& params) { 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Display paste pop-up only when selection is empty and editable. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (params.is_editable && params.selection_text.empty()) { 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::ContentViewCore* content_view_core = 36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::ContentViewCore::FromWebContents(web_contents_); 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (content_view_core) { 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content_view_core->ShowPastePopup(params.selection_start.x(), 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.selection_start.y()); 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TODO(dtrainor, kouhei): Give WebView a Populator/delegate so it can use the 45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // same context menu code. 46a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ContextMenuHelper* helper = ContextMenuHelper::FromWebContents(web_contents_); 47a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (helper) 48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) helper->ShowContextMenu(params); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chrome { 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)content::WebContentsViewDelegate* CreateWebContentsViewDelegate( 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* web_contents) { 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return new ChromeWebContentsViewDelegateAndroid(web_contents); 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace chrome 59