Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_GFX_RENDER_TEXT_LINUX_H_ | 5 #ifndef UI_GFX_RENDER_TEXT_LINUX_H_ |
| 6 #define UI_GFX_RENDER_TEXT_LINUX_H_ | 6 #define UI_GFX_RENDER_TEXT_LINUX_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <pango/pango.h> | |
| 10 | |
| 9 #include "ui/gfx/render_text.h" | 11 #include "ui/gfx/render_text.h" |
| 10 | 12 |
| 11 namespace gfx { | 13 namespace gfx { |
| 12 | 14 |
| 13 // RenderTextLinux is the Linux implementation of RenderText using Pango. | 15 // RenderTextLinux is the Linux implementation of RenderText using Pango. |
| 14 class RenderTextLinux : public RenderText { | 16 class RenderTextLinux : public RenderText { |
| 15 public: | 17 public: |
| 16 RenderTextLinux(); | 18 RenderTextLinux(); |
| 17 virtual ~RenderTextLinux(); | 19 virtual ~RenderTextLinux(); |
| 18 | 20 |
| 19 private: | 21 // Overridden from RenderText: |
| 22 virtual void SetText(const string16& text) OVERRIDE; | |
| 23 virtual void SetDisplayRect(const Rect&r) OVERRIDE; | |
| 24 virtual void SetCompositionRange(const ui::Range& composition_range) OVERRIDE; | |
| 25 virtual void ApplyStyleRange(StyleRange style_range) OVERRIDE; | |
| 26 virtual void ApplyDefaultStyle() OVERRIDE; | |
| 27 virtual base::i18n::TextDirection GetTextDirection() OVERRIDE; | |
| 28 virtual int GetStringWidth() OVERRIDE; | |
| 29 virtual void Draw(Canvas* canvas) OVERRIDE; | |
| 30 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; | |
| 31 virtual Rect GetCursorBounds(const SelectionModel& position, | |
| 32 bool insert_mode) OVERRIDE; | |
| 33 | |
| 34 protected: | |
| 35 // Overridden from RenderText: | |
| 36 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, | |
| 37 BreakType break_type) OVERRIDE; | |
| 38 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, | |
| 39 BreakType break_type) OVERRIDE; | |
| 40 virtual SelectionModel LeftEndSelectionModel() OVERRIDE; | |
| 41 virtual SelectionModel RightEndSelectionModel() OVERRIDE; | |
| 42 virtual size_t GetIndexOfPreviousGrapheme(size_t position) OVERRIDE; | |
| 43 | |
| 44 private: | |
| 45 enum RelativeLogicalPosition { | |
| 46 PREVIOUS, | |
| 47 NEXT | |
| 48 }; | |
| 49 | |
| 50 // Get the logical start index of the next grapheme after |position|. | |
| 51 size_t GetIndexOfNextGrapheme(size_t position); | |
| 52 | |
| 53 // Returns the run that contains |position|. Return NULL if not found. | |
| 54 GSList* GetRunContainingPosition(size_t position) const; | |
|
behdad_google
2011/09/06 16:05:03
Return PangoLayoutRun* instead?
xji
2011/09/06 19:54:13
The comments about the 3 functions using PangoLayo
| |
| 55 | |
| 56 // Given |utf8_index_of_current_grapheme|, returns the UTF8 or UTF16 index of | |
| 57 // next grapheme in the text if |pos| is NEXT, otherwise, returns the index of | |
| 58 // previous grapheme. Returns 0 if there is no previous grapheme, and returns | |
| 59 // the |text_| length if there is no next grapheme. | |
| 60 size_t Utf8IndexOfAdjacentGrapheme(size_t utf8_index_of_current_grapheme, | |
| 61 RelativeLogicalPosition pos) const; | |
| 62 size_t Utf16IndexOfAdjacentGrapheme(size_t utf8_index_of_current_grapheme, | |
| 63 RelativeLogicalPosition pos) const; | |
| 64 | |
| 65 // Given a |run|, returns the SelectionModel that contains the logical first | |
| 66 // or last caret position inside (not at a boundary of) the run. | |
| 67 // The returned value represents a cursor/caret position without a selection. | |
| 68 SelectionModel FirstSelectionModelInsideRun(const PangoItem* run) const; | |
| 69 SelectionModel LastSelectionModelInsideRun(const PangoItem* run) const; | |
| 70 | |
| 71 // Get the selection model visually left or right of |current| by one | |
| 72 // grapheme. | |
| 73 // The returned value represents a cursor/caret position without a selection. | |
| 74 SelectionModel LeftSelectionModel(const SelectionModel& current); | |
| 75 SelectionModel RightSelectionModel(const SelectionModel& current); | |
| 76 | |
| 77 // If |layout_| is NULL, create and setup |layout_|, retain and ref | |
| 78 // |layout_line_|. Return |layout_|. | |
| 79 PangoLayout* EnsureLayout(); | |
| 80 | |
| 81 // Unref |layout_| and |pango_line_|. Set them to NULL. | |
| 82 void ResetLayout(); | |
| 83 | |
| 84 // Setup pango attribute: foreground, background, font, strike. | |
| 85 void SetupPangoAttributes(PangoLayout* layout); | |
| 86 | |
| 87 // Append one pango attribute |pango_attr| into pango attribute list |attrs|. | |
| 88 void AppendPangoAttribute(size_t start, | |
| 89 size_t end, | |
| 90 PangoAttribute* pango_attr, | |
| 91 PangoAttrList* attrs); | |
| 92 | |
| 93 // Returns |run|'s visually previous run. | |
| 94 // The complexity is O(n) since it is a single-linked list. | |
| 95 GSList* GetPreviousRun(GSList* run) const; | |
|
behdad_google
2011/09/06 16:05:03
So, you search within the current line, right? I
xji
2011/09/06 19:54:13
input can not be PangoLayoutLine since it does not
| |
| 96 | |
| 97 // Returns the last run in |layout_line_|. | |
| 98 // The complexity is O(n) since it is a single-linked list. | |
| 99 GSList* GetLastRun() const; | |
|
behdad_google
2011/09/06 16:05:03
Same here. And in any other place a single run is
xji
2011/09/06 19:54:13
This could be changed to PangoLayoutLine*.
I have
| |
| 100 | |
| 101 size_t Utf16IndexToUtf8Index(size_t index) const; | |
| 102 size_t Utf8IndexToUtf16Index(size_t index) const; | |
| 103 | |
| 104 PangoLayout* layout_; | |
| 105 | |
| 106 PangoLayoutLine* layout_line_; | |
|
behdad_google
2011/09/06 16:05:03
Something like current_line_ may be more appropria
xji
2011/09/06 19:54:13
Done.
It is single line mode.
Does pango_layout_se
| |
| 107 | |
| 20 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); | 108 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); |
| 21 }; | 109 }; |
| 22 | 110 |
| 23 } // namespace gfx; | 111 } // namespace gfx; |
| 24 | 112 |
| 25 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ | 113 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ |
| OLD | NEW |