OLD | NEW |
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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "ui/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.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 28 matching lines...) Expand all Loading... |
39 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " | 39 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " |
40 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " | 40 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " |
41 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " | 41 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " |
42 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " | 42 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " |
43 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " | 43 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " |
44 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " | 44 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " |
45 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " | 45 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd! " |
46 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd!"; | 46 L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd!"; |
47 | 47 |
48 const char* kTextExamples[] = { "Short", "Long", "Ampersands", "RTL Hebrew", }; | 48 const char* kTextExamples[] = { "Short", "Long", "Ampersands", "RTL Hebrew", }; |
49 const char* kElideBehaviors[] = { "Elide", "Truncate", "Fade", }; | 49 const char* kElideBehaviors[] = { "Elide", "No Elide", "Fade", }; |
50 const char* kPrefixOptions[] = { "Default", "Show", "Hide", }; | 50 const char* kPrefixOptions[] = { "Default", "Show", "Hide", }; |
51 const char* kHorizontalAligments[] = { "Default", "Left", "Center", "Right", }; | 51 const char* kHorizontalAligments[] = { "Default", "Left", "Center", "Right", }; |
52 | 52 |
53 // Toggles bit |flag| on |flags| based on state of |checkbox|. | 53 // Toggles bit |flag| on |flags| based on state of |checkbox|. |
54 void SetFlagFromCheckbox(Checkbox* checkbox, int* flags, int flag) { | 54 void SetFlagFromCheckbox(Checkbox* checkbox, int* flags, int flag) { |
55 if (checkbox->checked()) | 55 if (checkbox->checked()) |
56 *flags |= flag; | 56 *flags |= flag; |
57 else | 57 else |
58 *flags &= ~flag; | 58 *flags &= ~flag; |
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), | 69 halo_(false), |
70 elide_(gfx::TRUNCATE) { | 70 elide_(gfx::NO_ELIDE) { |
71 } | 71 } |
72 | 72 |
73 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 73 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
74 View::OnPaint(canvas); | 74 View::OnPaint(canvas); |
75 const gfx::Rect bounds = GetContentsBounds(); | 75 const gfx::Rect bounds = GetContentsBounds(); |
76 const SkColor color = SK_ColorDKGRAY; | 76 const SkColor color = SK_ColorDKGRAY; |
77 if (elide_ == gfx::FADE_TAIL) { | 77 if (elide_ == gfx::FADE_TAIL) { |
78 canvas->DrawFadedString(text_, font_list_, color, bounds, flags_); | 78 canvas->DrawFadedString(text_, font_list_, color, bounds, flags_); |
79 } else if (halo_) { | 79 } else if (halo_) { |
80 canvas->DrawStringRectWithHalo(text_, font_list_, color, SK_ColorYELLOW, | 80 canvas->DrawStringRectWithHalo(text_, font_list_, color, SK_ColorYELLOW, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 case 3: | 232 case 3: |
233 text_view_->set_text(base::WideToUTF16(kRightToLeftText)); | 233 text_view_->set_text(base::WideToUTF16(kRightToLeftText)); |
234 break; | 234 break; |
235 } | 235 } |
236 } else if (combobox == eliding_cb_) { | 236 } else if (combobox == eliding_cb_) { |
237 switch (combobox->selected_index()) { | 237 switch (combobox->selected_index()) { |
238 case 0: | 238 case 0: |
239 text_view_->set_elide(gfx::ELIDE_TAIL); | 239 text_view_->set_elide(gfx::ELIDE_TAIL); |
240 break; | 240 break; |
241 case 1: | 241 case 1: |
242 text_view_->set_elide(gfx::TRUNCATE); | 242 text_view_->set_elide(gfx::NO_ELIDE); |
243 break; | 243 break; |
244 case 2: | 244 case 2: |
245 text_view_->set_elide(gfx::FADE_TAIL); | 245 text_view_->set_elide(gfx::FADE_TAIL); |
246 break; | 246 break; |
247 } | 247 } |
248 } else if (combobox == prefix_cb_) { | 248 } else if (combobox == prefix_cb_) { |
249 flags &= ~(gfx::Canvas::SHOW_PREFIX | gfx::Canvas::HIDE_PREFIX); | 249 flags &= ~(gfx::Canvas::SHOW_PREFIX | gfx::Canvas::HIDE_PREFIX); |
250 switch (combobox->selected_index()) { | 250 switch (combobox->selected_index()) { |
251 case 0: | 251 case 0: |
252 break; | 252 break; |
253 case 1: | 253 case 1: |
254 flags |= gfx::Canvas::SHOW_PREFIX; | 254 flags |= gfx::Canvas::SHOW_PREFIX; |
255 break; | 255 break; |
256 case 2: | 256 case 2: |
257 flags |= gfx::Canvas::HIDE_PREFIX; | 257 flags |= gfx::Canvas::HIDE_PREFIX; |
258 break; | 258 break; |
259 } | 259 } |
260 } | 260 } |
261 text_view_->set_flags(flags); | 261 text_view_->set_flags(flags); |
262 text_view_->SchedulePaint(); | 262 text_view_->SchedulePaint(); |
263 } | 263 } |
264 | 264 |
265 } // namespace examples | 265 } // namespace examples |
266 } // namespace views | 266 } // namespace views |
OLD | NEW |