diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-01 21:57:31 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-01 21:57:31 +0000 |
commit | 46cb5380832a688d32cc39a25080381f90a204f2 (patch) | |
tree | 66795e797e715e0a32b2098ad955f93cd8bb08b0 /ui/gfx/render_text.cc | |
parent | f06188681397c7d6bc785d5dc9c26092c1f3ac03 (diff) | |
download | chromium_src-46cb5380832a688d32cc39a25080381f90a204f2.zip chromium_src-46cb5380832a688d32cc39a25080381f90a204f2.tar.gz chromium_src-46cb5380832a688d32cc39a25080381f90a204f2.tar.bz2 |
Add RenderText DirectionalityMode enum and support; etc.
Add gfx::DirectionalityMode enum.
Add RenderText::SetDirectionalityMode and member.
Revise/consolidate RenderText::GetTextDirection.
Expand on existing unit tests; minor cleanup.
Consume GetTextDirection in layout initialization:
-Windows: RenderTextWin::ItemizeLogicalText()
-Linux: SetupPangoLayoutWithoutFont()
-Mac: Add TODO in RenderTextMac::EnsureLayout()
BUG=134746
TEST=Existing/updated unit tests, no behavioral changes!
Review URL: https://chromiumcodereview.appspot.com/10807082
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149503 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text.cc')
-rw-r--r-- | ui/gfx/render_text.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc index 85dc029..e4b4f64 100644 --- a/ui/gfx/render_text.cc +++ b/ui/gfx/render_text.cc @@ -15,6 +15,7 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/insets.h" #include "ui/gfx/skia_util.h" +#include "ui/gfx/text_constants.h" namespace { @@ -394,6 +395,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_ == DIRECTIONALITY_FROM_TEXT) + text_direction_ = base::i18n::UNKNOWN_DIRECTION; + ResetLayout(); } @@ -596,6 +601,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 DIRECTIONALITY_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 DIRECTIONALITY_FROM_UI: + text_direction_ = base::i18n::IsRTL() ? base::i18n::RIGHT_TO_LEFT : + base::i18n::LEFT_TO_RIGHT; + break; + case DIRECTIONALITY_FORCE_LTR: + text_direction_ = base::i18n::LEFT_TO_RIGHT; + break; + case DIRECTIONALITY_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 +742,8 @@ void RenderText::SetTextShadows(const ShadowValues& shadows) { RenderText::RenderText() : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), + directionality_mode_(DIRECTIONALITY_FROM_TEXT), + text_direction_(base::i18n::UNKNOWN_DIRECTION), cursor_enabled_(true), cursor_visible_(false), insert_mode_(true), |