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 #include "ui/views/window/dialog_client_view.h" | 5 #include "ui/views/window/dialog_client_view.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
11 #include <uxtheme.h> | 11 #include <uxtheme.h> |
12 #include <vsstyle.h> | 12 #include <vsstyle.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 | 16 |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "grit/ui_strings.h" | 18 #include "grit/ui_strings.h" |
19 #include "ui/base/hit_test.h" | 19 #include "ui/base/hit_test.h" |
20 #include "ui/base/keycodes/keyboard_codes.h" | 20 #include "ui/base/keycodes/keyboard_codes.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/native_theme/native_theme.h" | 22 #include "ui/base/native_theme/native_theme.h" |
23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
25 #include "ui/gfx/font.h" | 25 #include "ui/gfx/font.h" |
26 #include "ui/views/controls/button/text_button.h" | 26 #include "ui/views/controls/button/text_button.h" |
| 27 #include "ui/views/controls/button/chrome_style.h" |
27 #include "ui/views/layout/layout_constants.h" | 28 #include "ui/views/layout/layout_constants.h" |
28 #include "ui/views/widget/root_view.h" | 29 #include "ui/views/widget/root_view.h" |
29 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
30 #include "ui/views/window/dialog_delegate.h" | 31 #include "ui/views/window/dialog_delegate.h" |
31 | 32 |
32 namespace views { | 33 namespace views { |
33 namespace { | 34 namespace { |
34 | 35 |
35 const int kDialogMinButtonWidth = 75; | 36 const int kDialogMinButtonWidth = 75; |
36 const int kDialogButtonLabelSpacing = 16; | 37 const int kDialogButtonLabelSpacing = 16; |
37 const int kDialogButtonContentSpacing = 5; | 38 const int kDialogButtonContentSpacing = 5; |
38 | 39 |
39 // The group used by the buttons. This name is chosen voluntarily big not to | 40 // The group used by the buttons. This name is chosen voluntarily big not to |
40 // conflict with other groups that could be in the dialog content. | 41 // conflict with other groups that could be in the dialog content. |
41 const int kButtonGroup = 6666; | 42 const int kButtonGroup = 6666; |
42 | 43 |
43 const gfx::Font& GetDialogButtonFont() { | 44 const gfx::Font& GetDialogButtonFont() { |
44 static gfx::Font* font = NULL; | 45 static gfx::Font* font = NULL; |
45 if (!font) { | 46 if (!font) { |
46 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 47 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
47 font = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); | 48 font = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); |
48 } | 49 } |
49 return *font; | 50 return *font; |
50 } | 51 } |
51 | 52 |
52 // Updates any of the standard buttons according to the delegate. | 53 // Updates any of the standard buttons according to the delegate. |
53 void UpdateButtonHelper(NativeTextButton* button_view, | 54 void UpdateButtonHelper(TextButton* button_view, |
54 DialogDelegate* delegate, | 55 DialogDelegate* delegate, |
55 ui::DialogButton button) { | 56 ui::DialogButton button) { |
56 string16 label = delegate->GetDialogButtonLabel(button); | 57 string16 label = delegate->GetDialogButtonLabel(button); |
57 if (!label.empty()) | 58 if (!label.empty()) |
58 button_view->SetText(label); | 59 button_view->SetText(label); |
59 button_view->SetEnabled(delegate->IsDialogButtonEnabled(button)); | 60 button_view->SetEnabled(delegate->IsDialogButtonEnabled(button)); |
60 button_view->SetVisible(delegate->IsDialogButtonVisible(button)); | 61 button_view->SetVisible(delegate->IsDialogButtonVisible(button)); |
61 } | 62 } |
62 | 63 |
63 // DialogButton ---------------------------------------------------------------- | 64 // DialogButton ---------------------------------------------------------------- |
64 | 65 |
65 // DialogButtons is used for the ok/cancel buttons of the window. DialogButton | 66 // DialogButton forwards AcceleratorPressed to the delegate. It is used |
66 // forwards AcceleratorPressed to the delegate. | 67 // for the ok/cancel buttons of the window. |
67 | 68 |
68 class DialogButton : public NativeTextButton { | 69 template <class ButtonBase> |
| 70 class DialogButton : public ButtonBase { |
69 public: | 71 public: |
| 72 // The button's class name. |
| 73 static const char kViewClassName[]; |
| 74 |
70 DialogButton(ButtonListener* listener, | 75 DialogButton(ButtonListener* listener, |
71 Widget* owner, | 76 Widget* owner, |
72 ui::DialogButton type, | 77 ui::DialogButton type, |
73 const string16& title, | 78 const string16& title) |
74 bool is_default) | 79 : ButtonBase(listener, title), |
75 : NativeTextButton(listener, title), | |
76 owner_(owner), | 80 owner_(owner), |
77 type_(type) { | 81 type_(type) { |
78 SetIsDefault(is_default); | |
79 } | 82 } |
80 | 83 |
81 // Overridden to forward to the delegate. | 84 // Overridden to forward to the delegate. |
82 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { | 85 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { |
83 if (!owner_->widget_delegate()->AsDialogDelegate()-> | 86 if (!owner_->widget_delegate()->AsDialogDelegate()-> |
84 AreAcceleratorsEnabled(type_)) { | 87 AreAcceleratorsEnabled(type_)) { |
85 return false; | 88 return false; |
86 } | 89 } |
87 return NativeTextButton::AcceleratorPressed(accelerator); | 90 return ButtonBase::AcceleratorPressed(accelerator); |
| 91 } |
| 92 |
| 93 // Overridden from TextButton: |
| 94 virtual std::string GetClassName() const { |
| 95 return kViewClassName; |
88 } | 96 } |
89 | 97 |
90 private: | 98 private: |
91 Widget* owner_; | 99 Widget* owner_; |
92 const ui::DialogButton type_; | 100 const ui::DialogButton type_; |
93 | 101 |
94 DISALLOW_COPY_AND_ASSIGN(DialogButton); | 102 DISALLOW_COPY_AND_ASSIGN(DialogButton); |
95 }; | 103 }; |
96 | 104 |
| 105 template <> const char DialogButton<NativeTextButton>::kViewClassName[] = |
| 106 "NativeDialogButton"; |
| 107 |
| 108 template <> const char DialogButton<TextButton>::kViewClassName[] = |
| 109 "TextDialogButton"; |
97 } // namespace | 110 } // namespace |
98 | 111 |
99 /////////////////////////////////////////////////////////////////////////////// | 112 /////////////////////////////////////////////////////////////////////////////// |
100 // DialogClientView, public: | 113 // DialogClientView, public: |
101 | 114 |
102 DialogClientView::DialogClientView(Widget* owner, View* contents_view) | 115 DialogClientView::StyleParams::StyleParams() |
| 116 : button_vedge_margin(kButtonVEdgeMargin), |
| 117 button_hedge_margin(kButtonHEdgeMargin), |
| 118 min_button_width(kDialogMinButtonWidth), |
| 119 button_label_spacing(kDialogButtonLabelSpacing), |
| 120 button_content_spacing(kDialogButtonContentSpacing), |
| 121 text_button_factory(&DialogClientView::CreateNativeStyleDialogButton) { |
| 122 } |
| 123 |
| 124 DialogClientView::DialogClientView(Widget* owner, |
| 125 View* contents_view, |
| 126 const StyleParams ¶ms) |
103 : ClientView(owner, contents_view), | 127 : ClientView(owner, contents_view), |
| 128 style_params_(params), |
104 ok_button_(NULL), | 129 ok_button_(NULL), |
105 cancel_button_(NULL), | 130 cancel_button_(NULL), |
106 default_button_(NULL), | 131 default_button_(NULL), |
107 extra_view_(NULL), | 132 extra_view_(NULL), |
108 size_extra_view_height_to_buttons_(false), | 133 size_extra_view_height_to_buttons_(false), |
109 notified_delegate_(false), | 134 notified_delegate_(false), |
110 listening_to_focus_(false), | 135 listening_to_focus_(false), |
111 saved_focus_manager_(NULL) { | 136 saved_focus_manager_(NULL) { |
| 137 SkColor bg_color = ui::NativeTheme::instance()->GetSystemColor( |
| 138 ui::NativeTheme::kColorId_DialogBackground); |
| 139 set_background(views::Background::CreateSolidBackground(bg_color)); |
112 } | 140 } |
113 | 141 |
114 DialogClientView::~DialogClientView() { | 142 DialogClientView::~DialogClientView() { |
115 } | 143 } |
116 | 144 |
117 void DialogClientView::ShowDialogButtons() { | 145 void DialogClientView::ShowDialogButtons() { |
118 DialogDelegate* dd = GetDialogDelegate(); | 146 DialogDelegate* dd = GetDialogDelegate(); |
119 int buttons = dd->GetDialogButtons(); | 147 int buttons = dd->GetDialogButtons(); |
120 if (buttons & ui::DIALOG_BUTTON_OK && !ok_button_) { | 148 if (buttons & ui::DIALOG_BUTTON_OK && !ok_button_) { |
121 string16 label = dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_OK); | 149 string16 label = dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_OK); |
122 if (label.empty()) | 150 if (label.empty()) |
123 label = l10n_util::GetStringUTF16(IDS_APP_OK); | 151 label = l10n_util::GetStringUTF16(IDS_APP_OK); |
124 bool is_default_button = | 152 bool is_default_button = |
125 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0; | 153 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0; |
126 ok_button_ = new DialogButton(this, | 154 ok_button_ = style_params_.text_button_factory(this, |
127 GetWidget(), | 155 GetWidget(), |
128 ui::DIALOG_BUTTON_OK, | 156 ui::DIALOG_BUTTON_OK, |
129 label, | 157 label); |
130 is_default_button); | |
131 ok_button_->SetGroup(kButtonGroup); | 158 ok_button_->SetGroup(kButtonGroup); |
132 if (is_default_button) | 159 if (is_default_button) { |
133 default_button_ = ok_button_; | 160 default_button_ = ok_button_; |
| 161 default_button_->SetIsDefault(true); |
| 162 } |
134 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) | 163 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) |
135 ok_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 164 ok_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
136 AddChildView(ok_button_); | 165 AddChildView(ok_button_); |
137 } | 166 } |
138 if (buttons & ui::DIALOG_BUTTON_CANCEL && !cancel_button_) { | 167 if (buttons & ui::DIALOG_BUTTON_CANCEL && !cancel_button_) { |
139 string16 label = | 168 string16 label = |
140 dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL); | 169 dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL); |
141 if (label.empty()) { | 170 if (label.empty()) { |
142 if (buttons & ui::DIALOG_BUTTON_OK) { | 171 if (buttons & ui::DIALOG_BUTTON_OK) { |
143 label = l10n_util::GetStringUTF16(IDS_APP_CANCEL); | 172 label = l10n_util::GetStringUTF16(IDS_APP_CANCEL); |
144 } else { | 173 } else { |
145 label = l10n_util::GetStringUTF16(IDS_APP_CLOSE); | 174 label = l10n_util::GetStringUTF16(IDS_APP_CLOSE); |
146 } | 175 } |
147 } | 176 } |
148 bool is_default_button = | 177 bool is_default_button = |
149 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) | 178 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) |
150 != 0; | 179 != 0; |
151 cancel_button_ = new DialogButton(this, | 180 cancel_button_ = |
152 GetWidget(), | 181 style_params_.text_button_factory(this, |
153 ui::DIALOG_BUTTON_CANCEL, | 182 GetWidget(), |
154 label, | 183 ui::DIALOG_BUTTON_CANCEL, |
155 is_default_button); | 184 label); |
156 cancel_button_->SetGroup(kButtonGroup); | 185 cancel_button_->SetGroup(kButtonGroup); |
157 cancel_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, | 186 cancel_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, |
158 ui::EF_NONE)); | 187 ui::EF_NONE)); |
159 if (is_default_button) | 188 if (is_default_button) { |
160 default_button_ = ok_button_; | 189 default_button_ = cancel_button_; |
| 190 default_button_->SetIsDefault(true); |
| 191 } |
161 AddChildView(cancel_button_); | 192 AddChildView(cancel_button_); |
162 } | 193 } |
163 if (!buttons) { | 194 if (!buttons) { |
164 // Register the escape key as an accelerator which will close the window | 195 // Register the escape key as an accelerator which will close the window |
165 // if there are no dialog buttons. | 196 // if there are no dialog buttons. |
166 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 197 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
167 } | 198 } |
168 } | 199 } |
169 | 200 |
170 void DialogClientView::SetDefaultButton(NativeTextButton* new_default_button) { | 201 void DialogClientView::SetDefaultButton(TextButton* new_default_button) { |
171 if (default_button_ && default_button_ != new_default_button) { | 202 if (default_button_ && default_button_ != new_default_button) { |
172 default_button_->SetIsDefault(false); | 203 default_button_->SetIsDefault(false); |
173 default_button_ = NULL; | 204 default_button_ = NULL; |
174 } | 205 } |
175 | 206 |
176 if (new_default_button) { | 207 if (new_default_button) { |
177 default_button_ = new_default_button; | 208 default_button_ = new_default_button; |
178 default_button_->SetIsDefault(true); | 209 default_button_->SetIsDefault(true); |
179 } | 210 } |
180 } | 211 } |
181 | 212 |
182 void DialogClientView::OnWillChangeFocus(View* focused_before, | 213 void DialogClientView::OnWillChangeFocus(View* focused_before, |
183 View* focused_now) { | 214 View* focused_now) { |
184 NativeTextButton* new_default_button = NULL; | 215 TextButton* new_default_button = NULL; |
| 216 // TODO(wittman): Identify TextButtons in a better way than |
| 217 // enumerating every possible subclass. |
185 if (focused_now && | 218 if (focused_now && |
186 focused_now->GetClassName() == NativeTextButton::kViewClassName) { | 219 ((focused_now->GetClassName() == NativeTextButton::kViewClassName) || |
187 new_default_button = static_cast<NativeTextButton*>(focused_now); | 220 (focused_now->GetClassName() == TextButton::kViewClassName) || |
| 221 (focused_now->GetClassName() == |
| 222 DialogButton<NativeTextButton>::kViewClassName) || |
| 223 (focused_now->GetClassName() == |
| 224 DialogButton<TextButton>::kViewClassName))) { |
| 225 new_default_button = static_cast<TextButton*>(focused_now); |
188 } else { | 226 } else { |
189 // The focused view is not a button, get the default button from the | 227 // The focused view is not a button, get the default button from the |
190 // delegate. | 228 // delegate. |
191 DialogDelegate* dd = GetDialogDelegate(); | 229 DialogDelegate* dd = GetDialogDelegate(); |
192 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0) | 230 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0) |
193 new_default_button = ok_button_; | 231 new_default_button = ok_button_; |
194 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) | 232 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) |
195 != 0) | 233 != 0) |
196 new_default_button = cancel_button_; | 234 new_default_button = cancel_button_; |
197 } | 235 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 268 } |
231 } | 269 } |
232 | 270 |
233 void DialogClientView::CancelWindow() { | 271 void DialogClientView::CancelWindow() { |
234 // Call the standard Close handler, which checks with the delegate before | 272 // Call the standard Close handler, which checks with the delegate before |
235 // proceeding. This checking _isn't_ done here, but in the WM_CLOSE handler, | 273 // proceeding. This checking _isn't_ done here, but in the WM_CLOSE handler, |
236 // so that the close box on the window also shares this code path. | 274 // so that the close box on the window also shares this code path. |
237 Close(); | 275 Close(); |
238 } | 276 } |
239 | 277 |
| 278 // static |
| 279 TextButton* DialogClientView::CreateNativeStyleDialogButton( |
| 280 ButtonListener* listener, |
| 281 Widget* owner, |
| 282 ui::DialogButton type, |
| 283 const string16& title) |
| 284 { |
| 285 return new DialogButton<NativeTextButton>(listener, owner, type, title); |
| 286 } |
| 287 |
| 288 // static |
| 289 TextButton* DialogClientView::CreateChromeStyleDialogButton( |
| 290 ButtonListener* listener, |
| 291 Widget* owner, |
| 292 ui::DialogButton type, |
| 293 const string16& title) |
| 294 { |
| 295 DialogButton<TextButton>* button = |
| 296 new DialogButton<TextButton>(listener, owner, type, title); |
| 297 ApplyChromeStyle(button); |
| 298 return button; |
| 299 } |
| 300 |
240 /////////////////////////////////////////////////////////////////////////////// | 301 /////////////////////////////////////////////////////////////////////////////// |
241 // DialogClientView, View overrides: | 302 // DialogClientView, View overrides: |
242 | 303 |
243 void DialogClientView::NativeViewHierarchyChanged( | 304 void DialogClientView::NativeViewHierarchyChanged( |
244 bool attached, | 305 bool attached, |
245 gfx::NativeView native_view, | 306 gfx::NativeView native_view, |
246 internal::RootView* root_view) { | 307 internal::RootView* root_view) { |
247 if (attached) { | 308 if (attached) { |
248 UpdateFocusListener(); | 309 UpdateFocusListener(); |
249 } | 310 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 return this; | 347 return this; |
287 } | 348 } |
288 | 349 |
289 const DialogClientView* DialogClientView::AsDialogClientView() const { | 350 const DialogClientView* DialogClientView::AsDialogClientView() const { |
290 return this; | 351 return this; |
291 } | 352 } |
292 | 353 |
293 //////////////////////////////////////////////////////////////////////////////// | 354 //////////////////////////////////////////////////////////////////////////////// |
294 // DialogClientView, View overrides: | 355 // DialogClientView, View overrides: |
295 | 356 |
296 void DialogClientView::OnPaint(gfx::Canvas* canvas) { | |
297 SkColor bg_color = ui::NativeTheme::instance()->GetSystemColor( | |
298 ui::NativeTheme::kColorId_DialogBackground); | |
299 canvas->FillRect(GetLocalBounds(), bg_color); | |
300 } | |
301 | |
302 void DialogClientView::PaintChildren(gfx::Canvas* canvas) { | 357 void DialogClientView::PaintChildren(gfx::Canvas* canvas) { |
303 View::PaintChildren(canvas); | 358 View::PaintChildren(canvas); |
304 if (!GetWidget()->IsMaximized() && !GetWidget()->IsMinimized()) | 359 if (!GetWidget()->IsMaximized() && !GetWidget()->IsMinimized()) |
305 PaintSizeBox(canvas); | 360 PaintSizeBox(canvas); |
306 } | 361 } |
307 | 362 |
308 void DialogClientView::Layout() { | 363 void DialogClientView::Layout() { |
309 if (has_dialog_buttons()) | 364 if (has_dialog_buttons()) |
310 LayoutDialogButtons(); | 365 LayoutDialogButtons(); |
311 LayoutContentsView(); | 366 LayoutContentsView(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 width += GetButtonWidth(ui::DIALOG_BUTTON_OK); | 398 width += GetButtonWidth(ui::DIALOG_BUTTON_OK); |
344 if (cancel_button_) | 399 if (cancel_button_) |
345 width += kRelatedButtonHSpacing; | 400 width += kRelatedButtonHSpacing; |
346 } | 401 } |
347 if (extra_view_) { | 402 if (extra_view_) { |
348 width += extra_view_->GetPreferredSize().width(); | 403 width += extra_view_->GetPreferredSize().width(); |
349 if (cancel_button_ || ok_button_) | 404 if (cancel_button_ || ok_button_) |
350 width += kRelatedButtonHSpacing; | 405 width += kRelatedButtonHSpacing; |
351 } | 406 } |
352 if (width > 0) { | 407 if (width > 0) { |
353 width += 2 * kButtonHEdgeMargin; | 408 width += 2 * style_params_.button_hedge_margin; |
354 prefsize.set_width(std::max(prefsize.width(), width)); | 409 prefsize.set_width(std::max(prefsize.width(), width)); |
355 } | 410 } |
356 } | 411 } |
357 prefsize.Enlarge(0, button_height); | 412 prefsize.Enlarge(0, button_height); |
358 return prefsize; | 413 return prefsize; |
359 } | 414 } |
360 | 415 |
361 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 416 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
362 // We only expect Escape key. | 417 // We only expect Escape key. |
363 DCHECK(accelerator.key_code() == ui::VKEY_ESCAPE); | 418 DCHECK(accelerator.key_code() == ui::VKEY_ESCAPE); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 // TODO(port): paint size box | 467 // TODO(port): paint size box |
413 #endif | 468 #endif |
414 } | 469 } |
415 } | 470 } |
416 | 471 |
417 int DialogClientView::GetButtonWidth(int button) const { | 472 int DialogClientView::GetButtonWidth(int button) const { |
418 DialogDelegate* dd = GetDialogDelegate(); | 473 DialogDelegate* dd = GetDialogDelegate(); |
419 string16 button_label = dd->GetDialogButtonLabel( | 474 string16 button_label = dd->GetDialogButtonLabel( |
420 static_cast<ui::DialogButton>(button)); | 475 static_cast<ui::DialogButton>(button)); |
421 int string_width = GetDialogButtonFont().GetStringWidth(button_label); | 476 int string_width = GetDialogButtonFont().GetStringWidth(button_label); |
422 return std::max(string_width + kDialogButtonLabelSpacing, | 477 return std::max(string_width + style_params_.button_label_spacing, |
423 kDialogMinButtonWidth); | 478 style_params_.min_button_width); |
424 } | 479 } |
425 | 480 |
426 int DialogClientView::GetButtonsHeight() const { | 481 int DialogClientView::GetButtonsHeight() const { |
427 int button_height = 0; | 482 int button_height = 0; |
428 if (cancel_button_) | 483 if (cancel_button_) |
429 button_height = std::max(button_height, | 484 button_height = std::max(button_height, |
430 cancel_button_->GetPreferredSize().height()); | 485 cancel_button_->GetPreferredSize().height()); |
431 if (ok_button_) | 486 if (ok_button_) |
432 button_height = std::max(button_height, | 487 button_height = std::max(button_height, |
433 ok_button_->GetPreferredSize().height()); | 488 ok_button_->GetPreferredSize().height()); |
434 return button_height; | 489 return button_height; |
435 } | 490 } |
436 | 491 |
437 int DialogClientView::GetDialogButtonsAreaHeight() const { | 492 int DialogClientView::GetDialogButtonsAreaHeight() const { |
438 return !has_dialog_buttons() ? 0 : | 493 return !has_dialog_buttons() ? 0 : |
439 GetButtonsHeight() + kDialogButtonContentSpacing + kButtonVEdgeMargin; | 494 GetButtonsHeight() + style_params_.button_content_spacing + |
| 495 style_params_.button_vedge_margin; |
440 } | 496 } |
441 | 497 |
442 void DialogClientView::LayoutDialogButtons() { | 498 void DialogClientView::LayoutDialogButtons() { |
443 gfx::Rect lb = GetContentsBounds(); | 499 gfx::Rect lb = GetContentsBounds(); |
444 gfx::Rect extra_bounds; | 500 gfx::Rect extra_bounds; |
445 int bottom_y = lb.bottom() - kButtonVEdgeMargin; | 501 int bottom_y = lb.bottom() - style_params_.button_vedge_margin; |
446 int button_height = GetButtonsHeight(); | 502 int button_height = GetButtonsHeight(); |
447 if (cancel_button_) { | 503 if (cancel_button_) { |
448 gfx::Size ps = cancel_button_->GetPreferredSize(); | 504 gfx::Size ps = cancel_button_->GetPreferredSize(); |
449 int button_width = std::max( | 505 int button_width = std::max( |
450 GetButtonWidth(ui::DIALOG_BUTTON_CANCEL), ps.width()); | 506 GetButtonWidth(ui::DIALOG_BUTTON_CANCEL), ps.width()); |
451 int button_x = lb.right() - button_width - kButtonHEdgeMargin; | 507 int button_x = lb.right() - button_width - |
| 508 style_params_.button_hedge_margin; |
452 int button_y = bottom_y - ps.height(); | 509 int button_y = bottom_y - ps.height(); |
453 cancel_button_->SetBounds(button_x, button_y, button_width, ps.height()); | 510 cancel_button_->SetBounds(button_x, button_y, button_width, ps.height()); |
454 // The extra view bounds are dependent on this button. | 511 // The extra view bounds are dependent on this button. |
455 extra_bounds.set_width(std::max(0, cancel_button_->x())); | 512 extra_bounds.set_width(std::max(0, cancel_button_->x())); |
456 extra_bounds.set_y(cancel_button_->y()); | 513 extra_bounds.set_y(cancel_button_->y()); |
457 } | 514 } |
458 if (ok_button_) { | 515 if (ok_button_) { |
459 gfx::Size ps = ok_button_->GetPreferredSize(); | 516 gfx::Size ps = ok_button_->GetPreferredSize(); |
460 int button_width = std::max( | 517 int button_width = std::max( |
461 GetButtonWidth(ui::DIALOG_BUTTON_OK), ps.width()); | 518 GetButtonWidth(ui::DIALOG_BUTTON_OK), ps.width()); |
462 int ok_button_right = lb.right() - kButtonHEdgeMargin; | 519 int ok_button_right = lb.right() - style_params_.button_hedge_margin; |
463 if (cancel_button_) | 520 if (cancel_button_) |
464 ok_button_right = cancel_button_->x() - kRelatedButtonHSpacing; | 521 ok_button_right = cancel_button_->x() - kRelatedButtonHSpacing; |
465 int button_x = ok_button_right - button_width; | 522 int button_x = ok_button_right - button_width; |
466 int button_y = bottom_y - ps.height(); | 523 int button_y = bottom_y - ps.height(); |
467 ok_button_->SetBounds(button_x, button_y, ok_button_right - button_x, | 524 ok_button_->SetBounds(button_x, button_y, ok_button_right - button_x, |
468 ps.height()); | 525 ps.height()); |
469 // The extra view bounds are dependent on this button. | 526 // The extra view bounds are dependent on this button. |
470 extra_bounds.set_width(std::max(0, ok_button_->x())); | 527 extra_bounds.set_width(std::max(0, ok_button_->x())); |
471 extra_bounds.set_y(ok_button_->y()); | 528 extra_bounds.set_y(ok_button_->y()); |
472 } | 529 } |
473 if (extra_view_) { | 530 if (extra_view_) { |
474 gfx::Size ps = extra_view_->GetPreferredSize(); | 531 gfx::Size ps = extra_view_->GetPreferredSize(); |
475 extra_bounds.set_x(lb.x() + kButtonHEdgeMargin); | 532 extra_bounds.set_x(lb.x() + style_params_.button_hedge_margin); |
476 int height = size_extra_view_height_to_buttons_ ? | 533 int height = size_extra_view_height_to_buttons_ ? |
477 std::max(ps.height(), button_height) : ps.height(); | 534 std::max(ps.height(), button_height) : ps.height(); |
478 extra_bounds.set_height(height); | 535 extra_bounds.set_height(height); |
479 extra_view_->SetBoundsRect(extra_bounds); | 536 extra_view_->SetBoundsRect(extra_bounds); |
480 } | 537 } |
481 } | 538 } |
482 | 539 |
483 void DialogClientView::LayoutContentsView() { | 540 void DialogClientView::LayoutContentsView() { |
484 gfx::Rect lb = GetContentsBounds(); | 541 gfx::Rect lb = GetContentsBounds(); |
485 lb.set_height(std::max(0, lb.height() - GetDialogButtonsAreaHeight())); | 542 lb.set_height(std::max(0, lb.height() - GetDialogButtonsAreaHeight())); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 } | 580 } |
524 saved_focus_manager_ = focus_manager; | 581 saved_focus_manager_ = focus_manager; |
525 // Listen for focus change events so we can update the default button. | 582 // Listen for focus change events so we can update the default button. |
526 if (focus_manager) { | 583 if (focus_manager) { |
527 focus_manager->AddFocusChangeListener(this); | 584 focus_manager->AddFocusChangeListener(this); |
528 listening_to_focus_ = true; | 585 listening_to_focus_ = true; |
529 } | 586 } |
530 } | 587 } |
531 | 588 |
532 } // namespace views | 589 } // namespace views |
OLD | NEW |