Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: ui/gfx/render_text_linux.h

Issue 7511029: Implement Pango RenderText for Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/render_text_linux.h
===================================================================
--- ui/gfx/render_text_linux.h (revision 96870)
+++ ui/gfx/render_text_linux.h (working copy)
@@ -8,6 +8,8 @@
#include "ui/gfx/render_text.h"
+#include <pango/pango.h>
oshima 2011/08/19 18:44:07 move this above chrome includes
xji 2011/08/20 00:53:05 Done.
+
namespace gfx {
// RenderTextLinux is the Linux implementation of RenderText using Pango.
@@ -16,7 +18,156 @@
RenderTextLinux();
virtual ~RenderTextLinux();
oshima 2011/08/19 18:44:07 // Overridden from RenderText
xji 2011/08/20 00:53:05 Done.
-private:
+ virtual void SetText(const string16& text) {
+ RenderText::SetText(text);
+ ResetLayout();
+ }
oshima 2011/08/19 18:44:07 please move all virtuals to .cc and OVERRIDE
xji 2011/08/20 00:53:05 Done.
+
+ virtual void SetDisplayRect(const Rect&r) {
+ RenderText::SetDisplayRect(r);
+ ResetLayout();
+ }
+
+ virtual void ApplyStyleRange(StyleRange style_range) {
+ RenderText::ApplyStyleRange(style_range);
+ ResetLayout();
+ }
+
+ virtual void ApplyDefaultStyle() {
+ RenderText::ApplyDefaultStyle();
+ ResetLayout();
+ }
+
+ virtual int GetStringWidth();
+
+ virtual void Draw(Canvas* canvas);
+
+ virtual SelectionModel FindCursorPosition(const Point& point);
+
+ virtual Rect GetCursorBounds(const SelectionModel& position,
+ bool insert_mode);
+
+ private:
+ enum CursorMovementDirection {
+ LEFT,
+ RIGHT
+ };
+
+ enum RelativeLogicalPosition {
+ PREVIOUS,
+ NEXT
+ };
+
+ virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current,
+ BreakType break_type);
+ virtual SelectionModel GetRightSelectionModel(const SelectionModel& current,
+ BreakType break_type);
+
+ virtual size_t GetIndexOfPreviousGrapheme(size_t position);
+
+ // Returns the SelectionModel for visual leftmost position in the line.
+ // The returned value represents a cursor/caret position without a selection.
+ SelectionModel GetSelectionModelForVisualLeftmost() const;
+
+ // Returns the run that contains the caret_pos in |current|. Based on moving
+ // direction, set whether the (caret_pos, caret_placement) is at the boundary
+ // of the run. If moving right, the trailing edge of LTR run or the leading
+ // edge of RTL run is at boundary of run. If moving left, the leading edge of
+ // LTR run or the trailing edge of RTL run is at the boundary of run.
+ //
+ // This does not work if |current| is the visually rightmost END position,
+ // which is SelectionModel(text().length(), text().length(), LEADING).
+ // This END position does not belong to any run.
+ GSList* GetRunContainsCaretPos(const SelectionModel& current,
+ CursorMovementDirection dir,
+ bool* at_boundary) const;
+
+ // Given |utf16_index_of_current_grapheme|, returns the UTF8 index of next
+ // graphame in the text if |pos| is NEXT, otherwise, returns the UTF8 index of
+ // previous grapheme.
+ size_t Utf8IndexOfAdjacentGrapheme(size_t utf16_index_of_current_grapheme,
+ RelativeLogicalPosition pos) const;
+
+ // Given |utf16_index_of_current_grapheme|, returns the UTF16 index of next
+ // graphame in the text if |pos| is NEXT, otherwise, returns the UTF16 index
+ // of previous grapheme.
+ size_t Utf16IndexOfAdjacentGrapheme(size_t utf16_index_of_current_grapheme,
+ RelativeLogicalPosition pos) const;
+
+ // Given a |run|, returns the SelectionModel that contains the logical first
+ // caret position inside (not at bounary of) the run.
+ // The returned value represents a cursor/caret position without a selection.
+ SelectionModel FirstSelectionModelInsideRun(const PangoItem* run) const;
+
+ // Given a |run|, returns the SelectionModel that contains the logical last
+ // caret position inside (not at bounary of) the run.
+ // The returned value represents a cursor/caret position without a selection.
+ SelectionModel LastSelectionModelInsideRun(const PangoItem* run) const;
+
+ // Given a |run|, returns the SelectionModel that contains the leftmost caret
+ // position inside (not at bounary of) the run.
+ // The returned value represents a cursor/caret position without a selection.
+ SelectionModel LeftmostSelectionModelInsideRun(const PangoItem* run) const;
+
+ // Given a |run|, returns the SelectionModel that contains the rightmost caret
+ // position inside (not at bounary of) the run.
+ // The returned value represents a cursor/caret position without a selection.
+ SelectionModel RightmostSelectionModelInsideRun(const PangoItem* run) const;
+
+ // when |sel| is the visually rightmost END position of line, set |adjacent|
+ // as the left or right (depends on |dir|) of |sel| and return true.
+ // Otherwise, return false.
+ // The value set in |adjacent| represnts a cursor/caret positin without a
+ // selection.
+ bool GetVisuallyAdjacentCursorPositionForEnd(const SelectionModel& current,
+ CursorMovementDirection dir,
+ SelectionModel* adjacent) const;
+
+ // Get the selection model that visually left of |current| by one grapheme.
+ // The returned value represents a cursor/caret position without a selection.
+ SelectionModel GetLeftSelectionModelByGrapheme(
+ const SelectionModel& current) const;
+
+ // Get the selection model that visually right of |current| by one grapheme.
+ // The returned value represents a cursor/caret position without a selection.
+ SelectionModel GetRightSelectionModelByGrapheme(
+ const SelectionModel& current) const;
+
+ // Creates, setup, and returns pango layout and pango layout line if layout_
+ // is NULL. Otherwise, return the cached layout_.
+ PangoLayout* EnsureLayout();
+
+ // Unref pango layout (layout_) and pango layout line (pango_line_). Set them
+ // to NULL. nds_.
+ void ResetLayout();
+
+ // Setup pango attribute: foreground, background, font, strike.
+ void SetupPangoAttributes(PangoLayout* layout);
+
+ // Append one pango attribute |pango_attr| into pango attribute list |attrs|.
+ void AppendPangoAttribute(size_t start,
+ size_t end,
+ PangoAttribute* pango_attr,
+ PangoAttrList* attrs);
+
+ // Returns |run|'s visually previous run.
+ GSList* GetPreviousRun(GSList* run) const;
+
+ // Returns last run in Layout_line_.
+ GSList* GetLastRun() const;
+
+ size_t Utf16IndexToUtf8Index(const string16& text, size_t index) const;
+ size_t Utf8IndexToUtf16Index(const string16& text, size_t index) const;
+
+ // Adjust |bounds| for non insert mode.
+ void AdjustBoundsForNonInsertMode(const SelectionModel& selection,
+ const PangoRectangle& pos,
+ Rect* bounds) const;
+
+ PangoLayout* layout_;
+
+ PangoLayoutLine* layout_line_;
+
DISALLOW_COPY_AND_ASSIGN(RenderTextLinux);
};

Powered by Google App Engine
This is Rietveld 408576698