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 size_t GetIndexOfPreviousGrapheme(size_t position) OVERRIDE; |
| 41 |
| 42 private: |
| 43 enum RelativeLogicalPosition { |
| 44 PREVIOUS, |
| 45 NEXT |
| 46 }; |
| 47 |
| 48 // Get the SelectionModels corresponding to the left or right text ends. |
| 49 // The returned value represents a cursor/caret position without a selection. |
| 50 SelectionModel LeftEndSelectionModel(); |
| 51 SelectionModel RightEndSelectionModel(); |
| 52 |
| 53 // Returns the run that contains |position|. Return NULL if not found. |
| 54 GSList* GetRunContainingPosition(size_t position) const; |
| 55 |
| 56 // Given |utf16_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 utf16_index_of_current_grapheme, |
| 61 RelativeLogicalPosition pos) const; |
| 62 size_t Utf16IndexOfAdjacentGrapheme(size_t utf16_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 that 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 // Create, setup, and return pango layout and pango layout line if |layout_| |
| 78 // is NULL. Otherwise, return the cached |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 GSList* GetPreviousRun(GSList* run) const; |
| 95 |
| 96 // Returns the last run in |layout_line_|. |
| 97 GSList* GetLastRun() const; |
| 98 |
| 99 size_t Utf16IndexToUtf8Index(size_t index) const; |
| 100 size_t Utf8IndexToUtf16Index(size_t index) const; |
| 101 |
| 102 PangoLayout* layout_; |
| 103 |
| 104 PangoLayoutLine* layout_line_; |
| 105 |
20 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); | 106 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); |
21 }; | 107 }; |
22 | 108 |
23 } // namespace gfx; | 109 } // namespace gfx; |
24 | 110 |
25 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ | 111 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ |
OLD | NEW |