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#ifndef CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_CHROME_WEB_CONTENTS_VIEW_DELEGATE_VIEWS_H_ 6#define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_CHROME_WEB_CONTENTS_VIEW_DELEGATE_VIEWS_H_ 7 8#include "base/basictypes.h" 9#include "base/compiler_specific.h" 10#include "base/memory/scoped_ptr.h" 11#include "components/renderer_context_menu/context_menu_delegate.h" 12#include "content/public/browser/web_contents_view_delegate.h" 13 14class LinkDisambiguationPopup; 15class RenderViewContextMenu; 16class RenderViewContextMenuViews; 17 18namespace aura { 19class Window; 20} 21 22namespace content { 23class WebContents; 24class WebDragDestDelegate; 25class RenderFrameHost; 26} 27 28namespace views { 29class FocusManager; 30class Widget; 31} 32 33// A chrome specific class that extends WebContentsViewWin with features like 34// focus management, which live in chrome. 35class ChromeWebContentsViewDelegateViews 36 : public content::WebContentsViewDelegate, 37 public ContextMenuDelegate { 38 public: 39 explicit ChromeWebContentsViewDelegateViews( 40 content::WebContents* web_contents); 41 virtual ~ChromeWebContentsViewDelegateViews(); 42 43 // Overridden from WebContentsViewDelegate: 44 virtual content::WebDragDestDelegate* GetDragDestDelegate() OVERRIDE; 45 virtual void StoreFocus() OVERRIDE; 46 virtual void RestoreFocus() OVERRIDE; 47 virtual bool Focus() OVERRIDE; 48 virtual void TakeFocus(bool reverse) OVERRIDE; 49 virtual void ShowContextMenu( 50 content::RenderFrameHost* render_frame_host, 51 const content::ContextMenuParams& params) OVERRIDE; 52 virtual void SizeChanged(const gfx::Size& size) OVERRIDE; 53 virtual void ShowDisambiguationPopup( 54 const gfx::Rect& target_rect, 55 const SkBitmap& zoomed_bitmap, 56 const gfx::NativeView content, 57 const base::Callback<void(ui::GestureEvent*)>& gesture_cb, 58 const base::Callback<void(ui::MouseEvent*)>& mouse_cb) OVERRIDE; 59 virtual void HideDisambiguationPopup() OVERRIDE; 60 61 // Overridden from ContextMenuDelegate. 62 virtual scoped_ptr<RenderViewContextMenu> BuildMenu( 63 content::WebContents* web_contents, 64 const content::ContextMenuParams& params) OVERRIDE; 65 virtual void ShowMenu(scoped_ptr<RenderViewContextMenu> menu) OVERRIDE; 66 67 private: 68 aura::Window* GetActiveNativeView(); 69 views::Widget* GetTopLevelWidget(); 70 views::FocusManager* GetFocusManager(); 71 void SetInitialFocus(); 72 73 // The id used in the ViewStorage to store the last focused view. 74 int last_focused_view_storage_id_; 75 76 // The context menu is reset every time we show it, but we keep a pointer to 77 // between uses so that it won't go out of scope before we're done with it. 78 scoped_ptr<RenderViewContextMenuViews> context_menu_; 79 80 // The chrome specific delegate that receives events from WebDragDest. 81 scoped_ptr<content::WebDragDestDelegate> bookmark_handler_; 82 83 content::WebContents* web_contents_; 84 85 scoped_ptr<LinkDisambiguationPopup> link_disambiguation_popup_; 86 87 DISALLOW_COPY_AND_ASSIGN(ChromeWebContentsViewDelegateViews); 88}; 89 90#endif // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_CHROME_WEB_CONTENTS_VIEW_DELEGATE_VIEWS_H_ 91