OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/multiline_example.h" | 5 #include "ui/views/examples/multiline_example.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 // A simple View that hosts a RenderText object. | 51 // A simple View that hosts a RenderText object. |
52 class MultilineExample::RenderTextView : public View { | 52 class MultilineExample::RenderTextView : public View { |
53 public: | 53 public: |
54 RenderTextView() : render_text_(gfx::RenderText::CreateInstanceForEditing()) { | 54 RenderTextView() : render_text_(gfx::RenderText::CreateInstanceForEditing()) { |
55 render_text_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); | 55 render_text_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); |
56 render_text_->SetColor(SK_ColorBLACK); | 56 render_text_->SetColor(SK_ColorBLACK); |
57 render_text_->SetMultiline(true); | 57 render_text_->SetMultiline(true); |
58 SetBorder(Border::CreateSolidBorder(2, SK_ColorGRAY)); | 58 SetBorder(CreateSolidBorder(2, SK_ColorGRAY)); |
59 } | 59 } |
60 | 60 |
61 void OnPaint(gfx::Canvas* canvas) override { | 61 void OnPaint(gfx::Canvas* canvas) override { |
62 View::OnPaint(canvas); | 62 View::OnPaint(canvas); |
63 render_text_->Draw(canvas); | 63 render_text_->Draw(canvas); |
64 } | 64 } |
65 | 65 |
66 gfx::Size GetPreferredSize() const override { | 66 gfx::Size GetPreferredSize() const override { |
67 // Turn off multiline mode to get the single-line text size, which is the | 67 // Turn off multiline mode to get the single-line text size, which is the |
68 // preferred size for this view. | 68 // preferred size for this view. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 const base::string16 kTestString = base::WideToUTF16(L"qwerty" | 138 const base::string16 kTestString = base::WideToUTF16(L"qwerty" |
139 L"\x627\x644\x631\x626\x64A\x633\x64A\x629" | 139 L"\x627\x644\x631\x626\x64A\x633\x64A\x629" |
140 L"asdfgh"); | 140 L"asdfgh"); |
141 | 141 |
142 render_text_view_ = new RenderTextView(); | 142 render_text_view_ = new RenderTextView(); |
143 render_text_view_->SetText(kTestString); | 143 render_text_view_->SetText(kTestString); |
144 | 144 |
145 label_ = new PreferredSizeLabel(); | 145 label_ = new PreferredSizeLabel(); |
146 label_->SetText(kTestString); | 146 label_->SetText(kTestString); |
147 label_->SetMultiLine(true); | 147 label_->SetMultiLine(true); |
148 label_->SetBorder(Border::CreateSolidBorder(2, SK_ColorCYAN)); | 148 label_->SetBorder(CreateSolidBorder(2, SK_ColorCYAN)); |
149 | 149 |
150 label_checkbox_ = new Checkbox(ASCIIToUTF16("views::Label:")); | 150 label_checkbox_ = new Checkbox(ASCIIToUTF16("views::Label:")); |
151 label_checkbox_->SetChecked(true); | 151 label_checkbox_->SetChecked(true); |
152 label_checkbox_->set_listener(this); | 152 label_checkbox_->set_listener(this); |
153 label_checkbox_->set_request_focus_on_press(false); | 153 label_checkbox_->set_request_focus_on_press(false); |
154 | 154 |
155 elision_checkbox_ = new Checkbox(ASCIIToUTF16("elide text?")); | 155 elision_checkbox_ = new Checkbox(ASCIIToUTF16("elide text?")); |
156 elision_checkbox_->SetChecked(false); | 156 elision_checkbox_->SetChecked(false); |
157 elision_checkbox_->set_listener(this); | 157 elision_checkbox_->set_listener(this); |
158 elision_checkbox_->set_request_focus_on_press(false); | 158 elision_checkbox_->set_request_focus_on_press(false); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 : base::string16()); | 201 : base::string16()); |
202 } else if (sender == elision_checkbox_) { | 202 } else if (sender == elision_checkbox_) { |
203 render_text_view_->SetMaxLines(elision_checkbox_->checked() ? 3 : 0); | 203 render_text_view_->SetMaxLines(elision_checkbox_->checked() ? 3 : 0); |
204 } | 204 } |
205 container()->Layout(); | 205 container()->Layout(); |
206 container()->SchedulePaint(); | 206 container()->SchedulePaint(); |
207 } | 207 } |
208 | 208 |
209 } // namespace examples | 209 } // namespace examples |
210 } // namespace views | 210 } // namespace views |
OLD | NEW |