Add exclamation and question mark to the accent keys.
[chromium-blink-merge.git] / ui / gfx / render_text_win.h
blob704829d65c7e91735930e9e4914e665976e2c162
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.
5 #ifndef UI_GFX_RENDER_TEXT_WIN_H_
6 #define UI_GFX_RENDER_TEXT_WIN_H_
8 #include <usp10.h>
10 #include <map>
11 #include <string>
12 #include <vector>
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "ui/gfx/render_text.h"
18 namespace gfx {
20 namespace internal {
22 struct TextRun {
23 TextRun();
24 ~TextRun();
26 ui::Range range;
27 Font font;
28 // A gfx::Font::FontStyle flag to specify bold and italic styles.
29 // Supersedes |font.GetFontStyle()|. Stored separately to avoid calling
30 // |font.DeriveFont()|, which is expensive on Windows.
31 int font_style;
33 // TODO(msw): Disambiguate color/style from TextRuns for proper glyph shaping.
34 // See an example: http://www.catch22.net/tuts/uniscribe-mysteries
35 SkColor foreground;
36 bool strike;
37 bool diagonal_strike;
38 bool underline;
40 int width;
41 // The cumulative widths of preceding runs.
42 int preceding_run_widths;
44 SCRIPT_ANALYSIS script_analysis;
46 scoped_ptr<WORD[]> glyphs;
47 scoped_ptr<WORD[]> logical_clusters;
48 scoped_ptr<SCRIPT_VISATTR[]> visible_attributes;
49 int glyph_count;
51 scoped_ptr<int[]> advance_widths;
52 scoped_ptr<GOFFSET[]> offsets;
53 ABC abc_widths;
54 SCRIPT_CACHE script_cache;
56 private:
57 DISALLOW_COPY_AND_ASSIGN(TextRun);
60 } // namespace internal
62 // RenderTextWin is the Windows implementation of RenderText using Uniscribe.
63 class RenderTextWin : public RenderText {
64 public:
65 RenderTextWin();
66 virtual ~RenderTextWin();
68 // Overridden from RenderText:
69 virtual Size GetStringSize() OVERRIDE;
70 virtual int GetBaseline() OVERRIDE;
71 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE;
72 virtual std::vector<FontSpan> GetFontSpansForTesting() OVERRIDE;
74 protected:
75 // Overridden from RenderText:
76 virtual SelectionModel AdjacentCharSelectionModel(
77 const SelectionModel& selection,
78 VisualCursorDirection direction) OVERRIDE;
79 virtual SelectionModel AdjacentWordSelectionModel(
80 const SelectionModel& selection,
81 VisualCursorDirection direction) OVERRIDE;
82 virtual void SetSelectionModel(const SelectionModel& model) OVERRIDE;
83 virtual ui::Range GetGlyphBounds(size_t index) OVERRIDE;
84 virtual std::vector<Rect> GetSubstringBounds(const ui::Range& range) OVERRIDE;
85 virtual size_t TextIndexToLayoutIndex(size_t index) const OVERRIDE;
86 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE;
87 virtual bool IsCursorablePosition(size_t position) OVERRIDE;
88 virtual void ResetLayout() OVERRIDE;
89 virtual void EnsureLayout() OVERRIDE;
90 virtual void DrawVisualText(Canvas* canvas) OVERRIDE;
92 private:
93 void ItemizeLogicalText();
94 void LayoutVisualText();
95 void LayoutTextRun(internal::TextRun* run);
97 // Helper function that calls |ScriptShape()| on the run, which has logic to
98 // handle E_OUTOFMEMORY return codes.
99 HRESULT ShapeTextRunWithFont(internal::TextRun* run, const Font& font);
101 // Returns the number of characters in |run| that have missing glyphs.
102 int CountCharsWithMissingGlyphs(internal::TextRun* run) const;
104 // Return the run index that contains the argument; or the length of the
105 // |runs_| vector if argument exceeds the text length or width.
106 size_t GetRunContainingCaret(const SelectionModel& caret) const;
107 size_t GetRunContainingXCoord(int x) const;
109 // Given a |run|, returns the SelectionModel that contains the logical first
110 // or last caret position inside (not at a boundary of) the run.
111 // The returned value represents a cursor/caret position without a selection.
112 SelectionModel FirstSelectionModelInsideRun(const internal::TextRun* run);
113 SelectionModel LastSelectionModelInsideRun(const internal::TextRun* run);
115 // Cached HDC for performing Uniscribe API calls.
116 static HDC cached_hdc_;
118 // Cached map from font name to the last successful substitute font used.
119 // TODO(asvitkine): Move the caching logic to font_fallback_win.cc.
120 static std::map<std::string, Font> successful_substitute_fonts_;
122 SCRIPT_CONTROL script_control_;
123 SCRIPT_STATE script_state_;
125 ScopedVector<internal::TextRun> runs_;
126 Size string_size_;
128 // A common vertical baseline for all the text runs. This is computed as the
129 // largest baseline over all the runs' fonts.
130 int common_baseline_;
132 scoped_ptr<int[]> visual_to_logical_;
133 scoped_ptr<int[]> logical_to_visual_;
135 bool needs_layout_;
137 DISALLOW_COPY_AND_ASSIGN(RenderTextWin);
140 } // namespace gfx
142 #endif // UI_GFX_RENDER_TEXT_WIN_H_