OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "chrome/browser/ui/views/dom_view.h" | 11 #include "chrome/browser/ui/views/dom_view.h" |
12 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" | 12 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" |
13 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 13 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
14 #include "content/common/notification_observer.h" | |
15 #include "content/common/notification_registrar.h" | |
14 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
15 #include "views/window/window_delegate.h" | 17 #include "views/window/window_delegate.h" |
16 | 18 |
17 class Browser; | 19 class Browser; |
18 namespace views { | 20 namespace views { |
19 class Window; | 21 class Window; |
20 } | 22 } |
21 | 23 |
22 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
23 // | 25 // |
24 // HtmlDialogView is a view used to display an HTML dialog to the user. The | 26 // HtmlDialogView is a view used to display an HTML dialog to the user. The |
25 // content of the dialogs is determined by the delegate | 27 // content of the dialogs is determined by the delegate |
26 // (HtmlDialogUIDelegate), but is basically a file URL along with a | 28 // (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 | 29 // 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. | 30 // expected to send back a JSON file as a return value. |
29 // | 31 // |
30 //////////////////////////////////////////////////////////////////////////////// | 32 //////////////////////////////////////////////////////////////////////////////// |
31 // | 33 // |
32 // TODO(akalin): Make HtmlDialogView contain an HtmlDialogTabContentsDelegate | 34 // TODO(akalin): Make HtmlDialogView contain an HtmlDialogTabContentsDelegate |
33 // instead of inheriting from it to avoid violating the "no multiple | 35 // instead of inheriting from it to avoid violating the "no multiple |
34 // inheritance" rule. | 36 // inheritance" rule. |
35 class HtmlDialogView | 37 class HtmlDialogView |
36 : public DOMView, | 38 : public DOMView, |
37 public HtmlDialogTabContentsDelegate, | 39 public HtmlDialogTabContentsDelegate, |
38 public HtmlDialogUIDelegate, | 40 public HtmlDialogUIDelegate, |
39 public views::WindowDelegate { | 41 public views::WindowDelegate, |
42 public NotificationObserver { | |
40 public: | 43 public: |
41 HtmlDialogView(Profile* profile, HtmlDialogUIDelegate* delegate); | 44 HtmlDialogView(Profile* profile, HtmlDialogUIDelegate* delegate); |
42 virtual ~HtmlDialogView(); | 45 virtual ~HtmlDialogView(); |
43 | 46 |
44 // Initializes the contents of the dialog (the DOMView and the callbacks). | 47 // Initializes the contents of the dialog (the DOMView and the callbacks). |
45 void InitDialog(); | 48 void InitDialog(); |
46 | 49 |
47 // Overridden from views::View: | 50 // Overridden from views::View: |
48 virtual gfx::Size GetPreferredSize(); | 51 virtual gfx::Size GetPreferredSize(); |
49 virtual bool AcceleratorPressed(const views::Accelerator& accelerator); | 52 virtual bool AcceleratorPressed(const views::Accelerator& accelerator); |
53 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); | |
50 | 54 |
51 // Overridden from views::WindowDelegate: | 55 // Overridden from views::WindowDelegate: |
52 virtual bool CanResize() const; | 56 virtual bool CanResize() const; |
53 virtual bool IsModal() const; | 57 virtual bool IsModal() const; |
54 virtual std::wstring GetWindowTitle() const; | 58 virtual std::wstring GetWindowTitle() const; |
55 virtual void WindowClosing(); | 59 virtual void WindowClosing(); |
56 virtual views::View* GetContentsView(); | 60 virtual views::View* GetContentsView(); |
57 virtual views::View* GetInitiallyFocusedView(); | 61 virtual views::View* GetInitiallyFocusedView(); |
58 virtual bool ShouldShowWindowTitle() const; | 62 virtual bool ShouldShowWindowTitle() const; |
59 | 63 |
60 // Overridden from HtmlDialogUIDelegate: | 64 // Overridden from HtmlDialogUIDelegate: |
61 virtual bool IsDialogModal() const; | 65 virtual bool IsDialogModal() const; |
62 virtual std::wstring GetDialogTitle() const; | 66 virtual std::wstring GetDialogTitle() const; |
63 virtual GURL GetDialogContentURL() const; | 67 virtual GURL GetDialogContentURL() const; |
64 virtual void GetWebUIMessageHandlers( | 68 virtual void GetWebUIMessageHandlers( |
65 std::vector<WebUIMessageHandler*>* handlers) const; | 69 std::vector<WebUIMessageHandler*>* handlers) const; |
66 virtual void GetDialogSize(gfx::Size* size) const; | 70 virtual void GetDialogSize(gfx::Size* size) const; |
67 virtual std::string GetDialogArgs() const; | 71 virtual std::string GetDialogArgs() const; |
68 virtual void OnWindowClosed(); | 72 virtual void OnWindowClosed(); |
69 virtual void OnDialogClosed(const std::string& json_retval); | 73 virtual void OnDialogClosed(const std::string& json_retval); |
70 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog); | 74 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog); |
71 virtual bool ShouldShowDialogTitle() const; | 75 virtual bool ShouldShowDialogTitle() const; |
72 virtual bool HandleContextMenu(const ContextMenuParams& params); | 76 virtual bool HandleContextMenu(const ContextMenuParams& params); |
73 | 77 |
74 // Overridden from TabContentsDelegate: | 78 // Overridden from TabContentsDelegate: |
75 virtual void MoveContents(TabContents* source, const gfx::Rect& pos); | 79 virtual void MoveContents(TabContents* source, const gfx::Rect& pos); |
76 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); | 80 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); |
77 virtual void CloseContents(TabContents* source); | 81 virtual void CloseContents(TabContents* source); |
78 | 82 |
83 // Overridden from NotificationObserver | |
84 virtual void Observe(NotificationType type, | |
85 const NotificationSource& source, | |
86 const NotificationDetails& details); | |
sky
2011/06/07 15:41:17
OVERRIDE
| |
87 | |
88 protected: | |
89 // Register accelerators for this dialog. | |
90 virtual void RegisterDialogAccelerators(); | |
91 | |
79 private: | 92 private: |
93 // A state used to ensure that we show the window only after the | |
94 // renderer painted the full page. | |
95 enum DialogState { | |
96 NONE, | |
97 INITIALIZED, // FreezeUpdates property is set to prevent WM from showing | |
98 // the window until the property is remoevd. | |
99 LOADED, // Renderer loaded the page. | |
100 PAINTED, // 1st paint event after the page is loaded. | |
101 // FreezeUpdates property is removed to tell WM to shows | |
102 // the window. | |
103 }; | |
104 DialogState state_; | |
sky
2011/06/07 15:41:17
newline between 103 and 104
| |
105 | |
80 // This view is a delegate to the HTML content since it needs to get notified | 106 // 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 | 107 // 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 | 108 // closing) we delegate to the creator of this view, which we keep track of |
83 // using this variable. | 109 // using this variable. |
84 HtmlDialogUIDelegate* delegate_; | 110 HtmlDialogUIDelegate* delegate_; |
85 | 111 |
112 NotificationRegistrar notification_registrar_; | |
113 | |
86 DISALLOW_COPY_AND_ASSIGN(HtmlDialogView); | 114 DISALLOW_COPY_AND_ASSIGN(HtmlDialogView); |
87 }; | 115 }; |
88 | 116 |
89 #endif // CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ | 117 #endif // CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ |
OLD | NEW |