summaryrefslogtreecommitdiffstats
path: root/ui/gfx/render_text.cc
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-20 20:53:29 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-20 20:53:29 +0000
commit2bb1b7efb0d745599287ba2807e6413b88025ba1 (patch)
tree9ca6cdf8794d14e1569a6a51fadd563d93044275 /ui/gfx/render_text.cc
parent79fcd382548808dcab8f58e736d4608bbed6c828 (diff)
downloadchromium_src-2bb1b7efb0d745599287ba2807e6413b88025ba1.zip
chromium_src-2bb1b7efb0d745599287ba2807e6413b88025ba1.tar.gz
chromium_src-2bb1b7efb0d745599287ba2807e6413b88025ba1.tar.bz2
Revert 114953 (breaks cros font sizes, etc.) - specify locale-dependent font list for UI on ChromeOS, so that those fonts have higher priority over the fallback fonts Pango picks up.
BUG=103860 TEST=build aura, start chromium in 'ar' locale. type in Arabic and check the Arabic text's shapes. remove IDS_UI_FONT_FAMILY_CROS from 'ar' resource file, build aura again, start chromium in 'ar', type in Arabic and the Arabic text's shapes should be different. Review URL: http://codereview.chromium.org/8770034 TBR=xji@chromium.org Review URL: http://codereview.chromium.org/9007028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115179 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text.cc')
-rw-r--r--ui/gfx/render_text.cc51
1 files changed, 38 insertions, 13 deletions
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 017ae73..657dd1a 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -163,9 +163,11 @@ void SkiaTextRenderer::DrawDecorations(int x, int y, int width,
StyleRange::StyleRange()
- : foreground(SK_ColorBLACK),
+ : font(),
+ foreground(SK_ColorBLACK),
strike(false),
- underline(false) {
+ underline(false),
+ range() {
}
RenderText::~RenderText() {
@@ -209,16 +211,6 @@ void RenderText::SetText(const string16& text) {
UpdateLayout();
}
-void RenderText::SetFontList(const FontList& font_list) {
- font_list_ = font_list;
- cached_bounds_and_offset_valid_ = false;
- UpdateLayout();
-}
-
-const Font& RenderText::GetFont() const {
- return font_list_.GetFonts()[0];
-}
-
void RenderText::ToggleInsertMode() {
insert_mode_ = !insert_mode_;
cached_bounds_and_offset_valid_ = false;
@@ -433,6 +425,10 @@ base::i18n::TextDirection RenderText::GetTextDirection() {
return base::i18n::LEFT_TO_RIGHT;
}
+int RenderText::GetStringWidth() {
+ return default_style_.font.GetStringWidth(text());
+}
+
void RenderText::Draw(Canvas* canvas) {
TRACE_EVENT0("gfx", "RenderText::Draw");
{
@@ -448,6 +444,35 @@ void RenderText::Draw(Canvas* canvas) {
DrawCursor(canvas);
}
+SelectionModel RenderText::FindCursorPosition(const Point& point) {
+ const Font& font = default_style_.font;
+ int left = 0;
+ int left_pos = 0;
+ int right = font.GetStringWidth(text());
+ int right_pos = text().length();
+
+ int x = point.x() - (display_rect_.x() + GetUpdatedDisplayOffset().x());
+ if (x <= left) return SelectionModel(left_pos);
+ if (x >= right) return SelectionModel(right_pos);
+ // binary searching the cursor position.
+ // TODO(oshima): use the center of character instead of edge.
+ // Binary search may not work for language like Arabic.
+ while (std::abs(right_pos - left_pos) > 1) {
+ int pivot_pos = left_pos + (right_pos - left_pos) / 2;
+ int pivot = font.GetStringWidth(text().substr(0, pivot_pos));
+ if (pivot < x) {
+ left = pivot;
+ left_pos = pivot_pos;
+ } else if (pivot == x) {
+ return SelectionModel(pivot_pos);
+ } else {
+ right = pivot;
+ right_pos = pivot_pos;
+ }
+ }
+ return SelectionModel(left_pos);
+}
+
const Rect& RenderText::GetUpdatedCursorBounds() {
UpdateCachedBoundsAndOffset();
return cursor_bounds_;
@@ -620,7 +645,7 @@ Point RenderText::ToViewPoint(const Point& point) {
Point RenderText::GetOriginForSkiaDrawing() {
Point origin(ToViewPoint(Point()));
// TODO(msw): Establish a vertical baseline for strings of mixed font heights.
- const Font& font = GetFont();
+ const Font& font = default_style().font;
size_t height = font.GetHeight();
// Center the text vertically in the display area.
origin.Offset(0, (display_rect().height() - height) / 2);