Chromium Code Reviews| 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" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 test_range.set_start(std::min(test_range.start(), new_contents.length())); | 65 test_range.set_start(std::min(test_range.start(), new_contents.length())); |
| 66 test_range.set_end(std::min(test_range.end(), new_contents.length())); | 66 test_range.set_end(std::min(test_range.end(), new_contents.length())); |
| 67 | 67 |
| 68 render_text_->SetText(new_contents); | 68 render_text_->SetText(new_contents); |
| 69 render_text_->SetColor(SK_ColorBLACK); | 69 render_text_->SetColor(SK_ColorBLACK); |
| 70 render_text_->ApplyColor(0xFFFF0000, test_range); | 70 render_text_->ApplyColor(0xFFFF0000, test_range); |
| 71 render_text_->SetStyle(gfx::DIAGONAL_STRIKE, false); | 71 render_text_->SetStyle(gfx::DIAGONAL_STRIKE, false); |
| 72 render_text_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, test_range); | 72 render_text_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, test_range); |
| 73 render_text_->SetStyle(gfx::UNDERLINE, false); | 73 render_text_->SetStyle(gfx::UNDERLINE, false); |
| 74 render_text_->ApplyStyle(gfx::UNDERLINE, true, test_range); | 74 render_text_->ApplyStyle(gfx::UNDERLINE, true, test_range); |
| 75 render_text_->ApplyStyle(gfx::BOLD, true, gfx::Range(3, 8)); | |
|
msw
2014/04/29 06:24:45
Handle strings shorter than these hardcoded ranges
ckocagil
2014/05/01 22:02:01
Done.
| |
| 76 render_text_->ApplyStyle(gfx::ITALIC, true, gfx::Range(5, 10)); | |
| 75 InvalidateLayout(); | 77 InvalidateLayout(); |
| 76 } | 78 } |
| 77 | 79 |
| 78 private: | 80 private: |
| 79 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE { | 81 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE { |
| 80 gfx::Rect bounds = GetLocalBounds(); | 82 gfx::Rect bounds = GetLocalBounds(); |
| 81 bounds.Inset(GetInsets()); | 83 bounds.Inset(GetInsets()); |
| 82 render_text_->SetDisplayRect(bounds); | 84 render_text_->SetDisplayRect(bounds); |
| 83 } | 85 } |
| 84 | 86 |
| 85 scoped_ptr<gfx::RenderText> render_text_; | 87 scoped_ptr<gfx::RenderText> render_text_; |
| 86 | 88 |
| 87 DISALLOW_COPY_AND_ASSIGN(RenderTextView); | 89 DISALLOW_COPY_AND_ASSIGN(RenderTextView); |
| 88 }; | 90 }; |
| 89 | 91 |
| 90 MultilineExample::MultilineExample() | 92 MultilineExample::MultilineExample() |
| 91 : ExampleBase("Multiline RenderText"), | 93 : ExampleBase("Multiline RenderText"), |
| 92 render_text_view_(NULL), | 94 render_text_view_(NULL), |
| 93 label_(NULL), | 95 label_(NULL), |
| 94 textfield_(NULL), | 96 textfield_(NULL), |
| 95 label_checkbox_(NULL) { | 97 label_checkbox_(NULL) { |
| 96 } | 98 } |
| 97 | 99 |
| 98 MultilineExample::~MultilineExample() { | 100 MultilineExample::~MultilineExample() { |
| 99 } | 101 } |
| 100 | 102 |
| 101 void MultilineExample::CreateExampleView(View* container) { | 103 void MultilineExample::CreateExampleView(View* container) { |
| 102 const char kTestString[] = "test string asdf 1234 test string asdf 1234 " | 104 const wchar_t kTestString[] = L"qwerty" |
|
msw
2014/04/29 06:24:45
Use base::char16
ckocagil
2014/05/01 22:02:01
I don't think we can do that (wchar_t isn't always
| |
| 103 "test string asdf 1234 test string asdf 1234"; | 105 L"\x627\x644\x631\x626\x64A\x633\x64A\x629" |
|
msw
2014/04/29 06:24:45
nit: Is there any reason for changing the content
ckocagil
2014/05/01 22:02:01
For testing RTL runs.
| |
| 106 L"asdfgh"; | |
| 104 | 107 |
| 105 render_text_view_ = new RenderTextView(); | 108 render_text_view_ = new RenderTextView(); |
| 106 render_text_view_->SetText(ASCIIToUTF16(kTestString)); | 109 render_text_view_->SetText(kTestString); |
| 107 | 110 |
| 108 label_ = new Label(); | 111 label_ = new Label(); |
| 109 label_->SetText(ASCIIToUTF16(kTestString)); | 112 label_->SetText(kTestString); |
| 110 label_->SetMultiLine(true); | 113 label_->SetMultiLine(true); |
| 111 label_->SetBorder(Border::CreateSolidBorder(2, SK_ColorCYAN)); | 114 label_->SetBorder(Border::CreateSolidBorder(2, SK_ColorCYAN)); |
| 112 | 115 |
| 113 label_checkbox_ = new Checkbox(ASCIIToUTF16("views::Label:")); | 116 label_checkbox_ = new Checkbox(ASCIIToUTF16("views::Label:")); |
| 114 label_checkbox_->SetChecked(true); | 117 label_checkbox_->SetChecked(true); |
| 115 label_checkbox_->set_listener(this); | 118 label_checkbox_->set_listener(this); |
| 116 label_checkbox_->set_request_focus_on_press(false); | 119 label_checkbox_->set_request_focus_on_press(false); |
| 117 | 120 |
| 118 textfield_ = new Textfield(); | 121 textfield_ = new Textfield(); |
| 119 textfield_->set_controller(this); | 122 textfield_->set_controller(this); |
| 120 textfield_->SetText(ASCIIToUTF16(kTestString)); | 123 textfield_->SetText(kTestString); |
| 121 | 124 |
| 122 GridLayout* layout = new GridLayout(container); | 125 GridLayout* layout = new GridLayout(container); |
| 123 container->SetLayoutManager(layout); | 126 container->SetLayoutManager(layout); |
| 124 | 127 |
| 125 ColumnSet* column_set = layout->AddColumnSet(0); | 128 ColumnSet* column_set = layout->AddColumnSet(0); |
| 126 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, | 129 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, |
| 127 0.0f, GridLayout::USE_PREF, 0, 0); | 130 0.0f, GridLayout::USE_PREF, 0, 0); |
| 128 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, | 131 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 129 1.0f, GridLayout::FIXED, 0, 0); | 132 1.0f, GridLayout::FIXED, 0, 0); |
| 130 | 133 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 158 void MultilineExample::ButtonPressed(Button* sender, const ui::Event& event) { | 161 void MultilineExample::ButtonPressed(Button* sender, const ui::Event& event) { |
| 159 DCHECK_EQ(sender, label_checkbox_); | 162 DCHECK_EQ(sender, label_checkbox_); |
| 160 label_->SetText(label_checkbox_->checked() ? textfield_->text() : | 163 label_->SetText(label_checkbox_->checked() ? textfield_->text() : |
| 161 base::string16()); | 164 base::string16()); |
| 162 container()->Layout(); | 165 container()->Layout(); |
| 163 container()->SchedulePaint(); | 166 container()->SchedulePaint(); |
| 164 } | 167 } |
| 165 | 168 |
| 166 } // namespace examples | 169 } // namespace examples |
| 167 } // namespace views | 170 } // namespace views |
| OLD | NEW |