| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/tabs/tab_renderer_gtk.h" | 5 #include "chrome/browser/gtk/tabs/tab_renderer_gtk.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/browser_theme_provider.h" | 10 #include "chrome/browser/browser_theme_provider.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 } // namespace | 85 } // namespace |
| 86 | 86 |
| 87 bool TabRendererGtk::initialized_ = false; | 87 bool TabRendererGtk::initialized_ = false; |
| 88 TabRendererGtk::TabImage TabRendererGtk::tab_active_ = {0}; | 88 TabRendererGtk::TabImage TabRendererGtk::tab_active_ = {0}; |
| 89 TabRendererGtk::TabImage TabRendererGtk::tab_inactive_ = {0}; | 89 TabRendererGtk::TabImage TabRendererGtk::tab_inactive_ = {0}; |
| 90 TabRendererGtk::TabImage TabRendererGtk::tab_alpha = {0}; | 90 TabRendererGtk::TabImage TabRendererGtk::tab_alpha = {0}; |
| 91 TabRendererGtk::TabImage TabRendererGtk::tab_hover_ = {0}; | 91 TabRendererGtk::TabImage TabRendererGtk::tab_hover_ = {0}; |
| 92 gfx::Font* TabRendererGtk::title_font_ = NULL; | 92 gfx::Font* TabRendererGtk::title_font_ = NULL; |
| 93 int TabRendererGtk::title_font_height_ = 0; | 93 int TabRendererGtk::title_font_height_ = 0; |
| 94 SkBitmap* TabRendererGtk::download_icon_ = NULL; | |
| 95 int TabRendererGtk::download_icon_width_ = 0; | |
| 96 int TabRendererGtk::download_icon_height_ = 0; | |
| 97 int TabRendererGtk::close_button_width_ = 0; | 94 int TabRendererGtk::close_button_width_ = 0; |
| 98 int TabRendererGtk::close_button_height_ = 0; | 95 int TabRendererGtk::close_button_height_ = 0; |
| 99 | 96 |
| 100 //////////////////////////////////////////////////////////////////////////////// | 97 //////////////////////////////////////////////////////////////////////////////// |
| 101 // TabRendererGtk::LoadingAnimation, public: | 98 // TabRendererGtk::LoadingAnimation, public: |
| 102 // | 99 // |
| 103 TabRendererGtk::LoadingAnimation::LoadingAnimation(const Data* data) | 100 TabRendererGtk::LoadingAnimation::LoadingAnimation(const Data* data) |
| 104 : data_(data), animation_state_(ANIMATION_NONE), animation_frame_(0) { | 101 : data_(data), animation_state_(ANIMATION_NONE), animation_frame_(0) { |
| 105 } | 102 } |
| 106 | 103 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 TabRendererGtk* target_; | 163 TabRendererGtk* target_; |
| 167 | 164 |
| 168 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation); | 165 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation); |
| 169 }; | 166 }; |
| 170 | 167 |
| 171 //////////////////////////////////////////////////////////////////////////////// | 168 //////////////////////////////////////////////////////////////////////////////// |
| 172 // TabRendererGtk, public: | 169 // TabRendererGtk, public: |
| 173 | 170 |
| 174 TabRendererGtk::TabRendererGtk() | 171 TabRendererGtk::TabRendererGtk() |
| 175 : showing_icon_(false), | 172 : showing_icon_(false), |
| 176 showing_download_icon_(false), | |
| 177 showing_close_button_(false), | 173 showing_close_button_(false), |
| 178 fav_icon_hiding_offset_(0), | 174 fav_icon_hiding_offset_(0), |
| 179 should_display_crashed_favicon_(false), | 175 should_display_crashed_favicon_(false), |
| 180 loading_animation_(&loading_animation_data) { | 176 loading_animation_(&loading_animation_data) { |
| 181 InitResources(); | 177 InitResources(); |
| 182 | 178 |
| 183 tab_.Own(gtk_fixed_new()); | 179 tab_.Own(gtk_fixed_new()); |
| 184 gtk_widget_set_app_paintable(tab_.get(), TRUE); | 180 gtk_widget_set_app_paintable(tab_.get(), TRUE); |
| 185 g_signal_connect(G_OBJECT(tab_.get()), "expose-event", | 181 g_signal_connect(G_OBJECT(tab_.get()), "expose-event", |
| 186 G_CALLBACK(OnExpose), this); | 182 G_CALLBACK(OnExpose), this); |
| 187 close_button_.reset(MakeCloseButton()); | 183 close_button_.reset(MakeCloseButton()); |
| 188 gtk_widget_show(tab_.get()); | 184 gtk_widget_show(tab_.get()); |
| 189 | 185 |
| 190 hover_animation_.reset(new SlideAnimation(this)); | 186 hover_animation_.reset(new SlideAnimation(this)); |
| 191 hover_animation_->SetSlideDuration(kHoverDurationMs); | 187 hover_animation_->SetSlideDuration(kHoverDurationMs); |
| 192 } | 188 } |
| 193 | 189 |
| 194 TabRendererGtk::~TabRendererGtk() { | 190 TabRendererGtk::~TabRendererGtk() { |
| 195 tab_.Destroy(); | 191 tab_.Destroy(); |
| 196 } | 192 } |
| 197 | 193 |
| 198 void TabRendererGtk::UpdateData(TabContents* contents, bool loading_only) { | 194 void TabRendererGtk::UpdateData(TabContents* contents, bool loading_only) { |
| 199 DCHECK(contents); | 195 DCHECK(contents); |
| 200 if (!loading_only) { | 196 if (!loading_only) { |
| 201 data_.title = UTF16ToWideHack(contents->GetTitle()); | 197 data_.title = UTF16ToWideHack(contents->GetTitle()); |
| 202 data_.off_the_record = contents->profile()->IsOffTheRecord(); | 198 data_.off_the_record = contents->profile()->IsOffTheRecord(); |
| 203 data_.show_download_icon = contents->IsDownloadShelfVisible(); | |
| 204 data_.crashed = contents->is_crashed(); | 199 data_.crashed = contents->is_crashed(); |
| 205 data_.favicon = contents->GetFavIcon(); | 200 data_.favicon = contents->GetFavIcon(); |
| 206 } | 201 } |
| 207 | 202 |
| 208 // Loading state also involves whether we show the favicon, since that's where | 203 // Loading state also involves whether we show the favicon, since that's where |
| 209 // we display the throbber. | 204 // we display the throbber. |
| 210 data_.loading = contents->is_loading(); | 205 data_.loading = contents->is_loading(); |
| 211 data_.show_icon = contents->ShouldDisplayFavIcon(); | 206 data_.show_icon = contents->ShouldDisplayFavIcon(); |
| 212 | 207 |
| 213 theme_provider_ = contents->profile()->GetThemeProvider(); | 208 theme_provider_ = contents->profile()->GetThemeProvider(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 tab_active_.r_width = tab_active_.image_r->width(); | 291 tab_active_.r_width = tab_active_.image_r->width(); |
| 297 | 292 |
| 298 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); | 293 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); |
| 299 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); | 294 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); |
| 300 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); | 295 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); |
| 301 tab_inactive_.l_width = tab_inactive_.image_l->width(); | 296 tab_inactive_.l_width = tab_inactive_.image_l->width(); |
| 302 tab_inactive_.r_width = tab_inactive_.image_r->width(); | 297 tab_inactive_.r_width = tab_inactive_.image_r->width(); |
| 303 | 298 |
| 304 close_button_width_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->width(); | 299 close_button_width_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->width(); |
| 305 close_button_height_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->height(); | 300 close_button_height_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->height(); |
| 306 | |
| 307 download_icon_ = rb.GetBitmapNamed(IDR_DOWNLOAD_ICON); | |
| 308 download_icon_width_ = download_icon_->width(); | |
| 309 download_icon_height_ = download_icon_->height(); | |
| 310 } | 301 } |
| 311 | 302 |
| 312 void TabRendererGtk::SetBounds(const gfx::Rect& bounds) { | 303 void TabRendererGtk::SetBounds(const gfx::Rect& bounds) { |
| 313 gtk_widget_set_size_request(tab_.get(), bounds.width(), bounds.height()); | 304 gtk_widget_set_size_request(tab_.get(), bounds.width(), bounds.height()); |
| 314 bounds_ = bounds; | 305 bounds_ = bounds; |
| 315 Layout(); | 306 Layout(); |
| 316 } | 307 } |
| 317 | 308 |
| 318 //////////////////////////////////////////////////////////////////////////////// | 309 //////////////////////////////////////////////////////////////////////////////// |
| 319 // TabRendererGtk, protected: | 310 // TabRendererGtk, protected: |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 } | 362 } |
| 372 | 363 |
| 373 void TabRendererGtk::Paint(gfx::Canvas* canvas) { | 364 void TabRendererGtk::Paint(gfx::Canvas* canvas) { |
| 374 // Don't paint if we're narrower than we can render correctly. (This should | 365 // Don't paint if we're narrower than we can render correctly. (This should |
| 375 // only happen during animations). | 366 // only happen during animations). |
| 376 if (width() < GetMinimumUnselectedSize().width()) | 367 if (width() < GetMinimumUnselectedSize().width()) |
| 377 return; | 368 return; |
| 378 | 369 |
| 379 // See if the model changes whether the icons should be painted. | 370 // See if the model changes whether the icons should be painted. |
| 380 const bool show_icon = ShouldShowIcon(); | 371 const bool show_icon = ShouldShowIcon(); |
| 381 const bool show_download_icon = data_.show_download_icon; | |
| 382 const bool show_close_button = ShouldShowCloseBox(); | 372 const bool show_close_button = ShouldShowCloseBox(); |
| 383 if (show_icon != showing_icon_ || | 373 if (show_icon != showing_icon_ || |
| 384 show_download_icon != showing_download_icon_ || | |
| 385 show_close_button != showing_close_button_) | 374 show_close_button != showing_close_button_) |
| 386 Layout(); | 375 Layout(); |
| 387 | 376 |
| 388 PaintTabBackground(canvas); | 377 PaintTabBackground(canvas); |
| 389 | 378 |
| 390 if (show_icon) { | 379 if (show_icon) { |
| 391 if (loading_animation_.animation_state() != ANIMATION_NONE) { | 380 if (loading_animation_.animation_state() != ANIMATION_NONE) { |
| 392 PaintLoadingAnimation(canvas); | 381 PaintLoadingAnimation(canvas); |
| 393 } else { | 382 } else { |
| 394 canvas->save(); | 383 canvas->save(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 411 favicon_bounds_.x(), | 400 favicon_bounds_.x(), |
| 412 favicon_bounds_.y() + fav_icon_hiding_offset_, | 401 favicon_bounds_.y() + fav_icon_hiding_offset_, |
| 413 kFavIconSize, kFavIconSize, | 402 kFavIconSize, kFavIconSize, |
| 414 true); | 403 true); |
| 415 } | 404 } |
| 416 } | 405 } |
| 417 canvas->restore(); | 406 canvas->restore(); |
| 418 } | 407 } |
| 419 } | 408 } |
| 420 | 409 |
| 421 if (show_download_icon) { | |
| 422 canvas->DrawBitmapInt(*download_icon_, | |
| 423 download_icon_bounds_.x(), download_icon_bounds_.y()); | |
| 424 } | |
| 425 | |
| 426 // Paint the Title. | 410 // Paint the Title. |
| 427 std::wstring title = data_.title; | 411 std::wstring title = data_.title; |
| 428 if (title.empty()) { | 412 if (title.empty()) { |
| 429 if (data_.loading) { | 413 if (data_.loading) { |
| 430 title = l10n_util::GetString(IDS_TAB_LOADING_TITLE); | 414 title = l10n_util::GetString(IDS_TAB_LOADING_TITLE); |
| 431 } else { | 415 } else { |
| 432 title = l10n_util::GetString(IDS_TAB_UNTITLED_TITLE); | 416 title = l10n_util::GetString(IDS_TAB_UNTITLED_TITLE); |
| 433 } | 417 } |
| 434 } else { | 418 } else { |
| 435 Browser::FormatTitleForDisplay(&title); | 419 Browser::FormatTitleForDisplay(&title); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 // Size the Favicon. | 452 // Size the Favicon. |
| 469 showing_icon_ = ShouldShowIcon(); | 453 showing_icon_ = ShouldShowIcon(); |
| 470 if (showing_icon_) { | 454 if (showing_icon_) { |
| 471 int favicon_top = kTopPadding + (content_height - kFavIconSize) / 2; | 455 int favicon_top = kTopPadding + (content_height - kFavIconSize) / 2; |
| 472 favicon_bounds_.SetRect(local_bounds.x(), favicon_top, | 456 favicon_bounds_.SetRect(local_bounds.x(), favicon_top, |
| 473 kFavIconSize, kFavIconSize); | 457 kFavIconSize, kFavIconSize); |
| 474 } else { | 458 } else { |
| 475 favicon_bounds_.SetRect(local_bounds.x(), local_bounds.y(), 0, 0); | 459 favicon_bounds_.SetRect(local_bounds.x(), local_bounds.y(), 0, 0); |
| 476 } | 460 } |
| 477 | 461 |
| 478 // Size the download icon. | |
| 479 showing_download_icon_ = data_.show_download_icon; | |
| 480 if (showing_download_icon_) { | |
| 481 int icon_top = kTopPadding + (content_height - download_icon_height_) / 2; | |
| 482 download_icon_bounds_.SetRect(local_bounds.width() - download_icon_width_, | |
| 483 icon_top, download_icon_width_, | |
| 484 download_icon_height_); | |
| 485 } | |
| 486 | |
| 487 // Size the Close button. | 462 // Size the Close button. |
| 488 showing_close_button_ = ShouldShowCloseBox(); | 463 showing_close_button_ = ShouldShowCloseBox(); |
| 489 if (showing_close_button_) { | 464 if (showing_close_button_) { |
| 490 int close_button_top = | 465 int close_button_top = |
| 491 kTopPadding + kCloseButtonVertFuzz + | 466 kTopPadding + kCloseButtonVertFuzz + |
| 492 (content_height - close_button_height_) / 2; | 467 (content_height - close_button_height_) / 2; |
| 493 close_button_bounds_.SetRect(local_bounds.width() + kCloseButtonHorzFuzz, | 468 close_button_bounds_.SetRect(local_bounds.width() + kCloseButtonHorzFuzz, |
| 494 close_button_top, close_button_width_, | 469 close_button_top, close_button_width_, |
| 495 close_button_height_); | 470 close_button_height_); |
| 496 } else { | 471 } else { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 511 if (text_height > minimum_size.height()) | 486 if (text_height > minimum_size.height()) |
| 512 title_top -= (text_height - minimum_size.height()) / 2; | 487 title_top -= (text_height - minimum_size.height()) / 2; |
| 513 | 488 |
| 514 int title_width; | 489 int title_width; |
| 515 if (close_button_bounds_.width() && close_button_bounds_.height()) { | 490 if (close_button_bounds_.width() && close_button_bounds_.height()) { |
| 516 title_width = std::max(close_button_bounds_.x() - | 491 title_width = std::max(close_button_bounds_.x() - |
| 517 kTitleCloseButtonSpacing - title_left, 0); | 492 kTitleCloseButtonSpacing - title_left, 0); |
| 518 } else { | 493 } else { |
| 519 title_width = std::max(local_bounds.width() - title_left, 0); | 494 title_width = std::max(local_bounds.width() - title_left, 0); |
| 520 } | 495 } |
| 521 if (data_.show_download_icon) | |
| 522 title_width = std::max(title_width - download_icon_width_, 0); | |
| 523 title_bounds_.SetRect(title_left, title_top, title_width, title_font_height_); | 496 title_bounds_.SetRect(title_left, title_top, title_width, title_font_height_); |
| 524 | 497 |
| 525 // TODO(jhawkins): Handle RTL layout. | 498 // TODO(jhawkins): Handle RTL layout. |
| 526 } | 499 } |
| 527 | 500 |
| 528 void TabRendererGtk::MoveCloseButtonWidget() { | 501 void TabRendererGtk::MoveCloseButtonWidget() { |
| 529 if (!close_button_bounds_.IsEmpty()) { | 502 if (!close_button_bounds_.IsEmpty()) { |
| 530 gtk_fixed_move(GTK_FIXED(tab_.get()), close_button_.get()->widget(), | 503 gtk_fixed_move(GTK_FIXED(tab_.get()), close_button_.get()->widget(), |
| 531 close_button_bounds_.x(), close_button_bounds_.y()); | 504 close_button_bounds_.x(), close_button_bounds_.y()); |
| 532 gtk_widget_show(close_button_.get()->widget()); | 505 gtk_widget_show(close_button_.get()->widget()); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 gfx::Font base_font = rb.GetFont(ResourceBundle::BaseFont); | 726 gfx::Font base_font = rb.GetFont(ResourceBundle::BaseFont); |
| 754 title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 10)); | 727 title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 10)); |
| 755 title_font_height_ = title_font_->height(); | 728 title_font_height_ = title_font_->height(); |
| 756 | 729 |
| 757 InitializeLoadingAnimationData(&rb, &loading_animation_data); | 730 InitializeLoadingAnimationData(&rb, &loading_animation_data); |
| 758 | 731 |
| 759 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); | 732 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); |
| 760 | 733 |
| 761 initialized_ = true; | 734 initialized_ = true; |
| 762 } | 735 } |
| OLD | NEW |