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

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

Issue 14230018: Handle dialog acclerators explicitly; nix default button switching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Limit the focused view handling to LabelButton; update tests. Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/view_unittest.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 "ui/base/ui_base_types.h" 8 #include "ui/base/ui_base_types.h"
9 #include "ui/views/controls/button/button.h" 9 #include "ui/views/controls/button/button.h"
10 #include "ui/views/focus/focus_manager.h"
11 #include "ui/views/window/client_view.h" 10 #include "ui/views/window/client_view.h"
12 11
13 namespace views { 12 namespace views {
14 13
15 class DialogDelegate; 14 class DialogDelegate;
16 class LabelButton; 15 class LabelButton;
17 class Widget; 16 class Widget;
18 17
19 // DialogClientView provides adornments for a dialog's content view, including 18 // DialogClientView provides adornments for a dialog's content view, including
20 // custom-labeled [OK] and [Cancel] buttons with [Enter] and [Esc] accelerators. 19 // custom-labeled [OK] and [Cancel] buttons with [Enter] and [Esc] accelerators.
21 // The view also displays the delegate's extra view alongside the buttons and 20 // The view also displays the delegate's extra view alongside the buttons and
22 // the delegate's footnote view below the buttons. The view appears like below. 21 // the delegate's footnote view below the buttons. The view appears like below.
23 // NOTE: The contents view is not inset on the top or side client view edges. 22 // NOTE: The contents view is not inset on the top or side client view edges.
24 // +------------------------------+ 23 // +------------------------------+
25 // | Contents View | 24 // | Contents View |
26 // +------------------------------+ 25 // +------------------------------+
27 // | [Extra View] [OK] [Cancel] | 26 // | [Extra View] [OK] [Cancel] |
28 // | [ Footnote View ] | 27 // | [ Footnote View ] |
29 // +------------------------------+ 28 // +------------------------------+
30 class VIEWS_EXPORT DialogClientView : public ClientView, 29 class VIEWS_EXPORT DialogClientView : public ClientView, public ButtonListener {
31 public ButtonListener,
32 public FocusChangeListener {
33 public: 30 public:
34 DialogClientView(Widget* widget, View* contents_view); 31 DialogClientView(Widget* widget, View* contents_view);
35 virtual ~DialogClientView(); 32 virtual ~DialogClientView();
36 33
37 // Accept or Cancel the dialog. 34 // Accept or Cancel the dialog.
38 void AcceptWindow(); 35 void AcceptWindow();
39 void CancelWindow(); 36 void CancelWindow();
40 37
41 // Accessors in case the user wishes to adjust these buttons. 38 // Accessors in case the user wishes to adjust these buttons.
42 LabelButton* ok_button() const { return ok_button_; } 39 LabelButton* ok_button() const { return ok_button_; }
43 LabelButton* cancel_button() const { return cancel_button_; } 40 LabelButton* cancel_button() const { return cancel_button_; }
44 41
45 // Update the dialog buttons to match the dialog's delegate. 42 // Update the dialog buttons to match the dialog's delegate.
46 void UpdateDialogButtons(); 43 void UpdateDialogButtons();
47 44
48 // ClientView implementation: 45 // ClientView implementation:
49 virtual bool CanClose() OVERRIDE; 46 virtual bool CanClose() OVERRIDE;
50 virtual DialogClientView* AsDialogClientView() OVERRIDE; 47 virtual DialogClientView* AsDialogClientView() OVERRIDE;
51 virtual const DialogClientView* AsDialogClientView() const OVERRIDE; 48 virtual const DialogClientView* AsDialogClientView() const OVERRIDE;
52 49
53 // FocusChangeListener implementation:
54 virtual void OnWillChangeFocus(View* focused_before,
55 View* focused_now) OVERRIDE;
56 virtual void OnDidChangeFocus(View* focused_before,
57 View* focused_now) OVERRIDE;
58
59 // View implementation: 50 // View implementation:
60 virtual gfx::Size GetPreferredSize() OVERRIDE; 51 virtual gfx::Size GetPreferredSize() OVERRIDE;
61 virtual void Layout() OVERRIDE; 52 virtual void Layout() OVERRIDE;
62 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; 53 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
63 virtual void ViewHierarchyChanged(bool is_add, 54 virtual void ViewHierarchyChanged(bool is_add,
64 View* parent, 55 View* parent,
65 View* child) OVERRIDE; 56 View* child) OVERRIDE;
66 57
67 // ButtonListener implementation: 58 // ButtonListener implementation:
68 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE; 59 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE;
(...skipping 23 matching lines...) Expand all
92 // Returns the insets for the buttons and extra view. 83 // Returns the insets for the buttons and extra view.
93 gfx::Insets GetButtonRowInsets() const; 84 gfx::Insets GetButtonRowInsets() const;
94 85
95 // Closes the widget. 86 // Closes the widget.
96 void Close(); 87 void Close();
97 88
98 // The dialog buttons. 89 // The dialog buttons.
99 LabelButton* ok_button_; 90 LabelButton* ok_button_;
100 LabelButton* cancel_button_; 91 LabelButton* cancel_button_;
101 92
102 // The button that is currently default; may be NULL.
103 LabelButton* default_button_;
104
105 // Observe |focus_manager_| to update the default button with focus changes.
106 FocusManager* focus_manager_;
107
108 // The extra view shown in the row of buttons; may be NULL. 93 // The extra view shown in the row of buttons; may be NULL.
109 View* extra_view_; 94 View* extra_view_;
110 95
111 // The footnote view shown below the buttons; may be NULL. 96 // The footnote view shown below the buttons; may be NULL.
112 View* footnote_view_; 97 View* footnote_view_;
113 98
114 // True if we've notified the delegate the window is closing and the delegate 99 // True if we've notified the delegate the window is closing and the delegate
115 // allosed the close. In some situations it's possible to get two closes (see 100 // allosed the close. In some situations it's possible to get two closes (see
116 // http://crbug.com/71940). This is used to avoid notifying the delegate 101 // http://crbug.com/71940). This is used to avoid notifying the delegate
117 // twice, which can have bad consequences. 102 // twice, which can have bad consequences.
118 bool notified_delegate_; 103 bool notified_delegate_;
119 104
120 DISALLOW_COPY_AND_ASSIGN(DialogClientView); 105 DISALLOW_COPY_AND_ASSIGN(DialogClientView);
121 }; 106 };
122 107
123 } // namespace views 108 } // namespace views
124 109
125 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ 110 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_
OLDNEW
« no previous file with comments | « ui/views/view_unittest.cc ('k') | ui/views/window/dialog_client_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698