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 | |
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
-rw-r--r-- | chrome/common/gfx/chrome_canvas.h | 4 | ||||
-rw-r--r-- | chrome/common/gfx/chrome_canvas_win.cc | 2 | ||||
-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 |
5 files changed, 23 insertions, 1 deletions
diff --git a/chrome/common/gfx/chrome_canvas.h b/chrome/common/gfx/chrome_canvas.h index dbf9466..a16f9da 100644 --- a/chrome/common/gfx/chrome_canvas.h +++ b/chrome/common/gfx/chrome_canvas.h @@ -59,6 +59,10 @@ class ChromeCanvas : public skia::PlatformCanvas { // Prevent ellipsizing NO_ELLIPSIS = 512, + + // Specifies if words can be split by new lines. + // This only works with MULTI_LINE. + CHARACTER_BREAK = 1024, }; // Creates an empty ChromeCanvas. Callers must use initialize before using diff --git a/chrome/common/gfx/chrome_canvas_win.cc b/chrome/common/gfx/chrome_canvas_win.cc index 38446ca..1f14703 100644 --- a/chrome/common/gfx/chrome_canvas_win.cc +++ b/chrome/common/gfx/chrome_canvas_win.cc @@ -54,6 +54,8 @@ int ComputeFormatFlags(int flags, const std::wstring& text) { if (flags & ChromeCanvas::MULTI_LINE) { f |= DT_WORDBREAK; + if (flags & ChromeCanvas::CHARACTER_BREAK) + f |= DT_EDITCONTROL; } else { f |= DT_SINGLELINE | DT_VCENTER; if (!(flags & ChromeCanvas::NO_ELLIPSIS)) 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. |