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 "ui/base/ui_base_types.h" |
8 #include "ui/gfx/font.h" | 9 #include "ui/gfx/font.h" |
9 #include "ui/views/controls/button/button.h" | 10 #include "ui/views/controls/button/button.h" |
10 #include "ui/views/focus/focus_manager.h" | 11 #include "ui/views/focus/focus_manager.h" |
11 #include "ui/views/window/client_view.h" | 12 #include "ui/views/window/client_view.h" |
12 | 13 |
13 namespace views { | 14 namespace views { |
14 | 15 |
15 class DialogDelegate; | 16 class DialogDelegate; |
16 class NativeTextButton; | 17 class TextButton; |
17 class Widget; | 18 class Widget; |
18 namespace internal { | 19 namespace internal { |
19 class RootView; | 20 class RootView; |
20 } | 21 } |
21 | 22 |
22 /////////////////////////////////////////////////////////////////////////////// | 23 /////////////////////////////////////////////////////////////////////////////// |
23 // DialogClientView | 24 // DialogClientView |
24 // | 25 // |
25 // This ClientView subclass provides the content of a typical dialog box, | 26 // This ClientView subclass provides the content of a typical dialog box, |
26 // including a strip of buttons at the bottom right of the window, default | 27 // including a strip of buttons at the bottom right of the window, default |
27 // accelerator handlers for accept and cancel, and the ability for the | 28 // accelerator handlers for accept and cancel, and the ability for the |
28 // embedded contents view to provide extra UI to be shown in the row of | 29 // embedded contents view to provide extra UI to be shown in the row of |
29 // buttons. | 30 // buttons. |
30 // | 31 // |
31 // DialogClientView also provides the ability to set an arbitrary view that is | 32 // DialogClientView also provides the ability to set an arbitrary view that is |
32 // positioned beneath the buttons. | 33 // positioned beneath the buttons. |
33 // | 34 // |
34 class VIEWS_EXPORT DialogClientView : public ClientView, | 35 class VIEWS_EXPORT DialogClientView : public ClientView, |
35 public ButtonListener, | 36 public ButtonListener, |
36 public FocusChangeListener { | 37 public FocusChangeListener { |
37 public: | 38 public: |
38 DialogClientView(Widget* widget, View* contents_view); | 39 typedef TextButton* (*TextButtonFactory)(ButtonListener* listener, |
| 40 Widget* owner, |
| 41 ui::DialogButton type, |
| 42 const string16& title); |
| 43 |
| 44 // Parameters for the internal dialog styling. Default construction |
| 45 // produces parameters for native dialog styling. |
| 46 struct VIEWS_EXPORT StyleParams { |
| 47 StyleParams(); |
| 48 |
| 49 int button_vedge_margin; |
| 50 int button_hedge_margin; |
| 51 int min_button_width; |
| 52 int button_label_spacing; |
| 53 int button_content_spacing; |
| 54 TextButtonFactory text_button_factory; |
| 55 }; |
| 56 |
| 57 DialogClientView(Widget* widget, |
| 58 View* contents_view, |
| 59 const StyleParams ¶ms); |
39 virtual ~DialogClientView(); | 60 virtual ~DialogClientView(); |
40 | 61 |
41 // Adds the dialog buttons required by the supplied DialogDelegate to the | 62 // Adds the dialog buttons required by the supplied DialogDelegate to the |
42 // view. | 63 // view. |
43 void ShowDialogButtons(); | 64 void ShowDialogButtons(); |
44 | 65 |
45 // Updates the enabled state and label of the buttons required by the | 66 // Updates the enabled state and label of the buttons required by the |
46 // supplied DialogDelegate | 67 // supplied DialogDelegate |
47 void UpdateDialogButtons(); | 68 void UpdateDialogButtons(); |
48 | 69 |
49 // Accept the changes made in the window that contains this ClientView. | 70 // Accept the changes made in the window that contains this ClientView. |
50 void AcceptWindow(); | 71 void AcceptWindow(); |
51 | 72 |
52 // Cancel the changes made in the window that contains this ClientView. | 73 // Cancel the changes made in the window that contains this ClientView. |
53 void CancelWindow(); | 74 void CancelWindow(); |
54 | 75 |
55 // Accessors in case the user wishes to adjust these buttons. | 76 // Accessors in case the user wishes to adjust these buttons. |
56 NativeTextButton* ok_button() const { return ok_button_; } | 77 TextButton* ok_button() const { return ok_button_; } |
57 NativeTextButton* cancel_button() const { return cancel_button_; } | 78 TextButton* cancel_button() const { return cancel_button_; } |
| 79 |
| 80 // Factory functions for creating buttons of the desired style. |
| 81 static TextButton* CreateNativeStyleDialogButton(ButtonListener* listener, |
| 82 Widget* owner, |
| 83 ui::DialogButton type, |
| 84 const string16& title); |
| 85 static TextButton* CreateChromeStyleDialogButton(ButtonListener* listener, |
| 86 Widget* owner, |
| 87 ui::DialogButton type, |
| 88 const string16& title); |
58 | 89 |
59 // Overridden from View: | 90 // Overridden from View: |
60 virtual void NativeViewHierarchyChanged( | 91 virtual void NativeViewHierarchyChanged( |
61 bool attached, | 92 bool attached, |
62 gfx::NativeView native_view, | 93 gfx::NativeView native_view, |
63 internal::RootView* root_view) OVERRIDE; | 94 internal::RootView* root_view) OVERRIDE; |
64 | 95 |
65 // Overridden from ClientView: | 96 // Overridden from ClientView: |
66 virtual bool CanClose() OVERRIDE; | 97 virtual bool CanClose() OVERRIDE; |
67 virtual void WidgetClosing() OVERRIDE; | 98 virtual void WidgetClosing() OVERRIDE; |
68 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; | 99 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; |
69 virtual DialogClientView* AsDialogClientView() OVERRIDE; | 100 virtual DialogClientView* AsDialogClientView() OVERRIDE; |
70 virtual const DialogClientView* AsDialogClientView() const OVERRIDE; | 101 virtual const DialogClientView* AsDialogClientView() const OVERRIDE; |
71 | 102 |
72 // FocusChangeListener implementation: | 103 // FocusChangeListener implementation: |
73 virtual void OnWillChangeFocus(View* focused_before, | 104 virtual void OnWillChangeFocus(View* focused_before, |
74 View* focused_now) OVERRIDE; | 105 View* focused_now) OVERRIDE; |
75 virtual void OnDidChangeFocus(View* focused_before, | 106 virtual void OnDidChangeFocus(View* focused_before, |
76 View* focused_now) OVERRIDE; | 107 View* focused_now) OVERRIDE; |
77 | 108 |
78 protected: | 109 protected: |
79 // View overrides: | 110 // View overrides: |
80 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
81 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | 111 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; |
82 virtual void Layout() OVERRIDE; | 112 virtual void Layout() OVERRIDE; |
83 virtual void ViewHierarchyChanged(bool is_add, View* parent, | 113 virtual void ViewHierarchyChanged(bool is_add, View* parent, |
84 View* child) OVERRIDE; | 114 View* child) OVERRIDE; |
85 virtual gfx::Size GetPreferredSize() OVERRIDE; | 115 virtual gfx::Size GetPreferredSize() OVERRIDE; |
86 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 116 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
87 | 117 |
88 // ButtonListener implementation: | 118 // ButtonListener implementation: |
89 virtual void ButtonPressed(Button* sender, | 119 virtual void ButtonPressed(Button* sender, |
90 const ui::Event& event) OVERRIDE; | 120 const ui::Event& event) OVERRIDE; |
(...skipping 12 matching lines...) Expand all Loading... |
103 // Returns the height of the dialog buttons area, including the spacing | 133 // Returns the height of the dialog buttons area, including the spacing |
104 // between bottom of contents view and top of buttons, the buttons height, | 134 // between bottom of contents view and top of buttons, the buttons height, |
105 // and the spacing between bottom of buttons to end of the dialog. | 135 // and the spacing between bottom of buttons to end of the dialog. |
106 int GetDialogButtonsAreaHeight() const; | 136 int GetDialogButtonsAreaHeight() const; |
107 | 137 |
108 // Position and size various sub-views. | 138 // Position and size various sub-views. |
109 void LayoutDialogButtons(); | 139 void LayoutDialogButtons(); |
110 void LayoutContentsView(); | 140 void LayoutContentsView(); |
111 | 141 |
112 // Makes the specified button the default button. | 142 // Makes the specified button the default button. |
113 void SetDefaultButton(NativeTextButton* button); | 143 void SetDefaultButton(TextButton* button); |
114 | 144 |
115 bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } | 145 bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } |
116 | 146 |
117 // Create and add the extra view, if supplied by the delegate. | 147 // Create and add the extra view, if supplied by the delegate. |
118 void CreateExtraView(); | 148 void CreateExtraView(); |
119 | 149 |
120 // Returns the DialogDelegate for the window. | 150 // Returns the DialogDelegate for the window. |
121 DialogDelegate* GetDialogDelegate() const; | 151 DialogDelegate* GetDialogDelegate() const; |
122 | 152 |
123 // Closes the widget. | 153 // Closes the widget. |
124 void Close(); | 154 void Close(); |
125 | 155 |
126 // Updates focus listener. | 156 // Updates focus listener. |
127 void UpdateFocusListener(); | 157 void UpdateFocusListener(); |
128 | 158 |
| 159 // Parameters for the internal dialog styling. |
| 160 StyleParams style_params_; |
| 161 |
129 // The dialog buttons. | 162 // The dialog buttons. |
130 NativeTextButton* ok_button_; | 163 TextButton* ok_button_; |
131 NativeTextButton* cancel_button_; | 164 TextButton* cancel_button_; |
132 | 165 |
133 // The button that is currently the default button if any. | 166 // The button that is currently the default button if any. |
134 NativeTextButton* default_button_; | 167 TextButton* default_button_; |
135 | 168 |
136 // The button-level extra view, NULL unless the dialog delegate supplies one. | 169 // The button-level extra view, NULL unless the dialog delegate supplies one. |
137 View* extra_view_; | 170 View* extra_view_; |
138 | 171 |
139 // See description of DialogDelegate::GetSizeExtraViewHeightToButtons for | 172 // See description of DialogDelegate::GetSizeExtraViewHeightToButtons for |
140 // details on this. | 173 // details on this. |
141 bool size_extra_view_height_to_buttons_; | 174 bool size_extra_view_height_to_buttons_; |
142 | 175 |
143 // The layout rect of the size box, when visible. | 176 // The layout rect of the size box, when visible. |
144 gfx::Rect size_box_bounds_; | 177 gfx::Rect size_box_bounds_; |
145 | 178 |
146 // True if we've notified the delegate the window is closing and the delegate | 179 // True if we've notified the delegate the window is closing and the delegate |
147 // allosed the close. In some situations it's possible to get two closes (see | 180 // allosed the close. In some situations it's possible to get two closes (see |
148 // http://crbug.com/71940). This is used to avoid notifying the delegate | 181 // http://crbug.com/71940). This is used to avoid notifying the delegate |
149 // twice, which can have bad consequences. | 182 // twice, which can have bad consequences. |
150 bool notified_delegate_; | 183 bool notified_delegate_; |
151 | 184 |
152 // true if focus listener is added. | 185 // true if focus listener is added. |
153 bool listening_to_focus_; | 186 bool listening_to_focus_; |
154 | 187 |
155 // When ancestor gets changed focus manager gets changed as well. | 188 // When ancestor gets changed focus manager gets changed as well. |
156 FocusManager* saved_focus_manager_; | 189 FocusManager* saved_focus_manager_; |
157 | 190 |
158 DISALLOW_COPY_AND_ASSIGN(DialogClientView); | 191 DISALLOW_COPY_AND_ASSIGN(DialogClientView); |
159 }; | 192 }; |
160 | 193 |
161 } // namespace views | 194 } // namespace views |
162 | 195 |
163 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ | 196 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ |
OLD | NEW |