render_text.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_GFX_RENDER_TEXT_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_GFX_RENDER_TEXT_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <algorithm> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <cstring> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <utility> 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/gtest_prod_util.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/i18n/rtl.h" 167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/string16.h" 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "skia/ext/refptr.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkPaint.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkRect.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/break_list.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/font_list.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/point.h" 2458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ui/gfx/range/range.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/selection_model.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/shadow_value.h" 284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/gfx/size_f.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/text_constants.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/vector2d.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SkCanvas; 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SkDrawLooper; 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct SkPoint; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SkShader; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SkTypeface; 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx { 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Canvas; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Font; 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RenderTextTest; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace internal { 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Internal helper class used by derived classes to draw text through Skia. 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SkiaTextRenderer { 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit SkiaTextRenderer(Canvas* canvas); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~SkiaTextRenderer(); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetDrawLooper(SkDrawLooper* draw_looper); 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetFontSmoothingSettings(bool enable_smoothing, bool enable_lcd_text); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetTypeface(SkTypeface* typeface); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetTextSize(SkScalar size); 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetFontFamilyWithStyle(const std::string& family, int font_style); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetForegroundColor(SkColor foreground); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetShader(SkShader* shader, const Rect& bounds); 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets underline metrics to use if the text will be drawn with an underline. 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If not set, default values based on the size of the text will be used. The 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // two metrics must be set together. 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetUnderlineMetrics(SkScalar thickness, SkScalar position); 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void DrawSelection(const std::vector<Rect>& selection, SkColor color); 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void DrawPosText(const SkPoint* pos, 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const uint16* glyphs, 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t glyph_count); 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Draw underline and strike-through text decorations. 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Based on |SkCanvas::DrawTextDecorations()| and constants from: 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // third_party/skia/src/core/SkTextFormatParams.h 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void DrawDecorations(int x, int y, int width, bool underline, bool strike, 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool diagonal_strike); 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void DrawUnderline(int x, int y, int width); 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void DrawStrike(int x, int y, int width) const; 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void DrawDiagonalStrike(int x, int y, int width) const; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkCanvas* canvas_skia_; 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool started_drawing_; 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkPaint paint_; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkRect bounds_; 8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) skia::RefPtr<SkShader> deferred_fade_shader_; 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkScalar underline_thickness_; 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkScalar underline_position_; 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer); 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Internal helper class used by derived classes to iterate colors and styles. 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class StyleIterator { 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StyleIterator(const BreakList<SkColor>& colors, 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::vector<BreakList<bool> >& styles); 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ~StyleIterator(); 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Get the colors and styles at the current iterator position. 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SkColor color() const { return color_->second; } 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool style(TextStyle s) const { return style_[s]->second; } 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Get the intersecting range of the current iterator set. 100d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Range GetRange() const; 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Update the iterator to point to colors and styles applicable at |position|. 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void UpdatePosition(size_t position); 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BreakList<SkColor> colors_; 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<BreakList<bool> > styles_; 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BreakList<SkColor>::const_iterator color_; 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<BreakList<bool>::const_iterator> style_; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(StyleIterator); 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Line segments are slices of the layout text to be rendered on a single line. 116d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)struct LineSegment { 117d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) LineSegment(); 118d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ~LineSegment(); 119d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 120d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // X coordinates of this line segment in text space. 121d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Range x_range; 122d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 123d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // The character range this segment corresponds to. 124d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Range char_range; 125d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 126d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Index of the text run that generated this segment. 127d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) size_t run; 128d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}; 129d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 130d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// A line of layout text, comprised of a line segment list and some metrics. 131d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)struct Line { 132d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Line(); 133d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ~Line(); 134d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 135d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Segments that make up this line in visual order. 136d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) std::vector<LineSegment> segments; 137d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 138d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // A line size is the sum of segment widths and the maximum of segment 139d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // heights. 140d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Size size; 141d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 142d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Sum of preceding lines' heights. 143d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) int preceding_heights; 144d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 145d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Maximum baseline of all segments on this line. 146d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) int baseline; 147d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}; 148d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace internal 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// RenderText represents an abstract model of styled text and its corresponding 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// visual layout. Support is built in for a cursor, a selection, simple styling, 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// complex scripts, and bi-directional text. Implementations provide mechanisms 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// for rendering and translation between logical and visual data. 1554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class GFX_EXPORT RenderText { 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~RenderText(); 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates a platform-specific RenderText instance. 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static RenderText* CreateInstance(); 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 162868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const base::string16& text() const { return text_; } 163868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void SetText(const base::string16& text); 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HorizontalAlignment horizontal_alignment() const { 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return horizontal_alignment_; 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetHorizontalAlignment(HorizontalAlignment alignment); 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const FontList& font_list() const { return font_list_; } 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetFontList(const FontList& font_list); 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetFont(const Font& font); 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set the font size to |size| in pixels. 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetFontSize(int size); 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the first font in |font_list_|. 178a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const Font& GetPrimaryFont() const; 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool cursor_enabled() const { return cursor_enabled_; } 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetCursorEnabled(bool cursor_enabled); 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool cursor_visible() const { return cursor_visible_; } 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_cursor_visible(bool visible) { cursor_visible_ = visible; } 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool insert_mode() const { return insert_mode_; } 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ToggleInsertMode(); 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor cursor_color() const { return cursor_color_; } 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_cursor_color(SkColor color) { cursor_color_ = color; } 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor selection_color() const { return selection_color_; } 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_selection_color(SkColor color) { selection_color_ = color; } 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor selection_background_focused_color() const { 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return selection_background_focused_color_; 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_selection_background_focused_color(SkColor color) { 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) selection_background_focused_color_ = color; 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool focused() const { return focused_; } 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_focused(bool focused) { focused_ = focused; } 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool clip_to_display_rect() const { return clip_to_display_rect_; } 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_clip_to_display_rect(bool clip) { clip_to_display_rect_ = clip; } 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // In an obscured (password) field, all text is drawn as asterisks or bullets. 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool obscured() const { return obscured_; } 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetObscured(bool obscured); 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Makes a char in obscured text at |index| to be revealed. |index| should be 213868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // a UTF16 text index. If there is a previous revealed index, the previous one 214868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // is cleared and only the last set index will be revealed. If |index| is -1 215868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // or out of range, no char will be revealed. The revealed index is also 216868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // cleared when SetText or SetObscured is called. 217868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void SetObscuredRevealIndex(int index); 218868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 219d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // TODO(ckocagil): Multiline text rendering is currently only supported on 220d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Windows. Support other platforms. 221d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool multiline() const { return multiline_; } 222d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void SetMultiline(bool multiline); 223d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 224eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Set the maximum length of the displayed layout text, not the actual text. 225eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // A |length| of 0 forgoes a hard limit, but does not guarantee proper 226eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // functionality of very long strings. Applies to subsequent SetText calls. 227eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // WARNING: Only use this for system limits, it lacks complex text support. 228eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void set_truncate_length(size_t length) { truncate_length_ = length; } 229eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Rect& display_rect() const { return display_rect_; } 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetDisplayRect(const Rect& r); 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_fade_head(bool fade_head) { fade_head_ = fade_head; } 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool fade_head() const { return fade_head_; } 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; } 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool fade_tail() const { return fade_tail_; } 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool background_is_transparent() const { return background_is_transparent_; } 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_background_is_transparent(bool transparent) { 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) background_is_transparent_ = transparent; 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SelectionModel& selection_model() const { return selection_model_; } 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const Range& selection() const { return selection_model_.selection(); } 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t cursor_position() const { return selection_model_.caret_pos(); } 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetCursorPosition(size_t position); 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Moves the cursor left or right. Cursor movement is visual, meaning that 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // left and right are relative to screen, not the directionality of the text. 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |select| is false, the selection start is moved to the same position. 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void MoveCursor(BreakType break_type, 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VisualCursorDirection direction, 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool select); 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set the selection_model_ to the value of |selection|. 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The selection range is clamped to text().length() if out of range. 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the cursor position or selection range changed. 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If any index in |selection_model| is not a cursorable position (not on a 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // grapheme boundary), it is a no-op and returns false. 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool MoveCursorTo(const SelectionModel& selection_model); 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Move the cursor to the position associated with the clicked point. 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |select| is false, the selection start is moved to the same position. 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the cursor position or selection range changed. 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool MoveCursorTo(const Point& point, bool select); 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set the selection_model_ based on |range|. 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the |range| start or end is greater than text length, it is modified 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to be the text length. 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the |range| start or end is not a cursorable position (not on grapheme 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // boundary), it is a NO-OP and returns false. Otherwise, returns true. 274d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool SelectRange(const Range& range); 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the local point is over selected text. 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool IsPointInSelection(const Point& point); 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Selects no text, keeping the current cursor position and caret affinity. 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ClearSelection(); 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Select the entire text range. If |reversed| is true, the range will end at 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the logical beginning of the text; this generally shows the leading portion 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of text that overflows its display area. 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SelectAll(bool reversed); 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 287a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Selects the word at the current cursor position. If there is a non-empty 288a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // selection, the selection bounds are extended to their nearest word 289a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // boundaries. 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SelectWord(); 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 292d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const Range& GetCompositionRange() const; 293d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void SetCompositionRange(const Range& composition_range); 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set the text color over the entire text or a logical character range. 2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The |range| should be valid, non-reversed, and within [0, text().length()]. 2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetColor(SkColor value); 298d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void ApplyColor(SkColor value, const Range& range); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set various text styles over the entire text or a logical character range. 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The respective |style| is applied if |value| is true, or removed if false. 3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The |range| should be valid, non-reversed, and within [0, text().length()]. 3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetStyle(TextStyle style, bool value); 304d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void ApplyStyle(TextStyle style, bool value, const Range& range); 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Returns whether this style is enabled consistently across the entire 3077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // RenderText. 3087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool GetStyle(TextStyle style) const; 3097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 310f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Set or get the text directionality mode and get the text direction yielded. 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetDirectionalityMode(DirectionalityMode mode); 312f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DirectionalityMode directionality_mode() const { 313f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return directionality_mode_; 314f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::i18n::TextDirection GetTextDirection(); 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the visual movement direction corresponding to the logical end 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of the text, considering only the dominant direction returned by 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |GetTextDirection()|, not the direction of a particular run. 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VisualCursorDirection GetVisualDirectionOfLogicalEnd(); 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 322d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns the size required to display the current string (which is the 323d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // wrapped size in multiline mode). Note that this returns the raw size of the 324d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // string, which does not include the cursor or the margin area of text 325d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // shadows. 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual Size GetStringSize() = 0; 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // This is same as GetStringSize except that fractional size is returned. 3294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The default implementation is same as GetStringSize. Certain platforms that 3304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // compute the text size as floating-point values, like Mac, will override 3314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // this method. 3324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // See comment in Canvas::GetStringWidthF for its usage. 3334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual SizeF GetStringSizeF(); 3344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 335d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns the width of the content (which is the wrapped width in multiline 336d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // mode). Reserves room for the cursor if |cursor_enabled_| is true. 337c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int GetContentWidth(); 338c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 3390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Returns the common baseline of the text. The return value is the vertical 3400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // offset from the top of |display_rect_| to the text baseline, in pixels. 3410f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // The baseline is determined from the font list and display rect, and does 3420f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // not depend on the text. 3430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int GetBaseline(); 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Draw(Canvas* canvas); 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 347c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Draws a cursor at |position|. 348c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void DrawCursor(Canvas* canvas, const SelectionModel& position); 349c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 350ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // Draw the selected text without a cursor or selection highlight. Subpixel 351ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // antialiasing is disabled and foreground color is forced to black. 352ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch void DrawSelectedTextForDrag(Canvas* canvas); 3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets the SelectionModel from a visual point in local coordinates. 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SelectionModel FindCursorPosition(const Point& point) = 0; 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 357a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Return true if cursor can appear in front of the character at |position|, 358a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // which means it is a grapheme boundary or the first character in the text. 359a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual bool IsCursorablePosition(size_t position) = 0; 360a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 361a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Get the visual bounds of a cursor at |caret|. These bounds typically 362a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // represent a vertical line if |insert_mode| is true. Pass false for 363a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |insert_mode| to retrieve the bounds of the associated glyph. These bounds 364a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // are in local coordinates, but may be outside the visible region if the text 365a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // is longer than the textfield. Subsequent text, cursor, or bounds changes 366a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // may invalidate returned values. Note that |caret| must be placed at 367a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // grapheme boundary, that is, |IsCursorablePosition(caret.caret_pos())| must 368a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // return true. 369a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) Rect GetCursorBounds(const SelectionModel& caret, bool insert_mode); 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Compute the current cursor bounds, panning the text to show the cursor in 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the display rect if necessary. These bounds are in local coordinates. 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Subsequent text, cursor, or bounds changes may invalidate returned values. 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Rect& GetUpdatedCursorBounds(); 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Given an |index| in text(), return the next or previous grapheme boundary 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in logical order (that is, the nearest index for which 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |IsCursorablePosition(index)| returns true). The return value is in the 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // range 0 to text().length() inclusive (the input is clamped if it is out of 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that range). Always moves by at least one character index unless the 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // supplied index is already at the boundary of the string. 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t IndexOfAdjacentGrapheme(size_t index, 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LogicalCursorDirection direction); 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return a SelectionModel with the cursor at the current selection's start. 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The returned value represents a cursor/caret position without a selection. 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SelectionModel GetSelectionModelForSelectionStart(); 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets shadows to drawn with text. 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetTextShadows(const ShadowValues& shadows); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 392d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) typedef std::pair<Font, Range> FontSpan; 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For testing purposes, returns which fonts were chosen for which parts of 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the text by returning a vector of Font and Range pairs, where each range 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // specifies the character range for which the corresponding font has been 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // chosen. 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual std::vector<FontSpan> GetFontSpansForTesting() = 0; 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderText(); 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const BreakList<SkColor>& colors() const { return colors_; } 4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::vector<BreakList<bool> >& styles() const { return styles_; } 4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 405d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const std::vector<internal::Line>& lines() const { return lines_; } 406d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } 407d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 4080f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Returns the baseline of the current text. The return value depends on 4090f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // the text and its layout while the return value of GetBaseline() doesn't. 4100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // GetAlignmentOffset() takes into account the difference between them. 4110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // 4120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // We'd like a RenderText to show the text always on the same baseline 4130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // regardless of the text, so the text does not jump up or down depending 4140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // on the text. However, underlying layout engines return different baselines 4150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // depending on the text. In general, layout engines determine the minimum 4160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // bounding box for the text and return the baseline from the top of the 4170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // bounding box. So the baseline changes depending on font metrics used to 4180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // layout the text. 4190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // 4200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // For example, suppose there are FontA and FontB and the baseline of FontA 4210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // is smaller than the one of FontB. If the text is laid out only with FontA, 4220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // then the baseline of FontA may be returned. If the text includes some 4230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // characters which are laid out with FontB, then the baseline of FontB may 4240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // be returned. 4250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // 4260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // GetBaseline() returns the fixed baseline regardless of the text. 4270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // GetLayoutTextBaseline() returns the baseline determined by the underlying 4280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // layout engine, and it changes depending on the text. GetAlignmentOffset() 4290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // returns the difference between them. 4300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual int GetLayoutTextBaseline() = 0; 4310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Vector2d& GetUpdatedDisplayOffset(); 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_cached_bounds_and_offset_valid(bool valid) { 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cached_bounds_and_offset_valid_ = valid; 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the selection model that visually neighbors |position| by |break_type|. 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The returned value represents a cursor/caret position without a selection. 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SelectionModel GetAdjacentSelectionModel(const SelectionModel& current, 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BreakType break_type, 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VisualCursorDirection direction); 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the selection model visually left/right of |selection| by one grapheme. 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The returned value represents a cursor/caret position without a selection. 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SelectionModel AdjacentCharSelectionModel( 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SelectionModel& selection, 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VisualCursorDirection direction) = 0; 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the selection model visually left/right of |selection| by one word. 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The returned value represents a cursor/caret position without a selection. 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SelectionModel AdjacentWordSelectionModel( 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SelectionModel& selection, 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VisualCursorDirection direction) = 0; 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the SelectionModels corresponding to visual text ends. 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The returned value represents a cursor/caret position without a selection. 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SelectionModel EdgeSelectionModel(VisualCursorDirection direction); 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the selection model, the argument is assumed to be valid. 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetSelectionModel(const SelectionModel& model); 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 46390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Get the horizontal bounds (relative to the left of the text, not the view) 46490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // of the glyph starting at |index|. If the glyph is RTL then the returned 46590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Range will have is_reversed() true. (This does not return a Rect because a 46690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Rect can't have a negative width.) 467d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual Range GetGlyphBounds(size_t index) = 0; 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the visual bounds containing the logical substring within the |range|. 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |range| is empty, the result is empty. These bounds could be visually 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // discontinuous if the substring is split by a LTR/RTL level change. 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These bounds are in local coordinates, but may be outside the visible 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // region if the text is longer than the textfield. Subsequent text, cursor, 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // or bounds changes may invalidate returned values. 475d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual std::vector<Rect> GetSubstringBounds(const Range& range) = 0; 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Convert between indices into |text_| and indices into |obscured_text_|, 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // which differ when the text is obscured. Regardless of whether or not the 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // text is obscured, the character (code point) offsets always match. 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual size_t TextIndexToLayoutIndex(size_t index) const = 0; 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual size_t LayoutIndexToTextIndex(size_t index) const = 0; 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reset the layout to be invalid. 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ResetLayout() = 0; 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 486d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Ensure the text is laid out, lines are computed, and |lines_| is valid. 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void EnsureLayout() = 0; 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Draw the text. 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DrawVisualText(Canvas* canvas) = 0; 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 492eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns the text used for layout, which may be obscured or truncated. 493868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const base::string16& GetLayoutText() const; 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns layout text positions that are suitable for breaking lines. 496d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const BreakList<size_t>& GetLineBreaks(); 497d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 4982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Apply (and undo) temporary composition underlines and selection colors. 4992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void ApplyCompositionAndSelectionStyles(); 5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void UndoCompositionAndSelectionStyles(); 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 502d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns the line offset from the origin after applying the text alignment 503d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // and the display offset. 504d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Vector2d GetLineOffset(size_t line_number); 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 506d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Convert points from the text space to the view space and back. Handles the 507d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // display area, display offset, application LTR/RTL mode and multiline. 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Point ToTextPoint(const Point& point); 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Point ToViewPoint(const Point& point); 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 511d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Convert a text space x-coordinate range to corresponding rects in view 512d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // space. 513d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) std::vector<Rect> TextBoundsToViewBounds(const Range& x); 514d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 515d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns the line offset from the origin, accounting for text alignment 51690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // only. 517d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Vector2d GetAlignmentOffset(size_t line_number); 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Applies fade effects to |renderer|. 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Applies text shadows to |renderer|. 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ApplyTextShadows(internal::SkiaTextRenderer* renderer); 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A convenience function to check whether the glyph attached to the caret 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is within the given range. 527d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) static bool RangeContainsCaret(const Range& range, 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t caret_pos, 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LogicalCursorDirection caret_affinity); 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class RenderTextTest; 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); 5342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle); 5352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyColorAndStyle); 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText); 537868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText); 538eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText); 539eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText); 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); 54290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); 54390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); 544d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); 545d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); 546d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth); 547a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline); 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set the cursor to |position|, with the caret trailing the previous 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // grapheme, or if there is no previous grapheme, leading the cursor position. 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |select| is false, the selection start is moved to the same position. 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the |position| is not a cursorable position (not on grapheme boundary), 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it is a NO-OP. 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void MoveCursorTo(size_t position, bool select); 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 556eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Updates |layout_text_| if the text is obscured or truncated. 557eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void UpdateLayoutText(); 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Update the cached bounds and display offset to ensure that the current 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cursor is within the visible display area. 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateCachedBoundsAndOffset(); 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 563c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Draw the selection. 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void DrawSelection(Canvas* canvas); 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Logical UTF-16 string data to be drawn. 567868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::string16 text_; 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 56990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Horizontal alignment of the text with respect to |display_rect_|. The 57090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // default is to align left if the application UI is LTR and right if RTL. 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HorizontalAlignment horizontal_alignment_; 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. 5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DirectionalityMode directionality_mode_; 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The cached text direction, potentially computed from the text or UI locale. 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use GetTextDirection(), do not use this potentially invalid value directly! 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::i18n::TextDirection text_direction_; 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A list of fonts used to render |text_|. 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FontList font_list_; 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Logical selection range and visual cursor position. 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SelectionModel selection_model_; 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Rect cursor_bounds_; 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Specifies whether the cursor is enabled. If disabled, no space is reserved 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the cursor when positioning text. 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool cursor_enabled_; 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The cursor visibility and insert mode. 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool cursor_visible_; 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool insert_mode_; 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The color used for the cursor. 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor cursor_color_; 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The color used for drawing selected text. 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor selection_color_; 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The background color used for drawing the selection when focused. 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor selection_background_focused_color_; 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The focus state of the text. 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool focused_; 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Composition text range. 610d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Range composition_range_; 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Color and style breaks, used to color and stylize ranges of text. 6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // BreakList positions are stored with text indices, not layout indices. 6142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(msw): Expand to support cursor, selection, background, etc. colors. 6152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BreakList<SkColor> colors_; 6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<BreakList<bool> > styles_; 6172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Breaks saved without temporary composition and selection styling. 6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BreakList<SkColor> saved_colors_; 6202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BreakList<bool> saved_underlines_; 6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool composition_and_selection_styles_applied_; 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 623eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // A flag to obscure actual text with asterisks for password fields. 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool obscured_; 625868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // The index at which the char should be revealed in the obscured text. 626868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int obscured_reveal_index_; 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 628eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The maximum length of text to display, 0 forgoes a hard limit. 629eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch size_t truncate_length_; 630eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 631eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The obscured and/or truncated text that will be displayed. 632eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::string16 layout_text_; 633eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 634d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Whether the text should be broken into multiple lines. Uses the width of 635d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // |display_rect_| as the width cap. 636d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool multiline_; 637d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Fade text head and/or tail, if text doesn't fit into |display_rect_|. 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool fade_head_; 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool fade_tail_; 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Is the background transparent (either partially or fully)? 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool background_is_transparent_; 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The local display area for rendering the text. 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Rect display_rect_; 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Flag to work around a Skia bug with the PDF path (http://crbug.com/133548) 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that results in incorrect clipping when drawing to the document margins. 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This field allows disabling clipping to work around the issue. 6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(asvitkine): Remove this when the underlying Skia bug is fixed. 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool clip_to_display_rect_; 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The offset for the text to be drawn, relative to the display area. 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Vector2d display_offset_; 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6580f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // The baseline of the text. This is determined from the height of the 6590f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // display area and the cap height of the font list so the text is vertically 6600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // centered. 6610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int baseline_; 6620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The cached bounds and offset are invalidated by changes to the cursor, 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // selection, font, and other operations that adjust the visible text bounds. 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool cached_bounds_and_offset_valid_; 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Text shadows to be drawn. 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShadowValues text_shadows_; 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 670d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // A list of valid layout text line break positions. 671d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) BreakList<size_t> line_breaks_; 672d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 673d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Lines computed by EnsureLayout. These should be invalidated with 674d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // ResetLayout and on |display_rect_| changes. 675d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) std::vector<internal::Line> lines_; 676d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(RenderText); 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace gfx 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // UI_GFX_RENDER_TEXT_H_ 683