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