Chromium Code Reviews| 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> |
| + |
| namespace gfx { |
| // RenderTextLinux is the Linux implementation of RenderText using Pango. |
| @@ -16,7 +18,156 @@ |
| RenderTextLinux(); |
| virtual ~RenderTextLinux(); |
| -private: |
| + virtual void SetText(const string16& text) OVERRIDE { |
| + RenderText::SetText(text); |
|
msw
2011/08/19 23:16:59
All of these definitions are simple, but non-trivi
xji
2011/08/22 23:57:28
Done.
|
| + ResetLayout(); |
| + } |
| + |
| + virtual void SetDisplayRect(const Rect&r) OVERRIDE { |
| + RenderText::SetDisplayRect(r); |
| + ResetLayout(); |
| + } |
| + |
| + virtual void ApplyStyleRange(StyleRange style_range) OVERRIDE { |
| + RenderText::ApplyStyleRange(style_range); |
| + ResetLayout(); |
| + } |
| + |
| + virtual void ApplyDefaultStyle() OVERRIDE { |
| + RenderText::ApplyDefaultStyle(); |
| + ResetLayout(); |
| + } |
| + |
| + virtual int GetStringWidth() OVERRIDE; |
| + |
| + virtual void Draw(Canvas* canvas) OVERRIDE; |
| + |
| + virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; |
| + |
| + virtual Rect GetCursorBounds(const SelectionModel& position, |
| + bool insert_mode) OVERRIDE; |
| + |
| + private: |
| + enum CursorMovementDirection { |
| + LEFT, |
| + RIGHT |
| + }; |
| + |
| + enum RelativeLogicalPosition { |
| + PREVIOUS, |
| + NEXT |
| + }; |
| + |
| + virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, |
|
msw
2011/08/19 23:16:59
Also add "// Overridden from RenderText:" here and
xji
2011/08/22 23:57:28
Done.
|
| + BreakType break_type) OVERRIDE; |
| + virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, |
| + BreakType break_type) OVERRIDE; |
| + |
| + virtual size_t GetIndexOfPreviousGrapheme(size_t position) OVERRIDE; |
| + |
| + // Returns the SelectionModel for visual leftmost position in the line. |
|
msw
2011/08/19 23:16:59
There are going to be lots of opportunities for us
xji
2011/08/22 23:57:28
Changed to the same names. But I can not declare t
msw
2011/08/23 08:01:01
Sounds good.
|
| + // 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. |
|
msw
2011/08/19 23:16:59
Interesting, instead of using a caret at (text().l
xji
2011/08/22 23:57:28
I think you are right. I changed it to your way.
msw
2011/08/23 08:01:01
:)
|
| + GSList* GetRunContainsCaretPos(const SelectionModel& current, |
|
msw
2011/08/19 23:16:59
Hopefully we'll be able to merge the signatures an
xji
2011/08/22 23:57:28
I changed the implementation as yours. But I am re
msw
2011/08/23 08:01:01
:) I'm so sorry about the GList, it's a tragedy.
|
| + 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. |
|
msw
2011/08/19 23:16:59
"not at *a* boundary" here and elsewhere
xji
2011/08/22 23:57:28
Done.
|
| + // 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| |
|
msw
2011/08/19 23:16:59
Wouldn't it be left-most for RTL text/UI?
xji
2011/08/22 23:57:28
this handles the right (visual) end (NOT the logic
|
| + // 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 |
|
msw
2011/08/19 23:16:59
positi*o*n
xji
2011/08/22 23:57:28
Done.
|
| + // 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_ |
|
msw
2011/08/19 23:16:59
"Create*, setup, and return*" to match the tense o
xji
2011/08/22 23:57:28
Done.
|
| + // is NULL. Otherwise, return the cached layout_. |
| + PangoLayout* EnsureLayout(); |
| + |
| + // Unref pango layout (layout_) and pango layout line (pango_line_). Set them |
|
msw
2011/08/19 23:16:59
Use vertical bars to indicate members, and you can
xji
2011/08/22 23:57:28
Done.
I thought we only use vertical bar for funct
msw
2011/08/23 08:01:01
Hmm, you might be right; I'm still learning chromi
xji
2011/08/23 23:52:52
I checked with my co-worker, and seems there is no
|
| + // to NULL. nds_. |
|
msw
2011/08/19 23:16:59
what is " nds_."?
xji
2011/08/22 23:57:28
must have done extra editing accidently. removed.
|
| + 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_. |
|
msw
2011/08/19 23:16:59
"*the* last run" and use bars and un-capitalize "|
xji
2011/08/22 23:57:28
Done.
|
| + GSList* GetLastRun() const; |
| + |
| + size_t Utf16IndexToUtf8Index(const string16& text, size_t index) const; |
|
msw
2011/08/19 23:16:59
These two functions don't use any class members, a
xji
2011/08/22 23:57:28
Done.
|
| + 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); |
| }; |