| 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/controls/message_box_view.h" | 5 #include "ui/views/controls/message_box_view.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 12 #include "ui/base/clipboard/clipboard.h" | 12 #include "ui/base/clipboard/clipboard.h" |
| 13 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 13 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 14 #include "ui/views/controls/button/checkbox.h" | 14 #include "ui/views/controls/button/checkbox.h" |
| 15 #include "ui/views/controls/image_view.h" | |
| 16 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/controls/link.h" | 16 #include "ui/views/controls/link.h" |
| 17 #include "ui/views/controls/scroll_view.h" |
| 18 #include "ui/views/controls/textfield/textfield.h" | 18 #include "ui/views/controls/textfield/textfield.h" |
| 19 #include "ui/views/layout/box_layout.h" |
| 19 #include "ui/views/layout/grid_layout.h" | 20 #include "ui/views/layout/grid_layout.h" |
| 20 #include "ui/views/layout/layout_constants.h" | 21 #include "ui/views/layout/layout_constants.h" |
| 21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 22 #include "ui/views/window/client_view.h" | 23 #include "ui/views/window/client_view.h" |
| 23 #include "ui/views/window/dialog_delegate.h" | 24 #include "ui/views/window/dialog_delegate.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const int kDefaultMessageWidth = 320; | 28 const int kDefaultMessageWidth = 320; |
| 28 | 29 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 : options(NO_OPTIONS), | 70 : options(NO_OPTIONS), |
| 70 message(message), | 71 message(message), |
| 71 message_width(kDefaultMessageWidth), | 72 message_width(kDefaultMessageWidth), |
| 72 inter_row_vertical_spacing(kRelatedControlVerticalSpacing) {} | 73 inter_row_vertical_spacing(kRelatedControlVerticalSpacing) {} |
| 73 | 74 |
| 74 MessageBoxView::InitParams::~InitParams() { | 75 MessageBoxView::InitParams::~InitParams() { |
| 75 } | 76 } |
| 76 | 77 |
| 77 MessageBoxView::MessageBoxView(const InitParams& params) | 78 MessageBoxView::MessageBoxView(const InitParams& params) |
| 78 : prompt_field_(NULL), | 79 : prompt_field_(NULL), |
| 79 icon_(NULL), | |
| 80 checkbox_(NULL), | 80 checkbox_(NULL), |
| 81 link_(NULL), | 81 link_(NULL), |
| 82 message_width_(params.message_width) { | 82 message_width_(params.message_width) { |
| 83 Init(params); | 83 Init(params); |
| 84 } | 84 } |
| 85 | 85 |
| 86 MessageBoxView::~MessageBoxView() {} | 86 MessageBoxView::~MessageBoxView() {} |
| 87 | 87 |
| 88 base::string16 MessageBoxView::GetInputText() { | 88 base::string16 MessageBoxView::GetInputText() { |
| 89 return prompt_field_ ? prompt_field_->text() : base::string16(); | 89 return prompt_field_ ? prompt_field_->text() : base::string16(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool MessageBoxView::IsCheckBoxSelected() { | 92 bool MessageBoxView::IsCheckBoxSelected() { |
| 93 return checkbox_ ? checkbox_->checked() : false; | 93 return checkbox_ ? checkbox_->checked() : false; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void MessageBoxView::SetIcon(const gfx::ImageSkia& icon) { | |
| 97 if (!icon_) | |
| 98 icon_ = new ImageView(); | |
| 99 icon_->SetImage(icon); | |
| 100 icon_->SetBounds(0, 0, icon.width(), icon.height()); | |
| 101 ResetLayoutManager(); | |
| 102 } | |
| 103 | |
| 104 void MessageBoxView::SetCheckBoxLabel(const base::string16& label) { | 96 void MessageBoxView::SetCheckBoxLabel(const base::string16& label) { |
| 105 if (!checkbox_) | 97 if (!checkbox_) |
| 106 checkbox_ = new Checkbox(label); | 98 checkbox_ = new Checkbox(label); |
| 107 else | 99 else |
| 108 checkbox_->SetText(label); | 100 checkbox_->SetText(label); |
| 109 ResetLayoutManager(); | 101 ResetLayoutManager(); |
| 110 } | 102 } |
| 111 | 103 |
| 112 void MessageBoxView::SetCheckBoxSelected(bool selected) { | 104 void MessageBoxView::SetCheckBoxSelected(bool selected) { |
| 113 if (!checkbox_) | 105 if (!checkbox_) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 inter_row_vertical_spacing_ = params.inter_row_vertical_spacing; | 194 inter_row_vertical_spacing_ = params.inter_row_vertical_spacing; |
| 203 | 195 |
| 204 ResetLayoutManager(); | 196 ResetLayoutManager(); |
| 205 } | 197 } |
| 206 | 198 |
| 207 void MessageBoxView::ResetLayoutManager() { | 199 void MessageBoxView::ResetLayoutManager() { |
| 208 // Initialize the Grid Layout Manager used for this dialog box. | 200 // Initialize the Grid Layout Manager used for this dialog box. |
| 209 GridLayout* layout = GridLayout::CreatePanel(this); | 201 GridLayout* layout = GridLayout::CreatePanel(this); |
| 210 SetLayoutManager(layout); | 202 SetLayoutManager(layout); |
| 211 | 203 |
| 212 gfx::Size icon_size; | |
| 213 if (icon_) | |
| 214 icon_size = icon_->GetPreferredSize(); | |
| 215 | |
| 216 // Add the column set for the message displayed at the top of the dialog box. | 204 // Add the column set for the message displayed at the top of the dialog box. |
| 217 // And an icon, if one has been set. | |
| 218 const int message_column_view_set_id = 0; | 205 const int message_column_view_set_id = 0; |
| 219 ColumnSet* column_set = layout->AddColumnSet(message_column_view_set_id); | 206 ColumnSet* column_set = layout->AddColumnSet(message_column_view_set_id); |
| 220 if (icon_) { | |
| 221 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, | |
| 222 GridLayout::FIXED, icon_size.width(), | |
| 223 icon_size.height()); | |
| 224 column_set->AddPaddingColumn(0, kUnrelatedControlHorizontalSpacing); | |
| 225 } | |
| 226 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 207 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 227 GridLayout::FIXED, message_width_, 0); | 208 GridLayout::FIXED, message_width_, 0); |
| 228 | 209 |
| 229 // Column set for extra elements, if any. | 210 // Column set for extra elements, if any. |
| 230 const int extra_column_view_set_id = 1; | 211 const int extra_column_view_set_id = 1; |
| 231 if (prompt_field_ || checkbox_ || link_) { | 212 if (prompt_field_ || checkbox_ || link_) { |
| 232 column_set = layout->AddColumnSet(extra_column_view_set_id); | 213 column_set = layout->AddColumnSet(extra_column_view_set_id); |
| 233 if (icon_) { | |
| 234 column_set->AddPaddingColumn( | |
| 235 0, icon_size.width() + kUnrelatedControlHorizontalSpacing); | |
| 236 } | |
| 237 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 214 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 238 GridLayout::USE_PREF, 0, 0); | 215 GridLayout::USE_PREF, 0, 0); |
| 239 } | 216 } |
| 240 | 217 |
| 241 for (size_t i = 0; i < message_labels_.size(); ++i) { | 218 const int kMaxScrollViewHeight = 600; |
| 242 layout->StartRow(i, message_column_view_set_id); | 219 views::View* message_contents = new views::View(); |
| 243 if (icon_) { | 220 message_contents->SetLayoutManager( |
| 244 if (i == 0) | 221 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 245 layout->AddView(icon_); | 222 for (size_t i = 0; i < message_labels_.size(); ++i) |
| 246 else | 223 message_contents->AddChildView(message_labels_[i]); |
| 247 layout->SkipColumns(1); | 224 ScrollView* scroll_view = new views::ScrollView(); |
| 248 } | 225 scroll_view->ClipHeightTo(0, kMaxScrollViewHeight); |
| 249 layout->AddView(message_labels_[i]); | 226 scroll_view->SetContents(message_contents); |
| 250 } | 227 layout->StartRow(0, message_column_view_set_id); |
| 228 layout->AddView(scroll_view); |
| 251 | 229 |
| 252 if (prompt_field_) { | 230 if (prompt_field_) { |
| 253 layout->AddPaddingRow(0, inter_row_vertical_spacing_); | 231 layout->AddPaddingRow(0, inter_row_vertical_spacing_); |
| 254 layout->StartRow(0, extra_column_view_set_id); | 232 layout->StartRow(0, extra_column_view_set_id); |
| 255 layout->AddView(prompt_field_); | 233 layout->AddView(prompt_field_); |
| 256 } | 234 } |
| 257 | 235 |
| 258 if (checkbox_) { | 236 if (checkbox_) { |
| 259 layout->AddPaddingRow(0, inter_row_vertical_spacing_); | 237 layout->AddPaddingRow(0, inter_row_vertical_spacing_); |
| 260 layout->StartRow(0, extra_column_view_set_id); | 238 layout->StartRow(0, extra_column_view_set_id); |
| 261 layout->AddView(checkbox_); | 239 layout->AddView(checkbox_); |
| 262 } | 240 } |
| 263 | 241 |
| 264 if (link_) { | 242 if (link_) { |
| 265 layout->AddPaddingRow(0, inter_row_vertical_spacing_); | 243 layout->AddPaddingRow(0, inter_row_vertical_spacing_); |
| 266 layout->StartRow(0, extra_column_view_set_id); | 244 layout->StartRow(0, extra_column_view_set_id); |
| 267 layout->AddView(link_); | 245 layout->AddView(link_); |
| 268 } | 246 } |
| 269 } | 247 } |
| 270 | 248 |
| 271 } // namespace views | 249 } // namespace views |
| OLD | NEW |