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

Side by Side Diff: ui/message_center/views/bounded_label.cc

Issue 271773002: Retain popup bubble mouse status even through updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/message_center/views/bounded_label.h ('k') | ui/message_center/views/message_center_view.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 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/message_center/views/bounded_label.h" 5 #include "ui/message_center/views/bounded_label.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 25 matching lines...) Expand all
36 InnerBoundedLabel(const BoundedLabel& owner); 36 InnerBoundedLabel(const BoundedLabel& owner);
37 virtual ~InnerBoundedLabel(); 37 virtual ~InnerBoundedLabel();
38 38
39 void SetNativeTheme(const ui::NativeTheme* theme); 39 void SetNativeTheme(const ui::NativeTheme* theme);
40 40
41 // Pass in a -1 width to use the preferred width, a -1 limit to skip limits. 41 // Pass in a -1 width to use the preferred width, a -1 limit to skip limits.
42 int GetLinesForWidthAndLimit(int width, int limit); 42 int GetLinesForWidthAndLimit(int width, int limit);
43 gfx::Size GetSizeForWidthAndLines(int width, int lines); 43 gfx::Size GetSizeForWidthAndLines(int width, int lines);
44 std::vector<base::string16> GetWrappedText(int width, int lines); 44 std::vector<base::string16> GetWrappedText(int width, int lines);
45 45
46 // Overridden from views::Label.
47 virtual void SetText(const base::string16& text) OVERRIDE;
48
46 protected: 49 protected:
47 // Overridden from views::Label. 50 // Overridden from views::Label.
48 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; 51 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
49 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 52 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
50 53
51 private: 54 private:
52 int GetTextFlags(); 55 int GetTextFlags();
53 56
54 void ClearCaches(); 57 void ClearCaches();
55 int GetCachedLines(int width); 58 int GetCachedLines(int width);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 if (bounds.width() != wrapped_text_width_ || lines != wrapped_text_lines_) { 186 if (bounds.width() != wrapped_text_width_ || lines != wrapped_text_lines_) {
184 wrapped_text_ = JoinString(GetWrappedText(bounds.width(), lines), '\n'); 187 wrapped_text_ = JoinString(GetWrappedText(bounds.width(), lines), '\n');
185 wrapped_text_width_ = bounds.width(); 188 wrapped_text_width_ = bounds.width();
186 wrapped_text_lines_ = lines; 189 wrapped_text_lines_ = lines;
187 } 190 }
188 bounds.set_x(GetMirroredXForRect(bounds)); 191 bounds.set_x(GetMirroredXForRect(bounds));
189 PaintText(canvas, wrapped_text_, bounds, GetTextFlags()); 192 PaintText(canvas, wrapped_text_, bounds, GetTextFlags());
190 } 193 }
191 } 194 }
192 195
196 void InnerBoundedLabel::SetText(const base::string16& text) {
197 views::Label::SetText(text);
198 ClearCaches();
199 }
200
193 int InnerBoundedLabel::GetTextFlags() { 201 int InnerBoundedLabel::GetTextFlags() {
194 int flags = gfx::Canvas::MULTI_LINE | gfx::Canvas::CHARACTER_BREAK; 202 int flags = gfx::Canvas::MULTI_LINE | gfx::Canvas::CHARACTER_BREAK;
195 203
196 // We can't use subpixel rendering if the background is non-opaque. 204 // We can't use subpixel rendering if the background is non-opaque.
197 if (SkColorGetA(background_color()) != 0xFF) 205 if (SkColorGetA(background_color()) != 0xFF)
198 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; 206 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING;
199 207
200 if (directionality_mode() == 208 if (directionality_mode() ==
201 views::Label::AUTO_DETECT_DIRECTIONALITY) { 209 views::Label::AUTO_DETECT_DIRECTIONALITY) {
202 base::i18n::TextDirection direction = 210 base::i18n::TextDirection direction =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 294 }
287 295
288 void BoundedLabel::SetLineHeight(int height) { 296 void BoundedLabel::SetLineHeight(int height) {
289 label_->SetLineHeight(height); 297 label_->SetLineHeight(height);
290 } 298 }
291 299
292 void BoundedLabel::SetLineLimit(int lines) { 300 void BoundedLabel::SetLineLimit(int lines) {
293 line_limit_ = std::max(lines, -1); 301 line_limit_ = std::max(lines, -1);
294 } 302 }
295 303
304 void BoundedLabel::SetText(const base::string16& text) {
305 label_->SetText(text);
306 }
307
296 int BoundedLabel::GetLineHeight() const { 308 int BoundedLabel::GetLineHeight() const {
297 return label_->line_height(); 309 return label_->line_height();
298 } 310 }
299 311
300 int BoundedLabel::GetLineLimit() const { 312 int BoundedLabel::GetLineLimit() const {
301 return line_limit_; 313 return line_limit_;
302 } 314 }
303 315
304 int BoundedLabel::GetLinesForWidthAndLimit(int width, int limit) { 316 int BoundedLabel::GetLinesForWidthAndLimit(int width, int limit) {
305 return visible() ? label_->GetLinesForWidthAndLimit(width, limit) : 0; 317 return visible() ? label_->GetLinesForWidthAndLimit(width, limit) : 0;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 355
344 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { 356 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) {
345 label_->SetNativeTheme(theme); 357 label_->SetNativeTheme(theme);
346 } 358 }
347 359
348 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { 360 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) {
349 return JoinString(label_->GetWrappedText(width, lines), '\n'); 361 return JoinString(label_->GetWrappedText(width, lines), '\n');
350 } 362 }
351 363
352 } // namespace message_center 364 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/bounded_label.h ('k') | ui/message_center/views/message_center_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698