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

Side by Side Diff: ui/views/corewm/tooltip_controller.cc

Issue 23731010: Move text_elider to gfx. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update3 Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/controls/styled_label.cc ('k') | ui/views/corewm/tooltip_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/corewm/tooltip_controller.h" 5 #include "ui/views/corewm/tooltip_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "ui/aura/client/cursor_client.h" 13 #include "ui/aura/client/cursor_client.h"
14 #include "ui/aura/client/drag_drop_client.h" 14 #include "ui/aura/client/drag_drop_client.h"
15 #include "ui/aura/env.h" 15 #include "ui/aura/env.h"
16 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/base/events/event.h" 18 #include "ui/base/events/event.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/base/text/text_elider.h"
21 #include "ui/gfx/font.h" 20 #include "ui/gfx/font.h"
22 #include "ui/gfx/point.h" 21 #include "ui/gfx/point.h"
23 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
24 #include "ui/gfx/screen.h" 23 #include "ui/gfx/screen.h"
24 #include "ui/gfx/text_elider.h"
25 #include "ui/views/background.h" 25 #include "ui/views/background.h"
26 #include "ui/views/border.h" 26 #include "ui/views/border.h"
27 #include "ui/views/controls/label.h" 27 #include "ui/views/controls/label.h"
28 #include "ui/views/corewm/corewm_switches.h" 28 #include "ui/views/corewm/corewm_switches.h"
29 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
30 #include "ui/views/widget/widget_observer.h" 30 #include "ui/views/widget/widget_observer.h"
31 31
32 namespace { 32 namespace {
33 33
34 const SkColor kTooltipBackground = 0xFFFFFFCC; 34 const SkColor kTooltipBackground = 0xFFFFFFCC;
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 current_width += word_width; 400 current_width += word_width;
401 line.append(word); 401 line.append(word);
402 } 402 }
403 result_lines.push_back(line); 403 result_lines.push_back(line);
404 } 404 }
405 405
406 // Clamp number of lines to |kMaxLines|. 406 // Clamp number of lines to |kMaxLines|.
407 if (result_lines.size() > kMaxLines) { 407 if (result_lines.size() > kMaxLines) {
408 result_lines.resize(kMaxLines); 408 result_lines.resize(kMaxLines);
409 // Add ellipses character to last line. 409 // Add ellipses character to last line.
410 result_lines[kMaxLines - 1] = ui::TruncateString( 410 result_lines[kMaxLines - 1] = gfx::TruncateString(
411 result_lines.back(), result_lines.back().length() - 1); 411 result_lines.back(), result_lines.back().length() - 1);
412 } 412 }
413 *line_count = result_lines.size(); 413 *line_count = result_lines.size();
414 414
415 // Flatten the result. 415 // Flatten the result.
416 string16 result; 416 string16 result;
417 for (std::vector<string16>::iterator l = result_lines.begin(); 417 for (std::vector<string16>::iterator l = result_lines.begin();
418 l != result_lines.end(); ++l) { 418 l != result_lines.end(); ++l) {
419 if (!result.empty()) 419 if (!result.empty())
420 result.push_back('\n'); 420 result.push_back('\n');
421 int line_width = font.GetStringWidth(*l); 421 int line_width = font.GetStringWidth(*l);
422 // Since we only break at word boundaries, it could happen that due to some 422 // Since we only break at word boundaries, it could happen that due to some
423 // very long word, line_width is greater than the available_width. In such 423 // very long word, line_width is greater than the available_width. In such
424 // case, we simply truncate at available_width and add ellipses at the end. 424 // case, we simply truncate at available_width and add ellipses at the end.
425 if (line_width > available_width) { 425 if (line_width > available_width) {
426 *width = available_width; 426 *width = available_width;
427 result.append(ui::ElideText(*l, font, available_width, ui::ELIDE_AT_END)); 427 result.append(gfx::ElideText(*l, font, available_width,
428 gfx::ELIDE_AT_END));
428 } else { 429 } else {
429 *width = std::max(*width, line_width); 430 *width = std::max(*width, line_width);
430 result.append(*l); 431 result.append(*l);
431 } 432 }
432 } 433 }
433 *text = result; 434 *text = result;
434 } 435 }
435 436
436 void TooltipController::TooltipTimerFired() { 437 void TooltipController::TooltipTimerFired() {
437 UpdateIfRequired(); 438 UpdateIfRequired();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 int TooltipController::GetTooltipShownTimeout() { 533 int TooltipController::GetTooltipShownTimeout() {
533 std::map<aura::Window*, int>::const_iterator it = 534 std::map<aura::Window*, int>::const_iterator it =
534 tooltip_shown_timeout_map_.find(tooltip_window_); 535 tooltip_shown_timeout_map_.find(tooltip_window_);
535 if (it == tooltip_shown_timeout_map_.end()) 536 if (it == tooltip_shown_timeout_map_.end())
536 return kDefaultTooltipShownTimeoutMs; 537 return kDefaultTooltipShownTimeoutMs;
537 return it->second; 538 return it->second;
538 } 539 }
539 540
540 } // namespace corewm 541 } // namespace corewm
541 } // namespace views 542 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/styled_label.cc ('k') | ui/views/corewm/tooltip_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698