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

Side by Side Diff: ui/views/controls/styled_label.cc

Issue 1915863004: Remove View::focusable() - Alternate approach. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SetFocusBehavior
Patch Set: Created 4 years, 7 months 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 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/controls/styled_label.h" 5 #include "ui/views/controls/styled_label.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <vector> 10 #include <vector>
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 break; 300 break;
301 } 301 }
302 302
303 x = 0; 303 x = 0;
304 line++; 304 line++;
305 continue; 305 continue;
306 } 306 }
307 307
308 base::string16 chunk = substrings[0]; 308 base::string16 chunk = substrings[0];
309 309
310 std::unique_ptr<Label> label; 310 std::unique_ptr<Label> label_ptr;
311 if (position >= range.start()) { 311 if (position >= range.start()) {
312 const RangeStyleInfo& style_info = current_range->style_info; 312 const RangeStyleInfo& style_info = current_range->style_info;
313 313
314 if (style_info.disable_line_wrapping && chunk.size() < range.length() && 314 if (style_info.disable_line_wrapping && chunk.size() < range.length() &&
315 position == range.start() && x != 0) { 315 position == range.start() && x != 0) {
316 // If the chunk should not be wrapped, try to fit it entirely on the 316 // If the chunk should not be wrapped, try to fit it entirely on the
317 // next line. 317 // next line.
318 x = 0; 318 x = 0;
319 line++; 319 line++;
320 continue; 320 continue;
321 } 321 }
322 322
323 if (chunk.size() > range.end() - position) 323 if (chunk.size() > range.end() - position)
324 chunk = chunk.substr(0, range.end() - position); 324 chunk = chunk.substr(0, range.end() - position);
325 325
326 label = CreateLabelRange(chunk, font_list_, style_info, this); 326 label_ptr = CreateLabelRange(chunk, font_list_, style_info, this);
327 327
328 if (style_info.is_link && !dry_run) 328 if (style_info.is_link && !dry_run)
329 link_targets_[label.get()] = range; 329 link_targets_[label_ptr.get()] = range;
330 330
331 if (position + chunk.size() >= range.end()) 331 if (position + chunk.size() >= range.end())
332 ++current_range; 332 ++current_range;
333 } else { 333 } else {
334 // This chunk is normal text. 334 // This chunk is normal text.
335 if (position + chunk.size() > range.start()) 335 if (position + chunk.size() > range.start())
336 chunk = chunk.substr(0, range.start() - position); 336 chunk = chunk.substr(0, range.start() - position);
337 label = CreateLabelRange(chunk, font_list_, default_style_info_, this); 337 label_ptr =
338 CreateLabelRange(chunk, font_list_, default_style_info_, this);
338 } 339 }
340 Label* label = label_ptr.get();
341
342 // Since Label::GetInsets() depends on IsFocusable(), add |label| to the
343 // view hierarchy first, to ensure Label::GetInsets returns the correct
344 // value.
345 if (!dry_run)
346 AddChildView(label_ptr.release());
339 347
340 if (displayed_on_background_color_set_) 348 if (displayed_on_background_color_set_)
341 label->SetBackgroundColor(displayed_on_background_color_); 349 label->SetBackgroundColor(displayed_on_background_color_);
342 label->SetAutoColorReadabilityEnabled(auto_color_readability_enabled_); 350 label->SetAutoColorReadabilityEnabled(auto_color_readability_enabled_);
343 351
344 // Calculate the size of the optional focus border, and overlap by that 352 // Calculate the size of the optional focus border, and overlap by that
345 // amount. Otherwise, "<a>link</a>," will render as "link ,". 353 // amount. Otherwise, "<a>link</a>," will render as "link ,".
346 gfx::Insets focus_border_insets(label->GetInsets()); 354 gfx::Insets focus_border_insets(label->GetInsets());
347 focus_border_insets += -label->View::GetInsets(); 355 focus_border_insets += -label->View::GetInsets();
348 const gfx::Size view_size = label->GetPreferredSize(); 356 const gfx::Size view_size = label->GetPreferredSize();
349 if (!dry_run) { 357 if (!dry_run) {
350 label->SetBoundsRect(gfx::Rect( 358 label->SetBoundsRect(gfx::Rect(
351 gfx::Point(GetInsets().left() + x - focus_border_insets.left(), 359 gfx::Point(GetInsets().left() + x - focus_border_insets.left(),
352 GetInsets().top() + line * line_height - 360 GetInsets().top() + line * line_height -
353 focus_border_insets.top()), 361 focus_border_insets.top()),
354 view_size)); 362 view_size));
355 AddChildView(label.release());
356 } 363 }
357 x += view_size.width() - focus_border_insets.width(); 364 x += view_size.width() - focus_border_insets.width();
358 used_width = std::max(used_width, x); 365 used_width = std::max(used_width, x);
359 366
360 // If |gfx::ElideRectangleText| returned more than one substring, that 367 // If |gfx::ElideRectangleText| returned more than one substring, that
361 // means the whole text did not fit into remaining line width, with text 368 // means the whole text did not fit into remaining line width, with text
362 // after |susbtring[0]| spilling into next line. If whole |substring[0]| 369 // after |susbtring[0]| spilling into next line. If whole |substring[0]|
363 // was added to the current line (this may not be the case if part of the 370 // was added to the current line (this may not be the case if part of the
364 // substring has different style), proceed to the next line. 371 // substring has different style), proceed to the next line.
365 if (substrings.size() > 1 && chunk.size() == substrings[0].size()) { 372 if (substrings.size() > 1 && chunk.size() == substrings[0].size()) {
366 x = 0; 373 x = 0;
367 ++line; 374 ++line;
368 } 375 }
369 376
370 remaining_string = remaining_string.substr(chunk.size()); 377 remaining_string = remaining_string.substr(chunk.size());
371 } 378 }
372 379
373 DCHECK_LE(used_width, width); 380 DCHECK_LE(used_width, width);
374 // The user-specified line height only applies to interline spacing, so the 381 // The user-specified line height only applies to interline spacing, so the
375 // final line's height is unaffected. 382 // final line's height is unaffected.
376 int total_height = line * line_height + 383 int total_height = line * line_height +
377 CalculateLineHeight(font_list_) + GetInsets().height(); 384 CalculateLineHeight(font_list_) + GetInsets().height();
378 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height); 385 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height);
379 return calculated_size_; 386 return calculated_size_;
380 } 387 }
381 388
382 } // namespace views 389 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698