| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ | 5 #ifndef UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ |
| 6 #define UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ | 6 #define UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ |
| 7 | 7 |
| 8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "ui/base/ui_base_types.h" | 10 #include "ui/base/ui_base_types.h" |
| 11 #include "ui/views/controls/button/button.h" | 11 #include "ui/views/controls/button/button.h" |
| 12 #include "ui/views/window/client_view.h" | 12 #include "ui/views/window/client_view.h" |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 namespace test { |
| 16 class TestDialogClientView; |
| 17 } |
| 15 | 18 |
| 16 class DialogDelegate; | 19 class DialogDelegate; |
| 17 class LabelButton; | 20 class LabelButton; |
| 18 class Widget; | 21 class Widget; |
| 19 | 22 |
| 20 // DialogClientView provides adornments for a dialog's content view, including | 23 // DialogClientView provides adornments for a dialog's content view, including |
| 21 // custom-labeled [OK] and [Cancel] buttons with [Enter] and [Esc] accelerators. | 24 // custom-labeled [OK] and [Cancel] buttons with [Enter] and [Esc] accelerators. |
| 22 // The view also displays the delegate's extra view alongside the buttons. The | 25 // The view also displays the delegate's extra view alongside the buttons. The |
| 23 // view appears like below. NOTE: The contents view is not inset on the top or | 26 // view appears like below. NOTE: The contents view is not inset on the top or |
| 24 // side client view edges. | 27 // side client view edges. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 62 |
| 60 // ButtonListener implementation: | 63 // ButtonListener implementation: |
| 61 void ButtonPressed(Button* sender, const ui::Event& event) override; | 64 void ButtonPressed(Button* sender, const ui::Event& event) override; |
| 62 | 65 |
| 63 void set_button_row_insets(const gfx::Insets& insets) { | 66 void set_button_row_insets(const gfx::Insets& insets) { |
| 64 button_row_insets_ = insets; | 67 button_row_insets_ = insets; |
| 65 } | 68 } |
| 66 | 69 |
| 67 void set_minimum_size(const gfx::Size& size) { minimum_size_ = size; } | 70 void set_minimum_size(const gfx::Size& size) { minimum_size_ = size; } |
| 68 | 71 |
| 69 protected: | 72 private: |
| 70 // For testing. | 73 friend class test::TestDialogClientView; |
| 71 explicit DialogClientView(View* contents_view); | 74 |
| 75 bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } |
| 72 | 76 |
| 73 // Returns the DialogDelegate for the window. Virtual for testing. | 77 // Returns the DialogDelegate for the window. Virtual for testing. |
| 74 virtual DialogDelegate* GetDialogDelegate() const; | 78 virtual DialogDelegate* GetDialogDelegate() const; |
| 75 | 79 |
| 76 // Create and add the extra view, if supplied by the delegate. | |
| 77 void CreateExtraView(); | |
| 78 | |
| 79 // View implementation. | 80 // View implementation. |
| 80 void ChildPreferredSizeChanged(View* child) override; | 81 void ChildPreferredSizeChanged(View* child) override; |
| 81 void ChildVisibilityChanged(View* child) override; | 82 void ChildVisibilityChanged(View* child) override; |
| 82 | 83 |
| 83 private: | |
| 84 bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } | |
| 85 | |
| 86 // Create a dialog button of the appropriate type. | 84 // Create a dialog button of the appropriate type. |
| 87 LabelButton* CreateDialogButton(ui::DialogButton type); | 85 LabelButton* CreateDialogButton(ui::DialogButton type); |
| 88 | 86 |
| 89 // Update |button|'s text and enabled state according to the delegate's state. | 87 // Update |button|'s text and enabled state according to the delegate's state. |
| 90 void UpdateButton(LabelButton* button, ui::DialogButton type); | 88 void UpdateButton(LabelButton* button, ui::DialogButton type); |
| 91 | 89 |
| 92 // Returns the height of the buttons. | 90 // Returns the height of the buttons. |
| 93 int GetButtonHeight() const; | 91 int GetButtonHeight() const; |
| 94 | 92 |
| 95 // Returns the height of the extra view. | 93 // Returns the height of the extra view. |
| 96 int GetExtraViewHeight() const; | 94 int GetExtraViewHeight() const; |
| 97 | 95 |
| 98 // Returns the height of the row containing the buttons and the extra view. | 96 // Returns the height of the row containing the buttons and the extra view. |
| 99 int GetButtonsAndExtraViewRowHeight() const; | 97 int GetButtonsAndExtraViewRowHeight() const; |
| 100 | 98 |
| 101 // Returns the insets for the buttons and extra view, including the vertical | 99 // Returns the insets for the buttons and extra view, including the vertical |
| 102 // padding between them and the contents view. | 100 // padding between them and the contents view. |
| 103 gfx::Insets GetButtonRowInsets() const; | 101 gfx::Insets GetButtonRowInsets() const; |
| 104 | 102 |
| 103 // Installs and configures the LayoutManager. Does not add any views. |
| 104 void SetupLayout(); |
| 105 |
| 106 // First removes all child views, creates or deletes any buttons that are |
| 107 // required. Then adds the contents view, buttons and ExtraView (if any) to |
| 108 // the LayoutManager. |
| 109 void SetupViews(); |
| 110 |
| 105 // Sets up the focus chain for the child views. This is required since the | 111 // Sets up the focus chain for the child views. This is required since the |
| 106 // delegate may choose to add/remove views at any time. | 112 // delegate may choose to add/remove views at any time. |
| 107 void SetupFocusChain(); | 113 void SetupFocusChain(); |
| 108 | 114 |
| 109 // How much to inset the button row. | 115 // How much to inset the button row. |
| 110 gfx::Insets button_row_insets_; | 116 gfx::Insets button_row_insets_; |
| 111 | 117 |
| 112 // The minimum size of this dialog, regardless of the size of its content | 118 // The minimum size of this dialog, regardless of the size of its content |
| 113 // view. | 119 // view. |
| 114 gfx::Size minimum_size_; | 120 gfx::Size minimum_size_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 125 // http://crbug.com/71940). This is used to avoid notifying the delegate | 131 // http://crbug.com/71940). This is used to avoid notifying the delegate |
| 126 // twice, which can have bad consequences. | 132 // twice, which can have bad consequences. |
| 127 bool delegate_allowed_close_ = false; | 133 bool delegate_allowed_close_ = false; |
| 128 | 134 |
| 129 DISALLOW_COPY_AND_ASSIGN(DialogClientView); | 135 DISALLOW_COPY_AND_ASSIGN(DialogClientView); |
| 130 }; | 136 }; |
| 131 | 137 |
| 132 } // namespace views | 138 } // namespace views |
| 133 | 139 |
| 134 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ | 140 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ |
| OLD | NEW |