| 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 "chrome/browser/views/tabs/tab_renderer.h" | 5 #include "chrome/browser/views/tabs/tab_renderer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
| 10 #include "app/gfx/font.h" | 10 #include "app/gfx/font.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // How long the pulse throb takes. | 47 // How long the pulse throb takes. |
| 48 static const int kPulseDurationMs = 200; | 48 static const int kPulseDurationMs = 200; |
| 49 | 49 |
| 50 // How opaque to make the hover state (out of 1). | 50 // How opaque to make the hover state (out of 1). |
| 51 static const double kHoverOpacity = 0.33; | 51 static const double kHoverOpacity = 0.33; |
| 52 | 52 |
| 53 // TODO(beng): (Cleanup) This stuff should move onto the class. | 53 // TODO(beng): (Cleanup) This stuff should move onto the class. |
| 54 static gfx::Font* title_font = NULL; | 54 static gfx::Font* title_font = NULL; |
| 55 static int title_font_height = 0; | 55 static int title_font_height = 0; |
| 56 static SkBitmap* close_button_n = NULL; | 56 static SkBitmap* close_button_n = NULL; |
| 57 static SkBitmap* close_button_m = NULL; |
| 57 static SkBitmap* close_button_h = NULL; | 58 static SkBitmap* close_button_h = NULL; |
| 58 static SkBitmap* close_button_p = NULL; | 59 static SkBitmap* close_button_p = NULL; |
| 59 static int close_button_height = 0; | 60 static int close_button_height = 0; |
| 60 static int close_button_width = 0; | 61 static int close_button_width = 0; |
| 61 | 62 |
| 62 static SkBitmap* waiting_animation_frames = NULL; | 63 static SkBitmap* waiting_animation_frames = NULL; |
| 63 static SkBitmap* loading_animation_frames = NULL; | 64 static SkBitmap* loading_animation_frames = NULL; |
| 64 static SkBitmap* crashed_fav_icon = NULL; | 65 static SkBitmap* crashed_fav_icon = NULL; |
| 65 static int loading_animation_frame_count = 0; | 66 static int loading_animation_frame_count = 0; |
| 66 static int waiting_animation_frame_count = 0; | 67 static int waiting_animation_frame_count = 0; |
| 67 static int waiting_to_loading_frame_count_ratio = 0; | 68 static int waiting_to_loading_frame_count_ratio = 0; |
| 68 | 69 |
| 69 TabRenderer::TabImage TabRenderer::tab_alpha = {0}; | 70 TabRenderer::TabImage TabRenderer::tab_alpha = {0}; |
| 70 TabRenderer::TabImage TabRenderer::tab_active = {0}; | 71 TabRenderer::TabImage TabRenderer::tab_active = {0}; |
| 71 TabRenderer::TabImage TabRenderer::tab_inactive = {0}; | 72 TabRenderer::TabImage TabRenderer::tab_inactive = {0}; |
| 72 | 73 |
| 73 namespace { | 74 namespace { |
| 74 | 75 |
| 75 void InitResources() { | 76 void InitResources() { |
| 76 static bool initialized = false; | 77 static bool initialized = false; |
| 77 if (!initialized) { | 78 if (!initialized) { |
| 78 // TODO(glen): Allow theming of these. | 79 // TODO(glen): Allow theming of these. |
| 79 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 80 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 80 title_font = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); | 81 title_font = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); |
| 81 title_font_height = title_font->height(); | 82 title_font_height = title_font->height(); |
| 82 | 83 |
| 83 close_button_n = rb.GetBitmapNamed(IDR_TAB_CLOSE); | 84 close_button_n = rb.GetBitmapNamed(IDR_TAB_CLOSE); |
| 85 close_button_m = rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK); |
| 84 close_button_h = rb.GetBitmapNamed(IDR_TAB_CLOSE_H); | 86 close_button_h = rb.GetBitmapNamed(IDR_TAB_CLOSE_H); |
| 85 close_button_p = rb.GetBitmapNamed(IDR_TAB_CLOSE_P); | 87 close_button_p = rb.GetBitmapNamed(IDR_TAB_CLOSE_P); |
| 86 close_button_width = close_button_n->width(); | 88 close_button_width = close_button_n->width(); |
| 87 close_button_height = close_button_n->height(); | 89 close_button_height = close_button_n->height(); |
| 88 | 90 |
| 89 TabRenderer::LoadTabImages(); | 91 TabRenderer::LoadTabImages(); |
| 90 | 92 |
| 91 // The loading animation image is a strip of states. Each state must be | 93 // The loading animation image is a strip of states. Each state must be |
| 92 // square, so the height must divide the width evenly. | 94 // square, so the height must divide the width evenly. |
| 93 loading_animation_frames = rb.GetBitmapNamed(IDR_THROBBER); | 95 loading_animation_frames = rb.GetBitmapNamed(IDR_THROBBER); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 227 |
| 226 //////////////////////////////////////////////////////////////////////////////// | 228 //////////////////////////////////////////////////////////////////////////////// |
| 227 // TabRenderer, public: | 229 // TabRenderer, public: |
| 228 | 230 |
| 229 TabRenderer::TabRenderer() | 231 TabRenderer::TabRenderer() |
| 230 : animation_state_(ANIMATION_NONE), | 232 : animation_state_(ANIMATION_NONE), |
| 231 animation_frame_(0), | 233 animation_frame_(0), |
| 232 showing_icon_(false), | 234 showing_icon_(false), |
| 233 showing_close_button_(false), | 235 showing_close_button_(false), |
| 234 fav_icon_hiding_offset_(0), | 236 fav_icon_hiding_offset_(0), |
| 237 close_button_color_(NULL), |
| 235 crash_animation_(NULL), | 238 crash_animation_(NULL), |
| 236 should_display_crashed_favicon_(false), | 239 should_display_crashed_favicon_(false), |
| 237 theme_provider_(NULL) { | 240 theme_provider_(NULL) { |
| 238 InitResources(); | 241 InitResources(); |
| 239 | 242 |
| 240 // Add the Close Button. | 243 // Add the Close Button. |
| 241 close_button_ = new TabCloseButton(this); | 244 close_button_ = new TabCloseButton(this); |
| 242 close_button_->SetImage(views::CustomButton::BS_NORMAL, close_button_n); | 245 close_button_->SetImage(views::CustomButton::BS_NORMAL, close_button_n); |
| 243 close_button_->SetImage(views::CustomButton::BS_HOT, close_button_h); | 246 close_button_->SetImage(views::CustomButton::BS_HOT, close_button_h); |
| 244 close_button_->SetImage(views::CustomButton::BS_PUSHED, close_button_p); | 247 close_button_->SetImage(views::CustomButton::BS_PUSHED, close_button_p); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 // Size the Close button. | 477 // Size the Close button. |
| 475 showing_close_button_ = ShouldShowCloseBox(); | 478 showing_close_button_ = ShouldShowCloseBox(); |
| 476 if (showing_close_button_) { | 479 if (showing_close_button_) { |
| 477 int close_button_top = | 480 int close_button_top = |
| 478 kTopPadding + kCloseButtonVertFuzz + | 481 kTopPadding + kCloseButtonVertFuzz + |
| 479 (content_height - close_button_height) / 2; | 482 (content_height - close_button_height) / 2; |
| 480 // If the ratio of the close button size to tab width exceeds the maximum. | 483 // If the ratio of the close button size to tab width exceeds the maximum. |
| 481 close_button_->SetBounds(lb.width() + kCloseButtonHorzFuzz, | 484 close_button_->SetBounds(lb.width() + kCloseButtonHorzFuzz, |
| 482 close_button_top, close_button_width, | 485 close_button_top, close_button_width, |
| 483 close_button_height); | 486 close_button_height); |
| 487 |
| 488 // If the close button color has changed, generate a new one. |
| 489 SkColor tab_text_color = |
| 490 GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_TAB_TEXT); |
| 491 if (!close_button_color_ || tab_text_color != close_button_color_) { |
| 492 close_button_color_ = tab_text_color; |
| 493 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 494 close_button_->SetBackground(close_button_color_, |
| 495 rb.GetBitmapNamed(IDR_TAB_CLOSE), |
| 496 rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK)); |
| 497 } |
| 498 |
| 484 close_button_->SetVisible(true); | 499 close_button_->SetVisible(true); |
| 485 } else { | 500 } else { |
| 486 close_button_->SetBounds(0, 0, 0, 0); | 501 close_button_->SetBounds(0, 0, 0, 0); |
| 487 close_button_->SetVisible(false); | 502 close_button_->SetVisible(false); |
| 488 } | 503 } |
| 489 | 504 |
| 490 // Size the Title text to fill the remaining space. | 505 // Size the Title text to fill the remaining space. |
| 491 int title_left = favicon_bounds_.right() + kFavIconTitleSpacing; | 506 int title_left = favicon_bounds_.right() + kFavIconTitleSpacing; |
| 492 int title_top = kTopPadding + (content_height - title_font_height) / 2; | 507 int title_top = kTopPadding + (content_height - title_font_height) / 2; |
| 493 | 508 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 tab_inactive.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); | 810 tab_inactive.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); |
| 796 tab_inactive.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); | 811 tab_inactive.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); |
| 797 tab_inactive.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); | 812 tab_inactive.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); |
| 798 | 813 |
| 799 tab_inactive.l_width = tab_inactive.image_l->width(); | 814 tab_inactive.l_width = tab_inactive.image_l->width(); |
| 800 tab_inactive.r_width = tab_inactive.image_r->width(); | 815 tab_inactive.r_width = tab_inactive.image_r->width(); |
| 801 | 816 |
| 802 loading_animation_frames = rb.GetBitmapNamed(IDR_THROBBER); | 817 loading_animation_frames = rb.GetBitmapNamed(IDR_THROBBER); |
| 803 waiting_animation_frames = rb.GetBitmapNamed(IDR_THROBBER_WAITING); | 818 waiting_animation_frames = rb.GetBitmapNamed(IDR_THROBBER_WAITING); |
| 804 } | 819 } |
| OLD | NEW |