| 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.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "ui/base/accessibility/accessible_view_state.h" | 11 #include "ui/base/accessibility/accessible_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" |
| 16 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/controls/textfield/textfield.h" | 17 #include "ui/views/controls/textfield/textfield.h" |
| 18 #include "ui/views/layout/grid_layout.h" | 18 #include "ui/views/layout/grid_layout.h" |
| 19 #include "ui/views/layout/layout_constants.h" | 19 #include "ui/views/layout/layout_constants.h" |
| 20 #include "ui/views/views_delegate.h" | 20 #include "ui/views/views_delegate.h" |
| 21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 22 #include "ui/views/window/client_view.h" | 22 #include "ui/views/window/client_view.h" |
| 23 | 23 |
| 24 namespace { |
| 25 |
| 24 const int kDefaultMessageWidth = 320; | 26 const int kDefaultMessageWidth = 320; |
| 25 | 27 |
| 26 namespace { | |
| 27 | |
| 28 // Paragraph separators are defined in | 28 // Paragraph separators are defined in |
| 29 // http://www.unicode.org/Public/6.0.0/ucd/extracted/DerivedBidiClass.txt | 29 // http://www.unicode.org/Public/6.0.0/ucd/extracted/DerivedBidiClass.txt |
| 30 // | 30 // |
| 31 // # Bidi_Class=Paragraph_Separator | 31 // # Bidi_Class=Paragraph_Separator |
| 32 // | 32 // |
| 33 // 000A ; B # Cc <control-000A> | 33 // 000A ; B # Cc <control-000A> |
| 34 // 000D ; B # Cc <control-000D> | 34 // 000D ; B # Cc <control-000D> |
| 35 // 001C..001E ; B # Cc [3] <control-001C>..<control-001E> | 35 // 001C..001E ; B # Cc [3] <control-001C>..<control-001E> |
| 36 // 0085 ; B # Cc <control-0085> | 36 // 0085 ; B # Cc <control-0085> |
| 37 // 2029 ; B # Zp PARAGRAPH SEPARATOR | 37 // 2029 ; B # Zp PARAGRAPH SEPARATOR |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 r->push_back(last); | 89 r->push_back(last); |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 namespace views { | 94 namespace views { |
| 95 | 95 |
| 96 /////////////////////////////////////////////////////////////////////////////// | 96 /////////////////////////////////////////////////////////////////////////////// |
| 97 // MessageBoxView, public: | 97 // MessageBoxView, public: |
| 98 | 98 |
| 99 MessageBoxView::MessageBoxView(int options, | 99 MessageBoxView::InitParams::InitParams(const string16& message) |
| 100 const string16& message, | 100 : options(NO_OPTIONS), |
| 101 const string16& default_prompt, | 101 message(message), |
| 102 int message_width) | 102 message_width(kDefaultMessageWidth) { |
| 103 } |
| 104 |
| 105 MessageBoxView::InitParams::~InitParams() { |
| 106 } |
| 107 |
| 108 MessageBoxView::MessageBoxView(const InitParams& params) |
| 103 : prompt_field_(NULL), | 109 : prompt_field_(NULL), |
| 104 icon_(NULL), | 110 icon_(NULL), |
| 105 checkbox_(NULL), | 111 checkbox_(NULL), |
| 106 message_width_(message_width) { | 112 message_width_(params.message_width) { |
| 107 Init(options, message, default_prompt); | 113 Init(params); |
| 108 } | |
| 109 | |
| 110 MessageBoxView::MessageBoxView(int options, | |
| 111 const string16& message, | |
| 112 const string16& default_prompt) | |
| 113 : prompt_field_(NULL), | |
| 114 icon_(NULL), | |
| 115 checkbox_(NULL), | |
| 116 message_width_(kDefaultMessageWidth) { | |
| 117 Init(options, message, default_prompt); | |
| 118 } | 114 } |
| 119 | 115 |
| 120 MessageBoxView::~MessageBoxView() {} | 116 MessageBoxView::~MessageBoxView() {} |
| 121 | 117 |
| 122 string16 MessageBoxView::GetInputText() { | 118 string16 MessageBoxView::GetInputText() { |
| 123 return prompt_field_ ? prompt_field_->text() : string16(); | 119 return prompt_field_ ? prompt_field_->text() : string16(); |
| 124 } | 120 } |
| 125 | 121 |
| 126 bool MessageBoxView::IsCheckBoxSelected() { | 122 bool MessageBoxView::IsCheckBoxSelected() { |
| 127 return checkbox_ ? checkbox_->checked() : false; | 123 return checkbox_ ? checkbox_->checked() : false; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 string16 text = message_labels_[0]->text(); | 183 string16 text = message_labels_[0]->text(); |
| 188 for (size_t i = 1; i < message_labels_.size(); ++i) | 184 for (size_t i = 1; i < message_labels_.size(); ++i) |
| 189 text += message_labels_[i]->text(); | 185 text += message_labels_[i]->text(); |
| 190 scw.WriteText(text); | 186 scw.WriteText(text); |
| 191 return true; | 187 return true; |
| 192 } | 188 } |
| 193 | 189 |
| 194 /////////////////////////////////////////////////////////////////////////////// | 190 /////////////////////////////////////////////////////////////////////////////// |
| 195 // MessageBoxView, private: | 191 // MessageBoxView, private: |
| 196 | 192 |
| 197 void MessageBoxView::Init(int options, | 193 void MessageBoxView::Init(const InitParams& params) { |
| 198 const string16& message, | 194 if (params.options & DETECT_DIRECTIONALITY) { |
| 199 const string16& prompt) { | |
| 200 if (options & DETECT_DIRECTIONALITY) { | |
| 201 std::vector<string16> texts; | 195 std::vector<string16> texts; |
| 202 SplitStringIntoParagraphs(message, &texts); | 196 SplitStringIntoParagraphs(params.message, &texts); |
| 203 // If the text originates from a web page, its alignment is based on its | 197 // If the text originates from a web page, its alignment is based on its |
| 204 // first character with strong directionality. | 198 // first character with strong directionality. |
| 205 base::i18n::TextDirection message_direction = | 199 base::i18n::TextDirection message_direction = |
| 206 base::i18n::GetFirstStrongCharacterDirection(message); | 200 base::i18n::GetFirstStrongCharacterDirection(params.message); |
| 207 Label::Alignment alignment = | 201 Label::Alignment alignment = |
| 208 (message_direction == base::i18n::RIGHT_TO_LEFT) ? | 202 (message_direction == base::i18n::RIGHT_TO_LEFT) ? |
| 209 Label::ALIGN_RIGHT : Label::ALIGN_LEFT; | 203 Label::ALIGN_RIGHT : Label::ALIGN_LEFT; |
| 210 for (size_t i = 0; i < texts.size(); ++i) { | 204 for (size_t i = 0; i < texts.size(); ++i) { |
| 211 Label* message_label = new Label(texts[i]); | 205 Label* message_label = new Label(texts[i]); |
| 212 message_label->SetMultiLine(true); | 206 message_label->SetMultiLine(true); |
| 213 message_label->SetAllowCharacterBreak(true); | 207 message_label->SetAllowCharacterBreak(true); |
| 214 message_label->set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); | 208 message_label->set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); |
| 215 message_label->SetHorizontalAlignment(alignment); | 209 message_label->SetHorizontalAlignment(alignment); |
| 216 message_labels_.push_back(message_label); | 210 message_labels_.push_back(message_label); |
| 217 } | 211 } |
| 218 } else { | 212 } else { |
| 219 Label* message_label = new Label(message); | 213 Label* message_label = new Label(params.message); |
| 220 message_label->SetMultiLine(true); | 214 message_label->SetMultiLine(true); |
| 221 message_label->SetAllowCharacterBreak(true); | 215 message_label->SetAllowCharacterBreak(true); |
| 222 message_label->SetHorizontalAlignment(Label::ALIGN_LEFT); | 216 message_label->SetHorizontalAlignment(Label::ALIGN_LEFT); |
| 223 message_labels_.push_back(message_label); | 217 message_labels_.push_back(message_label); |
| 224 } | 218 } |
| 225 | 219 |
| 226 if (options & HAS_PROMPT_FIELD) { | 220 if (params.options & HAS_PROMPT_FIELD) { |
| 227 prompt_field_ = new Textfield; | 221 prompt_field_ = new Textfield; |
| 228 prompt_field_->SetText(prompt); | 222 prompt_field_->SetText(params.default_prompt); |
| 229 } | 223 } |
| 230 | 224 |
| 231 ResetLayoutManager(); | 225 ResetLayoutManager(); |
| 232 } | 226 } |
| 233 | 227 |
| 234 void MessageBoxView::ResetLayoutManager() { | 228 void MessageBoxView::ResetLayoutManager() { |
| 235 // Initialize the Grid Layout Manager used for this dialog box. | 229 // Initialize the Grid Layout Manager used for this dialog box. |
| 236 GridLayout* layout = GridLayout::CreatePanel(this); | 230 GridLayout* layout = GridLayout::CreatePanel(this); |
| 237 SetLayoutManager(layout); | 231 SetLayoutManager(layout); |
| 238 | 232 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 if (checkbox_) { | 291 if (checkbox_) { |
| 298 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 292 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 299 layout->StartRow(0, checkbox_column_view_set_id); | 293 layout->StartRow(0, checkbox_column_view_set_id); |
| 300 layout->AddView(checkbox_); | 294 layout->AddView(checkbox_); |
| 301 } | 295 } |
| 302 | 296 |
| 303 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 297 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 304 } | 298 } |
| 305 | 299 |
| 306 } // namespace views | 300 } // namespace views |
| OLD | NEW |