Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: ui/views/window/dialog_client_view.h

Issue 1645013004: Views - dialog button defaultness shouldn't follow focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win compile Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/button/label_button.cc ('k') | ui/views/window/dialog_client_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/focus/focus_manager.h"
13 #include "ui/views/window/client_view.h" 12 #include "ui/views/window/client_view.h"
14 13
15 namespace views { 14 namespace views {
16 15
17 class DialogDelegate; 16 class DialogDelegate;
18 class LabelButton; 17 class LabelButton;
19 class Widget; 18 class Widget;
20 19
21 // DialogClientView provides adornments for a dialog's content view, including 20 // DialogClientView provides adornments for a dialog's content view, including
22 // custom-labeled [OK] and [Cancel] buttons with [Enter] and [Esc] accelerators. 21 // custom-labeled [OK] and [Cancel] buttons with [Enter] and [Esc] accelerators.
23 // 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 and
24 // the delegate's footnote view below the buttons. The view appears like below. 23 // the delegate's footnote view below the buttons. The view appears like below.
25 // NOTE: The contents view is not inset on the top or side client view edges. 24 // NOTE: The contents view is not inset on the top or side client view edges.
26 // +------------------------------+ 25 // +------------------------------+
27 // | Contents View | 26 // | Contents View |
28 // +------------------------------+ 27 // +------------------------------+
29 // | [Extra View] [OK] [Cancel] | 28 // | [Extra View] [OK] [Cancel] |
30 // | [ Footnote View ] | 29 // | [ Footnote View ] |
31 // +------------------------------+ 30 // +------------------------------+
32 class VIEWS_EXPORT DialogClientView : public ClientView, 31 class VIEWS_EXPORT DialogClientView : public ClientView,
33 public ButtonListener, 32 public ButtonListener {
34 public FocusChangeListener {
35 public: 33 public:
36 DialogClientView(Widget* widget, View* contents_view); 34 DialogClientView(Widget* widget, View* contents_view);
37 ~DialogClientView() override; 35 ~DialogClientView() override;
38 36
39 // Accept or Cancel the dialog. 37 // Accept or Cancel the dialog.
40 void AcceptWindow(); 38 void AcceptWindow();
41 void CancelWindow(); 39 void CancelWindow();
42 40
43 // Accessors in case the user wishes to adjust these buttons. 41 // Accessors in case the user wishes to adjust these buttons.
44 LabelButton* ok_button() const { return ok_button_; } 42 LabelButton* ok_button() const { return ok_button_; }
45 LabelButton* cancel_button() const { return cancel_button_; } 43 LabelButton* cancel_button() const { return cancel_button_; }
46 44
47 // Update the dialog buttons to match the dialog's delegate. 45 // Update the dialog buttons to match the dialog's delegate.
48 void UpdateDialogButtons(); 46 void UpdateDialogButtons();
49 47
50 // ClientView implementation: 48 // ClientView implementation:
51 bool CanClose() override; 49 bool CanClose() override;
52 DialogClientView* AsDialogClientView() override; 50 DialogClientView* AsDialogClientView() override;
53 const DialogClientView* AsDialogClientView() const override; 51 const DialogClientView* AsDialogClientView() const override;
54 52
55 // FocusChangeListener implementation:
56 void OnWillChangeFocus(View* focused_before, View* focused_now) override;
57 void OnDidChangeFocus(View* focused_before, View* focused_now) override;
58
59 // View implementation: 53 // View implementation:
60 gfx::Size GetPreferredSize() const override; 54 gfx::Size GetPreferredSize() const override;
61 void Layout() override; 55 void Layout() override;
62 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; 56 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
63 void ViewHierarchyChanged( 57 void ViewHierarchyChanged(
64 const ViewHierarchyChangedDetails& details) override; 58 const ViewHierarchyChangedDetails& details) override;
65 void NativeViewHierarchyChanged() override;
66 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; 59 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
67 60
68 // ButtonListener implementation: 61 // ButtonListener implementation:
69 void ButtonPressed(Button* sender, const ui::Event& event) override; 62 void ButtonPressed(Button* sender, const ui::Event& event) override;
70 63
71 protected: 64 protected:
72 // For testing. 65 // For testing.
73 explicit DialogClientView(View* contents_view); 66 explicit DialogClientView(View* contents_view);
74 67
75 // Returns the DialogDelegate for the window. Virtual for testing. 68 // Returns the DialogDelegate for the window. Virtual for testing.
76 virtual DialogDelegate* GetDialogDelegate() const; 69 virtual DialogDelegate* GetDialogDelegate() const;
77 70
78 // Create and add the extra view, if supplied by the delegate. 71 // Create and add the extra view, if supplied by the delegate.
79 void CreateExtraView(); 72 void CreateExtraView();
80 73
81 // Creates and adds the footnote view, if supplied by the delegate. 74 // Creates and adds the footnote view, if supplied by the delegate.
82 void CreateFootnoteView(); 75 void CreateFootnoteView();
83 76
84 // View implementation. 77 // View implementation.
85 void ChildPreferredSizeChanged(View* child) override; 78 void ChildPreferredSizeChanged(View* child) override;
86 void ChildVisibilityChanged(View* child) override; 79 void ChildVisibilityChanged(View* child) override;
87 80
88 private: 81 private:
89 FRIEND_TEST_ALL_PREFIXES(DialogClientViewTest, FocusManager);
90
91 bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } 82 bool has_dialog_buttons() const { return ok_button_ || cancel_button_; }
92 83
93 // Create a dialog button of the appropriate type. 84 // Create a dialog button of the appropriate type.
94 LabelButton* CreateDialogButton(ui::DialogButton type); 85 LabelButton* CreateDialogButton(ui::DialogButton type);
95 86
96 // 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.
97 void UpdateButton(LabelButton* button, ui::DialogButton type); 88 void UpdateButton(LabelButton* button, ui::DialogButton type);
98 89
99 // 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.
100 int GetButtonsAndExtraViewRowHeight() const; 91 int GetButtonsAndExtraViewRowHeight() const;
101 92
102 // Returns the insets for the buttons and extra view. 93 // Returns the insets for the buttons and extra view.
103 gfx::Insets GetButtonRowInsets() const; 94 gfx::Insets GetButtonRowInsets() const;
104 95
105 // Closes the widget. 96 // Closes the widget.
106 void Close(); 97 void Close();
107 98
108 // The dialog buttons. 99 // The dialog buttons.
109 LabelButton* ok_button_; 100 LabelButton* ok_button_;
110 LabelButton* cancel_button_; 101 LabelButton* cancel_button_;
111 102
112 // The button that is currently default; may be NULL.
113 LabelButton* default_button_;
114
115 // Observe |focus_manager_| to update the default button with focus changes.
116 FocusManager* focus_manager_;
117
118 // The extra view shown in the row of buttons; may be NULL. 103 // The extra view shown in the row of buttons; may be NULL.
119 View* extra_view_; 104 View* extra_view_;
120 105
121 // The footnote view shown below the buttons; may be NULL. 106 // The footnote view shown below the buttons; may be NULL.
122 View* footnote_view_; 107 View* footnote_view_;
123 108
124 // True if we've notified the delegate the window is closing and the delegate 109 // True if we've notified the delegate the window is closing and the delegate
125 // allosed the close. In some situations it's possible to get two closes (see 110 // allosed the close. In some situations it's possible to get two closes (see
126 // http://crbug.com/71940). This is used to avoid notifying the delegate 111 // http://crbug.com/71940). This is used to avoid notifying the delegate
127 // twice, which can have bad consequences. 112 // twice, which can have bad consequences.
128 bool notified_delegate_; 113 bool notified_delegate_;
129 114
130 DISALLOW_COPY_AND_ASSIGN(DialogClientView); 115 DISALLOW_COPY_AND_ASSIGN(DialogClientView);
131 }; 116 };
132 117
133 } // namespace views 118 } // namespace views
134 119
135 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ 120 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_
OLDNEW
« no previous file with comments | « ui/views/controls/button/label_button.cc ('k') | ui/views/window/dialog_client_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698