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/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #if defined(USE_ASH) | 34 #if defined(USE_ASH) |
35 #include "ui/aura/env.h" | 35 #include "ui/aura/env.h" |
36 #endif | 36 #endif |
37 | 37 |
38 // How long the pulse throb takes. | 38 // How long the pulse throb takes. |
39 static const int kPulseDurationMs = 200; | 39 static const int kPulseDurationMs = 200; |
40 | 40 |
41 // How long the hover state takes. | 41 // How long the hover state takes. |
42 static const int kHoverDurationMs = 400; | 42 static const int kHoverDurationMs = 400; |
43 | 43 |
| 44 // How long the recording button takes to fade in/out. |
| 45 static const int kRecordingDurationMs = 1000; |
| 46 |
44 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
45 // TabCloseButton | 48 // TabCloseButton |
46 // | 49 // |
47 // This is a Button subclass that causes middle clicks to be forwarded to the | 50 // This is a Button subclass that causes middle clicks to be forwarded to the |
48 // parent View by explicitly not handling them in OnMousePressed. | 51 // parent View by explicitly not handling them in OnMousePressed. |
49 class BaseTab::TabCloseButton : public views::ImageButton { | 52 class BaseTab::TabCloseButton : public views::ImageButton { |
50 public: | 53 public: |
51 explicit TabCloseButton(BaseTab* tab) : views::ImageButton(tab), tab_(tab) {} | 54 explicit TabCloseButton(BaseTab* tab) : views::ImageButton(tab), tab_(tab) {} |
52 virtual ~TabCloseButton() {} | 55 virtual ~TabCloseButton() {} |
53 | 56 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 110 |
108 namespace { | 111 namespace { |
109 | 112 |
110 // Draws the icon image at the center of |bounds|. | 113 // Draws the icon image at the center of |bounds|. |
111 void DrawIconCenter(gfx::Canvas* canvas, | 114 void DrawIconCenter(gfx::Canvas* canvas, |
112 const gfx::ImageSkia& image, | 115 const gfx::ImageSkia& image, |
113 int image_offset, | 116 int image_offset, |
114 int icon_width, | 117 int icon_width, |
115 int icon_height, | 118 int icon_height, |
116 const gfx::Rect& bounds, | 119 const gfx::Rect& bounds, |
117 bool filter) { | 120 bool filter, |
| 121 const SkPaint& paint) { |
118 // Center the image within bounds. | 122 // Center the image within bounds. |
119 int dst_x = bounds.x() - (icon_width - bounds.width()) / 2; | 123 int dst_x = bounds.x() - (icon_width - bounds.width()) / 2; |
120 int dst_y = bounds.y() - (icon_height - bounds.height()) / 2; | 124 int dst_y = bounds.y() - (icon_height - bounds.height()) / 2; |
121 // NOTE: the clipping is a work around for 69528, it shouldn't be necessary. | 125 // NOTE: the clipping is a work around for 69528, it shouldn't be necessary. |
122 canvas->Save(); | 126 canvas->Save(); |
123 canvas->ClipRect(gfx::Rect(dst_x, dst_y, icon_width, icon_height)); | 127 canvas->ClipRect(gfx::Rect(dst_x, dst_y, icon_width, icon_height)); |
124 canvas->DrawImageInt(image, | 128 canvas->DrawImageInt(image, |
125 image_offset, 0, icon_width, icon_height, | 129 image_offset, 0, icon_width, icon_height, |
126 dst_x, dst_y, icon_width, icon_height, | 130 dst_x, dst_y, icon_width, icon_height, |
127 filter); | 131 filter, paint); |
128 canvas->Restore(); | 132 canvas->Restore(); |
129 } | 133 } |
130 | 134 |
131 } // namespace | 135 } // namespace |
132 | 136 |
133 // static | 137 // static |
134 gfx::Font* BaseTab::font_ = NULL; | 138 gfx::Font* BaseTab::font_ = NULL; |
135 // static | 139 // static |
136 int BaseTab::font_height_ = 0; | 140 int BaseTab::font_height_ = 0; |
137 | 141 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 522 |
519 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { | 523 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { |
520 ui::ThemeProvider* tp = GetThemeProvider(); | 524 ui::ThemeProvider* tp = GetThemeProvider(); |
521 gfx::ImageSkia frames(*tp->GetImageSkiaNamed( | 525 gfx::ImageSkia frames(*tp->GetImageSkiaNamed( |
522 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? | 526 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? |
523 IDR_THROBBER_WAITING : IDR_THROBBER)); | 527 IDR_THROBBER_WAITING : IDR_THROBBER)); |
524 | 528 |
525 int icon_size = frames.height(); | 529 int icon_size = frames.height(); |
526 int image_offset = loading_animation_frame_ * icon_size; | 530 int image_offset = loading_animation_frame_ * icon_size; |
527 DrawIconCenter(canvas, frames, image_offset, | 531 DrawIconCenter(canvas, frames, image_offset, |
528 icon_size, icon_size, bounds, false); | 532 icon_size, icon_size, bounds, false, SkPaint()); |
529 } else { | 533 } else { |
530 canvas->Save(); | 534 canvas->Save(); |
531 canvas->ClipRect(GetLocalBounds()); | 535 canvas->ClipRect(GetLocalBounds()); |
532 if (should_display_crashed_favicon_) { | 536 if (should_display_crashed_favicon_) { |
533 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 537 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
534 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON)); | 538 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON)); |
535 bounds.set_y(bounds.y() + favicon_hiding_offset_); | 539 bounds.set_y(bounds.y() + favicon_hiding_offset_); |
536 DrawIconCenter(canvas, crashed_favicon, 0, | 540 DrawIconCenter(canvas, crashed_favicon, 0, |
537 crashed_favicon.width(), | 541 crashed_favicon.width(), |
538 crashed_favicon.height(), bounds, true); | 542 crashed_favicon.height(), bounds, true, SkPaint()); |
539 } else { | 543 } else { |
540 if (!data().favicon.isNull()) { | 544 if (!data().favicon.isNull()) { |
541 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch | 545 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch |
542 // to using that class to render the favicon). | 546 // to using that class to render the favicon). |
543 DrawIconCenter(canvas, data().favicon, 0, | 547 DrawIconCenter(canvas, data().favicon, 0, |
544 data().favicon.width(), | 548 data().favicon.width(), |
545 data().favicon.height(), | 549 data().favicon.height(), |
546 bounds, true); | 550 bounds, true, SkPaint()); |
547 } | 551 } |
548 } | 552 } |
549 canvas->Restore(); | 553 canvas->Restore(); |
| 554 |
| 555 // If recording, fade the recording icon on top of the favicon. |
| 556 if (data().recording) { |
| 557 if (!recording_animation_.get()) { |
| 558 recording_animation_.reset(new ui::ThrobAnimation(this)); |
| 559 recording_animation_->SetTweenType(ui::Tween::EASE_IN_OUT); |
| 560 recording_animation_->SetThrobDuration(kRecordingDurationMs); |
| 561 recording_animation_->StartThrobbing(-1); |
| 562 } |
| 563 SkPaint paint; |
| 564 paint.setAntiAlias(true); |
| 565 U8CPU alpha = recording_animation_->GetCurrentValue() * 0xff; |
| 566 paint.setAlpha(alpha); |
| 567 ui::ThemeProvider* tp = GetThemeProvider(); |
| 568 gfx::ImageSkia recording_dot(*tp->GetImageSkiaNamed(IDR_TAB_RECORDING)); |
| 569 DrawIconCenter(canvas, recording_dot, 0, |
| 570 recording_dot.width(), recording_dot.height(), |
| 571 bounds, false, paint); |
| 572 } else { |
| 573 recording_animation_.reset(); |
| 574 } |
550 } | 575 } |
551 } | 576 } |
552 | 577 |
553 void BaseTab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) { | 578 void BaseTab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) { |
554 // Paint the Title. | 579 // Paint the Title. |
555 const gfx::Rect& title_bounds = GetTitleBounds(); | 580 const gfx::Rect& title_bounds = GetTitleBounds(); |
556 string16 title = data().title; | 581 string16 title = data().title; |
557 | 582 |
558 if (title.empty()) { | 583 if (title.empty()) { |
559 title = data().loading ? | 584 title = data().loading ? |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 // static | 681 // static |
657 void BaseTab::InitResources() { | 682 void BaseTab::InitResources() { |
658 static bool initialized = false; | 683 static bool initialized = false; |
659 if (!initialized) { | 684 if (!initialized) { |
660 initialized = true; | 685 initialized = true; |
661 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 686 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
662 font_ = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); | 687 font_ = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); |
663 font_height_ = font_->GetHeight(); | 688 font_height_ = font_->GetHeight(); |
664 } | 689 } |
665 } | 690 } |
OLD | NEW |