Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/ui/views/tabs/tab_strip.cc

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

Powered by Google App Engine
This is Rietveld 408576698