OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "chrome/browser/views/tabs/tab_renderer.h" | 7 #include "chrome/browser/views/tabs/tab_renderer.h" |
8 | 8 |
9 #include "base/gfx/image_operations.h" | 9 #include "base/gfx/image_operations.h" |
10 #include "chrome/app/theme/theme_resources.h" | 10 #include "chrome/app/theme/theme_resources.h" |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 pulse_animation_->Reset(); | 323 pulse_animation_->Reset(); |
324 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); | 324 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); |
325 } | 325 } |
326 | 326 |
327 void TabRenderer::StopPulse() { | 327 void TabRenderer::StopPulse() { |
328 if (pulse_animation_->IsAnimating()) | 328 if (pulse_animation_->IsAnimating()) |
329 pulse_animation_->Stop(); | 329 pulse_animation_->Stop(); |
330 } | 330 } |
331 | 331 |
332 // static | 332 // static |
333 gfx::Size TabRenderer::GetMinimumSize() { | 333 gfx::Size TabRenderer::GetMinimumUnselectedSize() { |
334 InitResources(); | 334 InitResources(); |
335 | 335 |
336 gfx::Size minimum_size; | 336 gfx::Size minimum_size; |
337 minimum_size.set_width(kLeftPadding + kRightPadding); | 337 minimum_size.set_width(kLeftPadding + kRightPadding); |
338 // Since we use bitmap images, the real minimum height of the image is | 338 // Since we use bitmap images, the real minimum height of the image is |
339 // defined most accurately by the height of the end cap images. | 339 // defined most accurately by the height of the end cap images. |
340 minimum_size.set_height(tab_active_l->height()); | 340 minimum_size.set_height(tab_active_l->height()); |
341 return minimum_size; | 341 return minimum_size; |
342 } | 342 } |
343 | 343 |
344 // static | 344 // static |
345 gfx::Size TabRenderer::GetMinimumSelectedSize() { | 345 gfx::Size TabRenderer::GetMinimumSelectedSize() { |
346 gfx::Size minimum_size = GetMinimumSize(); | 346 gfx::Size minimum_size = GetMinimumUnselectedSize(); |
347 minimum_size.set_width(kLeftPadding + kFaviconSize + kRightPadding); | 347 minimum_size.set_width(kLeftPadding + kFaviconSize + kRightPadding); |
348 return minimum_size; | 348 return minimum_size; |
349 } | 349 } |
350 | 350 |
351 // static | 351 // static |
352 gfx::Size TabRenderer::GetStandardSize() { | 352 gfx::Size TabRenderer::GetStandardSize() { |
353 gfx::Size standard_size = GetMinimumSize(); | 353 gfx::Size standard_size = GetMinimumUnselectedSize(); |
354 standard_size.set_width( | 354 standard_size.set_width( |
355 standard_size.width() + kFavIconTitleSpacing + kStandardTitleWidth); | 355 standard_size.width() + kFavIconTitleSpacing + kStandardTitleWidth); |
356 return standard_size; | 356 return standard_size; |
357 } | 357 } |
358 | 358 |
359 //////////////////////////////////////////////////////////////////////////////// | 359 //////////////////////////////////////////////////////////////////////////////// |
360 // TabRenderer, protected: | 360 // TabRenderer, protected: |
361 | 361 |
362 std::wstring TabRenderer::GetTitle() const { | 362 std::wstring TabRenderer::GetTitle() const { |
363 return data_.title; | 363 return data_.title; |
364 } | 364 } |
365 | 365 |
366 //////////////////////////////////////////////////////////////////////////////// | 366 //////////////////////////////////////////////////////////////////////////////// |
367 // TabRenderer, ChromeViews::View overrides: | 367 // TabRenderer, ChromeViews::View overrides: |
368 | 368 |
369 void TabRenderer::Paint(ChromeCanvas* canvas) { | 369 void TabRenderer::Paint(ChromeCanvas* canvas) { |
370 // Don't paint if we're narrower than we can render correctly. (This should | 370 // Don't paint if we're narrower than we can render correctly. (This should |
371 // only happen during animations). | 371 // only happen during animations). |
372 if (width() < GetMinimumSize().width()) | 372 if (width() < GetMinimumUnselectedSize().width()) |
373 return; | 373 return; |
374 | 374 |
375 // See if the model changes whether the icons should be painted. | 375 // See if the model changes whether the icons should be painted. |
376 const bool show_icon = ShouldShowIcon(); | 376 const bool show_icon = ShouldShowIcon(); |
377 const bool show_download_icon = data_.show_download_icon; | 377 const bool show_download_icon = data_.show_download_icon; |
378 const bool show_close_button = ShouldShowCloseBox(); | 378 const bool show_close_button = ShouldShowCloseBox(); |
379 if (show_icon != showing_icon_ || | 379 if (show_icon != showing_icon_ || |
380 show_download_icon != showing_download_icon_ || | 380 show_download_icon != showing_download_icon_ || |
381 show_close_button != showing_close_button_) | 381 show_close_button != showing_close_button_) |
382 Layout(); | 382 Layout(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 close_button_->SetVisible(false); | 485 close_button_->SetVisible(false); |
486 } | 486 } |
487 | 487 |
488 // Size the Title text to fill the remaining space. | 488 // Size the Title text to fill the remaining space. |
489 int title_left = favicon_bounds_.right() + kFavIconTitleSpacing; | 489 int title_left = favicon_bounds_.right() + kFavIconTitleSpacing; |
490 int title_top = kTopPadding + (content_height - title_font_height) / 2; | 490 int title_top = kTopPadding + (content_height - title_font_height) / 2; |
491 | 491 |
492 // If the user has big fonts, the title will appear rendered too far down on | 492 // If the user has big fonts, the title will appear rendered too far down on |
493 // the y-axis if we use the regular top padding, so we need to adjust it so | 493 // the y-axis if we use the regular top padding, so we need to adjust it so |
494 // that the text appears centered. | 494 // that the text appears centered. |
495 gfx::Size minimum_size = GetMinimumSize(); | 495 gfx::Size minimum_size = GetMinimumUnselectedSize(); |
496 int text_height = title_top + title_font_height + kBottomPadding; | 496 int text_height = title_top + title_font_height + kBottomPadding; |
497 if (text_height > minimum_size.height()) | 497 if (text_height > minimum_size.height()) |
498 title_top -= (text_height - minimum_size.height()) / 2; | 498 title_top -= (text_height - minimum_size.height()) / 2; |
499 | 499 |
500 int title_width; | 500 int title_width; |
501 if (close_button_->IsVisible()) { | 501 if (close_button_->IsVisible()) { |
502 title_width = std::max(close_button_->x() - | 502 title_width = std::max(close_button_->x() - |
503 kTitleCloseButtonSpacing - title_left, 0); | 503 kTitleCloseButtonSpacing - title_left, 0); |
504 } else { | 504 } else { |
505 title_width = std::max(lb.Width() - title_left, 0); | 505 title_width = std::max(lb.Width() - title_left, 0); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 dst_x = width() - kLeftPadding - image_size; | 628 dst_x = width() - kLeftPadding - image_size; |
629 } else { | 629 } else { |
630 dst_x = kLeftPadding; | 630 dst_x = kLeftPadding; |
631 } | 631 } |
632 canvas->DrawBitmapInt(*frames, image_offset, 0, image_size, | 632 canvas->DrawBitmapInt(*frames, image_offset, 0, image_size, |
633 image_size, dst_x, dst_y, image_size, image_size, | 633 image_size, dst_x, dst_y, image_size, image_size, |
634 false); | 634 false); |
635 } | 635 } |
636 | 636 |
637 int TabRenderer::IconCapacity() const { | 637 int TabRenderer::IconCapacity() const { |
638 if (height() < GetMinimumSize().height()) { | 638 if (height() < GetMinimumUnselectedSize().height()) |
639 return 0; | 639 return 0; |
640 } | |
641 return (width() - kLeftPadding - kRightPadding) / kFaviconSize; | 640 return (width() - kLeftPadding - kRightPadding) / kFaviconSize; |
642 } | 641 } |
643 | 642 |
644 bool TabRenderer::ShouldShowIcon() const { | 643 bool TabRenderer::ShouldShowIcon() const { |
645 if (!data_.show_icon) { | 644 if (!data_.show_icon) { |
646 return false; | 645 return false; |
647 } else if (IsSelected()) { | 646 } else if (IsSelected()) { |
648 // The selected tab clips favicon before close button. | 647 // The selected tab clips favicon before close button. |
649 return IconCapacity() >= 2; | 648 return IconCapacity() >= 2; |
650 } | 649 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 } | 682 } |
684 | 683 |
685 void TabRenderer::DisplayCrashedFavIcon() { | 684 void TabRenderer::DisplayCrashedFavIcon() { |
686 should_display_crashed_favicon_ = true; | 685 should_display_crashed_favicon_ = true; |
687 } | 686 } |
688 | 687 |
689 void TabRenderer::ResetCrashedFavIcon() { | 688 void TabRenderer::ResetCrashedFavIcon() { |
690 should_display_crashed_favicon_ = false; | 689 should_display_crashed_favicon_ = false; |
691 } | 690 } |
692 | 691 |
OLD | NEW |