Chromium Code Reviews| Index: chrome/browser/ui/views/tabs/tab_strip.cc |
| diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc |
| index d6d02a9ce754b6d9f6683b15b34a88d31327258e..8a52fc675a10f5f98df8618cb2365b14e81f2b26 100644 |
| --- a/chrome/browser/ui/views/tabs/tab_strip.cc |
| +++ b/chrome/browser/ui/views/tabs/tab_strip.cc |
| @@ -38,7 +38,8 @@ |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/models/list_selection_model.h" |
| #include "ui/base/resource/resource_bundle.h" |
| -#include "ui/compositor/paint_context.h" |
| +#include "ui/compositor/compositing_recorder.h" |
| +#include "ui/compositor/paint_recorder.h" |
| #include "ui/gfx/animation/animation_container.h" |
| #include "ui/gfx/animation/throb_animation.h" |
| #include "ui/gfx/canvas.h" |
| @@ -1242,7 +1243,6 @@ void TabStrip::Layout() { |
| } |
| void TabStrip::PaintChildren(const ui::PaintContext& context) { |
| - gfx::Canvas* canvas = context.canvas(); |
| // The view order doesn't match the paint order (tabs_ contains the tab |
| // ordering). Additionally we need to paint the tabs that are closing in |
| // |tabs_closing_map_|. |
| @@ -1256,63 +1256,64 @@ void TabStrip::PaintChildren(const ui::PaintContext& context) { |
| const chrome::HostDesktopType host_desktop_type = |
| chrome::GetHostDesktopTypeForNativeView(GetWidget()->GetNativeView()); |
| const int inactive_tab_alpha = |
| - (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) ? |
| - kInactiveTabAndNewTabButtonAlphaAsh : kInactiveTabAndNewTabButtonAlpha; |
| + (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) |
| + ? kInactiveTabAndNewTabButtonAlphaAsh |
| + : 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
|
| - if (inactive_tab_alpha < 255) |
| - canvas->SaveLayerAlpha(inactive_tab_alpha); |
| + { |
| + 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
|
| - PaintClosingTabs(tab_count(), context); |
| + PaintClosingTabs(tab_count(), context); |
|
danakj
2015/04/07 20:51:43
This is all just reformatting...
|
| - for (int i = tab_count() - 1; i >= 0; --i) { |
| - Tab* tab = tab_at(i); |
| - if (tab->IsSelected()) |
| - selected_tab_count++; |
| - if (tab->dragging() && !stacked_layout_) { |
| - is_dragging = true; |
| - if (tab->IsActive()) { |
| + for (int i = tab_count() - 1; i >= 0; --i) { |
| + Tab* tab = tab_at(i); |
| + if (tab->IsSelected()) |
| + selected_tab_count++; |
| + if (tab->dragging() && !stacked_layout_) { |
| + is_dragging = true; |
| + if (tab->IsActive()) { |
| + active_tab = tab; |
| + active_tab_index = i; |
| + } else { |
| + tabs_dragging.push_back(tab); |
| + } |
| + } else if (!tab->IsActive()) { |
| + if (!tab->IsSelected()) { |
| + if (!stacked_layout_) |
| + tab->Paint(context); |
| + } else { |
| + selected_tabs.push_back(tab); |
| + } |
| + } else { |
| active_tab = tab; |
| active_tab_index = i; |
| - } else { |
| - tabs_dragging.push_back(tab); |
| } |
| - } else if (!tab->IsActive()) { |
| - if (!tab->IsSelected()) { |
| - if (!stacked_layout_) |
| - tab->Paint(context); |
| - } else { |
| - selected_tabs.push_back(tab); |
| - } |
| - } else { |
| - active_tab = tab; |
| - active_tab_index = i; |
| + PaintClosingTabs(i, context); |
| } |
| - PaintClosingTabs(i, context); |
| - } |
| - // Draw from the left and then the right if we're in touch mode. |
| - if (stacked_layout_ && active_tab_index >= 0) { |
| - for (int i = 0; i < active_tab_index; ++i) { |
| - Tab* tab = tab_at(i); |
| - tab->Paint(context); |
| - } |
| + // Draw from the left and then the right if we're in touch mode. |
| + if (stacked_layout_ && active_tab_index >= 0) { |
| + for (int i = 0; i < active_tab_index; ++i) { |
| + Tab* tab = tab_at(i); |
| + tab->Paint(context); |
| + } |
| - for (int i = tab_count() - 1; i > active_tab_index; --i) { |
| - Tab* tab = tab_at(i); |
| - tab->Paint(context); |
| + for (int i = tab_count() - 1; i > active_tab_index; --i) { |
| + Tab* tab = tab_at(i); |
| + tab->Paint(context); |
| + } |
| } |
| } |
| - if (inactive_tab_alpha < 255) |
| - canvas->Restore(); |
|
danakj
2015/04/07 20:51:43
This goes away thanks to scoped recorder.
|
| if (GetWidget()->ShouldWindowContentsBeTransparent()) { |
| + ui::PaintRecorder recorder(context); |
|
danakj
2015/04/07 20:51:43
A paint recorder to draw to a canvas
|
| // Make sure non-active tabs are somewhat transparent. |
| SkPaint paint; |
| // If there are multiple tabs selected, fade non-selected tabs more to make |
| // the selected tabs more noticable. |
| - int alpha = selected_tab_count > 1 ? |
| - kGlassFrameInactiveTabAlphaMultiSelection : |
| - kGlassFrameInactiveTabAlpha; |
| + int alpha = selected_tab_count > 1 |
| + ? kGlassFrameInactiveTabAlphaMultiSelection |
| + : kGlassFrameInactiveTabAlpha; |
| paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); |
| paint.setXfermodeMode(SkXfermode::kDstIn_Mode); |
| paint.setStyle(SkPaint::kFill_Style); |
| @@ -1324,7 +1325,7 @@ void TabStrip::PaintChildren(const ui::PaintContext& context) { |
| // overlap the avatar button, leading to visual artifacts. |
| const int kTopOffset = 4; |
| // The tabstrip area overlaps the toolbar area by 2 px. |
| - canvas->DrawRect( |
| + recorder.canvas()->DrawRect( |
| gfx::Rect(0, kTopOffset, width(), height() - kTopOffset - 2), paint); |
| } |
| @@ -1338,11 +1339,10 @@ void TabStrip::PaintChildren(const ui::PaintContext& context) { |
| active_tab->Paint(context); |
| // Paint the New Tab button. |
| - if (inactive_tab_alpha < 255) |
| - canvas->SaveLayerAlpha(inactive_tab_alpha); |
| - newtab_button_->Paint(context); |
| - if (inactive_tab_alpha < 255) |
| - canvas->Restore(); |
| + { |
| + ui::CompositingRecorder opacity_recorder(context, inactive_tab_alpha); |
|
danakj
2015/04/07 20:51:43
Another scoped recorder for alpha
|
| + newtab_button_->Paint(context); |
| + } |
| // And the dragged tabs. |
| for (size_t i = 0; i < tabs_dragging.size(); ++i) |