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_GTK_TAB_CONTENTS_CHROME_WEB_CONTENTS_VIEW_DELEGATE_GTK_H_ 6 #define CHROME_BROWSER_UI_GTK_TAB_CONTENTS_CHROME_WEB_CONTENTS_VIEW_DELEGATE_GTK_H_ 7 8 #include "base/compiler_specific.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "content/public/browser/web_contents_view_delegate.h" 11 #include "ui/base/gtk/gtk_signal.h" 12 #include "ui/base/gtk/scoped_gobject.h" 13 14 class RenderViewContextMenuGtk; 15 class WebDragBookmarkHandlerGtk; 16 17 namespace content { 18 class WebContents; 19 } 20 21 // A chrome/ specific class that extends WebContentsViewGtk with features like 22 // web contents modal dialogs, which live in chrome/. 23 class ChromeWebContentsViewDelegateGtk 24 : public content::WebContentsViewDelegate { 25 public: 26 explicit ChromeWebContentsViewDelegateGtk(content::WebContents* web_contents); 27 virtual ~ChromeWebContentsViewDelegateGtk(); 28 29 static ChromeWebContentsViewDelegateGtk* GetFor( 30 content::WebContents* web_contents); 31 32 GtkWidget* expanded_container() { return expanded_container_; } 33 ui::FocusStoreGtk* focus_store() { return focus_store_; } 34 35 // Unlike Windows, web contents modal dialogs need to collaborate with the 36 // WebContentsViewGtk to position the dialogs. 37 void AttachWebContentsModalDialog(GtkWidget* web_contents_modal_dialog); 38 void RemoveWebContentsModalDialog(GtkWidget* web_contents_modal_dialog); 39 40 // Overridden from WebContentsViewDelegate: 41 virtual void ShowContextMenu( 42 const content::ContextMenuParams& params) OVERRIDE; 43 virtual content::WebDragDestDelegate* GetDragDestDelegate() OVERRIDE; 44 virtual void Initialize(GtkWidget* expanded_container, 45 ui::FocusStoreGtk* focus_store) OVERRIDE; 46 virtual gfx::NativeView GetNativeView() const OVERRIDE; 47 virtual void Focus() OVERRIDE; 48 virtual gboolean OnNativeViewFocusEvent(GtkWidget* widget, 49 GtkDirectionType type, 50 gboolean* return_value) OVERRIDE; 51 52 private: 53 // Sets the location of the web contents modal dialogs. 54 CHROMEGTK_CALLBACK_1(ChromeWebContentsViewDelegateGtk, void, 55 OnSetFloatingPosition, 56 GtkAllocation*); 57 58 // Contains |expanded_| as its GtkBin member. 59 ui::ScopedGObject<GtkWidget>::Type floating_; 60 61 // The UI for the web contents modal dialog currently displayed. This is owned 62 // by WebContents, not the view. 63 GtkWidget* web_contents_modal_dialog_; 64 65 // The context menu is reset every time we show it, but we keep a pointer to 66 // between uses so that it won't go out of scope before we're done with it. 67 scoped_ptr<RenderViewContextMenuGtk> context_menu_; 68 69 // The chrome specific delegate that receives events from WebDragDestGtk. 70 scoped_ptr<WebDragBookmarkHandlerGtk> bookmark_handler_gtk_; 71 72 content::WebContents* web_contents_; 73 74 GtkWidget* expanded_container_; 75 ui::FocusStoreGtk* focus_store_; 76 }; 77 78 #endif // CHROME_BROWSER_UI_GTK_TAB_CONTENTS_CHROME_WEB_CONTENTS_VIEW_DELEGATE_GTK_H_ 79