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/tab_strip.h" | 5 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 | 1059 |
1060 void TabStrip::Layout() { | 1060 void TabStrip::Layout() { |
1061 // Only do a layout if our size changed. | 1061 // Only do a layout if our size changed. |
1062 if (last_layout_size_ == size()) | 1062 if (last_layout_size_ == size()) |
1063 return; | 1063 return; |
1064 if (IsDragSessionActive()) | 1064 if (IsDragSessionActive()) |
1065 return; | 1065 return; |
1066 DoLayout(); | 1066 DoLayout(); |
1067 } | 1067 } |
1068 | 1068 |
1069 void TabStrip::PaintChildren(const ui::PaintContext& context) { | 1069 void TabStrip::PaintChildren(const views::PaintInfo& paint_info) { |
1070 // The view order doesn't match the paint order (tabs_ contains the tab | 1070 // The view order doesn't match the paint order (tabs_ contains the tab |
1071 // ordering). Additionally we need to paint the tabs that are closing in | 1071 // ordering). Additionally we need to paint the tabs that are closing in |
1072 // |tabs_closing_map_|. | 1072 // |tabs_closing_map_|. |
1073 bool is_dragging = false; | 1073 bool is_dragging = false; |
1074 Tab* active_tab = NULL; | 1074 Tab* active_tab = NULL; |
1075 Tabs tabs_dragging; | 1075 Tabs tabs_dragging; |
1076 Tabs selected_tabs; | 1076 Tabs selected_tabs; |
1077 | 1077 |
1078 { | 1078 { |
1079 // We pass false for |lcd_text_requires_opaque_layer| so that background | 1079 // We pass false for |lcd_text_requires_opaque_layer| so that background |
1080 // tab titles will get LCD AA. These are rendered opaquely on an opaque tab | 1080 // tab titles will get LCD AA. These are rendered opaquely on an opaque tab |
1081 // background before the layer is composited, so this is safe. | 1081 // background before the layer is composited, so this is safe. |
1082 ui::CompositingRecorder opacity_recorder(context, GetInactiveAlpha(false), | 1082 ui::CompositingRecorder opacity_recorder(paint_info.context(), |
1083 false); | 1083 GetInactiveAlpha(false), false); |
1084 | 1084 |
1085 PaintClosingTabs(tab_count(), context); | 1085 PaintClosingTabs(tab_count(), paint_info); |
1086 | 1086 |
1087 int active_tab_index = -1; | 1087 int active_tab_index = -1; |
1088 for (int i = tab_count() - 1; i >= 0; --i) { | 1088 for (int i = tab_count() - 1; i >= 0; --i) { |
1089 Tab* tab = tab_at(i); | 1089 Tab* tab = tab_at(i); |
1090 if (tab->dragging() && !stacked_layout_) { | 1090 if (tab->dragging() && !stacked_layout_) { |
1091 is_dragging = true; | 1091 is_dragging = true; |
1092 if (tab->IsActive()) { | 1092 if (tab->IsActive()) { |
1093 active_tab = tab; | 1093 active_tab = tab; |
1094 active_tab_index = i; | 1094 active_tab_index = i; |
1095 } else { | 1095 } else { |
1096 tabs_dragging.push_back(tab); | 1096 tabs_dragging.push_back(tab); |
1097 } | 1097 } |
1098 } else if (!tab->IsActive()) { | 1098 } else if (!tab->IsActive()) { |
1099 if (!tab->IsSelected()) { | 1099 if (!tab->IsSelected()) { |
1100 if (!stacked_layout_) | 1100 if (!stacked_layout_) |
1101 tab->Paint(context); | 1101 tab->Paint(paint_info); |
1102 } else { | 1102 } else { |
1103 selected_tabs.push_back(tab); | 1103 selected_tabs.push_back(tab); |
1104 } | 1104 } |
1105 } else { | 1105 } else { |
1106 active_tab = tab; | 1106 active_tab = tab; |
1107 active_tab_index = i; | 1107 active_tab_index = i; |
1108 } | 1108 } |
1109 PaintClosingTabs(i, context); | 1109 PaintClosingTabs(i, paint_info); |
1110 } | 1110 } |
1111 | 1111 |
1112 // Draw from the left and then the right if we're in touch mode. | 1112 // Draw from the left and then the right if we're in touch mode. |
1113 if (stacked_layout_ && active_tab_index >= 0) { | 1113 if (stacked_layout_ && active_tab_index >= 0) { |
1114 for (int i = 0; i < active_tab_index; ++i) { | 1114 for (int i = 0; i < active_tab_index; ++i) { |
1115 Tab* tab = tab_at(i); | 1115 Tab* tab = tab_at(i); |
1116 tab->Paint(context); | 1116 tab->Paint(paint_info); |
1117 } | 1117 } |
1118 | 1118 |
1119 for (int i = tab_count() - 1; i > active_tab_index; --i) { | 1119 for (int i = tab_count() - 1; i > active_tab_index; --i) { |
1120 Tab* tab = tab_at(i); | 1120 Tab* tab = tab_at(i); |
1121 tab->Paint(context); | 1121 tab->Paint(paint_info); |
1122 } | 1122 } |
1123 } | 1123 } |
1124 } | 1124 } |
1125 | 1125 |
1126 // Now selected but not active. We don't want these dimmed if using native | 1126 // Now selected but not active. We don't want these dimmed if using native |
1127 // frame, so they're painted after initial pass. | 1127 // frame, so they're painted after initial pass. |
1128 for (size_t i = 0; i < selected_tabs.size(); ++i) | 1128 for (size_t i = 0; i < selected_tabs.size(); ++i) |
1129 selected_tabs[i]->Paint(context); | 1129 selected_tabs[i]->Paint(paint_info); |
1130 | 1130 |
1131 // Next comes the active tab. | 1131 // Next comes the active tab. |
1132 if (active_tab && !is_dragging) | 1132 if (active_tab && !is_dragging) |
1133 active_tab->Paint(context); | 1133 active_tab->Paint(paint_info); |
1134 | 1134 |
1135 // Paint the New Tab button. | 1135 // Paint the New Tab button. |
1136 if (new_tab_button_->state() == views::CustomButton::STATE_PRESSED) { | 1136 if (new_tab_button_->state() == views::CustomButton::STATE_PRESSED) { |
1137 new_tab_button_->Paint(context); | 1137 new_tab_button_->Paint(paint_info); |
1138 } else { | 1138 } else { |
1139 // Match the inactive tab opacity for non-pressed states. See comments in | 1139 // Match the inactive tab opacity for non-pressed states. See comments in |
1140 // NewTabButton::PaintFill() for why we don't do this for the pressed state. | 1140 // NewTabButton::PaintFill() for why we don't do this for the pressed state. |
1141 // This call doesn't need to set |lcd_text_requires_opaque_layer| to false | 1141 // This call doesn't need to set |lcd_text_requires_opaque_layer| to false |
1142 // because no text will be drawn. | 1142 // because no text will be drawn. |
1143 ui::CompositingRecorder opacity_recorder(context, GetInactiveAlpha(true), | 1143 ui::CompositingRecorder opacity_recorder(paint_info.context(), |
1144 true); | 1144 GetInactiveAlpha(true), true); |
1145 new_tab_button_->Paint(context); | 1145 new_tab_button_->Paint(paint_info); |
1146 } | 1146 } |
1147 | 1147 |
1148 // And the dragged tabs. | 1148 // And the dragged tabs. |
1149 for (size_t i = 0; i < tabs_dragging.size(); ++i) | 1149 for (size_t i = 0; i < tabs_dragging.size(); ++i) |
1150 tabs_dragging[i]->Paint(context); | 1150 tabs_dragging[i]->Paint(paint_info); |
1151 | 1151 |
1152 // If the active tab is being dragged, it goes last. | 1152 // If the active tab is being dragged, it goes last. |
1153 if (active_tab && is_dragging) | 1153 if (active_tab && is_dragging) |
1154 active_tab->Paint(context); | 1154 active_tab->Paint(paint_info); |
1155 | 1155 |
1156 ui::PaintRecorder recorder(context, size()); | 1156 ui::PaintRecorder recorder(paint_info.context(), size()); |
1157 gfx::Canvas* canvas = recorder.canvas(); | 1157 gfx::Canvas* canvas = recorder.canvas(); |
1158 if (active_tab) { | 1158 if (active_tab) { |
1159 canvas->sk_canvas()->clipRect( | 1159 canvas->sk_canvas()->clipRect( |
1160 gfx::RectToSkRect(active_tab->GetMirroredBounds()), | 1160 gfx::RectToSkRect(active_tab->GetMirroredBounds()), |
1161 SkClipOp::kDifference); | 1161 SkClipOp::kDifference); |
1162 } | 1162 } |
1163 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(), | 1163 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(), |
1164 GetLocalBounds(), true); | 1164 GetLocalBounds(), true); |
1165 } | 1165 } |
1166 | 1166 |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 for (TabsClosingMap::iterator i(tabs_closing_map_.begin()); | 1777 for (TabsClosingMap::iterator i(tabs_closing_map_.begin()); |
1778 i != tabs_closing_map_.end(); ++i) { | 1778 i != tabs_closing_map_.end(); ++i) { |
1779 Tabs::iterator j = std::find(i->second.begin(), i->second.end(), tab); | 1779 Tabs::iterator j = std::find(i->second.begin(), i->second.end(), tab); |
1780 if (j != i->second.end()) | 1780 if (j != i->second.end()) |
1781 return FindClosingTabResult(i, j); | 1781 return FindClosingTabResult(i, j); |
1782 } | 1782 } |
1783 NOTREACHED(); | 1783 NOTREACHED(); |
1784 return FindClosingTabResult(tabs_closing_map_.end(), Tabs::iterator()); | 1784 return FindClosingTabResult(tabs_closing_map_.end(), Tabs::iterator()); |
1785 } | 1785 } |
1786 | 1786 |
1787 void TabStrip::PaintClosingTabs(int index, const ui::PaintContext& context) { | 1787 void TabStrip::PaintClosingTabs(int index, const views::PaintInfo& paint_info) { |
1788 if (tabs_closing_map_.find(index) == tabs_closing_map_.end()) | 1788 if (tabs_closing_map_.find(index) == tabs_closing_map_.end()) |
1789 return; | 1789 return; |
1790 | 1790 |
1791 const Tabs& tabs = tabs_closing_map_[index]; | 1791 const Tabs& tabs = tabs_closing_map_[index]; |
1792 for (Tabs::const_reverse_iterator i(tabs.rbegin()); i != tabs.rend(); ++i) | 1792 for (Tabs::const_reverse_iterator i(tabs.rbegin()); i != tabs.rend(); ++i) |
1793 (*i)->Paint(context); | 1793 (*i)->Paint(paint_info); |
1794 } | 1794 } |
1795 | 1795 |
1796 void TabStrip::UpdateStackedLayoutFromMouseEvent(views::View* source, | 1796 void TabStrip::UpdateStackedLayoutFromMouseEvent(views::View* source, |
1797 const ui::MouseEvent& event) { | 1797 const ui::MouseEvent& event) { |
1798 if (!adjust_layout_) | 1798 if (!adjust_layout_) |
1799 return; | 1799 return; |
1800 | 1800 |
1801 // The following code attempts to switch to shrink (not stacked) layout when | 1801 // The following code attempts to switch to shrink (not stacked) layout when |
1802 // the mouse exits the tabstrip (or the mouse is pressed on a stacked tab) and | 1802 // the mouse exits the tabstrip (or the mouse is pressed on a stacked tab) and |
1803 // to stacked layout when a touch device is used. This is made problematic by | 1803 // to stacked layout when a touch device is used. This is made problematic by |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2486 ConvertPointToViewAndGetEventHandler(this, new_tab_button_, point); | 2486 ConvertPointToViewAndGetEventHandler(this, new_tab_button_, point); |
2487 if (view) | 2487 if (view) |
2488 return view; | 2488 return view; |
2489 } | 2489 } |
2490 Tab* tab = FindTabForEvent(point); | 2490 Tab* tab = FindTabForEvent(point); |
2491 if (tab) | 2491 if (tab) |
2492 return ConvertPointToViewAndGetEventHandler(this, tab, point); | 2492 return ConvertPointToViewAndGetEventHandler(this, tab, point); |
2493 } | 2493 } |
2494 return this; | 2494 return this; |
2495 } | 2495 } |
OLD | NEW |