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 <memory>
9 
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "components/renderer_context_menu/context_menu_delegate.h"
13 #include "content/public/browser/web_contents_view_delegate.h"
14 
15 class RenderViewContextMenuBase;
16 class ChromeWebContentsViewFocusHelper;
17 
18 namespace content {
19 class WebContents;
20 class WebDragDestDelegate;
21 class RenderFrameHost;
22 }
23 
24 // A chrome specific class that extends WebContentsViewWin with features like
25 // focus management, which live in chrome.
26 class ChromeWebContentsViewDelegateViews
27     : public content::WebContentsViewDelegate,
28       public ContextMenuDelegate {
29  public:
30   explicit ChromeWebContentsViewDelegateViews(
31       content::WebContents* web_contents);
32   ~ChromeWebContentsViewDelegateViews() override;
33 
34   // Overridden from WebContentsViewDelegate:
35   gfx::NativeWindow GetNativeWindow() override;
36   content::WebDragDestDelegate* GetDragDestDelegate() override;
37   void StoreFocus() override;
38   bool RestoreFocus() override;
39   void ResetStoredFocus() override;
40   bool Focus() override;
41   bool TakeFocus(bool reverse) override;
42   void ShowContextMenu(content::RenderFrameHost* render_frame_host,
43                        const content::ContextMenuParams& params) override;
44   void OnPerformDrop(const content::DropData& drop_data,
45                      DropCompletionCallback callback) override;
46 
47   // Overridden from ContextMenuDelegate.
48   std::unique_ptr<RenderViewContextMenuBase> BuildMenu(
49       content::WebContents* web_contents,
50       const content::ContextMenuParams& params) override;
51   void ShowMenu(std::unique_ptr<RenderViewContextMenuBase> menu) override;
52 
53  private:
54   // The context menu is reset every time we show it, but we keep a pointer to
55   // between uses so that it won't go out of scope before we're done with it.
56   std::unique_ptr<RenderViewContextMenuBase> context_menu_;
57 
58   // The chrome specific delegate that receives events from WebDragDest.
59   std::unique_ptr<content::WebDragDestDelegate> bookmark_handler_;
60 
61   content::WebContents* web_contents_;
62 
63   ChromeWebContentsViewFocusHelper* GetFocusHelper() const;
64 
65   DISALLOW_COPY_AND_ASSIGN(ChromeWebContentsViewDelegateViews);
66 };
67 
68 #endif  // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_CHROME_WEB_CONTENTS_VIEW_DELEGATE_VIEWS_H_
69