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/gtk/tabs/tab_renderer_gtk.h" | 5 #include "chrome/browser/gtk/tabs/tab_renderer_gtk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
12 #include "app/slide_animation.h" | |
13 #include "app/throb_animation.h" | |
14 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/defaults.h" | 13 #include "chrome/browser/defaults.h" |
16 #include "chrome/browser/gtk/bookmark_utils_gtk.h" | 14 #include "chrome/browser/gtk/bookmark_utils_gtk.h" |
17 #include "chrome/browser/gtk/custom_button.h" | 15 #include "chrome/browser/gtk/custom_button.h" |
18 #include "chrome/browser/gtk/gtk_theme_provider.h" | 16 #include "chrome/browser/gtk/gtk_theme_provider.h" |
19 #include "chrome/browser/gtk/gtk_util.h" | 17 #include "chrome/browser/gtk/gtk_util.h" |
20 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
22 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
24 #include "gfx/canvas_skia_paint.h" | 22 #include "gfx/canvas_skia_paint.h" |
25 #include "gfx/favicon_size.h" | 23 #include "gfx/favicon_size.h" |
26 #include "gfx/platform_font_gtk.h" | 24 #include "gfx/platform_font_gtk.h" |
27 #include "gfx/skbitmap_operations.h" | 25 #include "gfx/skbitmap_operations.h" |
28 #include "grit/app_resources.h" | 26 #include "grit/app_resources.h" |
29 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
30 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| 29 #include "ui/base/animation/slide_animation.h" |
| 30 #include "ui/base/animation/throb_animation.h" |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const int kLeftPadding = 16; | 34 const int kLeftPadding = 16; |
35 const int kTopPadding = 6; | 35 const int kTopPadding = 6; |
36 const int kRightPadding = 15; | 36 const int kRightPadding = 15; |
37 const int kBottomPadding = 5; | 37 const int kBottomPadding = 5; |
38 const int kDropShadowHeight = 2; | 38 const int kDropShadowHeight = 2; |
39 const int kFavIconTitleSpacing = 4; | 39 const int kFavIconTitleSpacing = 4; |
40 const int kTitleCloseButtonSpacing = 5; | 40 const int kTitleCloseButtonSpacing = 5; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 const NotificationSource& source, | 198 const NotificationSource& source, |
199 const NotificationDetails& details) { | 199 const NotificationDetails& details) { |
200 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED); | 200 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED); |
201 data_.reset(new Data(theme_provider_)); | 201 data_.reset(new Data(theme_provider_)); |
202 } | 202 } |
203 | 203 |
204 //////////////////////////////////////////////////////////////////////////////// | 204 //////////////////////////////////////////////////////////////////////////////// |
205 // FaviconCrashAnimation | 205 // FaviconCrashAnimation |
206 // | 206 // |
207 // A custom animation subclass to manage the favicon crash animation. | 207 // A custom animation subclass to manage the favicon crash animation. |
208 class TabRendererGtk::FavIconCrashAnimation : public LinearAnimation, | 208 class TabRendererGtk::FavIconCrashAnimation : public ui::LinearAnimation, |
209 public AnimationDelegate { | 209 public ui::AnimationDelegate { |
210 public: | 210 public: |
211 explicit FavIconCrashAnimation(TabRendererGtk* target) | 211 explicit FavIconCrashAnimation(TabRendererGtk* target) |
212 : ALLOW_THIS_IN_INITIALIZER_LIST(LinearAnimation(1000, 25, this)), | 212 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::LinearAnimation(1000, 25, this)), |
213 target_(target) { | 213 target_(target) { |
214 } | 214 } |
215 virtual ~FavIconCrashAnimation() {} | 215 virtual ~FavIconCrashAnimation() {} |
216 | 216 |
217 // Animation overrides: | 217 // ui::Animation overrides: |
218 virtual void AnimateToState(double state) { | 218 virtual void AnimateToState(double state) { |
219 const double kHidingOffset = 27; | 219 const double kHidingOffset = 27; |
220 | 220 |
221 if (state < .5) { | 221 if (state < .5) { |
222 target_->SetFavIconHidingOffset( | 222 target_->SetFavIconHidingOffset( |
223 static_cast<int>(floor(kHidingOffset * 2.0 * state))); | 223 static_cast<int>(floor(kHidingOffset * 2.0 * state))); |
224 } else { | 224 } else { |
225 target_->DisplayCrashedFavIcon(); | 225 target_->DisplayCrashedFavIcon(); |
226 target_->SetFavIconHidingOffset( | 226 target_->SetFavIconHidingOffset( |
227 static_cast<int>( | 227 static_cast<int>( |
228 floor(kHidingOffset - ((state - .5) * 2.0 * kHidingOffset)))); | 228 floor(kHidingOffset - ((state - .5) * 2.0 * kHidingOffset)))); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 // AnimationDelegate overrides: | 232 // ui::AnimationDelegate overrides: |
233 virtual void AnimationCanceled(const Animation* animation) { | 233 virtual void AnimationCanceled(const ui::Animation* animation) { |
234 target_->SetFavIconHidingOffset(0); | 234 target_->SetFavIconHidingOffset(0); |
235 } | 235 } |
236 | 236 |
237 private: | 237 private: |
238 TabRendererGtk* target_; | 238 TabRendererGtk* target_; |
239 | 239 |
240 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation); | 240 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation); |
241 }; | 241 }; |
242 | 242 |
243 //////////////////////////////////////////////////////////////////////////////// | 243 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 12 matching lines...) Expand all Loading... |
256 | 256 |
257 tab_.Own(gtk_fixed_new()); | 257 tab_.Own(gtk_fixed_new()); |
258 gtk_widget_set_app_paintable(tab_.get(), TRUE); | 258 gtk_widget_set_app_paintable(tab_.get(), TRUE); |
259 g_signal_connect(tab_.get(), "expose-event", | 259 g_signal_connect(tab_.get(), "expose-event", |
260 G_CALLBACK(OnExposeEventThunk), this); | 260 G_CALLBACK(OnExposeEventThunk), this); |
261 g_signal_connect(tab_.get(), "size-allocate", | 261 g_signal_connect(tab_.get(), "size-allocate", |
262 G_CALLBACK(OnSizeAllocateThunk), this); | 262 G_CALLBACK(OnSizeAllocateThunk), this); |
263 close_button_.reset(MakeCloseButton()); | 263 close_button_.reset(MakeCloseButton()); |
264 gtk_widget_show(tab_.get()); | 264 gtk_widget_show(tab_.get()); |
265 | 265 |
266 hover_animation_.reset(new SlideAnimation(this)); | 266 hover_animation_.reset(new ui::SlideAnimation(this)); |
267 hover_animation_->SetSlideDuration(kHoverDurationMs); | 267 hover_animation_->SetSlideDuration(kHoverDurationMs); |
268 | 268 |
269 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 269 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
270 NotificationService::AllSources()); | 270 NotificationService::AllSources()); |
271 } | 271 } |
272 | 272 |
273 TabRendererGtk::~TabRendererGtk() { | 273 TabRendererGtk::~TabRendererGtk() { |
274 tab_.Destroy(); | 274 tab_.Destroy(); |
275 for (BitmapCache::iterator it = cached_bitmaps_.begin(); | 275 for (BitmapCache::iterator it = cached_bitmaps_.begin(); |
276 it != cached_bitmaps_.end(); ++it) { | 276 it != cached_bitmaps_.end(); ++it) { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 return bounds; | 513 return bounds; |
514 } | 514 } |
515 | 515 |
516 gfx::Rect TabRendererGtk::GetRequisition() const { | 516 gfx::Rect TabRendererGtk::GetRequisition() const { |
517 return gfx::Rect(requisition_.x(), requisition_.y(), | 517 return gfx::Rect(requisition_.x(), requisition_.y(), |
518 requisition_.width(), requisition_.height()); | 518 requisition_.width(), requisition_.height()); |
519 } | 519 } |
520 | 520 |
521 void TabRendererGtk::StartMiniTabTitleAnimation() { | 521 void TabRendererGtk::StartMiniTabTitleAnimation() { |
522 if (!mini_title_animation_.get()) { | 522 if (!mini_title_animation_.get()) { |
523 mini_title_animation_.reset(new ThrobAnimation(this)); | 523 mini_title_animation_.reset(new ui::ThrobAnimation(this)); |
524 mini_title_animation_->SetThrobDuration(kMiniTitleChangeThrobDuration); | 524 mini_title_animation_->SetThrobDuration(kMiniTitleChangeThrobDuration); |
525 } | 525 } |
526 | 526 |
527 if (!mini_title_animation_->is_animating()) { | 527 if (!mini_title_animation_->is_animating()) { |
528 mini_title_animation_->StartThrobbing(2); | 528 mini_title_animation_->StartThrobbing(2); |
529 } else if (mini_title_animation_->cycles_remaining() <= 2) { | 529 } else if (mini_title_animation_->cycles_remaining() <= 2) { |
530 // The title changed while we're already animating. Add at most one more | 530 // The title changed while we're already animating. Add at most one more |
531 // cycle. This is done in an attempt to smooth out pages that continuously | 531 // cycle. This is done in an attempt to smooth out pages that continuously |
532 // change the title. | 532 // change the title. |
533 mini_title_animation_->set_cycles_remaining( | 533 mini_title_animation_->set_cycles_remaining( |
(...skipping 26 matching lines...) Expand all Loading... |
560 } | 560 } |
561 | 561 |
562 //////////////////////////////////////////////////////////////////////////////// | 562 //////////////////////////////////////////////////////////////////////////////// |
563 // TabRendererGtk, protected: | 563 // TabRendererGtk, protected: |
564 | 564 |
565 string16 TabRendererGtk::GetTitle() const { | 565 string16 TabRendererGtk::GetTitle() const { |
566 return data_.title; | 566 return data_.title; |
567 } | 567 } |
568 | 568 |
569 /////////////////////////////////////////////////////////////////////////////// | 569 /////////////////////////////////////////////////////////////////////////////// |
570 // TabRendererGtk, AnimationDelegate implementation: | 570 // TabRendererGtk, ui::AnimationDelegate implementation: |
571 | 571 |
572 void TabRendererGtk::AnimationProgressed(const Animation* animation) { | 572 void TabRendererGtk::AnimationProgressed(const ui::Animation* animation) { |
573 gtk_widget_queue_draw(tab_.get()); | 573 gtk_widget_queue_draw(tab_.get()); |
574 } | 574 } |
575 | 575 |
576 void TabRendererGtk::AnimationCanceled(const Animation* animation) { | 576 void TabRendererGtk::AnimationCanceled(const ui::Animation* animation) { |
577 AnimationEnded(animation); | 577 AnimationEnded(animation); |
578 } | 578 } |
579 | 579 |
580 void TabRendererGtk::AnimationEnded(const Animation* animation) { | 580 void TabRendererGtk::AnimationEnded(const ui::Animation* animation) { |
581 gtk_widget_queue_draw(tab_.get()); | 581 gtk_widget_queue_draw(tab_.get()); |
582 } | 582 } |
583 | 583 |
584 //////////////////////////////////////////////////////////////////////////////// | 584 //////////////////////////////////////////////////////////////////////////////// |
585 // TabRendererGtk, private: | 585 // TabRendererGtk, private: |
586 | 586 |
587 void TabRendererGtk::StartCrashAnimation() { | 587 void TabRendererGtk::StartCrashAnimation() { |
588 if (!crash_animation_.get()) | 588 if (!crash_animation_.get()) |
589 crash_animation_.reset(new FavIconCrashAnimation(this)); | 589 crash_animation_.reset(new FavIconCrashAnimation(this)); |
590 crash_animation_->Stop(); | 590 crash_animation_->Stop(); |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 // get an infinite loop of size-allocate signals. | 1045 // get an infinite loop of size-allocate signals. |
1046 if (bounds_ == bounds) | 1046 if (bounds_ == bounds) |
1047 return; | 1047 return; |
1048 | 1048 |
1049 bounds_ = bounds; | 1049 bounds_ = bounds; |
1050 Layout(); | 1050 Layout(); |
1051 } | 1051 } |
1052 | 1052 |
1053 gboolean TabRendererGtk::OnEnterNotifyEvent(GtkWidget* widget, | 1053 gboolean TabRendererGtk::OnEnterNotifyEvent(GtkWidget* widget, |
1054 GdkEventCrossing* event) { | 1054 GdkEventCrossing* event) { |
1055 hover_animation_->SetTweenType(Tween::EASE_OUT); | 1055 hover_animation_->SetTweenType(ui::Tween::EASE_OUT); |
1056 hover_animation_->Show(); | 1056 hover_animation_->Show(); |
1057 return FALSE; | 1057 return FALSE; |
1058 } | 1058 } |
1059 | 1059 |
1060 gboolean TabRendererGtk::OnLeaveNotifyEvent(GtkWidget* widget, | 1060 gboolean TabRendererGtk::OnLeaveNotifyEvent(GtkWidget* widget, |
1061 GdkEventCrossing* event) { | 1061 GdkEventCrossing* event) { |
1062 hover_animation_->SetTweenType(Tween::EASE_IN); | 1062 hover_animation_->SetTweenType(ui::Tween::EASE_IN); |
1063 hover_animation_->Hide(); | 1063 hover_animation_->Hide(); |
1064 return FALSE; | 1064 return FALSE; |
1065 } | 1065 } |
1066 | 1066 |
1067 // static | 1067 // static |
1068 void TabRendererGtk::InitResources() { | 1068 void TabRendererGtk::InitResources() { |
1069 if (initialized_) | 1069 if (initialized_) |
1070 return; | 1070 return; |
1071 | 1071 |
1072 LoadTabImages(); | 1072 LoadTabImages(); |
1073 | 1073 |
1074 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1074 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1075 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); | 1075 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); |
1076 // Dividing by the pango scale factor maintains an absolute pixel size across | 1076 // Dividing by the pango scale factor maintains an absolute pixel size across |
1077 // all DPIs. | 1077 // all DPIs. |
1078 int size = static_cast<int>(13 / gfx::PlatformFontGtk::GetPangoScaleFactor()); | 1078 int size = static_cast<int>(13 / gfx::PlatformFontGtk::GetPangoScaleFactor()); |
1079 title_font_ = new gfx::Font(base_font.GetFontName(), size); | 1079 title_font_ = new gfx::Font(base_font.GetFontName(), size); |
1080 title_font_height_ = title_font_->GetHeight(); | 1080 title_font_height_ = title_font_->GetHeight(); |
1081 | 1081 |
1082 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); | 1082 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); |
1083 | 1083 |
1084 initialized_ = true; | 1084 initialized_ = true; |
1085 } | 1085 } |
OLD | NEW |