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

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

Issue 2541313002: RenderTextHarfBuzz: Add support for multi line text selection. (Closed)
Patch Set: --- Created 4 years 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
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/label_example.h" 5 #include "ui/views/examples/label_example.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/gfx/geometry/vector2d.h" 10 #include "ui/gfx/geometry/vector2d.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 void LabelExample::ButtonPressed(Button* button, const ui::Event& event) { 125 void LabelExample::ButtonPressed(Button* button, const ui::Event& event) {
126 if (button == multiline_) { 126 if (button == multiline_) {
127 custom_label_->SetMultiLine(multiline_->checked()); 127 custom_label_->SetMultiLine(multiline_->checked());
128 } else if (button == shadows_) { 128 } else if (button == shadows_) {
129 gfx::ShadowValues shadows; 129 gfx::ShadowValues shadows;
130 if (shadows_->checked()) { 130 if (shadows_->checked()) {
131 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(), 1, SK_ColorRED)); 131 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(), 1, SK_ColorRED));
132 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(2, 2), 0, SK_ColorGRAY)); 132 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(2, 2), 0, SK_ColorGRAY));
133 } 133 }
134 custom_label_->SetShadows(shadows); 134 custom_label_->SetShadows(shadows);
135 } else if (button == text_selection_) {
136 custom_label_->SetSelectable(text_selection_->checked());
135 } 137 }
136 custom_label_->parent()->parent()->Layout(); 138 custom_label_->parent()->parent()->Layout();
137 custom_label_->SchedulePaint(); 139 custom_label_->SchedulePaint();
138 } 140 }
139 141
140 void LabelExample::OnPerformAction(Combobox* combobox) { 142 void LabelExample::OnPerformAction(Combobox* combobox) {
141 if (combobox == alignment_) { 143 if (combobox == alignment_) {
142 custom_label_->SetHorizontalAlignment( 144 custom_label_->SetHorizontalAlignment(
143 static_cast<gfx::HorizontalAlignment>(combobox->selected_index())); 145 static_cast<gfx::HorizontalAlignment>(combobox->selected_index()));
144 } else if (combobox == elide_behavior_) { 146 } else if (combobox == elide_behavior_) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 alignment_ = AddCombobox(layout, "Alignment: ", kAlignments, 181 alignment_ = AddCombobox(layout, "Alignment: ", kAlignments,
180 arraysize(kAlignments)); 182 arraysize(kAlignments));
181 elide_behavior_ = AddCombobox(layout, "Elide Behavior: ", kElideBehaviors, 183 elide_behavior_ = AddCombobox(layout, "Elide Behavior: ", kElideBehaviors,
182 arraysize(kElideBehaviors)); 184 arraysize(kElideBehaviors));
183 185
184 column_set = layout->AddColumnSet(1); 186 column_set = layout->AddColumnSet(1);
185 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 187 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
186 0, GridLayout::USE_PREF, 0, 0); 188 0, GridLayout::USE_PREF, 0, 0);
187 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 189 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
188 0, GridLayout::USE_PREF, 0, 0); 190 0, GridLayout::USE_PREF, 0, 0);
191 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,
192 GridLayout::USE_PREF, 0, 0);
189 layout->StartRow(0, 1); 193 layout->StartRow(0, 1);
190 multiline_ = new Checkbox(base::ASCIIToUTF16("Multiline")); 194 multiline_ = new Checkbox(base::ASCIIToUTF16("Multiline"));
191 multiline_->set_listener(this); 195 multiline_->set_listener(this);
192 layout->AddView(multiline_); 196 layout->AddView(multiline_);
193 shadows_ = new Checkbox(base::ASCIIToUTF16("Shadows")); 197 shadows_ = new Checkbox(base::ASCIIToUTF16("Shadows"));
194 shadows_->set_listener(this); 198 shadows_->set_listener(this);
195 layout->AddView(shadows_); 199 layout->AddView(shadows_);
200 text_selection_ = new Checkbox(base::ASCIIToUTF16("Text selection"));
msw 2016/12/07 20:20:35 nit: rename the identifier |selectable_| and chang
karandeepb 2016/12/12 10:36:19 Done.
201 text_selection_->set_listener(this);
202 layout->AddView(text_selection_);
196 layout->AddPaddingRow(0, 8); 203 layout->AddPaddingRow(0, 8);
197 204
198 column_set = layout->AddColumnSet(2); 205 column_set = layout->AddColumnSet(2);
199 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 206 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
200 1, GridLayout::USE_PREF, 0, 0); 207 1, GridLayout::USE_PREF, 0, 0);
201 layout->StartRow(0, 2); 208 layout->StartRow(0, 2);
202 custom_label_ = new PreferredSizeLabel(); 209 custom_label_ = new PreferredSizeLabel();
203 custom_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 210 custom_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
204 custom_label_->SetElideBehavior(gfx::NO_ELIDE); 211 custom_label_->SetElideBehavior(gfx::NO_ELIDE);
205 custom_label_->SetText(textfield_->text()); 212 custom_label_->SetText(textfield_->text());
206 layout->AddView(custom_label_); 213 layout->AddView(custom_label_);
207 214
215 // Disable the text selection checkbox if |custom_label_| does not support
216 // text selection.
217 if (custom_label_->SetSelectable(true))
218 text_selection_->SetChecked(true);
msw 2016/12/07 20:20:35 Don't set selectable and check by default, just di
karandeepb 2016/12/12 10:36:19 Done. This required making Label::IsSelectionSuppo
219 else
220 text_selection_->SetEnabled(false);
221
208 container->AddChildView(control_container); 222 container->AddChildView(control_container);
209 } 223 }
210 224
211 Combobox* LabelExample::AddCombobox(GridLayout* layout, 225 Combobox* LabelExample::AddCombobox(GridLayout* layout,
212 const char* name, 226 const char* name,
213 const char** strings, 227 const char** strings,
214 int count) { 228 int count) {
215 layout->StartRow(0, 0); 229 layout->StartRow(0, 0);
216 layout->AddView(new Label(base::ASCIIToUTF16(name))); 230 layout->AddView(new Label(base::ASCIIToUTF16(name)));
217 ExampleComboboxModel* model = new ExampleComboboxModel(strings, count); 231 ExampleComboboxModel* model = new ExampleComboboxModel(strings, count);
218 example_combobox_models_.push_back(base::WrapUnique(model)); 232 example_combobox_models_.push_back(base::WrapUnique(model));
219 Combobox* combobox = new Combobox(model); 233 Combobox* combobox = new Combobox(model);
220 combobox->SetSelectedIndex(0); 234 combobox->SetSelectedIndex(0);
221 combobox->set_listener(this); 235 combobox->set_listener(this);
222 layout->AddView(combobox); 236 layout->AddView(combobox);
223 return combobox; 237 return combobox;
224 } 238 }
225 239
226 } // namespace examples 240 } // namespace examples
227 } // namespace views 241 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698