• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_HTML_DIALOG_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "chrome/browser/ui/views/dom_view.h"
12 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h"
13 #include "chrome/browser/ui/webui/html_dialog_ui.h"
14 #include "ui/gfx/size.h"
15 #include "views/window/window_delegate.h"
16 
17 class Browser;
18 namespace views {
19 class Window;
20 }
21 
22 ////////////////////////////////////////////////////////////////////////////////
23 //
24 // HtmlDialogView is a view used to display an HTML dialog to the user. The
25 // content of the dialogs is determined by the delegate
26 // (HtmlDialogUIDelegate), but is basically a file URL along with a
27 // JSON input string. The HTML is supposed to show a UI to the user and is
28 // expected to send back a JSON file as a return value.
29 //
30 ////////////////////////////////////////////////////////////////////////////////
31 //
32 // TODO(akalin): Make HtmlDialogView contain an HtmlDialogTabContentsDelegate
33 // instead of inheriting from it to avoid violating the "no multiple
34 // inheritance" rule.
35 class HtmlDialogView
36     : public DOMView,
37       public HtmlDialogTabContentsDelegate,
38       public HtmlDialogUIDelegate,
39       public views::WindowDelegate {
40  public:
41   HtmlDialogView(Profile* profile, HtmlDialogUIDelegate* delegate);
42   virtual ~HtmlDialogView();
43 
44   // Initializes the contents of the dialog (the DOMView and the callbacks).
45   void InitDialog();
46 
47   // Overridden from views::View:
48   virtual gfx::Size GetPreferredSize();
49   virtual bool AcceleratorPressed(const views::Accelerator& accelerator);
50 
51   // Overridden from views::WindowDelegate:
52   virtual bool CanResize() const;
53   virtual bool IsModal() const;
54   virtual std::wstring GetWindowTitle() const;
55   virtual void WindowClosing();
56   virtual views::View* GetContentsView();
57   virtual views::View* GetInitiallyFocusedView();
58   virtual bool ShouldShowWindowTitle() const;
59 
60   // Overridden from HtmlDialogUIDelegate:
61   virtual bool IsDialogModal() const;
62   virtual std::wstring GetDialogTitle() const;
63   virtual GURL GetDialogContentURL() const;
64   virtual void GetWebUIMessageHandlers(
65       std::vector<WebUIMessageHandler*>* handlers) const;
66   virtual void GetDialogSize(gfx::Size* size) const;
67   virtual std::string GetDialogArgs() const;
68   virtual void OnWindowClosed();
69   virtual void OnDialogClosed(const std::string& json_retval);
70   virtual void OnCloseContents(TabContents* source, bool* out_close_dialog);
71   virtual bool ShouldShowDialogTitle() const;
72   virtual bool HandleContextMenu(const ContextMenuParams& params);
73 
74   // Overridden from TabContentsDelegate:
75   virtual void MoveContents(TabContents* source, const gfx::Rect& pos);
76   virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
77   virtual void CloseContents(TabContents* source);
78 
79  private:
80   // This view is a delegate to the HTML content since it needs to get notified
81   // about when the dialog is closing. For all other actions (besides dialog
82   // closing) we delegate to the creator of this view, which we keep track of
83   // using this variable.
84   HtmlDialogUIDelegate* delegate_;
85 
86   DISALLOW_COPY_AND_ASSIGN(HtmlDialogView);
87 };
88 
89 #endif  // CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_
90