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/controls/label.h" | 5 #include "ui/views/controls/label.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 void Label::SetMultiLine(bool multi_line) { | 168 void Label::SetMultiLine(bool multi_line) { |
169 DCHECK(!multi_line || (elide_behavior_ == gfx::ELIDE_TAIL || | 169 DCHECK(!multi_line || (elide_behavior_ == gfx::ELIDE_TAIL || |
170 elide_behavior_ == gfx::NO_ELIDE)); | 170 elide_behavior_ == gfx::NO_ELIDE)); |
171 if (this->multi_line() == multi_line) | 171 if (this->multi_line() == multi_line) |
172 return; | 172 return; |
173 is_first_paint_text_ = true; | 173 is_first_paint_text_ = true; |
174 multi_line_ = multi_line; | 174 multi_line_ = multi_line; |
175 if (render_text_->MultilineSupported()) | 175 if (render_text_->MultilineSupported()) |
176 render_text_->SetMultiline(multi_line); | 176 render_text_->SetMultiline(multi_line); |
177 render_text_->SetReplaceNewlineCharsWithSymbols(!multi_line); | 177 render_text_->SetReplaceNewlineCharsWithSymbols(!multi_line); |
178 if (multi_line) | |
179 SetSelectable(false); | |
180 ResetLayout(); | 178 ResetLayout(); |
181 } | 179 } |
182 | 180 |
183 void Label::SetObscured(bool obscured) { | 181 void Label::SetObscured(bool obscured) { |
184 if (this->obscured() == obscured) | 182 if (this->obscured() == obscured) |
185 return; | 183 return; |
186 is_first_paint_text_ = true; | 184 is_first_paint_text_ = true; |
187 render_text_->SetObscured(obscured); | 185 render_text_->SetObscured(obscured); |
188 if (obscured) | 186 if (obscured) |
189 SetSelectable(false); | 187 SetSelectable(false); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return result; | 241 return result; |
244 result.append(lines_[0]->GetDisplayText()); | 242 result.append(lines_[0]->GetDisplayText()); |
245 for (size_t i = 1; i < lines_.size(); ++i) { | 243 for (size_t i = 1; i < lines_.size(); ++i) { |
246 result.append(1, '\n'); | 244 result.append(1, '\n'); |
247 result.append(lines_[i]->GetDisplayText()); | 245 result.append(lines_[i]->GetDisplayText()); |
248 } | 246 } |
249 return result; | 247 return result; |
250 } | 248 } |
251 | 249 |
252 bool Label::IsSelectionSupported() const { | 250 bool Label::IsSelectionSupported() const { |
253 return !multi_line() && !obscured() && render_text_->IsSelectionSupported(); | 251 return !obscured() && render_text_->IsSelectionSupported(); |
254 } | 252 } |
255 | 253 |
256 bool Label::SetSelectable(bool value) { | 254 bool Label::SetSelectable(bool value) { |
257 if (value == selectable()) | 255 if (value == selectable()) |
258 return true; | 256 return true; |
259 | 257 |
260 if (!value) { | 258 if (!value) { |
261 ClearSelection(); | 259 ClearSelection(); |
262 stored_selection_range_ = gfx::Range::InvalidRange(); | 260 stored_selection_range_ = gfx::Range::InvalidRange(); |
263 selection_controller_.reset(); | 261 selection_controller_.reset(); |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 .WriteText(GetSelectedText()); | 1014 .WriteText(GetSelectedText()); |
1017 } | 1015 } |
1018 | 1016 |
1019 void Label::BuildContextMenuContents() { | 1017 void Label::BuildContextMenuContents() { |
1020 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1018 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
1021 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, | 1019 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, |
1022 IDS_APP_SELECT_ALL); | 1020 IDS_APP_SELECT_ALL); |
1023 } | 1021 } |
1024 | 1022 |
1025 } // namespace views | 1023 } // namespace views |
OLD | NEW |