| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 // while adding NO_ELLIPSIS to the flags works on Windows for forcing | 285 // while adding NO_ELLIPSIS to the flags works on Windows for forcing |
| 286 // SizeStringInt() to calculate the desired width, it doesn't seem to work | 286 // SizeStringInt() to calculate the desired width, it doesn't seem to work |
| 287 // on Linux. | 287 // on Linux. |
| 288 int w = is_multi_line_ ? | 288 int w = is_multi_line_ ? |
| 289 GetAvailableRect().width() : std::numeric_limits<int>::max(); | 289 GetAvailableRect().width() : std::numeric_limits<int>::max(); |
| 290 int h = font_.GetHeight(); | 290 int h = font_.GetHeight(); |
| 291 // For single-line strings, ignore the available width and calculate how | 291 // For single-line strings, ignore the available width and calculate how |
| 292 // wide the text wants to be. | 292 // wide the text wants to be. |
| 293 int flags = ComputeMultiLineFlags(); | 293 int flags = ComputeMultiLineFlags(); |
| 294 if (!is_multi_line_) | 294 if (!is_multi_line_) |
| 295 flags |= gfx::Canvas::NO_ELLIPSIS; | 295 flags |= gfx::CanvasSkia::NO_ELLIPSIS; |
| 296 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags); | 296 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags); |
| 297 text_size_.SetSize(w, h); | 297 text_size_.SetSize(w, h); |
| 298 text_size_valid_ = true; | 298 text_size_valid_ = true; |
| 299 } | 299 } |
| 300 | 300 |
| 301 return text_size_; | 301 return text_size_; |
| 302 } | 302 } |
| 303 | 303 |
| 304 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 304 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 305 text_size_valid_ &= !is_multi_line_; | 305 text_size_valid_ &= !is_multi_line_; |
| 306 } | 306 } |
| 307 | 307 |
| 308 void Label::OnPaint(gfx::Canvas* canvas) { | 308 void Label::OnPaint(gfx::Canvas* canvas) { |
| 309 OnPaintBackground(canvas); | 309 OnPaintBackground(canvas); |
| 310 // We skip painting the focus border because it is being handled seperately by | 310 // We skip painting the focus border because it is being handled seperately by |
| 311 // some subclasses of Label. We do not want View's focus border painting to | 311 // some subclasses of Label. We do not want View's focus border painting to |
| 312 // interfere with that. | 312 // interfere with that. |
| 313 OnPaintBorder(canvas); | 313 OnPaintBorder(canvas); |
| 314 | 314 |
| 315 string16 paint_text; | 315 string16 paint_text; |
| 316 gfx::Rect text_bounds; | 316 gfx::Rect text_bounds; |
| 317 int flags = 0; | 317 int flags = 0; |
| 318 CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 318 CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 319 PaintText(canvas, paint_text, text_bounds, flags); | 319 PaintText(canvas, paint_text, text_bounds, flags); |
| 320 } | 320 } |
| 321 | 321 |
| 322 void Label::OnPaintBackground(gfx::Canvas* canvas) { | 322 void Label::OnPaintBackground(gfx::CanvasSkia* canvas) { |
| 323 const Background* bg = contains_mouse_ ? GetMouseOverBackground() : NULL; | 323 const Background* bg = contains_mouse_ ? GetMouseOverBackground() : NULL; |
| 324 if (!bg) | 324 if (!bg) |
| 325 bg = background(); | 325 bg = background(); |
| 326 if (bg) | 326 if (bg) |
| 327 bg->Paint(canvas, this); | 327 bg->Paint(canvas, this); |
| 328 } | 328 } |
| 329 | 329 |
| 330 // static | 330 // static |
| 331 gfx::Font Label::GetDefaultFont() { | 331 gfx::Font Label::GetDefaultFont() { |
| 332 return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); | 332 return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 } | 423 } |
| 424 text_origin.Offset(0, | 424 text_origin.Offset(0, |
| 425 std::max(0, (available_rect.height() - text_size.height())) / 2); | 425 std::max(0, (available_rect.height() - text_size.height())) / 2); |
| 426 return gfx::Rect(text_origin, text_size); | 426 return gfx::Rect(text_origin, text_size); |
| 427 } | 427 } |
| 428 | 428 |
| 429 int Label::ComputeMultiLineFlags() const { | 429 int Label::ComputeMultiLineFlags() const { |
| 430 if (!is_multi_line_) | 430 if (!is_multi_line_) |
| 431 return 0; | 431 return 0; |
| 432 | 432 |
| 433 int flags = gfx::Canvas::MULTI_LINE; | 433 int flags = gfx::CanvasSkia::MULTI_LINE; |
| 434 #if !defined(OS_WIN) | 434 #if !defined(OS_WIN) |
| 435 // Don't elide multiline labels on Linux. | 435 // Don't elide multiline labels on Linux. |
| 436 // Todo(davemoore): Do we depend on eliding multiline text? | 436 // Todo(davemoore): Do we depend on eliding multiline text? |
| 437 // Pango insists on limiting the number of lines to one if text is | 437 // Pango insists on limiting the number of lines to one if text is |
| 438 // elided. You can get around this if you can pass a maximum height | 438 // elided. You can get around this if you can pass a maximum height |
| 439 // but we don't currently have that data when we call the pango code. | 439 // but we don't currently have that data when we call the pango code. |
| 440 flags |= gfx::Canvas::NO_ELLIPSIS; | 440 flags |= gfx::CanvasSkia::NO_ELLIPSIS; |
| 441 #endif | 441 #endif |
| 442 if (allow_character_break_) | 442 if (allow_character_break_) |
| 443 flags |= gfx::Canvas::CHARACTER_BREAK; | 443 flags |= gfx::CanvasSkia::CHARACTER_BREAK; |
| 444 switch (horiz_alignment_) { | 444 switch (horiz_alignment_) { |
| 445 case ALIGN_LEFT: | 445 case ALIGN_LEFT: |
| 446 flags |= gfx::Canvas::TEXT_ALIGN_LEFT; | 446 flags |= gfx::CanvasSkia::TEXT_ALIGN_LEFT; |
| 447 break; | 447 break; |
| 448 case ALIGN_CENTER: | 448 case ALIGN_CENTER: |
| 449 flags |= gfx::Canvas::TEXT_ALIGN_CENTER; | 449 flags |= gfx::CanvasSkia::TEXT_ALIGN_CENTER; |
| 450 break; | 450 break; |
| 451 case ALIGN_RIGHT: | 451 case ALIGN_RIGHT: |
| 452 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; | 452 flags |= gfx::CanvasSkia::TEXT_ALIGN_RIGHT; |
| 453 break; | 453 break; |
| 454 } | 454 } |
| 455 return flags; | 455 return flags; |
| 456 } | 456 } |
| 457 | 457 |
| 458 gfx::Rect Label::GetAvailableRect() const { | 458 gfx::Rect Label::GetAvailableRect() const { |
| 459 gfx::Rect bounds(gfx::Point(), size()); | 459 gfx::Rect bounds(gfx::Point(), size()); |
| 460 gfx::Insets insets(GetInsets()); | 460 gfx::Insets insets(GetInsets()); |
| 461 bounds.Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); | 461 bounds.Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); |
| 462 return bounds; | 462 return bounds; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 491 *paint_text = text_; | 491 *paint_text = text_; |
| 492 } | 492 } |
| 493 | 493 |
| 494 *text_bounds = GetTextBounds(); | 494 *text_bounds = GetTextBounds(); |
| 495 *flags = ComputeMultiLineFlags(); | 495 *flags = ComputeMultiLineFlags(); |
| 496 | 496 |
| 497 if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) { | 497 if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) { |
| 498 base::i18n::TextDirection direction = | 498 base::i18n::TextDirection direction = |
| 499 base::i18n::GetFirstStrongCharacterDirection(GetText()); | 499 base::i18n::GetFirstStrongCharacterDirection(GetText()); |
| 500 if (direction == base::i18n::RIGHT_TO_LEFT) | 500 if (direction == base::i18n::RIGHT_TO_LEFT) |
| 501 *flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY; | 501 *flags |= gfx::CanvasSkia::FORCE_RTL_DIRECTIONALITY; |
| 502 else | 502 else |
| 503 *flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | 503 *flags |= gfx::CanvasSkia::FORCE_LTR_DIRECTIONALITY; |
| 504 } | 504 } |
| 505 } | 505 } |
| 506 | 506 |
| 507 } // namespace views | 507 } // namespace views |
| OLD | NEW |