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/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" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 : controller_(controller), | 91 : controller_(controller), |
92 widget_(NULL) { | 92 widget_(NULL) { |
93 label_.set_background( | 93 label_.set_background( |
94 views::Background::CreateSolidBackground(kTooltipBackground)); | 94 views::Background::CreateSolidBackground(kTooltipBackground)); |
95 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDropShadows)) { | 95 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDropShadows)) { |
96 label_.set_border( | 96 label_.set_border( |
97 views::Border::CreateSolidBorder(kTooltipBorderWidth, | 97 views::Border::CreateSolidBorder(kTooltipBorderWidth, |
98 kTooltipBorder)); | 98 kTooltipBorder)); |
99 } | 99 } |
100 label_.set_owned_by_client(); | 100 label_.set_owned_by_client(); |
| 101 label_.SetMultiLine(true); |
101 } | 102 } |
102 | 103 |
103 virtual ~Tooltip() { | 104 virtual ~Tooltip() { |
104 if (widget_) { | 105 if (widget_) { |
105 widget_->RemoveObserver(this); | 106 widget_->RemoveObserver(this); |
106 widget_->Close(); | 107 widget_->Close(); |
107 } | 108 } |
108 } | 109 } |
109 | 110 |
110 // Updates the text on the tooltip and resizes to fit. | 111 // Updates the text on the tooltip and resizes to fit. |
111 void SetText(aura::Window* window, | 112 void SetText(aura::Window* window, |
112 const string16& tooltip_text, | 113 const string16& tooltip_text, |
113 const gfx::Point& location) { | 114 const gfx::Point& location) { |
114 int max_width, line_count; | 115 int max_width, line_count; |
115 string16 trimmed_text(tooltip_text); | 116 string16 trimmed_text(tooltip_text); |
116 controller_->TrimTooltipToFit( | 117 controller_->TrimTooltipToFit( |
117 controller_->GetMaxWidth(location), &trimmed_text, &max_width, | 118 controller_->GetMaxWidth(location), &trimmed_text, &max_width, |
118 &line_count); | 119 &line_count); |
119 label_.SetText(trimmed_text); | 120 label_.SetText(trimmed_text); |
120 | 121 |
121 int width = max_width + 2 * kTooltipHorizontalPadding; | 122 int width = max_width + 2 * kTooltipHorizontalPadding; |
122 int height = label_.GetPreferredSize().height() + | 123 int height = label_.GetHeightForWidth(max_width) + |
123 2 * kTooltipVerticalPadding; | 124 2 * kTooltipVerticalPadding; |
124 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDropShadows)) { | 125 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDropShadows)) { |
125 width += 2 * kTooltipBorderWidth; | 126 width += 2 * kTooltipBorderWidth; |
126 height += 2 * kTooltipBorderWidth; | 127 height += 2 * kTooltipBorderWidth; |
127 } | 128 } |
128 CreateWidgetIfNecessary(window); | 129 CreateWidgetIfNecessary(window); |
129 SetTooltipBounds(location, width, height); | 130 SetTooltipBounds(location, width, height); |
130 } | 131 } |
131 | 132 |
132 // Shows the tooltip. | 133 // Shows the tooltip. |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 if (!root) | 511 if (!root) |
511 return false; | 512 return false; |
512 aura::client::CursorClient* cursor_client = | 513 aura::client::CursorClient* cursor_client = |
513 aura::client::GetCursorClient(root); | 514 aura::client::GetCursorClient(root); |
514 // |cursor_client| may be NULL in tests, treat NULL as always visible. | 515 // |cursor_client| may be NULL in tests, treat NULL as always visible. |
515 return !cursor_client || cursor_client->IsCursorVisible(); | 516 return !cursor_client || cursor_client->IsCursorVisible(); |
516 } | 517 } |
517 | 518 |
518 } // namespace corewm | 519 } // namespace corewm |
519 } // namespace views | 520 } // namespace views |
OLD | NEW |