| 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 "chrome/browser/ui/views/tabs/base_tab.h" | 5 #include "chrome/browser/ui/views/tabs/base_tab.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 private: | 86 private: |
| 87 BaseTab* tab_; | 87 BaseTab* tab_; |
| 88 | 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(TabCloseButton); | 89 DISALLOW_COPY_AND_ASSIGN(TabCloseButton); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 namespace { | 92 namespace { |
| 93 | 93 |
| 94 // Draws the icon image at the center of |bounds|. | 94 // Draws the icon image at the center of |bounds|. |
| 95 void DrawIconCenter(gfx::Canvas* canvas, | 95 void DrawIconCenter(gfx::Canvas* canvas, |
| 96 const SkBitmap& image, | 96 const gfx::ImageSkia& image, |
| 97 int image_offset, | 97 int image_offset, |
| 98 int icon_width, | 98 int icon_width, |
| 99 int icon_height, | 99 int icon_height, |
| 100 const gfx::Rect& bounds, | 100 const gfx::Rect& bounds, |
| 101 bool filter) { | 101 bool filter) { |
| 102 // Center the image within bounds. | 102 // Center the image within bounds. |
| 103 int dst_x = bounds.x() - (icon_width - bounds.width()) / 2; | 103 int dst_x = bounds.x() - (icon_width - bounds.width()) / 2; |
| 104 int dst_y = bounds.y() - (icon_height - bounds.height()) / 2; | 104 int dst_y = bounds.y() - (icon_height - bounds.height()) / 2; |
| 105 // NOTE: the clipping is a work around for 69528, it shouldn't be necessary. | 105 // NOTE: the clipping is a work around for 69528, it shouldn't be necessary. |
| 106 canvas->Save(); | 106 canvas->Save(); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 415 |
| 416 void BaseTab::AdvanceLoadingAnimation(TabRendererData::NetworkState old_state, | 416 void BaseTab::AdvanceLoadingAnimation(TabRendererData::NetworkState old_state, |
| 417 TabRendererData::NetworkState state) { | 417 TabRendererData::NetworkState state) { |
| 418 static bool initialized = false; | 418 static bool initialized = false; |
| 419 static int loading_animation_frame_count = 0; | 419 static int loading_animation_frame_count = 0; |
| 420 static int waiting_animation_frame_count = 0; | 420 static int waiting_animation_frame_count = 0; |
| 421 static int waiting_to_loading_frame_count_ratio = 0; | 421 static int waiting_to_loading_frame_count_ratio = 0; |
| 422 if (!initialized) { | 422 if (!initialized) { |
| 423 initialized = true; | 423 initialized = true; |
| 424 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 424 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 425 SkBitmap loading_animation(*rb.GetBitmapNamed(IDR_THROBBER)); | 425 gfx::ImageSkia loading_animation(*rb.GetImageSkiaNamed(IDR_THROBBER)); |
| 426 loading_animation_frame_count = | 426 loading_animation_frame_count = |
| 427 loading_animation.width() / loading_animation.height(); | 427 loading_animation.width() / loading_animation.height(); |
| 428 SkBitmap waiting_animation(*rb.GetBitmapNamed(IDR_THROBBER_WAITING)); | 428 gfx::ImageSkia waiting_animation(*rb.GetImageSkiaNamed( |
| 429 IDR_THROBBER_WAITING)); |
| 429 waiting_animation_frame_count = | 430 waiting_animation_frame_count = |
| 430 waiting_animation.width() / waiting_animation.height(); | 431 waiting_animation.width() / waiting_animation.height(); |
| 431 waiting_to_loading_frame_count_ratio = | 432 waiting_to_loading_frame_count_ratio = |
| 432 waiting_animation_frame_count / loading_animation_frame_count; | 433 waiting_animation_frame_count / loading_animation_frame_count; |
| 433 } | 434 } |
| 434 | 435 |
| 435 // The waiting animation is the reverse of the loading animation, but at a | 436 // The waiting animation is the reverse of the loading animation, but at a |
| 436 // different rate - the following reverses and scales the animation_frame_ | 437 // different rate - the following reverses and scales the animation_frame_ |
| 437 // so that the frame is at an equivalent position when going from one | 438 // so that the frame is at an equivalent position when going from one |
| 438 // animation to the other. | 439 // animation to the other. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 453 | 454 |
| 454 void BaseTab::PaintIcon(gfx::Canvas* canvas) { | 455 void BaseTab::PaintIcon(gfx::Canvas* canvas) { |
| 455 gfx::Rect bounds = GetIconBounds(); | 456 gfx::Rect bounds = GetIconBounds(); |
| 456 if (bounds.IsEmpty()) | 457 if (bounds.IsEmpty()) |
| 457 return; | 458 return; |
| 458 | 459 |
| 459 bounds.set_x(GetMirroredXForRect(bounds)); | 460 bounds.set_x(GetMirroredXForRect(bounds)); |
| 460 | 461 |
| 461 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { | 462 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { |
| 462 ui::ThemeProvider* tp = GetThemeProvider(); | 463 ui::ThemeProvider* tp = GetThemeProvider(); |
| 463 SkBitmap frames(*tp->GetBitmapNamed( | 464 gfx::ImageSkia frames(*tp->GetImageSkiaNamed( |
| 464 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? | 465 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? |
| 465 IDR_THROBBER_WAITING : IDR_THROBBER)); | 466 IDR_THROBBER_WAITING : IDR_THROBBER)); |
| 466 | 467 |
| 467 int icon_size = frames.height(); | 468 int icon_size = frames.height(); |
| 468 int image_offset = loading_animation_frame_ * icon_size; | 469 int image_offset = loading_animation_frame_ * icon_size; |
| 469 DrawIconCenter(canvas, frames, image_offset, | 470 DrawIconCenter(canvas, frames, image_offset, |
| 470 icon_size, icon_size, bounds, false); | 471 icon_size, icon_size, bounds, false); |
| 471 } else { | 472 } else { |
| 472 canvas->Save(); | 473 canvas->Save(); |
| 473 canvas->ClipRect(GetLocalBounds()); | 474 canvas->ClipRect(GetLocalBounds()); |
| 474 if (should_display_crashed_favicon_) { | 475 if (should_display_crashed_favicon_) { |
| 475 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 476 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 476 SkBitmap crashed_favicon(*rb.GetBitmapNamed(IDR_SAD_FAVICON)); | 477 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON)); |
| 477 bounds.set_y(bounds.y() + favicon_hiding_offset_); | 478 bounds.set_y(bounds.y() + favicon_hiding_offset_); |
| 478 DrawIconCenter(canvas, crashed_favicon, 0, | 479 DrawIconCenter(canvas, crashed_favicon, 0, |
| 479 crashed_favicon.width(), | 480 crashed_favicon.width(), |
| 480 crashed_favicon.height(), bounds, true); | 481 crashed_favicon.height(), bounds, true); |
| 481 } else { | 482 } else { |
| 482 if (!data().favicon.isNull()) { | 483 if (!data().favicon.isNull()) { |
| 483 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch | 484 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch |
| 484 // to using that class to render the favicon). | 485 // to using that class to render the favicon). |
| 485 DrawIconCenter(canvas, data().favicon, 0, | 486 DrawIconCenter(canvas, data().favicon, 0, |
| 486 data().favicon.width(), | 487 data().favicon.width(), |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 // static | 601 // static |
| 601 void BaseTab::InitResources() { | 602 void BaseTab::InitResources() { |
| 602 static bool initialized = false; | 603 static bool initialized = false; |
| 603 if (!initialized) { | 604 if (!initialized) { |
| 604 initialized = true; | 605 initialized = true; |
| 605 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 606 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 606 font_ = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); | 607 font_ = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); |
| 607 font_height_ = font_->GetHeight(); | 608 font_height_ = font_->GetHeight(); |
| 608 } | 609 } |
| 609 } | 610 } |
| OLD | NEW |