OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/base_tab.h" | 5 #include "chrome/browser/views/tabs/base_tab.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
11 #include "app/slide_animation.h" | |
12 #include "app/theme_provider.h" | 11 #include "app/theme_provider.h" |
13 #include "app/throb_animation.h" | |
14 #include "base/command_line.h" | 12 #include "base/command_line.h" |
15 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
17 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/view_ids.h" | 16 #include "chrome/browser/ui/view_ids.h" |
19 #include "chrome/browser/ui/views/tabs/tab_controller.h" | 17 #include "chrome/browser/ui/views/tabs/tab_controller.h" |
20 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
21 #include "gfx/canvas_skia.h" | 19 #include "gfx/canvas_skia.h" |
22 #include "gfx/favicon_size.h" | 20 #include "gfx/favicon_size.h" |
23 #include "gfx/font.h" | 21 #include "gfx/font.h" |
24 #include "grit/app_resources.h" | 22 #include "grit/app_resources.h" |
25 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
26 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 #include "ui/base/animation/slide_animation.h" |
| 26 #include "ui/base/animation/throb_animation.h" |
27 #include "views/controls/button/image_button.h" | 27 #include "views/controls/button/image_button.h" |
28 | 28 |
29 // How long the pulse throb takes. | 29 // How long the pulse throb takes. |
30 static const int kPulseDurationMs = 200; | 30 static const int kPulseDurationMs = 200; |
31 | 31 |
32 // How long the hover state takes. | 32 // How long the hover state takes. |
33 static const int kHoverDurationMs = 400; | 33 static const int kHoverDurationMs = 400; |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 // static | 75 // static |
76 gfx::Font* BaseTab::font_ = NULL; | 76 gfx::Font* BaseTab::font_ = NULL; |
77 // static | 77 // static |
78 int BaseTab::font_height_ = 0; | 78 int BaseTab::font_height_ = 0; |
79 | 79 |
80 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
81 // FaviconCrashAnimation | 81 // FaviconCrashAnimation |
82 // | 82 // |
83 // A custom animation subclass to manage the favicon crash animation. | 83 // A custom animation subclass to manage the favicon crash animation. |
84 class BaseTab::FavIconCrashAnimation : public LinearAnimation, | 84 class BaseTab::FavIconCrashAnimation : public ui::LinearAnimation, |
85 public AnimationDelegate { | 85 public ui::AnimationDelegate { |
86 public: | 86 public: |
87 explicit FavIconCrashAnimation(BaseTab* target) | 87 explicit FavIconCrashAnimation(BaseTab* target) |
88 : ALLOW_THIS_IN_INITIALIZER_LIST(LinearAnimation(1000, 25, this)), | 88 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::LinearAnimation(1000, 25, this)), |
89 target_(target) { | 89 target_(target) { |
90 } | 90 } |
91 virtual ~FavIconCrashAnimation() {} | 91 virtual ~FavIconCrashAnimation() {} |
92 | 92 |
93 // Animation overrides: | 93 // ui::Animation overrides: |
94 virtual void AnimateToState(double state) { | 94 virtual void AnimateToState(double state) { |
95 const double kHidingOffset = 27; | 95 const double kHidingOffset = 27; |
96 | 96 |
97 if (state < .5) { | 97 if (state < .5) { |
98 target_->SetFavIconHidingOffset( | 98 target_->SetFavIconHidingOffset( |
99 static_cast<int>(floor(kHidingOffset * 2.0 * state))); | 99 static_cast<int>(floor(kHidingOffset * 2.0 * state))); |
100 } else { | 100 } else { |
101 target_->DisplayCrashedFavIcon(); | 101 target_->DisplayCrashedFavIcon(); |
102 target_->SetFavIconHidingOffset( | 102 target_->SetFavIconHidingOffset( |
103 static_cast<int>( | 103 static_cast<int>( |
104 floor(kHidingOffset - ((state - .5) * 2.0 * kHidingOffset)))); | 104 floor(kHidingOffset - ((state - .5) * 2.0 * kHidingOffset)))); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 // AnimationDelegate overrides: | 108 // ui::AnimationDelegate overrides: |
109 virtual void AnimationCanceled(const Animation* animation) { | 109 virtual void AnimationCanceled(const ui::Animation* animation) { |
110 target_->SetFavIconHidingOffset(0); | 110 target_->SetFavIconHidingOffset(0); |
111 } | 111 } |
112 | 112 |
113 private: | 113 private: |
114 BaseTab* target_; | 114 BaseTab* target_; |
115 | 115 |
116 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation); | 116 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation); |
117 }; | 117 }; |
118 | 118 |
119 BaseTab::BaseTab(TabController* controller) | 119 BaseTab::BaseTab(TabController* controller) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 return; | 190 return; |
191 } | 191 } |
192 | 192 |
193 TabRendererData::NetworkState old_state = data_.network_state; | 193 TabRendererData::NetworkState old_state = data_.network_state; |
194 data_.network_state = state; | 194 data_.network_state = state; |
195 AdvanceLoadingAnimation(old_state, state); | 195 AdvanceLoadingAnimation(old_state, state); |
196 } | 196 } |
197 | 197 |
198 void BaseTab::StartPulse() { | 198 void BaseTab::StartPulse() { |
199 if (!pulse_animation_.get()) { | 199 if (!pulse_animation_.get()) { |
200 pulse_animation_.reset(new ThrobAnimation(this)); | 200 pulse_animation_.reset(new ui::ThrobAnimation(this)); |
201 pulse_animation_->SetSlideDuration(kPulseDurationMs); | 201 pulse_animation_->SetSlideDuration(kPulseDurationMs); |
202 if (animation_container_.get()) | 202 if (animation_container_.get()) |
203 pulse_animation_->SetContainer(animation_container_.get()); | 203 pulse_animation_->SetContainer(animation_container_.get()); |
204 } | 204 } |
205 pulse_animation_->Reset(); | 205 pulse_animation_->Reset(); |
206 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); | 206 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); |
207 } | 207 } |
208 | 208 |
209 void BaseTab::StopPulse() { | 209 void BaseTab::StopPulse() { |
210 if (!pulse_animation_.get()) | 210 if (!pulse_animation_.get()) |
211 return; | 211 return; |
212 | 212 |
213 pulse_animation_->Stop(); // Do stop so we get notified. | 213 pulse_animation_->Stop(); // Do stop so we get notified. |
214 pulse_animation_.reset(NULL); | 214 pulse_animation_.reset(NULL); |
215 } | 215 } |
216 | 216 |
217 bool BaseTab::IsSelected() const { | 217 bool BaseTab::IsSelected() const { |
218 return controller() ? controller()->IsTabSelected(this) : true; | 218 return controller() ? controller()->IsTabSelected(this) : true; |
219 } | 219 } |
220 | 220 |
221 bool BaseTab::IsCloseable() const { | 221 bool BaseTab::IsCloseable() const { |
222 return controller() ? controller()->IsTabCloseable(this) : true; | 222 return controller() ? controller()->IsTabCloseable(this) : true; |
223 } | 223 } |
224 | 224 |
225 void BaseTab::OnMouseEntered(const views::MouseEvent& e) { | 225 void BaseTab::OnMouseEntered(const views::MouseEvent& e) { |
226 if (!hover_animation_.get()) { | 226 if (!hover_animation_.get()) { |
227 hover_animation_.reset(new SlideAnimation(this)); | 227 hover_animation_.reset(new ui::SlideAnimation(this)); |
228 hover_animation_->SetContainer(animation_container_.get()); | 228 hover_animation_->SetContainer(animation_container_.get()); |
229 hover_animation_->SetSlideDuration(kHoverDurationMs); | 229 hover_animation_->SetSlideDuration(kHoverDurationMs); |
230 } | 230 } |
231 hover_animation_->SetTweenType(Tween::EASE_OUT); | 231 hover_animation_->SetTweenType(ui::Tween::EASE_OUT); |
232 hover_animation_->Show(); | 232 hover_animation_->Show(); |
233 } | 233 } |
234 | 234 |
235 void BaseTab::OnMouseExited(const views::MouseEvent& e) { | 235 void BaseTab::OnMouseExited(const views::MouseEvent& e) { |
236 hover_animation_->SetTweenType(Tween::EASE_IN); | 236 hover_animation_->SetTweenType(ui::Tween::EASE_IN); |
237 hover_animation_->Hide(); | 237 hover_animation_->Hide(); |
238 } | 238 } |
239 | 239 |
240 bool BaseTab::OnMousePressed(const views::MouseEvent& event) { | 240 bool BaseTab::OnMousePressed(const views::MouseEvent& event) { |
241 if (!controller()) | 241 if (!controller()) |
242 return false; | 242 return false; |
243 | 243 |
244 if (event.IsOnlyLeftMouseButton()) { | 244 if (event.IsOnlyLeftMouseButton()) { |
245 // Store whether or not we were selected just now... we only want to be | 245 // Store whether or not we were selected just now... we only want to be |
246 // able to drag foreground tabs, so we don't start dragging the tab if | 246 // able to drag foreground tabs, so we don't start dragging the tab if |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 TabContents::GetDefaultTitle(); | 404 TabContents::GetDefaultTitle(); |
405 } else { | 405 } else { |
406 Browser::FormatTitleForDisplay(&title); | 406 Browser::FormatTitleForDisplay(&title); |
407 } | 407 } |
408 | 408 |
409 canvas->DrawStringInt(UTF16ToWideHack(title), *font_, title_color, | 409 canvas->DrawStringInt(UTF16ToWideHack(title), *font_, title_color, |
410 title_bounds().x(), title_bounds().y(), | 410 title_bounds().x(), title_bounds().y(), |
411 title_bounds().width(), title_bounds().height()); | 411 title_bounds().width(), title_bounds().height()); |
412 } | 412 } |
413 | 413 |
414 void BaseTab::AnimationProgressed(const Animation* animation) { | 414 void BaseTab::AnimationProgressed(const ui::Animation* animation) { |
415 SchedulePaint(); | 415 SchedulePaint(); |
416 } | 416 } |
417 | 417 |
418 void BaseTab::AnimationCanceled(const Animation* animation) { | 418 void BaseTab::AnimationCanceled(const ui::Animation* animation) { |
419 SchedulePaint(); | 419 SchedulePaint(); |
420 } | 420 } |
421 | 421 |
422 void BaseTab::AnimationEnded(const Animation* animation) { | 422 void BaseTab::AnimationEnded(const ui::Animation* animation) { |
423 SchedulePaint(); | 423 SchedulePaint(); |
424 } | 424 } |
425 | 425 |
426 void BaseTab::ButtonPressed(views::Button* sender, const views::Event& event) { | 426 void BaseTab::ButtonPressed(views::Button* sender, const views::Event& event) { |
427 DCHECK(sender == close_button_); | 427 DCHECK(sender == close_button_); |
428 controller()->CloseTab(this); | 428 controller()->CloseTab(this); |
429 } | 429 } |
430 | 430 |
431 void BaseTab::ShowContextMenu(views::View* source, | 431 void BaseTab::ShowContextMenu(views::View* source, |
432 const gfx::Point& p, | 432 const gfx::Point& p, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 // static | 468 // static |
469 void BaseTab::InitResources() { | 469 void BaseTab::InitResources() { |
470 static bool initialized = false; | 470 static bool initialized = false; |
471 if (!initialized) { | 471 if (!initialized) { |
472 initialized = true; | 472 initialized = true; |
473 font_ = new gfx::Font( | 473 font_ = new gfx::Font( |
474 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); | 474 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); |
475 font_height_ = font_->GetHeight(); | 475 font_height_ = font_->GetHeight(); |
476 } | 476 } |
477 } | 477 } |
OLD | NEW |