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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windowsx.h> | 8 #include <windowsx.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
33 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
34 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
35 #include "ui/accessibility/ax_view_state.h" | 35 #include "ui/accessibility/ax_view_state.h" |
36 #include "ui/base/default_theme_provider.h" | 36 #include "ui/base/default_theme_provider.h" |
37 #include "ui/base/dragdrop/drag_drop_types.h" | 37 #include "ui/base/dragdrop/drag_drop_types.h" |
38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
39 #include "ui/base/models/list_selection_model.h" | 39 #include "ui/base/models/list_selection_model.h" |
40 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
41 #include "ui/compositor/paint_context.h" | 41 #include "ui/compositor/compositing_recorder.h" |
42 #include "ui/compositor/paint_recorder.h" | |
42 #include "ui/gfx/animation/animation_container.h" | 43 #include "ui/gfx/animation/animation_container.h" |
43 #include "ui/gfx/animation/throb_animation.h" | 44 #include "ui/gfx/animation/throb_animation.h" |
44 #include "ui/gfx/canvas.h" | 45 #include "ui/gfx/canvas.h" |
45 #include "ui/gfx/display.h" | 46 #include "ui/gfx/display.h" |
46 #include "ui/gfx/geometry/rect_conversions.h" | 47 #include "ui/gfx/geometry/rect_conversions.h" |
47 #include "ui/gfx/geometry/size.h" | 48 #include "ui/gfx/geometry/size.h" |
48 #include "ui/gfx/image/image_skia.h" | 49 #include "ui/gfx/image/image_skia.h" |
49 #include "ui/gfx/image/image_skia_operations.h" | 50 #include "ui/gfx/image/image_skia_operations.h" |
50 #include "ui/gfx/path.h" | 51 #include "ui/gfx/path.h" |
51 #include "ui/gfx/screen.h" | 52 #include "ui/gfx/screen.h" |
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1235 void TabStrip::Layout() { | 1236 void TabStrip::Layout() { |
1236 // Only do a layout if our size changed. | 1237 // Only do a layout if our size changed. |
1237 if (last_layout_size_ == size()) | 1238 if (last_layout_size_ == size()) |
1238 return; | 1239 return; |
1239 if (IsDragSessionActive()) | 1240 if (IsDragSessionActive()) |
1240 return; | 1241 return; |
1241 DoLayout(); | 1242 DoLayout(); |
1242 } | 1243 } |
1243 | 1244 |
1244 void TabStrip::PaintChildren(const ui::PaintContext& context) { | 1245 void TabStrip::PaintChildren(const ui::PaintContext& context) { |
1245 gfx::Canvas* canvas = context.canvas(); | |
1246 // The view order doesn't match the paint order (tabs_ contains the tab | 1246 // The view order doesn't match the paint order (tabs_ contains the tab |
1247 // ordering). Additionally we need to paint the tabs that are closing in | 1247 // ordering). Additionally we need to paint the tabs that are closing in |
1248 // |tabs_closing_map_|. | 1248 // |tabs_closing_map_|. |
1249 Tab* active_tab = NULL; | 1249 Tab* active_tab = NULL; |
1250 Tabs tabs_dragging; | 1250 Tabs tabs_dragging; |
1251 Tabs selected_tabs; | 1251 Tabs selected_tabs; |
1252 int selected_tab_count = 0; | 1252 int selected_tab_count = 0; |
1253 bool is_dragging = false; | 1253 bool is_dragging = false; |
1254 int active_tab_index = -1; | 1254 int active_tab_index = -1; |
1255 | 1255 |
1256 const chrome::HostDesktopType host_desktop_type = | 1256 const chrome::HostDesktopType host_desktop_type = |
1257 chrome::GetHostDesktopTypeForNativeView(GetWidget()->GetNativeView()); | 1257 chrome::GetHostDesktopTypeForNativeView(GetWidget()->GetNativeView()); |
1258 const int inactive_tab_alpha = | 1258 const int inactive_tab_alpha = |
1259 (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) ? | 1259 (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) |
1260 kInactiveTabAndNewTabButtonAlphaAsh : kInactiveTabAndNewTabButtonAlpha; | 1260 ? kInactiveTabAndNewTabButtonAlphaAsh |
1261 : kInactiveTabAndNewTabButtonAlpha; | |
Peter Kasting
2015/04/07 21:32:39
It would have been nice not to reformat this or th
danakj
2015/04/07 21:36:26
git cl format did it, cuz I touched them, but I th
| |
1261 | 1262 |
1262 if (inactive_tab_alpha < 255) | 1263 { |
1263 canvas->SaveLayerAlpha(inactive_tab_alpha); | 1264 ui::CompositingRecorder opacity_recorder(context, inactive_tab_alpha); |
danakj
2015/04/07 20:51:43
This looks like a big change but it's mostly just
| |
1264 | 1265 |
1265 PaintClosingTabs(tab_count(), context); | 1266 PaintClosingTabs(tab_count(), context); |
danakj
2015/04/07 20:51:43
This is all just reformatting...
| |
1266 | 1267 |
1267 for (int i = tab_count() - 1; i >= 0; --i) { | 1268 for (int i = tab_count() - 1; i >= 0; --i) { |
1268 Tab* tab = tab_at(i); | 1269 Tab* tab = tab_at(i); |
1269 if (tab->IsSelected()) | 1270 if (tab->IsSelected()) |
1270 selected_tab_count++; | 1271 selected_tab_count++; |
1271 if (tab->dragging() && !stacked_layout_) { | 1272 if (tab->dragging() && !stacked_layout_) { |
1272 is_dragging = true; | 1273 is_dragging = true; |
1273 if (tab->IsActive()) { | 1274 if (tab->IsActive()) { |
1275 active_tab = tab; | |
1276 active_tab_index = i; | |
1277 } else { | |
1278 tabs_dragging.push_back(tab); | |
1279 } | |
1280 } else if (!tab->IsActive()) { | |
1281 if (!tab->IsSelected()) { | |
1282 if (!stacked_layout_) | |
1283 tab->Paint(context); | |
1284 } else { | |
1285 selected_tabs.push_back(tab); | |
1286 } | |
1287 } else { | |
1274 active_tab = tab; | 1288 active_tab = tab; |
1275 active_tab_index = i; | 1289 active_tab_index = i; |
1276 } else { | |
1277 tabs_dragging.push_back(tab); | |
1278 } | 1290 } |
1279 } else if (!tab->IsActive()) { | 1291 PaintClosingTabs(i, context); |
1280 if (!tab->IsSelected()) { | 1292 } |
1281 if (!stacked_layout_) | 1293 |
1282 tab->Paint(context); | 1294 // Draw from the left and then the right if we're in touch mode. |
1283 } else { | 1295 if (stacked_layout_ && active_tab_index >= 0) { |
1284 selected_tabs.push_back(tab); | 1296 for (int i = 0; i < active_tab_index; ++i) { |
1297 Tab* tab = tab_at(i); | |
1298 tab->Paint(context); | |
1285 } | 1299 } |
1286 } else { | 1300 |
1287 active_tab = tab; | 1301 for (int i = tab_count() - 1; i > active_tab_index; --i) { |
1288 active_tab_index = i; | 1302 Tab* tab = tab_at(i); |
1303 tab->Paint(context); | |
1304 } | |
1289 } | 1305 } |
1290 PaintClosingTabs(i, context); | |
1291 } | 1306 } |
1292 | 1307 |
1293 // Draw from the left and then the right if we're in touch mode. | |
1294 if (stacked_layout_ && active_tab_index >= 0) { | |
1295 for (int i = 0; i < active_tab_index; ++i) { | |
1296 Tab* tab = tab_at(i); | |
1297 tab->Paint(context); | |
1298 } | |
1299 | |
1300 for (int i = tab_count() - 1; i > active_tab_index; --i) { | |
1301 Tab* tab = tab_at(i); | |
1302 tab->Paint(context); | |
1303 } | |
1304 } | |
1305 if (inactive_tab_alpha < 255) | |
1306 canvas->Restore(); | |
danakj
2015/04/07 20:51:43
This goes away thanks to scoped recorder.
| |
1307 | |
1308 if (GetWidget()->ShouldWindowContentsBeTransparent()) { | 1308 if (GetWidget()->ShouldWindowContentsBeTransparent()) { |
1309 ui::PaintRecorder recorder(context); | |
danakj
2015/04/07 20:51:43
A paint recorder to draw to a canvas
| |
1309 // Make sure non-active tabs are somewhat transparent. | 1310 // Make sure non-active tabs are somewhat transparent. |
1310 SkPaint paint; | 1311 SkPaint paint; |
1311 // If there are multiple tabs selected, fade non-selected tabs more to make | 1312 // If there are multiple tabs selected, fade non-selected tabs more to make |
1312 // the selected tabs more noticable. | 1313 // the selected tabs more noticable. |
1313 int alpha = selected_tab_count > 1 ? | 1314 int alpha = selected_tab_count > 1 |
1314 kGlassFrameInactiveTabAlphaMultiSelection : | 1315 ? kGlassFrameInactiveTabAlphaMultiSelection |
1315 kGlassFrameInactiveTabAlpha; | 1316 : kGlassFrameInactiveTabAlpha; |
1316 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); | 1317 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); |
1317 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); | 1318 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); |
1318 paint.setStyle(SkPaint::kFill_Style); | 1319 paint.setStyle(SkPaint::kFill_Style); |
1319 | 1320 |
1320 // The tab graphics include some shadows at the top, so the actual | 1321 // The tab graphics include some shadows at the top, so the actual |
1321 // tabstrip top is 4 px. above the apparent top of the tab, to provide room | 1322 // tabstrip top is 4 px. above the apparent top of the tab, to provide room |
1322 // to draw these. Exclude this region when trying to make tabs transparent | 1323 // to draw these. Exclude this region when trying to make tabs transparent |
1323 // as it's transparent enough already, and drawing in this region can | 1324 // as it's transparent enough already, and drawing in this region can |
1324 // overlap the avatar button, leading to visual artifacts. | 1325 // overlap the avatar button, leading to visual artifacts. |
1325 const int kTopOffset = 4; | 1326 const int kTopOffset = 4; |
1326 // The tabstrip area overlaps the toolbar area by 2 px. | 1327 // The tabstrip area overlaps the toolbar area by 2 px. |
1327 canvas->DrawRect( | 1328 recorder.canvas()->DrawRect( |
1328 gfx::Rect(0, kTopOffset, width(), height() - kTopOffset - 2), paint); | 1329 gfx::Rect(0, kTopOffset, width(), height() - kTopOffset - 2), paint); |
1329 } | 1330 } |
1330 | 1331 |
1331 // Now selected but not active. We don't want these dimmed if using native | 1332 // Now selected but not active. We don't want these dimmed if using native |
1332 // frame, so they're painted after initial pass. | 1333 // frame, so they're painted after initial pass. |
1333 for (size_t i = 0; i < selected_tabs.size(); ++i) | 1334 for (size_t i = 0; i < selected_tabs.size(); ++i) |
1334 selected_tabs[i]->Paint(context); | 1335 selected_tabs[i]->Paint(context); |
1335 | 1336 |
1336 // Next comes the active tab. | 1337 // Next comes the active tab. |
1337 if (active_tab && !is_dragging) | 1338 if (active_tab && !is_dragging) |
1338 active_tab->Paint(context); | 1339 active_tab->Paint(context); |
1339 | 1340 |
1340 // Paint the New Tab button. | 1341 // Paint the New Tab button. |
1341 if (inactive_tab_alpha < 255) | 1342 { |
1342 canvas->SaveLayerAlpha(inactive_tab_alpha); | 1343 ui::CompositingRecorder opacity_recorder(context, inactive_tab_alpha); |
danakj
2015/04/07 20:51:43
Another scoped recorder for alpha
| |
1343 newtab_button_->Paint(context); | 1344 newtab_button_->Paint(context); |
1344 if (inactive_tab_alpha < 255) | 1345 } |
1345 canvas->Restore(); | |
1346 | 1346 |
1347 // And the dragged tabs. | 1347 // And the dragged tabs. |
1348 for (size_t i = 0; i < tabs_dragging.size(); ++i) | 1348 for (size_t i = 0; i < tabs_dragging.size(); ++i) |
1349 tabs_dragging[i]->Paint(context); | 1349 tabs_dragging[i]->Paint(context); |
1350 | 1350 |
1351 // If the active tab is being dragged, it goes last. | 1351 // If the active tab is being dragged, it goes last. |
1352 if (active_tab && is_dragging) | 1352 if (active_tab && is_dragging) |
1353 active_tab->Paint(context); | 1353 active_tab->Paint(context); |
1354 } | 1354 } |
1355 | 1355 |
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2758 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); | 2758 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); |
2759 if (view) | 2759 if (view) |
2760 return view; | 2760 return view; |
2761 } | 2761 } |
2762 Tab* tab = FindTabForEvent(point); | 2762 Tab* tab = FindTabForEvent(point); |
2763 if (tab) | 2763 if (tab) |
2764 return ConvertPointToViewAndGetEventHandler(this, tab, point); | 2764 return ConvertPointToViewAndGetEventHandler(this, tab, point); |
2765 } | 2765 } |
2766 return this; | 2766 return this; |
2767 } | 2767 } |
OLD | NEW |