| 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.h" | 5 #include "ui/gfx/render_text.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/gfx/break_list.h" | 15 #include "ui/gfx/break_list.h" |
| 16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 | 17 |
| 18 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 19 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
| 20 #include "ui/gfx/render_text_win.h" | 20 #include "ui/gfx/render_text_win.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 #if defined(OS_LINUX) && !defined(USE_OZONE) | 23 #if defined(OS_LINUX) && !defined(USE_OZONE) |
| 24 #include "ui/gfx/render_text_pango.h" | 24 #include "ui/gfx/render_text_pango.h" |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 #if defined(TOOLKIT_GTK) | |
| 28 #include <gtk/gtk.h> | |
| 29 #endif | |
| 30 | |
| 31 using base::ASCIIToUTF16; | 27 using base::ASCIIToUTF16; |
| 32 using base::UTF8ToUTF16; | 28 using base::UTF8ToUTF16; |
| 33 using base::WideToUTF16; | 29 using base::WideToUTF16; |
| 34 | 30 |
| 35 namespace gfx { | 31 namespace gfx { |
| 36 | 32 |
| 37 namespace { | 33 namespace { |
| 38 | 34 |
| 39 // Various weak, LTR, RTL, and Bidi string cases with three characters each. | 35 // Various weak, LTR, RTL, and Bidi string cases with three characters each. |
| 40 const wchar_t kWeak[] = L" . "; | 36 const wchar_t kWeak[] = L" . "; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 | 52 |
| 57 base::string16 GetSelectedText(RenderText* render_text) { | 53 base::string16 GetSelectedText(RenderText* render_text) { |
| 58 return render_text->text().substr(render_text->selection().GetMin(), | 54 return render_text->text().substr(render_text->selection().GetMin(), |
| 59 render_text->selection().length()); | 55 render_text->selection().length()); |
| 60 } | 56 } |
| 61 | 57 |
| 62 // A test utility function to set the application default text direction. | 58 // A test utility function to set the application default text direction. |
| 63 void SetRTL(bool rtl) { | 59 void SetRTL(bool rtl) { |
| 64 // Override the current locale/direction. | 60 // Override the current locale/direction. |
| 65 base::i18n::SetICUDefaultLocale(rtl ? "he" : "en"); | 61 base::i18n::SetICUDefaultLocale(rtl ? "he" : "en"); |
| 66 #if defined(TOOLKIT_GTK) | |
| 67 // Do the same for GTK, which does not rely on the ICU default locale. | |
| 68 gtk_widget_set_default_direction(rtl ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); | |
| 69 #endif | |
| 70 EXPECT_EQ(rtl, base::i18n::IsRTL()); | 62 EXPECT_EQ(rtl, base::i18n::IsRTL()); |
| 71 } | 63 } |
| 72 | 64 |
| 73 #if !defined(OS_MACOSX) | 65 #if !defined(OS_MACOSX) |
| 74 // Ensure cursor movement in the specified |direction| yields |expected| values. | 66 // Ensure cursor movement in the specified |direction| yields |expected| values. |
| 75 void RunMoveCursorLeftRightTest(RenderText* render_text, | 67 void RunMoveCursorLeftRightTest(RenderText* render_text, |
| 76 const std::vector<SelectionModel>& expected, | 68 const std::vector<SelectionModel>& expected, |
| 77 VisualCursorDirection direction) { | 69 VisualCursorDirection direction) { |
| 78 for (size_t i = 0; i < expected.size(); ++i) { | 70 for (size_t i = 0; i < expected.size(); ++i) { |
| 79 SCOPED_TRACE(base::StringPrintf("Going %s; expected value index %d.", | 71 SCOPED_TRACE(base::StringPrintf("Going %s; expected value index %d.", |
| (...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1885 render_text->SetText(WideToUTF16(L"x \x25B6 y")); | 1877 render_text->SetText(WideToUTF16(L"x \x25B6 y")); |
| 1886 render_text->EnsureLayout(); | 1878 render_text->EnsureLayout(); |
| 1887 ASSERT_EQ(3U, render_text->runs_.size()); | 1879 ASSERT_EQ(3U, render_text->runs_.size()); |
| 1888 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); | 1880 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); |
| 1889 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); | 1881 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); |
| 1890 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); | 1882 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); |
| 1891 } | 1883 } |
| 1892 #endif // defined(OS_WIN) | 1884 #endif // defined(OS_WIN) |
| 1893 | 1885 |
| 1894 } // namespace gfx | 1886 } // namespace gfx |
| OLD | NEW |