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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // Update the dialog buttons to match the dialog's delegate. | 44 // Update the dialog buttons to match the dialog's delegate. |
45 void UpdateDialogButtons(); | 45 void UpdateDialogButtons(); |
46 | 46 |
47 // ClientView implementation: | 47 // ClientView implementation: |
48 bool CanClose() override; | 48 bool CanClose() override; |
49 DialogClientView* AsDialogClientView() override; | 49 DialogClientView* AsDialogClientView() override; |
50 const DialogClientView* AsDialogClientView() const override; | 50 const DialogClientView* AsDialogClientView() const override; |
51 | 51 |
52 // View implementation: | 52 // View implementation: |
53 gfx::Size GetPreferredSize() const override; | 53 gfx::Size GetPreferredSize() const override; |
| 54 gfx::Size GetMinimumSize() const override; |
| 55 gfx::Size GetMaximumSize() const override; |
| 56 |
54 void Layout() override; | 57 void Layout() override; |
55 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 58 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
56 void ViewHierarchyChanged( | 59 void ViewHierarchyChanged( |
57 const ViewHierarchyChangedDetails& details) override; | 60 const ViewHierarchyChangedDetails& details) override; |
58 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 61 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
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 private: | 72 private: |
70 bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } | 73 enum { |
| 74 // The number of buttons that DialogClientView can support. |
| 75 kNumButtons = 3 |
| 76 }; |
| 77 class ButtonRowContainer; |
71 | 78 |
72 // Returns the DialogDelegate for the window. | 79 // Returns the DialogDelegate for the window. |
73 DialogDelegate* GetDialogDelegate() const; | 80 DialogDelegate* GetDialogDelegate() const; |
74 | 81 |
75 // View implementation. | 82 // View implementation. |
76 void ChildPreferredSizeChanged(View* child) override; | 83 void ChildPreferredSizeChanged(View* child) override; |
77 void ChildVisibilityChanged(View* child) override; | 84 void ChildVisibilityChanged(View* child) override; |
78 | 85 |
79 // Create a dialog button of the appropriate type. | 86 // Creates, deletes, or updates the appearance of the button of type |type| |
80 LabelButton* CreateDialogButton(ui::DialogButton type); | 87 // (which must be pointed to by |member|). Which action is chosen is based on |
81 | 88 // whether DialogDelegate::GetDialogButtons() includes |type|, and whether |
82 // Update |button|'s text and enabled state according to the delegate's state. | 89 // |member| points to a button that already exists. |
83 void UpdateButton(LabelButton* button, ui::DialogButton type); | 90 void UpdateDialogButton(LabelButton** member, ui::DialogButton type); |
84 | |
85 // Returns the height of the buttons. | |
86 int GetButtonHeight() const; | |
87 | |
88 // Returns the height of the extra view. | |
89 int GetExtraViewHeight() const; | |
90 | |
91 // Returns the height of the row containing the buttons and the extra view. | |
92 int GetButtonsAndExtraViewRowHeight() const; | |
93 | |
94 // Returns the insets for the buttons and extra view, including the vertical | |
95 // padding between them and the contents view. | |
96 gfx::Insets GetButtonRowInsets() const; | |
97 | |
98 // Sets up the focus chain for the child views. This is required since the | |
99 // delegate may choose to add/remove views at any time. | |
100 void SetupFocusChain(); | |
101 | 91 |
102 // Returns the spacing between the extra view and the ok/cancel buttons. 0 if | 92 // Returns the spacing between the extra view and the ok/cancel buttons. 0 if |
103 // no extra view. Otherwise uses GetExtraViewPadding() or the default padding. | 93 // no extra view. Otherwise uses GetExtraViewPadding() or the default padding. |
104 int GetExtraViewSpacing() const; | 94 int GetExtraViewSpacing() const; |
105 | 95 |
| 96 // Returns Views in the button row, as they should appear in the layout. If |
| 97 // a View should not appear, it will be null. |
| 98 std::array<View*, kNumButtons> GetButtonRowViews(); |
| 99 |
| 100 // Installs and configures the LayoutManager for |button_row_container_|. |
| 101 void SetupLayout(); |
| 102 |
106 // Creates or deletes any buttons that are required. Updates data members. | 103 // Creates or deletes any buttons that are required. Updates data members. |
| 104 // After calling this, no button row Views will be in the view hierarchy. |
107 void SetupViews(); | 105 void SetupViews(); |
108 | 106 |
109 // How much to inset the button row. | 107 // How much to inset the button row. |
110 gfx::Insets button_row_insets_; | 108 gfx::Insets button_row_insets_; |
111 | 109 |
112 // The minimum size of this dialog, regardless of the size of its content | 110 // The minimum size of this dialog, regardless of the size of its content |
113 // view. | 111 // view. |
114 gfx::Size minimum_size_; | 112 gfx::Size minimum_size_; |
115 | 113 |
116 // The dialog buttons. | 114 // The dialog buttons. |
117 LabelButton* ok_button_ = nullptr; | 115 LabelButton* ok_button_ = nullptr; |
118 LabelButton* cancel_button_ = nullptr; | 116 LabelButton* cancel_button_ = nullptr; |
119 | 117 |
120 // The extra view shown in the row of buttons; may be NULL. | 118 // The extra view shown in the row of buttons; may be NULL. |
121 View* extra_view_ = nullptr; | 119 View* extra_view_ = nullptr; |
122 | 120 |
| 121 // Container view for the button row. |
| 122 ButtonRowContainer* button_row_container_ = nullptr; |
| 123 |
123 // True if we've notified the delegate the window is closing and the delegate | 124 // True if we've notified the delegate the window is closing and the delegate |
124 // allowed the close. In some situations it's possible to get two closes (see | 125 // allowed the close. In some situations it's possible to get two closes (see |
125 // http://crbug.com/71940). This is used to avoid notifying the delegate | 126 // http://crbug.com/71940). This is used to avoid notifying the delegate |
126 // twice, which can have bad consequences. | 127 // twice, which can have bad consequences. |
127 bool delegate_allowed_close_ = false; | 128 bool delegate_allowed_close_ = false; |
128 | 129 |
| 130 // When true, prevents ViewHierarchyChanged() from clearing out data members. |
| 131 bool preserve_button_row_data_members_ = false; |
| 132 |
129 DISALLOW_COPY_AND_ASSIGN(DialogClientView); | 133 DISALLOW_COPY_AND_ASSIGN(DialogClientView); |
130 }; | 134 }; |
131 | 135 |
132 } // namespace views | 136 } // namespace views |
133 | 137 |
134 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ | 138 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ |
OLD | NEW |