Chromium Code Reviews| 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" | 15 #include "ui/views/controls/image_view.h" |
|
msw
2014/07/09 15:56:59
nit: remove this
meacer
2014/07/09 18:06:56
Done.
| |
| 16 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/controls/link.h" | 17 #include "ui/views/controls/link.h" |
| 18 #include "ui/views/controls/scroll_view.h" | |
| 19 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" | |
| 18 #include "ui/views/controls/textfield/textfield.h" | 20 #include "ui/views/controls/textfield/textfield.h" |
| 21 #include "ui/views/layout/box_layout.h" | |
| 19 #include "ui/views/layout/grid_layout.h" | 22 #include "ui/views/layout/grid_layout.h" |
| 20 #include "ui/views/layout/layout_constants.h" | 23 #include "ui/views/layout/layout_constants.h" |
| 21 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 22 #include "ui/views/window/client_view.h" | 25 #include "ui/views/window/client_view.h" |
| 23 #include "ui/views/window/dialog_delegate.h" | 26 #include "ui/views/window/dialog_delegate.h" |
| 24 | 27 |
| 25 namespace { | 28 namespace { |
| 26 | 29 |
| 27 const int kDefaultMessageWidth = 320; | 30 const int kDefaultMessageWidth = 320; |
| 28 | 31 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 : options(NO_OPTIONS), | 72 : options(NO_OPTIONS), |
| 70 message(message), | 73 message(message), |
| 71 message_width(kDefaultMessageWidth), | 74 message_width(kDefaultMessageWidth), |
| 72 inter_row_vertical_spacing(kRelatedControlVerticalSpacing) {} | 75 inter_row_vertical_spacing(kRelatedControlVerticalSpacing) {} |
| 73 | 76 |
| 74 MessageBoxView::InitParams::~InitParams() { | 77 MessageBoxView::InitParams::~InitParams() { |
| 75 } | 78 } |
| 76 | 79 |
| 77 MessageBoxView::MessageBoxView(const InitParams& params) | 80 MessageBoxView::MessageBoxView(const InitParams& params) |
| 78 : prompt_field_(NULL), | 81 : prompt_field_(NULL), |
| 79 icon_(NULL), | |
| 80 checkbox_(NULL), | 82 checkbox_(NULL), |
| 81 link_(NULL), | 83 link_(NULL), |
| 82 message_width_(params.message_width) { | 84 message_width_(params.message_width) { |
| 83 Init(params); | 85 Init(params); |
| 84 } | 86 } |
| 85 | 87 |
| 86 MessageBoxView::~MessageBoxView() {} | 88 MessageBoxView::~MessageBoxView() {} |
| 87 | 89 |
| 88 base::string16 MessageBoxView::GetInputText() { | 90 base::string16 MessageBoxView::GetInputText() { |
| 89 return prompt_field_ ? prompt_field_->text() : base::string16(); | 91 return prompt_field_ ? prompt_field_->text() : base::string16(); |
| 90 } | 92 } |
| 91 | 93 |
| 92 bool MessageBoxView::IsCheckBoxSelected() { | 94 bool MessageBoxView::IsCheckBoxSelected() { |
| 93 return checkbox_ ? checkbox_->checked() : false; | 95 return checkbox_ ? checkbox_->checked() : false; |
| 94 } | 96 } |
| 95 | 97 |
| 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) { | 98 void MessageBoxView::SetCheckBoxLabel(const base::string16& label) { |
| 105 if (!checkbox_) | 99 if (!checkbox_) |
| 106 checkbox_ = new Checkbox(label); | 100 checkbox_ = new Checkbox(label); |
| 107 else | 101 else |
| 108 checkbox_->SetText(label); | 102 checkbox_->SetText(label); |
| 109 ResetLayoutManager(); | 103 ResetLayoutManager(); |
| 110 } | 104 } |
| 111 | 105 |
| 112 void MessageBoxView::SetCheckBoxSelected(bool selected) { | 106 void MessageBoxView::SetCheckBoxSelected(bool selected) { |
| 113 if (!checkbox_) | 107 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; | 196 inter_row_vertical_spacing_ = params.inter_row_vertical_spacing; |
| 203 | 197 |
| 204 ResetLayoutManager(); | 198 ResetLayoutManager(); |
| 205 } | 199 } |
| 206 | 200 |
| 207 void MessageBoxView::ResetLayoutManager() { | 201 void MessageBoxView::ResetLayoutManager() { |
| 208 // Initialize the Grid Layout Manager used for this dialog box. | 202 // Initialize the Grid Layout Manager used for this dialog box. |
| 209 GridLayout* layout = GridLayout::CreatePanel(this); | 203 GridLayout* layout = GridLayout::CreatePanel(this); |
| 210 SetLayoutManager(layout); | 204 SetLayoutManager(layout); |
| 211 | 205 |
| 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. | 206 // Add the column set for the message displayed at the top of the dialog box. |
| 217 // And an icon, if one has been set. | 207 // And an icon, if one has been set. |
|
msw
2014/07/09 15:56:59
nit: remove this part of the comment
meacer
2014/07/09 18:06:56
Done.
| |
| 218 const int message_column_view_set_id = 0; | 208 const int message_column_view_set_id = 0; |
| 219 ColumnSet* column_set = layout->AddColumnSet(message_column_view_set_id); | 209 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, | 210 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 227 GridLayout::FIXED, message_width_, 0); | 211 GridLayout::FIXED, message_width_, 0); |
| 228 | 212 |
| 229 // Column set for extra elements, if any. | 213 // Column set for extra elements, if any. |
| 230 const int extra_column_view_set_id = 1; | 214 const int extra_column_view_set_id = 1; |
| 231 if (prompt_field_ || checkbox_ || link_) { | 215 if (prompt_field_ || checkbox_ || link_) { |
| 232 column_set = layout->AddColumnSet(extra_column_view_set_id); | 216 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, | 217 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 238 GridLayout::USE_PREF, 0, 0); | 218 GridLayout::USE_PREF, 0, 0); |
| 239 } | 219 } |
| 240 | 220 |
| 241 for (size_t i = 0; i < message_labels_.size(); ++i) { | 221 const int kMaxScrollViewHeight = 600; |
|
sky
2014/07/09 16:20:15
Why do you need to clip this? Wouldn't it be bette
meacer
2014/07/09 18:06:56
The clipping + overlay scroll bar gave a useful co
sky
2014/07/09 23:21:08
'Clip' was a bad choice on my side. I'm suggesting
meacer
2014/07/10 00:27:53
The message view is constrained by the browser win
msw
2014/07/10 00:34:58
You may be able to override MessageBoxView::GetMin
meacer
2014/07/10 19:36:10
I've tried a couple of approaches, and none seem t
| |
| 242 layout->StartRow(i, message_column_view_set_id); | 222 views::View* message_contents = new views::View(); |
| 243 if (icon_) { | 223 message_contents->SetLayoutManager( |
| 244 if (i == 0) | 224 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 245 layout->AddView(icon_); | 225 for (size_t i = 0; i < message_labels_.size(); ++i) |
| 246 else | 226 message_contents->AddChildView(message_labels_[i]); |
| 247 layout->SkipColumns(1); | 227 ScrollView* scroll_view = new views::ScrollView(); |
| 248 } | 228 scroll_view->SetVerticalScrollBar(new views::OverlayScrollBar(false)); |
|
sky
2014/07/09 16:20:15
Why are you going with overlay?
meacer
2014/07/09 18:06:56
Oddly, NativeScrollBar doesn't show for me at all,
sky
2014/07/09 23:21:08
You should go with the default. The NativeScrollBa
| |
| 249 layout->AddView(message_labels_[i]); | 229 scroll_view->ClipHeightTo(0, kMaxScrollViewHeight); |
| 250 } | 230 scroll_view->SetContents(message_contents); |
| 231 layout->StartRow(0, message_column_view_set_id); | |
| 232 layout->AddView(scroll_view); | |
| 251 | 233 |
| 252 if (prompt_field_) { | 234 if (prompt_field_) { |
| 253 layout->AddPaddingRow(0, inter_row_vertical_spacing_); | 235 layout->AddPaddingRow(0, inter_row_vertical_spacing_); |
| 254 layout->StartRow(0, extra_column_view_set_id); | 236 layout->StartRow(0, extra_column_view_set_id); |
| 255 layout->AddView(prompt_field_); | 237 layout->AddView(prompt_field_); |
| 256 } | 238 } |
| 257 | 239 |
| 258 if (checkbox_) { | 240 if (checkbox_) { |
| 259 layout->AddPaddingRow(0, inter_row_vertical_spacing_); | 241 layout->AddPaddingRow(0, inter_row_vertical_spacing_); |
| 260 layout->StartRow(0, extra_column_view_set_id); | 242 layout->StartRow(0, extra_column_view_set_id); |
| 261 layout->AddView(checkbox_); | 243 layout->AddView(checkbox_); |
| 262 } | 244 } |
| 263 | 245 |
| 264 if (link_) { | 246 if (link_) { |
| 265 layout->AddPaddingRow(0, inter_row_vertical_spacing_); | 247 layout->AddPaddingRow(0, inter_row_vertical_spacing_); |
| 266 layout->StartRow(0, extra_column_view_set_id); | 248 layout->StartRow(0, extra_column_view_set_id); |
| 267 layout->AddView(link_); | 249 layout->AddView(link_); |
| 268 } | 250 } |
| 269 } | 251 } |
| 270 | 252 |
| 271 } // namespace views | 253 } // namespace views |
| OLD | NEW |