| Index: ui/gfx/render_text.h
|
| diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..bdc88e4a24d1edd1540bb90f214c3177c66c1df8
|
| --- /dev/null
|
| +++ b/ui/gfx/render_text.h
|
| @@ -0,0 +1,207 @@
|
| +// Copyright (c) 2011 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.
|
| +
|
| +#ifndef UI_GFX_RENDER_TEXT_H_
|
| +#define UI_GFX_RENDER_TEXT_H_
|
| +#pragma once
|
| +
|
| +#include <string>
|
| +#include <vector>
|
| +
|
| +#include "base/gtest_prod_util.h"
|
| +#include "base/i18n/rtl.h"
|
| +#include "base/string16.h"
|
| +#include "third_party/skia/include/core/SkColor.h"
|
| +#include "ui/base/range/range.h"
|
| +#include "ui/gfx/font.h"
|
| +#include "ui/gfx/rect.h"
|
| +#include "ui/gfx/point.h"
|
| +
|
| +namespace {
|
| +class RenderTextTest;
|
| +}
|
| +
|
| +namespace gfx {
|
| +
|
| +class Canvas;
|
| +
|
| +struct StyleRange {
|
| +
|
| + StyleRange::StyleRange()
|
| + : font(),
|
| + foreground(SK_ColorBLACK),
|
| + strike(false),
|
| + underline(false),
|
| + range() {
|
| + }
|
| +
|
| + Font font;
|
| + SkColor foreground;
|
| + // TODO(msw): SkColor background; ???
|
| + bool strike;
|
| + bool underline;
|
| + ui::Range range;
|
| +};
|
| +
|
| +typedef std::vector<StyleRange> StyleRanges;
|
| +
|
| +// TODO(msw): Implement RenderText[Win|Linux] for Uniscribe/Pango BiDi...
|
| +
|
| +// RenderText represents an abstract model of styled text and its corresponding
|
| +// visual layout. Support is built in for a cursor, a selection, simple styling,
|
| +// complex scripts, and bi-directional text. Implementations provide mechanisms
|
| +// for rendering and translation between logical and visual data.
|
| +class RenderText {
|
| + public:
|
| + virtual ~RenderText();
|
| +
|
| + // Creates a platform-specific RenderText instance.
|
| + static RenderText* CreateRenderText();
|
| +
|
| + const string16& text() const { return text_; }
|
| + virtual void SetText(const string16& text);
|
| +
|
| + void set_cursor_visible(bool visible) { is_cursor_visible_ = visible; }
|
| +
|
| + bool get_insert_mode() const { return insert_mode_; }
|
| + void set_insert_mode(bool insert_mode) { insert_mode_ = insert_mode; }
|
| +
|
| + void set_focused(bool focused) { is_focused_ = focused; }
|
| +
|
| + // TODO(msw): Make protected, fix RenderTextTest friending.
|
| + const StyleRanges& get_style_ranges() const { return style_ranges_; }
|
| +
|
| + void set_default_style(StyleRange style) { default_style_ = style; }
|
| +
|
| + const gfx::Rect& get_display_rect() const { return display_rect_; }
|
| + void set_display_rect(const gfx::Rect& r) { display_rect_ = r; }
|
| +
|
| + int get_flags() const { return flags_; }
|
| + void set_flags(int flags) { flags_ = flags; }
|
| +
|
| + size_t GetCursor() const;
|
| + void SetCursor(const size_t position);
|
| +
|
| + // Moves the cursor left or right. Cursor movement is visual, meaning that
|
| + // left and right are relative to screen, not the directionality of the text.
|
| + // If |select| is false, the selection range is emptied at the new position.
|
| + // If |move_by_word| is true, the cursor moves to the nearest word boundary.
|
| + void MoveCursorLeft(bool select, bool move_by_word);
|
| + void MoveCursorRight(bool select, bool move_by_word);
|
| +
|
| + // Moves the cursor to left or right end of the text as shown on screen.
|
| + // If |select| is false, the selection range is emptied at the new position.
|
| + void MoveCursorToLeftEnd(bool select);
|
| + void MoveCursorToRightEnd(bool select);
|
| +
|
| + // Moves the cursor to the specified logical |position|.
|
| + // If |select| is false, the selection range is emptied at the new position.
|
| + // Returns true if the cursor position or selection range changed.
|
| + bool MoveCursorTo(size_t position, bool select);
|
| +
|
| + const ui::Range& GetSelection() const;
|
| + void SetSelection(const ui::Range& range);
|
| +
|
| + // Selects no text, all text, or the word at the current cursor position.
|
| + void ClearSelection();
|
| + void SelectAll();
|
| + void SelectWord();
|
| +
|
| + const ui::Range& GetComposition() const;
|
| + void SetComposition(const ui::Range& composition_range);
|
| +
|
| + // Apply |style_range| to the internal style model.
|
| + void ApplyStyleRange(StyleRange style_range);
|
| + // Apply |default_style_| over the entire text range.
|
| + void ApplyDefaultStyle();
|
| +
|
| + base::i18n::TextDirection GetTextDirection() const;
|
| +
|
| + // Get the width of the entire string.
|
| + int GetStringWidth() const;
|
| +
|
| + virtual void Draw(gfx::Canvas* canvas) const;
|
| +
|
| + // Get the logical cursor position from a visual point in local coordinates.
|
| + virtual size_t FindCursorPosition(const gfx::Point& point) const;
|
| +
|
| + // Get the visual bounds containing the logical substring within |range|.
|
| + // These bounds could be visually discontiguous if the logical selection range
|
| + // is split by a single LTR/RTL level change.
|
| + virtual std::vector<gfx::Rect> GetSubstringBounds(
|
| + const ui::Range& range) const;
|
| +
|
| + // Get the visual bounds describing the cursor at |position|. These bounds
|
| + // typically represent a vertical line, but if |insert_mode| is true they
|
| + // contain the bounds of the associated glyph.
|
| + virtual gfx::Rect GetCursorBounds(size_t position, bool insert_mode) const;
|
| +
|
| + protected:
|
| + RenderText();
|
| +
|
| + // Get the cursor position that visually neighbors |position|.
|
| + // If |move_by_word| is true, return the neighboring word delimiter position.
|
| + virtual size_t GetLeftCursorPosition(size_t position,
|
| + bool move_by_word) const;
|
| + virtual size_t GetRightCursorPosition(size_t position,
|
| + bool move_by_word) const;
|
| +
|
| + private:
|
| + friend class ::RenderTextTest;
|
| +
|
| + FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle);
|
| + FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle);
|
| + FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange);
|
| + FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust);
|
| +
|
| + // Clear out |style_ranges_|.
|
| + void ClearStyleRanges();
|
| +
|
| + // TODO(msw): Revise SelectWord to eliminate this?
|
| + bool IsPositionAtWordSelectionBoundary(size_t pos);
|
| +
|
| + // Logical UTF-16 string data to be drawn.
|
| + string16 text_;
|
| +
|
| + // Logical selection range; the range end is also the logical cursor position.
|
| + ui::Range selection_range_;
|
| +
|
| + // The cursor visibility and insert mode.
|
| + bool is_cursor_visible_;
|
| + bool insert_mode_;
|
| +
|
| + // The focus state of the text.
|
| + bool is_focused_;
|
| +
|
| + // Composition text range.
|
| + ui::Range composition_range_;
|
| +
|
| + // List of style ranges. Elements in the list never overlap each other.
|
| + StyleRanges style_ranges_;
|
| + // The default text style.
|
| + StyleRange default_style_;
|
| + // TODO(msw): Use StyleRange selection_style_ and composition_style_?
|
| +
|
| + // The local display area for rendering the text.
|
| + gfx::Rect display_rect_;
|
| + // The offset for the text to be drawn, relative to the display area.
|
| + gfx::Point display_offset_;
|
| +
|
| + // TODO(msw): Cache these bounds?
|
| + // The visual cursor bounds. These bounds typically represent a vertical line,
|
| + // but in insert mode they contain the bounds of the associated glyph.
|
| + //gfx::Rect cursor_bounds_;
|
| + // The visual selection bounds. These bounds could be visually discontiguous
|
| + // if the logical selection range is split by a single LTR/RTL level change.
|
| + //std::vector<gfx::Rect> selection_bounds_;
|
| +
|
| + // Rendering flags, defined in Canvas.
|
| + int flags_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(RenderText);
|
| +};
|
| +
|
| +} // namespace gfx;
|
| +
|
| +#endif // UI_GFX_RENDER_TEXT_H_
|
|
|