| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "ui/base/accessibility/accessible_view_state.h" | 10 #include "ui/base/accessibility/accessible_view_state.h" |
| 11 #include "ui/base/clipboard/clipboard.h" | 11 #include "ui/base/clipboard/clipboard.h" |
| 12 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 12 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 13 #include "ui/base/message_box_flags.h" | |
| 14 #include "ui/views/controls/button/checkbox.h" | 13 #include "ui/views/controls/button/checkbox.h" |
| 15 #include "ui/views/controls/image_view.h" | 14 #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/textfield/textfield.h" | 16 #include "ui/views/controls/textfield/textfield.h" |
| 18 #include "ui/views/layout/grid_layout.h" | 17 #include "ui/views/layout/grid_layout.h" |
| 19 #include "ui/views/layout/layout_constants.h" | 18 #include "ui/views/layout/layout_constants.h" |
| 20 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 21 #include "ui/views/window/client_view.h" | 20 #include "ui/views/window/client_view.h" |
| 22 #include "views/views_delegate.h" | 21 #include "views/views_delegate.h" |
| 23 | 22 |
| 24 const int kDefaultMessageWidth = 320; | 23 const int kDefaultMessageWidth = 320; |
| 25 | 24 |
| 26 namespace views { | 25 namespace views { |
| 27 | 26 |
| 28 /////////////////////////////////////////////////////////////////////////////// | 27 /////////////////////////////////////////////////////////////////////////////// |
| 29 // MessageBoxView, public: | 28 // MessageBoxView, public: |
| 30 | 29 |
| 31 MessageBoxView::MessageBoxView(int dialog_flags, | 30 MessageBoxView::MessageBoxView(int options, |
| 32 const string16& message, | 31 const string16& message, |
| 33 const string16& default_prompt, | 32 const string16& default_prompt, |
| 34 int message_width) | 33 int message_width) |
| 35 : message_label_(new Label(message)), | 34 : message_label_(new Label(message)), |
| 36 prompt_field_(NULL), | 35 prompt_field_(NULL), |
| 37 icon_(NULL), | 36 icon_(NULL), |
| 38 checkbox_(NULL), | 37 checkbox_(NULL), |
| 39 message_width_(message_width) { | 38 message_width_(message_width) { |
| 40 Init(dialog_flags, default_prompt); | 39 Init(options, default_prompt); |
| 41 } | 40 } |
| 42 | 41 |
| 43 MessageBoxView::MessageBoxView(int dialog_flags, | 42 MessageBoxView::MessageBoxView(int options, |
| 44 const string16& message, | 43 const string16& message, |
| 45 const string16& default_prompt) | 44 const string16& default_prompt) |
| 46 : message_label_(new Label(message)), | 45 : message_label_(new Label(message)), |
| 47 prompt_field_(NULL), | 46 prompt_field_(NULL), |
| 48 icon_(NULL), | 47 icon_(NULL), |
| 49 checkbox_(NULL), | 48 checkbox_(NULL), |
| 50 message_width_(kDefaultMessageWidth) { | 49 message_width_(kDefaultMessageWidth) { |
| 51 Init(dialog_flags, default_prompt); | 50 Init(options, default_prompt); |
| 52 } | 51 } |
| 53 | 52 |
| 54 MessageBoxView::~MessageBoxView() {} | 53 MessageBoxView::~MessageBoxView() {} |
| 55 | 54 |
| 56 string16 MessageBoxView::GetInputText() { | 55 string16 MessageBoxView::GetInputText() { |
| 57 return prompt_field_ ? prompt_field_->text() : string16(); | 56 return prompt_field_ ? prompt_field_->text() : string16(); |
| 58 } | 57 } |
| 59 | 58 |
| 60 bool MessageBoxView::IsCheckBoxSelected() { | 59 bool MessageBoxView::IsCheckBoxSelected() { |
| 61 return checkbox_ ? checkbox_->checked() : false; | 60 return checkbox_ ? checkbox_->checked() : false; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 return false; | 117 return false; |
| 119 | 118 |
| 120 ui::ScopedClipboardWriter scw(clipboard); | 119 ui::ScopedClipboardWriter scw(clipboard); |
| 121 scw.WriteText(message_label_->GetText()); | 120 scw.WriteText(message_label_->GetText()); |
| 122 return true; | 121 return true; |
| 123 } | 122 } |
| 124 | 123 |
| 125 /////////////////////////////////////////////////////////////////////////////// | 124 /////////////////////////////////////////////////////////////////////////////// |
| 126 // MessageBoxView, private: | 125 // MessageBoxView, private: |
| 127 | 126 |
| 128 void MessageBoxView::Init(int dialog_flags, | 127 void MessageBoxView::Init(int options, |
| 129 const string16& default_prompt) { | 128 const string16& default_prompt) { |
| 130 message_label_->SetMultiLine(true); | 129 message_label_->SetMultiLine(true); |
| 131 message_label_->SetAllowCharacterBreak(true); | 130 message_label_->SetAllowCharacterBreak(true); |
| 132 if (dialog_flags & ui::MessageBoxFlags::kAutoDetectAlignment) { | 131 if (options & DETECT_ALIGNMENT) { |
| 133 // Determine the alignment and directionality based on the first character | 132 // Determine the alignment and directionality based on the first character |
| 134 // with strong directionality. | 133 // with strong directionality. |
| 135 base::i18n::TextDirection direction = | 134 base::i18n::TextDirection direction = |
| 136 base::i18n::GetFirstStrongCharacterDirection( | 135 base::i18n::GetFirstStrongCharacterDirection( |
| 137 message_label_->GetText()); | 136 message_label_->GetText()); |
| 138 Label::Alignment alignment; | 137 Label::Alignment alignment; |
| 139 if (direction == base::i18n::RIGHT_TO_LEFT) | 138 if (direction == base::i18n::RIGHT_TO_LEFT) |
| 140 alignment = Label::ALIGN_RIGHT; | 139 alignment = Label::ALIGN_RIGHT; |
| 141 else | 140 else |
| 142 alignment = Label::ALIGN_LEFT; | 141 alignment = Label::ALIGN_LEFT; |
| 143 // In addition, we should set the RTL alignment mode as | 142 // In addition, we should set the RTL alignment mode as |
| 144 // AUTO_DETECT_ALIGNMENT so that the alignment will not be flipped around | 143 // AUTO_DETECT_ALIGNMENT so that the alignment will not be flipped around |
| 145 // in RTL locales. | 144 // in RTL locales. |
| 146 message_label_->set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); | 145 message_label_->set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); |
| 147 message_label_->SetHorizontalAlignment(alignment); | 146 message_label_->SetHorizontalAlignment(alignment); |
| 148 } else { | 147 } else { |
| 149 message_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); | 148 message_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); |
| 150 } | 149 } |
| 151 | 150 |
| 152 if (dialog_flags & ui::MessageBoxFlags::kFlagHasPromptField) { | 151 if (options & HAS_PROMPT_FIELD) { |
| 153 prompt_field_ = new Textfield; | 152 prompt_field_ = new Textfield; |
| 154 prompt_field_->SetText(default_prompt); | 153 prompt_field_->SetText(default_prompt); |
| 155 } | 154 } |
| 156 | 155 |
| 157 ResetLayoutManager(); | 156 ResetLayoutManager(); |
| 158 } | 157 } |
| 159 | 158 |
| 160 void MessageBoxView::ResetLayoutManager() { | 159 void MessageBoxView::ResetLayoutManager() { |
| 161 // Initialize the Grid Layout Manager used for this dialog box. | 160 // Initialize the Grid Layout Manager used for this dialog box. |
| 162 GridLayout* layout = GridLayout::CreatePanel(this); | 161 GridLayout* layout = GridLayout::CreatePanel(this); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 if (checkbox_) { | 217 if (checkbox_) { |
| 219 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 218 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 220 layout->StartRow(0, checkbox_column_view_set_id); | 219 layout->StartRow(0, checkbox_column_view_set_id); |
| 221 layout->AddView(checkbox_); | 220 layout->AddView(checkbox_); |
| 222 } | 221 } |
| 223 | 222 |
| 224 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 223 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 225 } | 224 } |
| 226 | 225 |
| 227 } // namespace views | 226 } // namespace views |
| OLD | NEW |