| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/render_text_win.h" | 5 #include "ui/gfx/render_text_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 needs_layout_(false) { | 295 needs_layout_(false) { |
| 296 memset(&script_control_, 0, sizeof(script_control_)); | 296 memset(&script_control_, 0, sizeof(script_control_)); |
| 297 memset(&script_state_, 0, sizeof(script_state_)); | 297 memset(&script_state_, 0, sizeof(script_state_)); |
| 298 | 298 |
| 299 MoveCursorTo(EdgeSelectionModel(CURSOR_LEFT)); | 299 MoveCursorTo(EdgeSelectionModel(CURSOR_LEFT)); |
| 300 } | 300 } |
| 301 | 301 |
| 302 RenderTextWin::~RenderTextWin() { | 302 RenderTextWin::~RenderTextWin() { |
| 303 } | 303 } |
| 304 | 304 |
| 305 base::i18n::TextDirection RenderTextWin::GetTextDirection() { | |
| 306 EnsureLayout(); | |
| 307 return (script_state_.uBidiLevel == 0) ? | |
| 308 base::i18n::LEFT_TO_RIGHT : base::i18n::RIGHT_TO_LEFT; | |
| 309 } | |
| 310 | |
| 311 Size RenderTextWin::GetStringSize() { | 305 Size RenderTextWin::GetStringSize() { |
| 312 EnsureLayout(); | 306 EnsureLayout(); |
| 313 return string_size_; | 307 return string_size_; |
| 314 } | 308 } |
| 315 | 309 |
| 316 int RenderTextWin::GetBaseline() { | 310 int RenderTextWin::GetBaseline() { |
| 317 EnsureLayout(); | 311 EnsureLayout(); |
| 318 return common_baseline_; | 312 return common_baseline_; |
| 319 } | 313 } |
| 320 | 314 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 | 584 |
| 591 x = glyph_x; | 585 x = glyph_x; |
| 592 } | 586 } |
| 593 } | 587 } |
| 594 | 588 |
| 595 void RenderTextWin::ItemizeLogicalText() { | 589 void RenderTextWin::ItemizeLogicalText() { |
| 596 runs_.clear(); | 590 runs_.clear(); |
| 597 string_size_ = Size(0, GetFont().GetHeight()); | 591 string_size_ = Size(0, GetFont().GetHeight()); |
| 598 common_baseline_ = 0; | 592 common_baseline_ = 0; |
| 599 | 593 |
| 600 // Use the first strong character direction as the base text direction. | 594 // Set the base text direction yeilded by the directionality mode. |
| 601 // TODO(msw): Use the application text direction instead of LTR by default? | |
| 602 script_state_.uBidiLevel = | 595 script_state_.uBidiLevel = |
| 603 (base::i18n::GetFirstStrongCharacterDirection(text()) == | 596 (GetTextDirection() == base::i18n::RIGHT_TO_LEFT) ? 1 : 0; |
| 604 base::i18n::RIGHT_TO_LEFT) ? 1 : 0; | |
| 605 | 597 |
| 606 if (text().empty()) | 598 if (text().empty()) |
| 607 return; | 599 return; |
| 608 | 600 |
| 609 const wchar_t* raw_text = text().c_str(); | 601 const wchar_t* raw_text = text().c_str(); |
| 610 const int text_length = text().length(); | 602 const int text_length = text().length(); |
| 611 | 603 |
| 612 HRESULT hr = E_OUTOFMEMORY; | 604 HRESULT hr = E_OUTOFMEMORY; |
| 613 int script_items_count = 0; | 605 int script_items_count = 0; |
| 614 std::vector<SCRIPT_ITEM> script_items; | 606 std::vector<SCRIPT_ITEM> script_items; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 const internal::TextRun* run) { | 941 const internal::TextRun* run) { |
| 950 size_t caret = IndexOfAdjacentGrapheme(run->range.end(), CURSOR_BACKWARD); | 942 size_t caret = IndexOfAdjacentGrapheme(run->range.end(), CURSOR_BACKWARD); |
| 951 return SelectionModel(caret, CURSOR_FORWARD); | 943 return SelectionModel(caret, CURSOR_FORWARD); |
| 952 } | 944 } |
| 953 | 945 |
| 954 RenderText* RenderText::CreateInstance() { | 946 RenderText* RenderText::CreateInstance() { |
| 955 return new RenderTextWin; | 947 return new RenderTextWin; |
| 956 } | 948 } |
| 957 | 949 |
| 958 } // namespace gfx | 950 } // namespace gfx |
| OLD | NEW |