summaryrefslogtreecommitdiffstats
path: root/ui/gfx/render_text.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gfx/render_text.cc')
-rw-r--r--ui/gfx/render_text.cc53
1 files changed, 14 insertions, 39 deletions
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 2badc05..d058501 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -163,11 +163,9 @@ void SkiaTextRenderer::DrawDecorations(int x, int y, int width,
StyleRange::StyleRange()
- : font(),
- foreground(SK_ColorBLACK),
+ : foreground(SK_ColorBLACK),
strike(false),
- underline(false),
- range() {
+ underline(false) {
}
RenderText::~RenderText() {
@@ -211,6 +209,16 @@ 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;
@@ -425,10 +433,6 @@ 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");
{
@@ -444,35 +448,6 @@ 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_;
@@ -646,7 +621,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 = default_style().font;
+ const Font& font = GetFont();
size_t height = font.GetHeight();
// Center the text vertically in the display area.
origin.Offset(0, (display_rect().height() - height) / 2);