diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-29 20:30:27 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-29 20:30:27 +0000 |
commit | 135c20361491522381a596cf036d17eedc501a46 (patch) | |
tree | e40bdee98460c61b637750ee35618a76a6e7abd0 /chrome/views | |
parent | 309934c4ceea5086567f275cef17bbfefa29996b (diff) | |
download | chromium_src-135c20361491522381a596cf036d17eedc501a46.zip chromium_src-135c20361491522381a596cf036d17eedc501a46.tar.gz chromium_src-135c20361491522381a596cf036d17eedc501a46.tar.bz2 |
Patch by Shinichiro Hamaji <hamaji@google.com>:
Allow words to be wrapped in message box.
We use DT_WORDBREK|DT_EDITCONTROL as the argument of DrawText().
With this option, DrawText() try to wrap texts at word-breaks first,
then wraps at non-word-breaks if one line is still too long.
This change only affects for Labels in MessageBox.
If we can always use this policy, please let me know
and I'll fix the code.
http://crbug.com/2441
Review URL: http://codereview.chromium.org/100013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14878 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r-- | chrome/views/controls/label.cc | 10 | ||||
-rw-r--r-- | chrome/views/controls/label.h | 7 | ||||
-rw-r--r-- | chrome/views/controls/message_box_view.cc | 1 |
3 files changed, 17 insertions, 1 deletions
diff --git a/chrome/views/controls/label.cc b/chrome/views/controls/label.cc index 7f1a886..f517686 100644 --- a/chrome/views/controls/label.cc +++ b/chrome/views/controls/label.cc @@ -45,6 +45,7 @@ void Label::Init(const std::wstring& text, const ChromeFont& font) { color_ = kEnabledColor; horiz_alignment_ = ALIGN_CENTER; is_multi_line_ = false; + allow_character_break_ = false; collapse_when_hidden_ = false; rtl_alignment_mode_ = USE_UI_ALIGNMENT; paint_as_focused_ = false; @@ -80,6 +81,8 @@ gfx::Size Label::GetPreferredSize() { int Label::ComputeMultiLineFlags() { int flags = ChromeCanvas::MULTI_LINE; + if (allow_character_break_) + flags |= ChromeCanvas::CHARACTER_BREAK; switch (horiz_alignment_) { case ALIGN_LEFT: flags |= ChromeCanvas::TEXT_ALIGN_LEFT; @@ -282,6 +285,13 @@ void Label::SetMultiLine(bool f) { } } +void Label::SetAllowCharacterBreak(bool f) { + if (f != allow_character_break_) { + allow_character_break_ = f; + SchedulePaint(); + } +} + bool Label::IsMultiLine() { return is_multi_line_; } diff --git a/chrome/views/controls/label.h b/chrome/views/controls/label.h index fc4f897..b2f1679 100644 --- a/chrome/views/controls/label.h +++ b/chrome/views/controls/label.h @@ -121,9 +121,13 @@ class Label : public View { RTLAlignmentMode GetRTLAlignmentMode() const; // Set whether the label text can wrap on multiple lines. - // Default is false + // Default is false. void SetMultiLine(bool f); + // Set whether the label text can be split on words. + // Default is false. This only works when is_multi_line is true. + void SetAllowCharacterBreak(bool f); + // Return whether the label text can wrap on multiple lines bool IsMultiLine(); @@ -217,6 +221,7 @@ class Label : public View { gfx::Size text_size_; bool text_size_valid_; bool is_multi_line_; + bool allow_character_break_; bool url_set_; Alignment horiz_alignment_; std::wstring tooltip_text_; diff --git a/chrome/views/controls/message_box_view.cc b/chrome/views/controls/message_box_view.cc index 05bc6ac..afa2319 100644 --- a/chrome/views/controls/message_box_view.cc +++ b/chrome/views/controls/message_box_view.cc @@ -110,6 +110,7 @@ bool MessageBoxView::AcceleratorPressed( void MessageBoxView::Init(int dialog_flags, const std::wstring& default_prompt) { message_label_->SetMultiLine(true); + message_label_->SetAllowCharacterBreak(true); if (dialog_flags & MessageBoxFlags::kAutoDetectAlignment) { // Determine the alignment and directionality based on the first character // with strong directionality. |