Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Unified Diff: ui/gfx/render_text.cc

Issue 10807082: Add RenderText DirectionalityMode enum and support; etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore Label::SetURL; derive the direction from display text. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 85dc029782e0d43b9be9b73fd4c02af87629eec3..7af7cb3dd35337baab95f2315ddec6d1fb844a0b 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -394,6 +394,10 @@ void RenderText::SetText(const string16& text) {
// or SetCursorPosition in upper layer.
SetSelectionModel(SelectionModel());
+ // Invalidate the cached text direction if it depends on the text contents.
+ if (directionality_mode_ == DERIVE_FROM_TEXT)
+ text_direction_ = base::i18n::UNKNOWN_DIRECTION;
+
ResetLayout();
}
@@ -596,6 +600,42 @@ void RenderText::ApplyDefaultStyle() {
ResetLayout();
}
+void RenderText::SetDirectionalityMode(DirectionalityMode mode) {
+ if (mode == directionality_mode_)
+ return;
+
+ directionality_mode_ = mode;
+ text_direction_ = base::i18n::UNKNOWN_DIRECTION;
+ ResetLayout();
+}
+
+base::i18n::TextDirection RenderText::GetTextDirection() {
+ if (text_direction_ == base::i18n::UNKNOWN_DIRECTION) {
+ switch (directionality_mode_) {
+ case DERIVE_FROM_TEXT:
+ // Derive the direction from the display text, which differs from text()
+ // in the case of obscured (password) textfields.
+ text_direction_ =
+ base::i18n::GetFirstStrongCharacterDirection(GetDisplayText());
+ break;
+ case DERIVE_FROM_UI:
+ text_direction_ = base::i18n::IsRTL() ? base::i18n::RIGHT_TO_LEFT :
+ base::i18n::LEFT_TO_RIGHT;
+ break;
+ case FORCE_LTR:
+ text_direction_ = base::i18n::LEFT_TO_RIGHT;
+ break;
+ case FORCE_RTL:
+ text_direction_ = base::i18n::RIGHT_TO_LEFT;
+ break;
+ default:
+ NOTREACHED();
+ }
+ }
+
+ return text_direction_;
+}
+
VisualCursorDirection RenderText::GetVisualDirectionOfLogicalEnd() {
return GetTextDirection() == base::i18n::LEFT_TO_RIGHT ?
CURSOR_RIGHT : CURSOR_LEFT;
@@ -701,6 +741,8 @@ void RenderText::SetTextShadows(const ShadowValues& shadows) {
RenderText::RenderText()
: horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT),
+ directionality_mode_(DERIVE_FROM_TEXT),
+ text_direction_(base::i18n::UNKNOWN_DIRECTION),
cursor_enabled_(true),
cursor_visible_(false),
insert_mode_(true),
« ui/gfx/render_text.h ('K') | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698