| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef UI_GFX_RENDER_TEXT_PANGO_H_ | |
| 6 #define UI_GFX_RENDER_TEXT_PANGO_H_ | |
| 7 | |
| 8 #include <pango/pango.h> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "ui/gfx/render_text.h" | |
| 12 | |
| 13 namespace gfx { | |
| 14 | |
| 15 // RenderTextPango is the Linux implementation of RenderText using Pango. | |
| 16 class RenderTextPango : public RenderText { | |
| 17 public: | |
| 18 RenderTextPango(); | |
| 19 ~RenderTextPango() override; | |
| 20 | |
| 21 // Overridden from RenderText: | |
| 22 scoped_ptr<RenderText> CreateInstanceOfSameType() const override; | |
| 23 Size GetStringSize() override; | |
| 24 SelectionModel FindCursorPosition(const Point& point) override; | |
| 25 std::vector<FontSpan> GetFontSpansForTesting() override; | |
| 26 | |
| 27 protected: | |
| 28 // Overridden from RenderText: | |
| 29 int GetLayoutTextBaseline() override; | |
| 30 SelectionModel AdjacentCharSelectionModel( | |
| 31 const SelectionModel& selection, | |
| 32 VisualCursorDirection direction) override; | |
| 33 SelectionModel AdjacentWordSelectionModel( | |
| 34 const SelectionModel& selection, | |
| 35 VisualCursorDirection direction) override; | |
| 36 Range GetGlyphBounds(size_t index) override; | |
| 37 std::vector<Rect> GetSubstringBounds(const Range& range) override; | |
| 38 size_t TextIndexToLayoutIndex(size_t index) const override; | |
| 39 size_t LayoutIndexToTextIndex(size_t index) const override; | |
| 40 bool IsValidCursorIndex(size_t index) override; | |
| 41 void ResetLayout() override; | |
| 42 void EnsureLayout() override; | |
| 43 void DrawVisualText(Canvas* canvas) override; | |
| 44 | |
| 45 private: | |
| 46 friend class RenderTextTest; | |
| 47 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, PangoAttributes); | |
| 48 | |
| 49 // Returns the run that contains the character attached to the caret in the | |
| 50 // given selection model. Return NULL if not found. | |
| 51 GSList* GetRunContainingCaret(const SelectionModel& caret) const; | |
| 52 | |
| 53 // Given a |run|, returns the SelectionModel that contains the logical first | |
| 54 // or last caret position inside (not at a boundary of) the run. | |
| 55 // The returned value represents a cursor/caret position without a selection. | |
| 56 SelectionModel FirstSelectionModelInsideRun(const PangoItem* run); | |
| 57 SelectionModel LastSelectionModelInsideRun(const PangoItem* run); | |
| 58 | |
| 59 // Setup pango attribute: foreground, background, font, strike. | |
| 60 void SetupPangoAttributes(PangoLayout* layout); | |
| 61 | |
| 62 // Append one pango attribute |pango_attr| into pango attribute list |attrs|. | |
| 63 void AppendPangoAttribute(size_t start, | |
| 64 size_t end, | |
| 65 PangoAttribute* pango_attr, | |
| 66 PangoAttrList* attrs); | |
| 67 | |
| 68 // Get the text index corresponding to the |run|'s |glyph_index|. | |
| 69 size_t GetGlyphTextIndex(PangoLayoutRun* run, int glyph_index) const; | |
| 70 | |
| 71 // Pango Layout. | |
| 72 PangoLayout* layout_; | |
| 73 // A single line layout resulting from laying out via |layout_|. | |
| 74 PangoLayoutLine* current_line_; | |
| 75 | |
| 76 // Information about character attributes. | |
| 77 PangoLogAttr* log_attrs_; | |
| 78 // Number of attributes in |log_attrs_|. | |
| 79 int num_log_attrs_; | |
| 80 | |
| 81 // The text in the |layout_|. | |
| 82 const char* layout_text_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(RenderTextPango); | |
| 85 }; | |
| 86 | |
| 87 } // namespace gfx | |
| 88 | |
| 89 #endif // UI_GFX_RENDER_TEXT_PANGO_H_ | |
| OLD | NEW |