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 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "chrome/browser/tab_first_render_watcher.h" | |
13 #include "chrome/browser/ui/views/dom_view.h" | 15 #include "chrome/browser/ui/views/dom_view.h" |
14 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" | 16 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" |
15 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 17 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
16 #include "content/public/browser/notification_observer.h" | |
17 #include "content/public/browser/notification_registrar.h" | |
18 #include "ui/gfx/size.h" | 18 #include "ui/gfx/size.h" |
19 #include "views/widget/widget_delegate.h" | 19 #include "views/widget/widget_delegate.h" |
20 | 20 |
21 class Browser; | 21 class Browser; |
22 | 22 |
23 //////////////////////////////////////////////////////////////////////////////// | 23 //////////////////////////////////////////////////////////////////////////////// |
24 // | 24 // |
25 // HtmlDialogView is a view used to display an HTML dialog to the user. The | 25 // HtmlDialogView is a view used to display an HTML dialog to the user. The |
26 // content of the dialogs is determined by the delegate | 26 // content of the dialogs is determined by the delegate |
27 // (HtmlDialogUIDelegate), but is basically a file URL along with a | 27 // (HtmlDialogUIDelegate), but is basically a file URL along with a |
28 // JSON input string. The HTML is supposed to show a UI to the user and is | 28 // JSON input string. The HTML is supposed to show a UI to the user and is |
29 // expected to send back a JSON file as a return value. | 29 // expected to send back a JSON file as a return value. |
30 // | 30 // |
31 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
32 // | 32 // |
33 // TODO(akalin): Make HtmlDialogView contain an HtmlDialogTabContentsDelegate | 33 // TODO(akalin): Make HtmlDialogView contain an HtmlDialogTabContentsDelegate |
34 // instead of inheriting from it to avoid violating the "no multiple | 34 // instead of inheriting from it to avoid violating the "no multiple |
35 // inheritance" rule. | 35 // inheritance" rule. |
36 class HtmlDialogView | 36 class HtmlDialogView |
37 : public DOMView, | 37 : public DOMView, |
38 public HtmlDialogTabContentsDelegate, | 38 public HtmlDialogTabContentsDelegate, |
39 public HtmlDialogUIDelegate, | 39 public HtmlDialogUIDelegate, |
40 public views::WidgetDelegate, | 40 public views::WidgetDelegate, |
41 public content::NotificationObserver { | 41 public TabFirstRenderWatcher::Delegate { |
42 public: | 42 public: |
43 HtmlDialogView(Profile* profile, HtmlDialogUIDelegate* delegate); | 43 HtmlDialogView(Profile* profile, HtmlDialogUIDelegate* delegate); |
44 virtual ~HtmlDialogView(); | 44 virtual ~HtmlDialogView(); |
45 | 45 |
46 // Initializes the contents of the dialog (the DOMView and the callbacks). | 46 // Initializes the contents of the dialog (the DOMView and the callbacks). |
47 void InitDialog(); | 47 void InitDialog(); |
48 | 48 |
49 // Overridden from views::View: | 49 // Overridden from views::View: |
50 virtual gfx::Size GetPreferredSize() OVERRIDE; | 50 virtual gfx::Size GetPreferredSize() OVERRIDE; |
51 virtual bool AcceleratorPressed(const views::Accelerator& accelerator) | 51 virtual bool AcceleratorPressed(const views::Accelerator& accelerator) |
(...skipping 25 matching lines...) Expand all Loading... | |
77 OVERRIDE; | 77 OVERRIDE; |
78 virtual bool ShouldShowDialogTitle() const OVERRIDE; | 78 virtual bool ShouldShowDialogTitle() const OVERRIDE; |
79 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; | 79 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; |
80 | 80 |
81 // Overridden from TabContentsDelegate: | 81 // Overridden from TabContentsDelegate: |
82 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) OVERRIDE; | 82 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) OVERRIDE; |
83 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) | 83 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) |
84 OVERRIDE; | 84 OVERRIDE; |
85 virtual void CloseContents(TabContents* source) OVERRIDE; | 85 virtual void CloseContents(TabContents* source) OVERRIDE; |
86 | 86 |
87 // Overridden from content::NotificationObserver | |
88 virtual void Observe(int type, | |
89 const content::NotificationSource& source, | |
90 const content::NotificationDetails& details) OVERRIDE; | |
91 | |
92 protected: | 87 protected: |
93 // Register accelerators for this dialog. | 88 // Register accelerators for this dialog. |
94 virtual void RegisterDialogAccelerators(); | 89 virtual void RegisterDialogAccelerators(); |
95 | 90 |
91 // TabFirstRenderWatcher::Delegate implementation. | |
92 virtual void OnRenderHostCreated(RenderViewHost* host) OVERRIDE {} | |
93 virtual void OnTabMainFrameLoaded() OVERRIDE {} | |
oshima
2011/11/01 18:28:27
no inline for virtual functions
xiyuan
2011/11/01 20:18:15
Done.
| |
94 virtual void OnTabMainFrameFirstRender() OVERRIDE; | |
95 | |
96 private: | 96 private: |
97 FRIEND_TEST_ALL_PREFIXES(HtmlDialogBrowserTest, TestStateTransition); | 97 FRIEND_TEST_ALL_PREFIXES(HtmlDialogBrowserTest, WebContentRendered); |
98 | 98 |
99 // A state used to ensure that we show the window only after the | 99 // Whether the view is initialized. That is, dialog acceleartors is registered |
100 // renderer painted the full page. | 100 // and FreezeUpdates property is set to prevent WM from showing the window |
101 enum DialogState { | 101 // until the property is removed. |
102 NONE, | 102 bool initialized_; |
103 INITIALIZED, // FreezeUpdates property is set to prevent WM from showing | 103 |
104 // the window until the property is remoevd. | 104 // Watches for TabContents rendering. |
105 LOADED, // Renderer loaded the page. | 105 scoped_ptr<TabFirstRenderWatcher> tab_watcher_; |
106 PAINTED, // 1st paint event after the page is loaded. | |
107 // FreezeUpdates property is removed to tell WM to shows | |
108 // the window. | |
109 }; | |
110 DialogState state_; | |
111 | 106 |
112 // This view is a delegate to the HTML content since it needs to get notified | 107 // This view is a delegate to the HTML content since it needs to get notified |
113 // about when the dialog is closing. For all other actions (besides dialog | 108 // about when the dialog is closing. For all other actions (besides dialog |
114 // closing) we delegate to the creator of this view, which we keep track of | 109 // closing) we delegate to the creator of this view, which we keep track of |
115 // using this variable. | 110 // using this variable. |
116 HtmlDialogUIDelegate* delegate_; | 111 HtmlDialogUIDelegate* delegate_; |
117 | 112 |
118 content::NotificationRegistrar notification_registrar_; | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(HtmlDialogView); | 113 DISALLOW_COPY_AND_ASSIGN(HtmlDialogView); |
121 }; | 114 }; |
122 | 115 |
123 #endif // CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ | 116 #endif // CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ |
OLD | NEW |