summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 21:38:43 +0000
committerxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 21:38:43 +0000
commit4976429ed6f0ae52a2eae8ad501768c225709210 (patch)
tree46d7ff63426a923bd52448424ddd48c6f4b40f5c /ui
parent27d6e85b17d0d418d8cc39ab1ce0c109396fee36 (diff)
downloadchromium_src-4976429ed6f0ae52a2eae8ad501768c225709210.zip
chromium_src-4976429ed6f0ae52a2eae8ad501768c225709210.tar.gz
chromium_src-4976429ed6f0ae52a2eae8ad501768c225709210.tar.bz2
If script text is in right-to-left directionality, it got truncated because the width calculated in SizeStringInt() and DrawStringInt() are different since they are passed in different flags. DrawStringInt() was passed in an extra flag DT_RTLREADING through FORCE_RTL_DIRECTIONALITY.
Fix by passing in the same flag for size calculation and drawing. BUG=104117 TEST=manual. JS alert a text begins with Hebrew letter followed by a punctuation, such as "A?". It should not be truncated. Review URL: http://codereview.chromium.org/9569025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124736 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/views/controls/label.cc33
-rw-r--r--ui/views/controls/label.h2
2 files changed, 19 insertions, 16 deletions
diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc
index 3c93e3c..58377cd 100644
--- a/ui/views/controls/label.cc
+++ b/ui/views/controls/label.cc
@@ -215,7 +215,7 @@ int Label::GetHeightForWidth(int w) {
w = std::max(0, w - GetInsets().width());
int h = font_.GetHeight();
gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h,
- ComputeMultiLineFlags());
+ ComputeDrawStringFlags());
return h + GetInsets().height();
}
@@ -290,7 +290,7 @@ gfx::Size Label::GetTextSize() const {
int h = font_.GetHeight();
// For single-line strings, ignore the available width and calculate how
// wide the text wants to be.
- int flags = ComputeMultiLineFlags();
+ int flags = ComputeDrawStringFlags();
if (!is_multi_line_)
flags |= gfx::Canvas::NO_ELLIPSIS;
gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags);
@@ -426,11 +426,22 @@ gfx::Rect Label::GetTextBounds() const {
return gfx::Rect(text_origin, text_size);
}
-int Label::ComputeMultiLineFlags() const {
+int Label::ComputeDrawStringFlags() const {
+ int flags = 0;
+
+ if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) {
+ base::i18n::TextDirection direction =
+ base::i18n::GetFirstStrongCharacterDirection(GetText());
+ if (direction == base::i18n::RIGHT_TO_LEFT)
+ flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY;
+ else
+ flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
+ }
+
if (!is_multi_line_)
- return 0;
+ return flags;
- int flags = gfx::Canvas::MULTI_LINE;
+ flags |= gfx::Canvas::MULTI_LINE;
#if !defined(OS_WIN)
// Don't elide multiline labels on Linux.
// Todo(davemoore): Do we depend on eliding multiline text?
@@ -452,6 +463,7 @@ int Label::ComputeMultiLineFlags() const {
flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
break;
}
+
return flags;
}
@@ -492,16 +504,7 @@ void Label::CalculateDrawStringParams(string16* paint_text,
}
*text_bounds = GetTextBounds();
- *flags = ComputeMultiLineFlags();
-
- if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) {
- base::i18n::TextDirection direction =
- base::i18n::GetFirstStrongCharacterDirection(GetText());
- if (direction == base::i18n::RIGHT_TO_LEFT)
- *flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY;
- else
- *flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
- }
+ *flags = ComputeDrawStringFlags();
}
} // namespace views
diff --git a/ui/views/controls/label.h b/ui/views/controls/label.h
index 2321242..adff7c1 100644
--- a/ui/views/controls/label.h
+++ b/ui/views/controls/label.h
@@ -237,7 +237,7 @@ class VIEWS_EXPORT Label : public View {
// Returns where the text is drawn, in the receivers coordinate system.
gfx::Rect GetTextBounds() const;
- int ComputeMultiLineFlags() const;
+ int ComputeDrawStringFlags() const;
gfx::Rect GetAvailableRect() const;