| 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 | 15 |
| 16 class DialogDelegate; | 16 class DialogDelegate; |
| 17 class LabelButton; | 17 class LabelButton; |
| 18 class Widget; | 18 class Widget; |
| 19 | 19 |
| 20 // DialogClientView provides adornments for a dialog's content view, including | 20 // DialogClientView provides adornments for a dialog's content view, including |
| 21 // custom-labeled [OK] and [Cancel] buttons with [Enter] and [Esc] accelerators. | 21 // custom-labeled [OK] and [Cancel] buttons with [Enter] and [Esc] accelerators. |
| 22 // The view also displays the delegate's extra view alongside the buttons and | 22 // The view also displays the delegate's extra view alongside the buttons. The |
| 23 // the delegate's footnote view below the buttons. The view appears like below. | 23 // view appears like below. NOTE: The contents view is not inset on the top or |
| 24 // NOTE: The contents view is not inset on the top or side client view edges. | 24 // side client view edges. |
| 25 // +------------------------------+ | 25 // +------------------------------+ |
| 26 // | Contents View | | 26 // | Contents View | |
| 27 // +------------------------------+ | 27 // +------------------------------+ |
| 28 // | [Extra View] [OK] [Cancel] | | 28 // | [Extra View] [OK] [Cancel] | |
| 29 // | [ Footnote View ] | | |
| 30 // +------------------------------+ | 29 // +------------------------------+ |
| 31 class VIEWS_EXPORT DialogClientView : public ClientView, | 30 class VIEWS_EXPORT DialogClientView : public ClientView, |
| 32 public ButtonListener { | 31 public ButtonListener { |
| 33 public: | 32 public: |
| 34 DialogClientView(Widget* widget, View* contents_view); | 33 DialogClientView(Widget* widget, View* contents_view); |
| 35 ~DialogClientView() override; | 34 ~DialogClientView() override; |
| 36 | 35 |
| 37 // Accept or Cancel the dialog. | 36 // Accept or Cancel the dialog. |
| 38 void AcceptWindow(); | 37 void AcceptWindow(); |
| 39 void CancelWindow(); | 38 void CancelWindow(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 54 gfx::Size GetPreferredSize() const override; | 53 gfx::Size GetPreferredSize() const override; |
| 55 void Layout() override; | 54 void Layout() override; |
| 56 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 55 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
| 57 void ViewHierarchyChanged( | 56 void ViewHierarchyChanged( |
| 58 const ViewHierarchyChangedDetails& details) override; | 57 const ViewHierarchyChangedDetails& details) override; |
| 59 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 58 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 60 | 59 |
| 61 // ButtonListener implementation: | 60 // ButtonListener implementation: |
| 62 void ButtonPressed(Button* sender, const ui::Event& event) override; | 61 void ButtonPressed(Button* sender, const ui::Event& event) override; |
| 63 | 62 |
| 63 void set_button_row_insets(const gfx::Insets& insets) { |
| 64 button_row_insets_ = insets; |
| 65 } |
| 66 |
| 64 protected: | 67 protected: |
| 65 // For testing. | 68 // For testing. |
| 66 explicit DialogClientView(View* contents_view); | 69 explicit DialogClientView(View* contents_view); |
| 67 | 70 |
| 68 // Returns the DialogDelegate for the window. Virtual for testing. | 71 // Returns the DialogDelegate for the window. Virtual for testing. |
| 69 virtual DialogDelegate* GetDialogDelegate() const; | 72 virtual DialogDelegate* GetDialogDelegate() const; |
| 70 | 73 |
| 71 // Create and add the extra view, if supplied by the delegate. | 74 // Create and add the extra view, if supplied by the delegate. |
| 72 void CreateExtraView(); | 75 void CreateExtraView(); |
| 73 | 76 |
| 74 // Creates and adds the footnote view, if supplied by the delegate. | |
| 75 void CreateFootnoteView(); | |
| 76 | |
| 77 // View implementation. | 77 // View implementation. |
| 78 void ChildPreferredSizeChanged(View* child) override; | 78 void ChildPreferredSizeChanged(View* child) override; |
| 79 void ChildVisibilityChanged(View* child) override; | 79 void ChildVisibilityChanged(View* child) override; |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } | 82 bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } |
| 83 | 83 |
| 84 // Create a dialog button of the appropriate type. | 84 // Create a dialog button of the appropriate type. |
| 85 LabelButton* CreateDialogButton(ui::DialogButton type); | 85 LabelButton* CreateDialogButton(ui::DialogButton type); |
| 86 | 86 |
| 87 // 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. |
| 88 void UpdateButton(LabelButton* button, ui::DialogButton type); | 88 void UpdateButton(LabelButton* button, ui::DialogButton type); |
| 89 | 89 |
| 90 // Returns the height of the row containing the buttons and the extra view. | 90 // Returns the height of the row containing the buttons and the extra view. |
| 91 int GetButtonsAndExtraViewRowHeight() const; | 91 int GetButtonsAndExtraViewRowHeight() const; |
| 92 | 92 |
| 93 // Returns the insets for the buttons and extra view. | 93 // Returns the insets for the buttons and extra view. |
| 94 gfx::Insets GetButtonRowInsets() const; | 94 gfx::Insets GetButtonRowInsets() const; |
| 95 | 95 |
| 96 // How much to inset the button row. |
| 97 gfx::Insets button_row_insets_; |
| 98 |
| 96 // Sets up the focus chain for the child views. This is required since the | 99 // Sets up the focus chain for the child views. This is required since the |
| 97 // delegate may choose to add/remove views at any time. | 100 // delegate may choose to add/remove views at any time. |
| 98 void SetupFocusChain(); | 101 void SetupFocusChain(); |
| 99 | 102 |
| 100 // The dialog buttons. | 103 // The dialog buttons. |
| 101 LabelButton* ok_button_; | 104 LabelButton* ok_button_; |
| 102 LabelButton* cancel_button_; | 105 LabelButton* cancel_button_; |
| 103 | 106 |
| 104 // The extra view shown in the row of buttons; may be NULL. | 107 // The extra view shown in the row of buttons; may be NULL. |
| 105 View* extra_view_; | 108 View* extra_view_; |
| 106 | 109 |
| 107 // The footnote view shown below the buttons; may be NULL. | |
| 108 View* footnote_view_; | |
| 109 | |
| 110 // True if we've notified the delegate the window is closing and the delegate | 110 // True if we've notified the delegate the window is closing and the delegate |
| 111 // allowed the close. In some situations it's possible to get two closes (see | 111 // allowed the close. In some situations it's possible to get two closes (see |
| 112 // http://crbug.com/71940). This is used to avoid notifying the delegate | 112 // http://crbug.com/71940). This is used to avoid notifying the delegate |
| 113 // twice, which can have bad consequences. | 113 // twice, which can have bad consequences. |
| 114 bool delegate_allowed_close_; | 114 bool delegate_allowed_close_; |
| 115 | 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(DialogClientView); | 116 DISALLOW_COPY_AND_ASSIGN(DialogClientView); |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 } // namespace views | 119 } // namespace views |
| 120 | 120 |
| 121 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ | 121 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ |
| OLD | NEW |