| 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 "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
| 9 #include "ui/gfx/render_text.h" | 9 #include "ui/gfx/render_text.h" |
| 10 #include "ui/views/background.h" | 10 #include "ui/views/background.h" |
| 11 #include "ui/views/border.h" | 11 #include "ui/views/border.h" |
| 12 #include "ui/views/controls/button/checkbox.h" | 12 #include "ui/views/controls/button/checkbox.h" |
| 13 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
| 14 #include "ui/views/controls/textfield/textfield.h" | 14 #include "ui/views/controls/textfield/textfield.h" |
| 15 #include "ui/views/layout/grid_layout.h" | 15 #include "ui/views/layout/grid_layout.h" |
| 16 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
| 17 | 17 |
| 18 using base::ASCIIToUTF16; | 18 using base::ASCIIToUTF16; |
| 19 | 19 |
| 20 namespace views { | 20 namespace views { |
| 21 namespace examples { | 21 namespace examples { |
| 22 | 22 |
| 23 // A simple View that hosts a RenderText object. | 23 // A simple View that hosts a RenderText object. |
| 24 class MultilineExample::RenderTextView : public View { | 24 class MultilineExample::RenderTextView : public View { |
| 25 public: | 25 public: |
| 26 RenderTextView() : render_text_(gfx::RenderText::CreateInstance()) { | 26 RenderTextView() : render_text_(gfx::RenderText::CreateInstance()) { |
| 27 render_text_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 27 render_text_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 28 render_text_->SetColor(SK_ColorBLACK); | 28 render_text_->SetColor(SK_ColorBLACK); |
| 29 render_text_->SetMultiline(true); | 29 render_text_->SetMultiline(true); |
| 30 set_border(Border::CreateSolidBorder(2, SK_ColorGRAY)); | 30 SetBorder(Border::CreateSolidBorder(2, SK_ColorGRAY)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 33 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 34 View::OnPaint(canvas); | 34 View::OnPaint(canvas); |
| 35 render_text_->Draw(canvas); | 35 render_text_->Draw(canvas); |
| 36 } | 36 } |
| 37 | 37 |
| 38 virtual gfx::Size GetPreferredSize() OVERRIDE { | 38 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 39 // Turn off multiline mode to get the single-line text size, which is the | 39 // Turn off multiline mode to get the single-line text size, which is the |
| 40 // preferred size for this view. | 40 // preferred size for this view. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 void MultilineExample::CreateExampleView(View* container) { | 101 void MultilineExample::CreateExampleView(View* container) { |
| 102 const char kTestString[] = "test string asdf 1234 test string asdf 1234 " | 102 const char kTestString[] = "test string asdf 1234 test string asdf 1234 " |
| 103 "test string asdf 1234 test string asdf 1234"; | 103 "test string asdf 1234 test string asdf 1234"; |
| 104 | 104 |
| 105 render_text_view_ = new RenderTextView(); | 105 render_text_view_ = new RenderTextView(); |
| 106 render_text_view_->SetText(ASCIIToUTF16(kTestString)); | 106 render_text_view_->SetText(ASCIIToUTF16(kTestString)); |
| 107 | 107 |
| 108 label_ = new Label(); | 108 label_ = new Label(); |
| 109 label_->SetText(ASCIIToUTF16(kTestString)); | 109 label_->SetText(ASCIIToUTF16(kTestString)); |
| 110 label_->SetMultiLine(true); | 110 label_->SetMultiLine(true); |
| 111 label_->set_border(Border::CreateSolidBorder(2, SK_ColorCYAN)); | 111 label_->SetBorder(Border::CreateSolidBorder(2, SK_ColorCYAN)); |
| 112 | 112 |
| 113 label_checkbox_ = new Checkbox(ASCIIToUTF16("views::Label:")); | 113 label_checkbox_ = new Checkbox(ASCIIToUTF16("views::Label:")); |
| 114 label_checkbox_->SetChecked(true); | 114 label_checkbox_->SetChecked(true); |
| 115 label_checkbox_->set_listener(this); | 115 label_checkbox_->set_listener(this); |
| 116 label_checkbox_->set_request_focus_on_press(false); | 116 label_checkbox_->set_request_focus_on_press(false); |
| 117 | 117 |
| 118 textfield_ = new Textfield(); | 118 textfield_ = new Textfield(); |
| 119 textfield_->set_controller(this); | 119 textfield_->set_controller(this); |
| 120 textfield_->SetText(ASCIIToUTF16(kTestString)); | 120 textfield_->SetText(ASCIIToUTF16(kTestString)); |
| 121 | 121 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 void MultilineExample::ButtonPressed(Button* sender, const ui::Event& event) { | 158 void MultilineExample::ButtonPressed(Button* sender, const ui::Event& event) { |
| 159 DCHECK_EQ(sender, label_checkbox_); | 159 DCHECK_EQ(sender, label_checkbox_); |
| 160 label_->SetText(label_checkbox_->checked() ? textfield_->text() : | 160 label_->SetText(label_checkbox_->checked() ? textfield_->text() : |
| 161 base::string16()); | 161 base::string16()); |
| 162 container()->Layout(); | 162 container()->Layout(); |
| 163 container()->SchedulePaint(); | 163 container()->SchedulePaint(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace examples | 166 } // namespace examples |
| 167 } // namespace views | 167 } // namespace views |
| OLD | NEW |