| 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 "views/controls/message_box_view.h" | 5 #include "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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace views { | 26 namespace views { |
| 27 | 27 |
| 28 /////////////////////////////////////////////////////////////////////////////// | 28 /////////////////////////////////////////////////////////////////////////////// |
| 29 // MessageBoxView, public: | 29 // MessageBoxView, public: |
| 30 | 30 |
| 31 MessageBoxView::MessageBoxView(int dialog_flags, | 31 MessageBoxView::MessageBoxView(int dialog_flags, |
| 32 const std::wstring& message, | 32 const std::wstring& message, |
| 33 const std::wstring& default_prompt, | 33 const std::wstring& default_prompt, |
| 34 int message_width) | 34 int message_width) |
| 35 : message_label_(new Label(WideToUTF16Hack(message))), | 35 : message_label_(new Label(message)), |
| 36 prompt_field_(NULL), | 36 prompt_field_(NULL), |
| 37 icon_(NULL), | 37 icon_(NULL), |
| 38 checkbox_(NULL), | 38 checkbox_(NULL), |
| 39 message_width_(message_width) { | 39 message_width_(message_width) { |
| 40 Init(dialog_flags, default_prompt); | 40 Init(dialog_flags, default_prompt); |
| 41 } | 41 } |
| 42 | 42 |
| 43 MessageBoxView::MessageBoxView(int dialog_flags, | 43 MessageBoxView::MessageBoxView(int dialog_flags, |
| 44 const std::wstring& message, | 44 const std::wstring& message, |
| 45 const std::wstring& default_prompt) | 45 const std::wstring& default_prompt) |
| 46 : message_label_(new Label(WideToUTF16Hack(message))), | 46 : message_label_(new Label(message)), |
| 47 prompt_field_(NULL), | 47 prompt_field_(NULL), |
| 48 icon_(NULL), | 48 icon_(NULL), |
| 49 checkbox_(NULL), | 49 checkbox_(NULL), |
| 50 message_width_(kDefaultMessageWidth) { | 50 message_width_(kDefaultMessageWidth) { |
| 51 Init(dialog_flags, default_prompt); | 51 Init(dialog_flags, default_prompt); |
| 52 } | 52 } |
| 53 | 53 |
| 54 MessageBoxView::~MessageBoxView() {} | 54 MessageBoxView::~MessageBoxView() {} |
| 55 | 55 |
| 56 string16 MessageBoxView::GetInputText() { | 56 string16 MessageBoxView::GetInputText() { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 return false; | 112 return false; |
| 113 | 113 |
| 114 if (!ViewsDelegate::views_delegate) | 114 if (!ViewsDelegate::views_delegate) |
| 115 return false; | 115 return false; |
| 116 | 116 |
| 117 ui::Clipboard* clipboard = ViewsDelegate::views_delegate->GetClipboard(); | 117 ui::Clipboard* clipboard = ViewsDelegate::views_delegate->GetClipboard(); |
| 118 if (!clipboard) | 118 if (!clipboard) |
| 119 return false; | 119 return false; |
| 120 | 120 |
| 121 ui::ScopedClipboardWriter scw(clipboard); | 121 ui::ScopedClipboardWriter scw(clipboard); |
| 122 scw.WriteText(message_label_->GetText()); | 122 scw.WriteText(WideToUTF16Hack(message_label_->GetText())); |
| 123 return true; | 123 return true; |
| 124 } | 124 } |
| 125 | 125 |
| 126 /////////////////////////////////////////////////////////////////////////////// | 126 /////////////////////////////////////////////////////////////////////////////// |
| 127 // MessageBoxView, private: | 127 // MessageBoxView, private: |
| 128 | 128 |
| 129 void MessageBoxView::Init(int dialog_flags, | 129 void MessageBoxView::Init(int dialog_flags, |
| 130 const std::wstring& default_prompt) { | 130 const std::wstring& default_prompt) { |
| 131 message_label_->SetMultiLine(true); | 131 message_label_->SetMultiLine(true); |
| 132 message_label_->SetAllowCharacterBreak(true); | 132 message_label_->SetAllowCharacterBreak(true); |
| 133 if (dialog_flags & ui::MessageBoxFlags::kAutoDetectAlignment) { | 133 if (dialog_flags & ui::MessageBoxFlags::kAutoDetectAlignment) { |
| 134 // Determine the alignment and directionality based on the first character | 134 // Determine the alignment and directionality based on the first character |
| 135 // with strong directionality. | 135 // with strong directionality. |
| 136 base::i18n::TextDirection direction = | 136 base::i18n::TextDirection direction = |
| 137 base::i18n::GetFirstStrongCharacterDirection( | 137 base::i18n::GetFirstStrongCharacterDirection( |
| 138 message_label_->GetText()); | 138 WideToUTF16(message_label_->GetText())); |
| 139 Label::Alignment alignment; | 139 Label::Alignment alignment; |
| 140 if (direction == base::i18n::RIGHT_TO_LEFT) | 140 if (direction == base::i18n::RIGHT_TO_LEFT) |
| 141 alignment = Label::ALIGN_RIGHT; | 141 alignment = Label::ALIGN_RIGHT; |
| 142 else | 142 else |
| 143 alignment = Label::ALIGN_LEFT; | 143 alignment = Label::ALIGN_LEFT; |
| 144 // In addition, we should set the RTL alignment mode as | 144 // In addition, we should set the RTL alignment mode as |
| 145 // AUTO_DETECT_ALIGNMENT so that the alignment will not be flipped around | 145 // AUTO_DETECT_ALIGNMENT so that the alignment will not be flipped around |
| 146 // in RTL locales. | 146 // in RTL locales. |
| 147 message_label_->set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); | 147 message_label_->set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); |
| 148 message_label_->SetHorizontalAlignment(alignment); | 148 message_label_->SetHorizontalAlignment(alignment); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 if (checkbox_) { | 219 if (checkbox_) { |
| 220 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 220 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 221 layout->StartRow(0, checkbox_column_view_set_id); | 221 layout->StartRow(0, checkbox_column_view_set_id); |
| 222 layout->AddView(checkbox_); | 222 layout->AddView(checkbox_); |
| 223 } | 223 } |
| 224 | 224 |
| 225 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 225 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 226 } | 226 } |
| 227 | 227 |
| 228 } // namespace views | 228 } // namespace views |
| OLD | NEW |