Home | History | Annotate | Download | only in gtk
      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_WEB_DIALOG_GTK_H_
      6 #define CHROME_BROWSER_UI_GTK_WEB_DIALOG_GTK_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/compiler_specific.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "ui/base/gtk/gtk_signal.h"
     14 #include "ui/gfx/native_widget_types.h"
     15 #include "ui/gfx/size.h"
     16 #include "ui/web_dialogs/web_dialog_delegate.h"
     17 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h"
     18 
     19 typedef struct _GtkWidget GtkWidget;
     20 
     21 namespace content {
     22 class BrowserContext;
     23 class WebContents;
     24 }
     25 
     26 class WebDialogGtk : public ui::WebDialogWebContentsDelegate,
     27                      public ui::WebDialogDelegate {
     28  public:
     29   WebDialogGtk(content::BrowserContext* context,
     30                ui::WebDialogDelegate* delegate,
     31                gfx::NativeWindow parent_window);
     32   virtual ~WebDialogGtk();
     33 
     34   // Initializes the contents of the dialog (the DOMView and the callbacks).
     35   gfx::NativeWindow InitDialog();
     36 
     37   // Overridden from ui::WebDialogDelegate:
     38   virtual ui::ModalType GetDialogModalType() const OVERRIDE;
     39   virtual string16 GetDialogTitle() const OVERRIDE;
     40   virtual GURL GetDialogContentURL() const OVERRIDE;
     41   virtual void GetWebUIMessageHandlers(
     42       std::vector<content::WebUIMessageHandler*>* handlers) const OVERRIDE;
     43   virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
     44   virtual void GetMinimumDialogSize(gfx::Size* size) const OVERRIDE;
     45   virtual std::string GetDialogArgs() const OVERRIDE;
     46   virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
     47   virtual void OnCloseContents(content::WebContents* source,
     48                                bool* out_close_dialog) OVERRIDE;
     49   virtual bool ShouldShowDialogTitle() const OVERRIDE;
     50 
     51   // Overridden from content::WebContentsDelegate:
     52   virtual void HandleKeyboardEvent(
     53       content::WebContents* source,
     54       const content::NativeWebKeyboardEvent& event) OVERRIDE;
     55   virtual void CloseContents(content::WebContents* source) OVERRIDE;
     56   virtual content::WebContents* OpenURLFromTab(
     57       content::WebContents* source,
     58       const content::OpenURLParams& params) OVERRIDE;
     59   virtual void AddNewContents(content::WebContents* source,
     60                               content::WebContents* new_contents,
     61                               WindowOpenDisposition disposition,
     62                               const gfx::Rect& initial_pos,
     63                               bool user_gesture,
     64                               bool* was_blocked) OVERRIDE;
     65   virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE;
     66 
     67  private:
     68   CHROMEGTK_CALLBACK_1(WebDialogGtk, void, OnResponse, int);
     69 
     70   // This view is a delegate to the HTML content since it needs to get notified
     71   // about when the dialog is closing. For all other actions (besides dialog
     72   // closing) we delegate to the creator of this view, which we keep track of
     73   // using this variable.
     74   ui::WebDialogDelegate* delegate_;
     75 
     76   gfx::NativeWindow parent_window_;
     77 
     78   GtkWidget* dialog_;
     79 
     80   scoped_ptr<content::WebContents> web_contents_;
     81 
     82   DISALLOW_COPY_AND_ASSIGN(WebDialogGtk);
     83 };
     84 
     85 #endif  // CHROME_BROWSER_UI_GTK_WEB_DIALOG_GTK_H_
     86