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/web_style_text_button.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 |
| 40 const int kWebStyleButtonVEdgeMargin = 0; |
| 41 const int kWebStyleButtonHEdgeMargin = 0; |
| 42 const int kWebStyleDialogButtonLabelSpacing = 24; |
| 43 |
39 // The group used by the buttons. This name is chosen voluntarily big not to | 44 // 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. | 45 // conflict with other groups that could be in the dialog content. |
41 const int kButtonGroup = 6666; | 46 const int kButtonGroup = 6666; |
42 | 47 |
43 const gfx::Font& GetDialogButtonFont() { | 48 const gfx::Font& GetDialogButtonFont() { |
44 static gfx::Font* font = NULL; | 49 static gfx::Font* font = NULL; |
45 if (!font) { | 50 if (!font) { |
46 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 51 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
47 font = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); | 52 font = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); |
48 } | 53 } |
49 return *font; | 54 return *font; |
50 } | 55 } |
51 | 56 |
52 // Updates any of the standard buttons according to the delegate. | 57 // Updates any of the standard buttons according to the delegate. |
53 void UpdateButtonHelper(NativeTextButton* button_view, | 58 void UpdateButtonHelper(TextButton* button_view, |
54 DialogDelegate* delegate, | 59 DialogDelegate* delegate, |
55 ui::DialogButton button) { | 60 ui::DialogButton button) { |
56 string16 label = delegate->GetDialogButtonLabel(button); | 61 string16 label = delegate->GetDialogButtonLabel(button); |
57 if (!label.empty()) | 62 if (!label.empty()) |
58 button_view->SetText(label); | 63 button_view->SetText(label); |
59 button_view->SetEnabled(delegate->IsDialogButtonEnabled(button)); | 64 button_view->SetEnabled(delegate->IsDialogButtonEnabled(button)); |
60 button_view->SetVisible(delegate->IsDialogButtonVisible(button)); | 65 button_view->SetVisible(delegate->IsDialogButtonVisible(button)); |
61 } | 66 } |
62 | 67 |
63 // DialogButton ---------------------------------------------------------------- | 68 // DialogButton ---------------------------------------------------------------- |
64 | 69 |
65 // DialogButtons is used for the ok/cancel buttons of the window. DialogButton | 70 // DialogButton forwards AcceleratorPressed to the delegate. It is used |
66 // forwards AcceleratorPressed to the delegate. | 71 // for the ok/cancel buttons of the window. |
67 | 72 |
68 class DialogButton : public NativeTextButton { | 73 template <class ButtonBase> |
| 74 class DialogButton : public ButtonBase { |
69 public: | 75 public: |
| 76 // The button's class name. |
| 77 static const char kViewClassName[]; |
| 78 |
70 DialogButton(ButtonListener* listener, | 79 DialogButton(ButtonListener* listener, |
71 Widget* owner, | 80 Widget* owner, |
72 ui::DialogButton type, | 81 ui::DialogButton type, |
73 const string16& title, | 82 const string16& title, |
74 bool is_default) | 83 bool is_default) |
75 : NativeTextButton(listener, title), | 84 : ButtonBase(listener, title), |
76 owner_(owner), | 85 owner_(owner), |
77 type_(type) { | 86 type_(type) { |
78 SetIsDefault(is_default); | 87 SetIsDefault(is_default); |
79 } | 88 } |
80 | 89 |
81 // Overridden to forward to the delegate. | 90 // Overridden to forward to the delegate. |
82 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { | 91 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { |
83 if (!owner_->widget_delegate()->AsDialogDelegate()-> | 92 if (!owner_->widget_delegate()->AsDialogDelegate()-> |
84 AreAcceleratorsEnabled(type_)) { | 93 AreAcceleratorsEnabled(type_)) { |
85 return false; | 94 return false; |
86 } | 95 } |
87 return NativeTextButton::AcceleratorPressed(accelerator); | 96 return ButtonBase::AcceleratorPressed(accelerator); |
| 97 } |
| 98 |
| 99 // Overridden from TextButton: |
| 100 virtual std::string GetClassName() const { |
| 101 return kViewClassName; |
88 } | 102 } |
89 | 103 |
90 private: | 104 private: |
91 Widget* owner_; | 105 Widget* owner_; |
92 const ui::DialogButton type_; | 106 const ui::DialogButton type_; |
93 | 107 |
94 DISALLOW_COPY_AND_ASSIGN(DialogButton); | 108 DISALLOW_COPY_AND_ASSIGN(DialogButton); |
95 }; | 109 }; |
96 | 110 |
| 111 const char DialogButton<NativeTextButton>::kViewClassName[] = |
| 112 "NativeDialogButton"; |
| 113 |
| 114 const char DialogButton<WebStyleTextButton>::kViewClassName[] = |
| 115 "WebStyleDialogButton"; |
| 116 |
| 117 |
| 118 typedef TextButton* (*TextButtonFactory)(ButtonListener* listener, |
| 119 Widget* owner, |
| 120 ui::DialogButton type, |
| 121 const string16& title, |
| 122 bool is_default); |
| 123 |
| 124 // Factory function for DialogButtons. |
| 125 template <class ButtonBase> |
| 126 TextButton* CreateDialogButton(ButtonListener* listener, |
| 127 Widget* owner, |
| 128 ui::DialogButton type, |
| 129 const string16& title, |
| 130 bool is_default) |
| 131 { |
| 132 return new DialogButton<ButtonBase>(listener, owner, type, title, is_default); |
| 133 } |
| 134 |
97 } // namespace | 135 } // namespace |
98 | 136 |
| 137 struct DialogClientView::StyleParams { |
| 138 StyleParams() |
| 139 : button_vedge_margin(kButtonVEdgeMargin), |
| 140 button_hedge_margin(kButtonHEdgeMargin), |
| 141 min_button_width(kDialogMinButtonWidth), |
| 142 button_label_spacing(kDialogButtonLabelSpacing), |
| 143 button_content_spacing(kDialogButtonContentSpacing), |
| 144 text_button_factory(&CreateDialogButton<NativeTextButton>) |
| 145 { |
| 146 } |
| 147 |
| 148 int button_vedge_margin; |
| 149 int button_hedge_margin; |
| 150 int min_button_width; |
| 151 int button_label_spacing; |
| 152 int button_content_spacing; |
| 153 TextButtonFactory text_button_factory; |
| 154 }; |
| 155 |
99 /////////////////////////////////////////////////////////////////////////////// | 156 /////////////////////////////////////////////////////////////////////////////// |
100 // DialogClientView, public: | 157 // DialogClientView, public: |
101 | 158 |
102 DialogClientView::DialogClientView(Widget* owner, View* contents_view) | 159 DialogClientView::DialogClientView(Widget* owner, View* contents_view, |
| 160 Style style) |
103 : ClientView(owner, contents_view), | 161 : ClientView(owner, contents_view), |
| 162 style_params_(CreateStyleParams(style)), |
104 ok_button_(NULL), | 163 ok_button_(NULL), |
105 cancel_button_(NULL), | 164 cancel_button_(NULL), |
106 default_button_(NULL), | 165 default_button_(NULL), |
107 extra_view_(NULL), | 166 extra_view_(NULL), |
108 size_extra_view_height_to_buttons_(false), | 167 size_extra_view_height_to_buttons_(false), |
109 notified_delegate_(false), | 168 notified_delegate_(false), |
110 listening_to_focus_(false), | 169 listening_to_focus_(false), |
111 saved_focus_manager_(NULL) { | 170 saved_focus_manager_(NULL) { |
| 171 SkColor bg_color = ui::NativeTheme::instance()->GetSystemColor( |
| 172 ui::NativeTheme::kColorId_DialogBackground); |
| 173 set_background(views::Background::CreateSolidBackground(bg_color)); |
112 } | 174 } |
113 | 175 |
114 DialogClientView::~DialogClientView() { | 176 DialogClientView::~DialogClientView() { |
115 } | 177 } |
116 | 178 |
117 void DialogClientView::ShowDialogButtons() { | 179 void DialogClientView::ShowDialogButtons() { |
118 DialogDelegate* dd = GetDialogDelegate(); | 180 DialogDelegate* dd = GetDialogDelegate(); |
119 int buttons = dd->GetDialogButtons(); | 181 int buttons = dd->GetDialogButtons(); |
120 if (buttons & ui::DIALOG_BUTTON_OK && !ok_button_) { | 182 if (buttons & ui::DIALOG_BUTTON_OK && !ok_button_) { |
121 string16 label = dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_OK); | 183 string16 label = dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_OK); |
122 if (label.empty()) | 184 if (label.empty()) |
123 label = l10n_util::GetStringUTF16(IDS_APP_OK); | 185 label = l10n_util::GetStringUTF16(IDS_APP_OK); |
124 bool is_default_button = | 186 bool is_default_button = |
125 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0; | 187 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0; |
126 ok_button_ = new DialogButton(this, | 188 ok_button_ = style_params_->text_button_factory(this, |
127 GetWidget(), | 189 GetWidget(), |
128 ui::DIALOG_BUTTON_OK, | 190 ui::DIALOG_BUTTON_OK, |
129 label, | 191 label, |
130 is_default_button); | 192 is_default_button); |
131 ok_button_->SetGroup(kButtonGroup); | 193 ok_button_->SetGroup(kButtonGroup); |
132 if (is_default_button) | 194 if (is_default_button) |
133 default_button_ = ok_button_; | 195 default_button_ = ok_button_; |
134 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) | 196 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) |
135 ok_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 197 ok_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
136 AddChildView(ok_button_); | 198 AddChildView(ok_button_); |
137 } | 199 } |
138 if (buttons & ui::DIALOG_BUTTON_CANCEL && !cancel_button_) { | 200 if (buttons & ui::DIALOG_BUTTON_CANCEL && !cancel_button_) { |
139 string16 label = | 201 string16 label = |
140 dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL); | 202 dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL); |
141 if (label.empty()) { | 203 if (label.empty()) { |
142 if (buttons & ui::DIALOG_BUTTON_OK) { | 204 if (buttons & ui::DIALOG_BUTTON_OK) { |
143 label = l10n_util::GetStringUTF16(IDS_APP_CANCEL); | 205 label = l10n_util::GetStringUTF16(IDS_APP_CANCEL); |
144 } else { | 206 } else { |
145 label = l10n_util::GetStringUTF16(IDS_APP_CLOSE); | 207 label = l10n_util::GetStringUTF16(IDS_APP_CLOSE); |
146 } | 208 } |
147 } | 209 } |
148 bool is_default_button = | 210 bool is_default_button = |
149 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) | 211 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) |
150 != 0; | 212 != 0; |
151 cancel_button_ = new DialogButton(this, | 213 cancel_button_ = |
152 GetWidget(), | 214 style_params_->text_button_factory(this, |
153 ui::DIALOG_BUTTON_CANCEL, | 215 GetWidget(), |
154 label, | 216 ui::DIALOG_BUTTON_CANCEL, |
155 is_default_button); | 217 label, |
| 218 is_default_button); |
156 cancel_button_->SetGroup(kButtonGroup); | 219 cancel_button_->SetGroup(kButtonGroup); |
157 cancel_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, | 220 cancel_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, |
158 ui::EF_NONE)); | 221 ui::EF_NONE)); |
159 if (is_default_button) | 222 if (is_default_button) |
160 default_button_ = ok_button_; | 223 default_button_ = ok_button_; |
161 AddChildView(cancel_button_); | 224 AddChildView(cancel_button_); |
162 } | 225 } |
163 if (!buttons) { | 226 if (!buttons) { |
164 // Register the escape key as an accelerator which will close the window | 227 // Register the escape key as an accelerator which will close the window |
165 // if there are no dialog buttons. | 228 // if there are no dialog buttons. |
166 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 229 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
167 } | 230 } |
168 } | 231 } |
169 | 232 |
170 void DialogClientView::SetDefaultButton(NativeTextButton* new_default_button) { | 233 void DialogClientView::SetDefaultButton(TextButton* new_default_button) { |
171 if (default_button_ && default_button_ != new_default_button) { | 234 if (default_button_ && default_button_ != new_default_button) { |
172 default_button_->SetIsDefault(false); | 235 default_button_->SetIsDefault(false); |
173 default_button_ = NULL; | 236 default_button_ = NULL; |
174 } | 237 } |
175 | 238 |
176 if (new_default_button) { | 239 if (new_default_button) { |
177 default_button_ = new_default_button; | 240 default_button_ = new_default_button; |
178 default_button_->SetIsDefault(true); | 241 default_button_->SetIsDefault(true); |
179 } | 242 } |
180 } | 243 } |
181 | 244 |
182 void DialogClientView::OnWillChangeFocus(View* focused_before, | 245 void DialogClientView::OnWillChangeFocus(View* focused_before, |
183 View* focused_now) { | 246 View* focused_now) { |
184 NativeTextButton* new_default_button = NULL; | 247 TextButton* new_default_button = NULL; |
185 if (focused_now && | 248 if (focused_now && |
186 focused_now->GetClassName() == NativeTextButton::kViewClassName) { | 249 ((focused_now->GetClassName() == |
187 new_default_button = static_cast<NativeTextButton*>(focused_now); | 250 DialogButton<NativeTextButton>::kViewClassName) || |
| 251 (focused_now->GetClassName() == |
| 252 DialogButton<WebStyleTextButton>::kViewClassName))) { |
| 253 new_default_button = static_cast<TextButton*>(focused_now); |
188 } else { | 254 } else { |
189 // The focused view is not a button, get the default button from the | 255 // The focused view is not a button, get the default button from the |
190 // delegate. | 256 // delegate. |
191 DialogDelegate* dd = GetDialogDelegate(); | 257 DialogDelegate* dd = GetDialogDelegate(); |
192 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0) | 258 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0) |
193 new_default_button = ok_button_; | 259 new_default_button = ok_button_; |
194 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) | 260 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) |
195 != 0) | 261 != 0) |
196 new_default_button = cancel_button_; | 262 new_default_button = cancel_button_; |
197 } | 263 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 return this; | 351 return this; |
286 } | 352 } |
287 | 353 |
288 const DialogClientView* DialogClientView::AsDialogClientView() const { | 354 const DialogClientView* DialogClientView::AsDialogClientView() const { |
289 return this; | 355 return this; |
290 } | 356 } |
291 | 357 |
292 //////////////////////////////////////////////////////////////////////////////// | 358 //////////////////////////////////////////////////////////////////////////////// |
293 // DialogClientView, View overrides: | 359 // DialogClientView, View overrides: |
294 | 360 |
295 void DialogClientView::OnPaint(gfx::Canvas* canvas) { | |
296 SkColor bg_color = ui::NativeTheme::instance()->GetSystemColor( | |
297 ui::NativeTheme::kColorId_DialogBackground); | |
298 canvas->FillRect(GetLocalBounds(), bg_color); | |
299 } | |
300 | |
301 void DialogClientView::PaintChildren(gfx::Canvas* canvas) { | 361 void DialogClientView::PaintChildren(gfx::Canvas* canvas) { |
302 View::PaintChildren(canvas); | 362 View::PaintChildren(canvas); |
303 if (!GetWidget()->IsMaximized() && !GetWidget()->IsMinimized()) | 363 if (!GetWidget()->IsMaximized() && !GetWidget()->IsMinimized()) |
304 PaintSizeBox(canvas); | 364 PaintSizeBox(canvas); |
305 } | 365 } |
306 | 366 |
307 void DialogClientView::Layout() { | 367 void DialogClientView::Layout() { |
308 if (has_dialog_buttons()) | 368 if (has_dialog_buttons()) |
309 LayoutDialogButtons(); | 369 LayoutDialogButtons(); |
310 LayoutContentsView(); | 370 LayoutContentsView(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 width += GetButtonWidth(ui::DIALOG_BUTTON_OK); | 402 width += GetButtonWidth(ui::DIALOG_BUTTON_OK); |
343 if (cancel_button_) | 403 if (cancel_button_) |
344 width += kRelatedButtonHSpacing; | 404 width += kRelatedButtonHSpacing; |
345 } | 405 } |
346 if (extra_view_) { | 406 if (extra_view_) { |
347 width += extra_view_->GetPreferredSize().width(); | 407 width += extra_view_->GetPreferredSize().width(); |
348 if (cancel_button_ || ok_button_) | 408 if (cancel_button_ || ok_button_) |
349 width += kRelatedButtonHSpacing; | 409 width += kRelatedButtonHSpacing; |
350 } | 410 } |
351 if (width > 0) { | 411 if (width > 0) { |
352 width += 2 * kButtonHEdgeMargin; | 412 width += 2 * style_params_->button_hedge_margin; |
353 prefsize.set_width(std::max(prefsize.width(), width)); | 413 prefsize.set_width(std::max(prefsize.width(), width)); |
354 } | 414 } |
355 } | 415 } |
356 prefsize.Enlarge(0, button_height); | 416 prefsize.Enlarge(0, button_height); |
357 return prefsize; | 417 return prefsize; |
358 } | 418 } |
359 | 419 |
360 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 420 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
361 // We only expect Escape key. | 421 // We only expect Escape key. |
362 DCHECK(accelerator.key_code() == ui::VKEY_ESCAPE); | 422 DCHECK(accelerator.key_code() == ui::VKEY_ESCAPE); |
(...skipping 15 matching lines...) Expand all Loading... |
378 } else if (sender == cancel_button_) { | 438 } else if (sender == cancel_button_) { |
379 CancelWindow(); | 439 CancelWindow(); |
380 } else { | 440 } else { |
381 NOTREACHED(); | 441 NOTREACHED(); |
382 } | 442 } |
383 } | 443 } |
384 | 444 |
385 //////////////////////////////////////////////////////////////////////////////// | 445 //////////////////////////////////////////////////////////////////////////////// |
386 // DialogClientView, private: | 446 // DialogClientView, private: |
387 | 447 |
| 448 DialogClientView::StyleParams* DialogClientView::CreateStyleParams( |
| 449 DialogClientView::Style style) { |
| 450 StyleParams* params = new StyleParams; |
| 451 |
| 452 if (style == STYLE_WEB) { |
| 453 params->button_vedge_margin = kWebStyleButtonVEdgeMargin; |
| 454 params->button_hedge_margin = kWebStyleButtonHEdgeMargin; |
| 455 params->button_label_spacing = kWebStyleDialogButtonLabelSpacing; |
| 456 params->text_button_factory = &CreateDialogButton<WebStyleTextButton>; |
| 457 } |
| 458 |
| 459 return params; |
| 460 } |
| 461 |
388 void DialogClientView::PaintSizeBox(gfx::Canvas* canvas) { | 462 void DialogClientView::PaintSizeBox(gfx::Canvas* canvas) { |
389 if (GetWidget()->widget_delegate()->CanResize() || | 463 if (GetWidget()->widget_delegate()->CanResize() || |
390 GetWidget()->widget_delegate()->CanMaximize()) { | 464 GetWidget()->widget_delegate()->CanMaximize()) { |
391 #if defined(OS_WIN) | 465 #if defined(OS_WIN) |
392 ui::NativeTheme::ExtraParams extra; | 466 ui::NativeTheme::ExtraParams extra; |
393 gfx::Size gripper_size = ui::NativeTheme::instance()->GetPartSize( | 467 gfx::Size gripper_size = ui::NativeTheme::instance()->GetPartSize( |
394 ui::NativeTheme::kWindowResizeGripper, ui::NativeTheme::kNormal, extra); | 468 ui::NativeTheme::kWindowResizeGripper, ui::NativeTheme::kNormal, extra); |
395 | 469 |
396 // TODO(beng): (http://b/1085509) In "classic" rendering mode, there isn't | 470 // TODO(beng): (http://b/1085509) In "classic" rendering mode, there isn't |
397 // a theme-supplied gripper. We should probably improvise | 471 // a theme-supplied gripper. We should probably improvise |
(...skipping 13 matching lines...) Expand all Loading... |
411 // TODO(port): paint size box | 485 // TODO(port): paint size box |
412 #endif | 486 #endif |
413 } | 487 } |
414 } | 488 } |
415 | 489 |
416 int DialogClientView::GetButtonWidth(int button) const { | 490 int DialogClientView::GetButtonWidth(int button) const { |
417 DialogDelegate* dd = GetDialogDelegate(); | 491 DialogDelegate* dd = GetDialogDelegate(); |
418 string16 button_label = dd->GetDialogButtonLabel( | 492 string16 button_label = dd->GetDialogButtonLabel( |
419 static_cast<ui::DialogButton>(button)); | 493 static_cast<ui::DialogButton>(button)); |
420 int string_width = GetDialogButtonFont().GetStringWidth(button_label); | 494 int string_width = GetDialogButtonFont().GetStringWidth(button_label); |
421 return std::max(string_width + kDialogButtonLabelSpacing, | 495 return std::max(string_width + style_params_->button_label_spacing, |
422 kDialogMinButtonWidth); | 496 style_params_->min_button_width); |
423 } | 497 } |
424 | 498 |
425 int DialogClientView::GetButtonsHeight() const { | 499 int DialogClientView::GetButtonsHeight() const { |
426 int button_height = 0; | 500 int button_height = 0; |
427 if (cancel_button_) | 501 if (cancel_button_) |
428 button_height = std::max(button_height, | 502 button_height = std::max(button_height, |
429 cancel_button_->GetPreferredSize().height()); | 503 cancel_button_->GetPreferredSize().height()); |
430 if (ok_button_) | 504 if (ok_button_) |
431 button_height = std::max(button_height, | 505 button_height = std::max(button_height, |
432 ok_button_->GetPreferredSize().height()); | 506 ok_button_->GetPreferredSize().height()); |
433 return button_height; | 507 return button_height; |
434 } | 508 } |
435 | 509 |
436 int DialogClientView::GetDialogButtonsAreaHeight() const { | 510 int DialogClientView::GetDialogButtonsAreaHeight() const { |
437 return !has_dialog_buttons() ? 0 : | 511 return !has_dialog_buttons() ? 0 : |
438 GetButtonsHeight() + kDialogButtonContentSpacing + kButtonVEdgeMargin; | 512 GetButtonsHeight() + style_params_->button_content_spacing + |
| 513 style_params_->button_vedge_margin; |
439 } | 514 } |
440 | 515 |
441 void DialogClientView::LayoutDialogButtons() { | 516 void DialogClientView::LayoutDialogButtons() { |
442 gfx::Rect lb = GetContentsBounds(); | 517 gfx::Rect lb = GetContentsBounds(); |
443 gfx::Rect extra_bounds; | 518 gfx::Rect extra_bounds; |
444 int bottom_y = lb.bottom() - kButtonVEdgeMargin; | 519 int bottom_y = lb.bottom() - style_params_->button_vedge_margin; |
445 int button_height = GetButtonsHeight(); | 520 int button_height = GetButtonsHeight(); |
446 if (cancel_button_) { | 521 if (cancel_button_) { |
447 gfx::Size ps = cancel_button_->GetPreferredSize(); | 522 gfx::Size ps = cancel_button_->GetPreferredSize(); |
448 int button_width = std::max( | 523 int button_width = std::max( |
449 GetButtonWidth(ui::DIALOG_BUTTON_CANCEL), ps.width()); | 524 GetButtonWidth(ui::DIALOG_BUTTON_CANCEL), ps.width()); |
450 int button_x = lb.right() - button_width - kButtonHEdgeMargin; | 525 int button_x = lb.right() - button_width - |
| 526 style_params_->button_hedge_margin; |
451 int button_y = bottom_y - ps.height(); | 527 int button_y = bottom_y - ps.height(); |
452 cancel_button_->SetBounds(button_x, button_y, button_width, ps.height()); | 528 cancel_button_->SetBounds(button_x, button_y, button_width, ps.height()); |
453 // The extra view bounds are dependent on this button. | 529 // The extra view bounds are dependent on this button. |
454 extra_bounds.set_width(std::max(0, cancel_button_->x())); | 530 extra_bounds.set_width(std::max(0, cancel_button_->x())); |
455 extra_bounds.set_y(cancel_button_->y()); | 531 extra_bounds.set_y(cancel_button_->y()); |
456 } | 532 } |
457 if (ok_button_) { | 533 if (ok_button_) { |
458 gfx::Size ps = ok_button_->GetPreferredSize(); | 534 gfx::Size ps = ok_button_->GetPreferredSize(); |
459 int button_width = std::max( | 535 int button_width = std::max( |
460 GetButtonWidth(ui::DIALOG_BUTTON_OK), ps.width()); | 536 GetButtonWidth(ui::DIALOG_BUTTON_OK), ps.width()); |
461 int ok_button_right = lb.right() - kButtonHEdgeMargin; | 537 int ok_button_right = lb.right() - style_params_->button_hedge_margin; |
462 if (cancel_button_) | 538 if (cancel_button_) |
463 ok_button_right = cancel_button_->x() - kRelatedButtonHSpacing; | 539 ok_button_right = cancel_button_->x() - kRelatedButtonHSpacing; |
464 int button_x = ok_button_right - button_width; | 540 int button_x = ok_button_right - button_width; |
465 int button_y = bottom_y - ps.height(); | 541 int button_y = bottom_y - ps.height(); |
466 ok_button_->SetBounds(button_x, button_y, ok_button_right - button_x, | 542 ok_button_->SetBounds(button_x, button_y, ok_button_right - button_x, |
467 ps.height()); | 543 ps.height()); |
468 // The extra view bounds are dependent on this button. | 544 // The extra view bounds are dependent on this button. |
469 extra_bounds.set_width(std::max(0, ok_button_->x())); | 545 extra_bounds.set_width(std::max(0, ok_button_->x())); |
470 extra_bounds.set_y(ok_button_->y()); | 546 extra_bounds.set_y(ok_button_->y()); |
471 } | 547 } |
472 if (extra_view_) { | 548 if (extra_view_) { |
473 gfx::Size ps = extra_view_->GetPreferredSize(); | 549 gfx::Size ps = extra_view_->GetPreferredSize(); |
474 extra_bounds.set_x(lb.x() + kButtonHEdgeMargin); | 550 extra_bounds.set_x(lb.x() + style_params_->button_hedge_margin); |
475 int height = size_extra_view_height_to_buttons_ ? | 551 int height = size_extra_view_height_to_buttons_ ? |
476 std::max(ps.height(), button_height) : ps.height(); | 552 std::max(ps.height(), button_height) : ps.height(); |
477 extra_bounds.set_height(height); | 553 extra_bounds.set_height(height); |
478 extra_view_->SetBoundsRect(extra_bounds); | 554 extra_view_->SetBoundsRect(extra_bounds); |
479 } | 555 } |
480 } | 556 } |
481 | 557 |
482 void DialogClientView::LayoutContentsView() { | 558 void DialogClientView::LayoutContentsView() { |
483 gfx::Rect lb = GetContentsBounds(); | 559 gfx::Rect lb = GetContentsBounds(); |
484 lb.set_height(std::max(0, lb.height() - GetDialogButtonsAreaHeight())); | 560 lb.set_height(std::max(0, lb.height() - GetDialogButtonsAreaHeight())); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 } | 598 } |
523 saved_focus_manager_ = focus_manager; | 599 saved_focus_manager_ = focus_manager; |
524 // Listen for focus change events so we can update the default button. | 600 // Listen for focus change events so we can update the default button. |
525 if (focus_manager) { | 601 if (focus_manager) { |
526 focus_manager->AddFocusChangeListener(this); | 602 focus_manager->AddFocusChangeListener(this); |
527 listening_to_focus_ = true; | 603 listening_to_focus_ = true; |
528 } | 604 } |
529 } | 605 } |
530 | 606 |
531 } // namespace views | 607 } // namespace views |
OLD | NEW |