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_strip.h" | 5 #include "chrome/browser/views/tabs/tab_strip.h" |
6 | 6 |
7 #include "app/drag_drop_types.h" | 7 #include "app/drag_drop_types.h" |
8 #include "app/gfx/canvas.h" | 8 #include "app/gfx/canvas.h" |
9 #include "app/gfx/path.h" | 9 #include "app/gfx/path.h" |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "app/os_exchange_data.h" | 11 #include "app/os_exchange_data.h" |
12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
13 #include "app/slide_animation.h" | 13 #include "app/slide_animation.h" |
14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
15 #include "app/win_util.h" | 15 #include "app/win_util.h" |
16 #endif | 16 #endif |
17 #include "base/gfx/size.h" | 17 #include "base/gfx/size.h" |
18 #include "base/stl_util-inl.h" | 18 #include "base/stl_util-inl.h" |
19 #include "chrome/browser/browser_theme_provider.h" | |
20 #include "chrome/browser/metrics/user_metrics.h" | 19 #include "chrome/browser/metrics/user_metrics.h" |
21 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
22 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
23 #include "chrome/browser/tabs/tab_strip_model.h" | 22 #include "chrome/browser/tabs/tab_strip_model.h" |
24 #include "chrome/browser/view_ids.h" | 23 #include "chrome/browser/view_ids.h" |
25 #include "chrome/browser/views/tabs/dragged_tab_controller.h" | 24 #include "chrome/browser/views/tabs/dragged_tab_controller.h" |
26 #include "chrome/browser/views/tabs/tab.h" | 25 #include "chrome/browser/views/tabs/tab.h" |
27 #include "chrome/browser/tab_contents/tab_contents.h" | 26 #include "chrome/browser/tab_contents/tab_contents.h" |
28 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
29 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 } | 588 } |
590 } | 589 } |
591 } | 590 } |
592 | 591 |
593 void TabStrip::SetBackgroundOffset(gfx::Point offset) { | 592 void TabStrip::SetBackgroundOffset(gfx::Point offset) { |
594 int tab_count = GetTabCount(); | 593 int tab_count = GetTabCount(); |
595 for (int i = 0; i < tab_count; ++i) | 594 for (int i = 0; i < tab_count; ++i) |
596 GetTabAt(i)->SetBackgroundOffset(offset); | 595 GetTabAt(i)->SetBackgroundOffset(offset); |
597 } | 596 } |
598 | 597 |
599 void TabStrip::InitTabStripButtons() { | |
600 newtab_button_ = new NewTabButton(this); | |
601 LoadNewTabButtonImage(); | |
602 newtab_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_NEWTAB)); | |
603 AddChildView(newtab_button_); | |
604 } | |
605 | |
606 /////////////////////////////////////////////////////////////////////////////// | 598 /////////////////////////////////////////////////////////////////////////////// |
607 // TabStrip, views::View overrides: | 599 // TabStrip, views::View overrides: |
608 | 600 |
609 void TabStrip::PaintChildren(gfx::Canvas* canvas) { | 601 void TabStrip::PaintChildren(gfx::Canvas* canvas) { |
610 // Paint the tabs in reverse order, so they stack to the left. | 602 // Paint the tabs in reverse order, so they stack to the left. |
611 Tab* selected_tab = NULL; | 603 Tab* selected_tab = NULL; |
612 for (int i = GetTabCount() - 1; i >= 0; --i) { | 604 for (int i = GetTabCount() - 1; i >= 0; --i) { |
613 Tab* tab = GetTabAt(i); | 605 Tab* tab = GetTabAt(i); |
614 // We must ask the _Tab's_ model, not ourselves, because in some situations | 606 // We must ask the _Tab's_ model, not ourselves, because in some situations |
615 // the model will be different to this object, e.g. when a Tab is being | 607 // the model will be different to this object, e.g. when a Tab is being |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 return next_tab; | 761 return next_tab; |
770 Tab* tab = GetTabAt(i); | 762 Tab* tab = GetTabAt(i); |
771 if (IsPointInTab(tab, point)) | 763 if (IsPointInTab(tab, point)) |
772 return tab; | 764 return tab; |
773 } | 765 } |
774 | 766 |
775 // No need to do any floating view stuff, we don't use them in the TabStrip. | 767 // No need to do any floating view stuff, we don't use them in the TabStrip. |
776 return this; | 768 return this; |
777 } | 769 } |
778 | 770 |
779 void TabStrip::ThemeChanged() { | |
780 LoadNewTabButtonImage(); | |
781 } | |
782 | |
783 /////////////////////////////////////////////////////////////////////////////// | 771 /////////////////////////////////////////////////////////////////////////////// |
784 // TabStrip, TabStripModelObserver implementation: | 772 // TabStrip, TabStripModelObserver implementation: |
785 | 773 |
786 void TabStrip::TabInsertedAt(TabContents* contents, | 774 void TabStrip::TabInsertedAt(TabContents* contents, |
787 int index, | 775 int index, |
788 bool foreground) { | 776 bool foreground) { |
789 DCHECK(contents); | 777 DCHECK(contents); |
790 DCHECK(index == TabStripModel::kNoTab || model_->ContainsIndex(index)); | 778 DCHECK(index == TabStripModel::kNoTab || model_->ContainsIndex(index)); |
791 | 779 |
792 if (active_animation_.get()) | 780 if (active_animation_.get()) |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 break; | 1068 break; |
1081 } | 1069 } |
1082 } | 1070 } |
1083 #endif | 1071 #endif |
1084 | 1072 |
1085 /////////////////////////////////////////////////////////////////////////////// | 1073 /////////////////////////////////////////////////////////////////////////////// |
1086 // TabStrip, private: | 1074 // TabStrip, private: |
1087 | 1075 |
1088 void TabStrip::Init() { | 1076 void TabStrip::Init() { |
1089 model_->AddObserver(this); | 1077 model_->AddObserver(this); |
| 1078 newtab_button_ = new NewTabButton(this); |
| 1079 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1080 SkBitmap* bitmap; |
| 1081 |
| 1082 bitmap = rb.GetBitmapNamed(IDR_NEWTAB_BUTTON); |
| 1083 newtab_button_->SetImage(views::CustomButton::BS_NORMAL, bitmap); |
| 1084 newtab_button_->SetImage(views::CustomButton::BS_PUSHED, |
| 1085 rb.GetBitmapNamed(IDR_NEWTAB_BUTTON_P)); |
| 1086 newtab_button_->SetImage(views::CustomButton::BS_HOT, |
| 1087 rb.GetBitmapNamed(IDR_NEWTAB_BUTTON_H)); |
| 1088 |
| 1089 newtab_button_size_.SetSize(bitmap->width(), bitmap->height()); |
| 1090 actual_newtab_button_size_ = newtab_button_size_; |
| 1091 |
| 1092 newtab_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_NEWTAB)); |
| 1093 AddChildView(newtab_button_); |
1090 | 1094 |
1091 if (drop_indicator_width == 0) { | 1095 if (drop_indicator_width == 0) { |
1092 // Direction doesn't matter, both images are the same size. | 1096 // Direction doesn't matter, both images are the same size. |
1093 SkBitmap* drop_image = GetDropArrowImage(true); | 1097 SkBitmap* drop_image = GetDropArrowImage(true); |
1094 drop_indicator_width = drop_image->width(); | 1098 drop_indicator_width = drop_image->width(); |
1095 drop_indicator_height = drop_image->height(); | 1099 drop_indicator_height = drop_image->height(); |
1096 } | 1100 } |
1097 } | 1101 } |
1098 | 1102 |
1099 void TabStrip::LoadNewTabButtonImage() { | |
1100 ThemeProvider* tp = GetThemeProvider(); | |
1101 | |
1102 SkBitmap* bitmap = tp->GetBitmapNamed(IDR_NEWTAB_BUTTON); | |
1103 SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); | |
1104 SkBitmap* background = tp->GetBitmapNamed( | |
1105 IDR_THEME_WINDOW_CONTROL_BACKGROUND); | |
1106 | |
1107 newtab_button_->SetImage(views::CustomButton::BS_NORMAL, bitmap); | |
1108 newtab_button_->SetImage(views::CustomButton::BS_PUSHED, | |
1109 tp->GetBitmapNamed(IDR_NEWTAB_BUTTON_P)); | |
1110 newtab_button_->SetImage(views::CustomButton::BS_HOT, | |
1111 tp->GetBitmapNamed(IDR_NEWTAB_BUTTON_H)); | |
1112 newtab_button_->SetBackground(color, background, | |
1113 tp->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK)); | |
1114 newtab_button_size_.SetSize(bitmap->width(), bitmap->height()); | |
1115 } | |
1116 | |
1117 Tab* TabStrip::GetTabAt(int index) const { | 1103 Tab* TabStrip::GetTabAt(int index) const { |
1118 DCHECK(index >= 0 && index < GetTabCount()); | 1104 DCHECK(index >= 0 && index < GetTabCount()); |
1119 return tab_data_.at(index).tab; | 1105 return tab_data_.at(index).tab; |
1120 } | 1106 } |
1121 | 1107 |
1122 Tab* TabStrip::GetTabAtAdjustForAnimation(int index) const { | 1108 Tab* TabStrip::GetTabAtAdjustForAnimation(int index) const { |
1123 if (active_animation_.get() && | 1109 if (active_animation_.get() && |
1124 active_animation_->type() == TabAnimation::REMOVE && | 1110 active_animation_->type() == TabAnimation::REMOVE && |
1125 index >= | 1111 index >= |
1126 static_cast<RemoveTabAnimation*>(active_animation_.get())->index()) { | 1112 static_cast<RemoveTabAnimation*>(active_animation_.get())->index()) { |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 &TabStrip::ResizeLayoutTabs), | 1577 &TabStrip::ResizeLayoutTabs), |
1592 kResizeTabsTimeMs); | 1578 kResizeTabsTimeMs); |
1593 } | 1579 } |
1594 } else { | 1580 } else { |
1595 // Mouse moved quickly out of the tab strip and then into it again, so | 1581 // Mouse moved quickly out of the tab strip and then into it again, so |
1596 // cancel the timer so that the strip doesn't move when the mouse moves | 1582 // cancel the timer so that the strip doesn't move when the mouse moves |
1597 // back over it. | 1583 // back over it. |
1598 resize_layout_factory_.RevokeAll(); | 1584 resize_layout_factory_.RevokeAll(); |
1599 } | 1585 } |
1600 } | 1586 } |
OLD | NEW |