Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: ui/views/examples/text_example.cc

Issue 2654853002: Remove gfx::Canvas::DrawStringRectWithHalo. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« ui/gfx/render_text.cc ('K') | « ui/views/examples/text_example.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "ui/views/examples/text_example.h" 5 #include "ui/views/examples/text_example.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/font_list.h" 10 #include "ui/gfx/font_list.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 60
61 } // namespace 61 } // namespace
62 62
63 // TextExample's content view, which draws stylized string. 63 // TextExample's content view, which draws stylized string.
64 class TextExample::TextExampleView : public View { 64 class TextExample::TextExampleView : public View {
65 public: 65 public:
66 TextExampleView() 66 TextExampleView()
67 : text_(base::ASCIIToUTF16(kShortText)), 67 : text_(base::ASCIIToUTF16(kShortText)),
68 flags_(0), 68 flags_(0),
69 halo_(false),
70 elide_(gfx::NO_ELIDE) { 69 elide_(gfx::NO_ELIDE) {
71 } 70 }
72 71
73 void OnPaint(gfx::Canvas* canvas) override { 72 void OnPaint(gfx::Canvas* canvas) override {
74 View::OnPaint(canvas); 73 View::OnPaint(canvas);
75 const gfx::Rect bounds = GetContentsBounds(); 74 const gfx::Rect bounds = GetContentsBounds();
76 const SkColor color = SK_ColorDKGRAY; 75 const SkColor color = SK_ColorDKGRAY;
77 if (elide_ == gfx::FADE_TAIL) { 76 if (elide_ == gfx::FADE_TAIL) {
78 canvas->DrawFadedString(text_, font_list_, color, bounds, flags_); 77 canvas->DrawFadedString(text_, font_list_, color, bounds, flags_);
79 } else if (halo_) {
80 canvas->DrawStringRectWithHalo(text_, font_list_, color, SK_ColorYELLOW,
81 bounds, flags_);
82 } else { 78 } else {
83 canvas->DrawStringRectWithFlags(text_, font_list_, color, bounds, flags_); 79 canvas->DrawStringRectWithFlags(text_, font_list_, color, bounds, flags_);
84 } 80 }
85 } 81 }
86 82
87 int flags() const { return flags_; } 83 int flags() const { return flags_; }
88 void set_flags(int flags) { flags_ = flags; } 84 void set_flags(int flags) { flags_ = flags; }
89 void set_text(const base::string16& text) { text_ = text; } 85 void set_text(const base::string16& text) { text_ = text; }
90 void set_halo(bool halo) { halo_ = halo; }
91 void set_elide(gfx::ElideBehavior elide) { elide_ = elide; } 86 void set_elide(gfx::ElideBehavior elide) { elide_ = elide; }
92 87
93 int GetStyle() const { return font_list_.GetFontStyle(); } 88 int GetStyle() const { return font_list_.GetFontStyle(); }
94 void SetStyle(int style) { font_list_ = font_list_.DeriveWithStyle(style); } 89 void SetStyle(int style) { font_list_ = font_list_.DeriveWithStyle(style); }
95 90
96 gfx::Font::Weight GetWeight() const { return font_list_.GetFontWeight(); } 91 gfx::Font::Weight GetWeight() const { return font_list_.GetFontWeight(); }
97 void SetWeight(gfx::Font::Weight weight) { 92 void SetWeight(gfx::Font::Weight weight) {
98 font_list_ = font_list_.DeriveWithWeight(weight); 93 font_list_ = font_list_.DeriveWithWeight(weight);
99 } 94 }
100 95
101 private: 96 private:
102 // The font used for drawing the text. 97 // The font used for drawing the text.
103 gfx::FontList font_list_; 98 gfx::FontList font_list_;
104 99
105 // The text to draw. 100 // The text to draw.
106 base::string16 text_; 101 base::string16 text_;
107 102
108 // Text flags for passing to |DrawStringRect()|. 103 // Text flags for passing to |DrawStringRect()|.
109 int flags_; 104 int flags_;
110 105
111 // A flag to draw a halo around the text.
112 bool halo_;
113
114 // The eliding, fading, or truncating behavior. 106 // The eliding, fading, or truncating behavior.
115 gfx::ElideBehavior elide_; 107 gfx::ElideBehavior elide_;
116 108
117 DISALLOW_COPY_AND_ASSIGN(TextExampleView); 109 DISALLOW_COPY_AND_ASSIGN(TextExampleView);
118 }; 110 };
119 111
120 TextExample::TextExample() : ExampleBase("Text Styles") {} 112 TextExample::TextExample() : ExampleBase("Text Styles") {}
121 113
122 TextExample::~TextExample() { 114 TextExample::~TextExample() {
123 // Remove the views first as some reference combobox models. 115 // Remove the views first as some reference combobox models.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 eliding_cb_ = AddCombobox(layout, "Eliding", kElideBehaviors, 159 eliding_cb_ = AddCombobox(layout, "Eliding", kElideBehaviors,
168 arraysize(kElideBehaviors)); 160 arraysize(kElideBehaviors));
169 prefix_cb_ = AddCombobox(layout, "Prefix", kPrefixOptions, 161 prefix_cb_ = AddCombobox(layout, "Prefix", kPrefixOptions,
170 arraysize(kPrefixOptions)); 162 arraysize(kPrefixOptions));
171 text_cb_ = AddCombobox(layout, "Example Text", kTextExamples, 163 text_cb_ = AddCombobox(layout, "Example Text", kTextExamples,
172 arraysize(kTextExamples)); 164 arraysize(kTextExamples));
173 165
174 layout->StartRow(0, 0); 166 layout->StartRow(0, 0);
175 multiline_checkbox_ = AddCheckbox(layout, "Multiline"); 167 multiline_checkbox_ = AddCheckbox(layout, "Multiline");
176 break_checkbox_ = AddCheckbox(layout, "Character Break"); 168 break_checkbox_ = AddCheckbox(layout, "Character Break");
177 halo_checkbox_ = AddCheckbox(layout, "Halo");
178 bold_checkbox_ = AddCheckbox(layout, "Bold"); 169 bold_checkbox_ = AddCheckbox(layout, "Bold");
179 italic_checkbox_ = AddCheckbox(layout, "Italic"); 170 italic_checkbox_ = AddCheckbox(layout, "Italic");
180 underline_checkbox_ = AddCheckbox(layout, "Underline"); 171 underline_checkbox_ = AddCheckbox(layout, "Underline");
181 172
182 layout->AddPaddingRow(0, 20); 173 layout->AddPaddingRow(0, 20);
183 column_set = layout->AddColumnSet(1); 174 column_set = layout->AddColumnSet(1);
184 column_set->AddPaddingColumn(0, 16); 175 column_set->AddPaddingColumn(0, 16);
185 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 176 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
186 1, GridLayout::USE_PREF, 0, 0); 177 1, GridLayout::USE_PREF, 0, 0);
187 column_set->AddPaddingColumn(0, 16); 178 column_set->AddPaddingColumn(0, 16);
188 layout->StartRow(1, 1); 179 layout->StartRow(1, 1);
189 layout->AddView(text_view_); 180 layout->AddView(text_view_);
190 layout->AddPaddingRow(0, 8); 181 layout->AddPaddingRow(0, 8);
191 } 182 }
192 183
193 void TextExample::ButtonPressed(Button* button, const ui::Event& event) { 184 void TextExample::ButtonPressed(Button* button, const ui::Event& event) {
194 int flags = text_view_->flags(); 185 int flags = text_view_->flags();
195 int style = text_view_->GetStyle(); 186 int style = text_view_->GetStyle();
196 SetFlagFromCheckbox(multiline_checkbox_, &flags, gfx::Canvas::MULTI_LINE); 187 SetFlagFromCheckbox(multiline_checkbox_, &flags, gfx::Canvas::MULTI_LINE);
197 SetFlagFromCheckbox(break_checkbox_, &flags, gfx::Canvas::CHARACTER_BREAK); 188 SetFlagFromCheckbox(break_checkbox_, &flags, gfx::Canvas::CHARACTER_BREAK);
198 SetFlagFromCheckbox(italic_checkbox_, &style, gfx::Font::ITALIC); 189 SetFlagFromCheckbox(italic_checkbox_, &style, gfx::Font::ITALIC);
199 SetFlagFromCheckbox(underline_checkbox_, &style, gfx::Font::UNDERLINE); 190 SetFlagFromCheckbox(underline_checkbox_, &style, gfx::Font::UNDERLINE);
200 text_view_->set_halo(halo_checkbox_->checked());
201 text_view_->set_flags(flags); 191 text_view_->set_flags(flags);
202 text_view_->SetStyle(style); 192 text_view_->SetStyle(style);
203 text_view_->SetWeight(bold_checkbox_->checked() ? gfx::Font::Weight::BOLD 193 text_view_->SetWeight(bold_checkbox_->checked() ? gfx::Font::Weight::BOLD
204 : gfx::Font::Weight::NORMAL); 194 : gfx::Font::Weight::NORMAL);
205 text_view_->SchedulePaint(); 195 text_view_->SchedulePaint();
206 } 196 }
207 197
208 void TextExample::OnPerformAction(Combobox* combobox) { 198 void TextExample::OnPerformAction(Combobox* combobox) {
209 int flags = text_view_->flags(); 199 int flags = text_view_->flags();
210 if (combobox == h_align_cb_) { 200 if (combobox == h_align_cb_) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 flags |= gfx::Canvas::HIDE_PREFIX; 253 flags |= gfx::Canvas::HIDE_PREFIX;
264 break; 254 break;
265 } 255 }
266 } 256 }
267 text_view_->set_flags(flags); 257 text_view_->set_flags(flags);
268 text_view_->SchedulePaint(); 258 text_view_->SchedulePaint();
269 } 259 }
270 260
271 } // namespace examples 261 } // namespace examples
272 } // namespace views 262 } // namespace views
OLDNEW
« ui/gfx/render_text.cc ('K') | « ui/views/examples/text_example.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698