Chromium Code Reviews| Index: chrome/browser/ui/views/tabs/tab.cc |
| diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc |
| index 0d3ffbbc344abe846fd625011edccf68f13a0a57..f6ea473a87b0a0f68ab4a386f9740a41eff69c0c 100644 |
| --- a/chrome/browser/ui/views/tabs/tab.cc |
| +++ b/chrome/browser/ui/views/tabs/tab.cc |
| @@ -116,6 +116,32 @@ const int kImmersiveLoadingStepCount = 32; |
| const char kTabCloseButtonName[] = "TabCloseButton"; |
| +// Parameters for PaintTabBackgroundUsingParams(). |
| +struct PaintBackgroundParams { |
| + PaintBackgroundParams(bool is_active, |
| + gfx::ImageSkia* fill_image_ptr, |
| + bool has_custom_image, |
| + gfx::Rect rect, |
| + SkColor stroke_color, |
| + SkColor toolbar_color, |
| + SkColor background_color) |
| + : is_active(is_active), |
| + fill_image(fill_image_ptr ? *fill_image_ptr : gfx::ImageSkia()), |
| + has_custom_image(has_custom_image), |
| + rect(rect), |
| + stroke_color(stroke_color), |
| + toolbar_color(toolbar_color), |
| + background_color(background_color) {} |
| + |
| + const bool is_active; |
| + const gfx::ImageSkia fill_image; |
| + const bool has_custom_image; |
| + const gfx::Rect rect; |
| + const SkColor stroke_color; |
| + const SkColor toolbar_color; |
| + const SkColor background_color; |
| +}; |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // ImageCacheEntryMetadata |
| // |
| @@ -410,10 +436,8 @@ gfx::Path GetBorderPath(float scale, |
| } |
| void PaintTabFill(gfx::Canvas* canvas, |
| - gfx::ImageSkia* fill_image, |
| - int x_offset, |
| - int y_offset, |
| - const gfx::Size& size, |
| + const gfx::ImageSkia& fill_image, |
| + gfx::Rect rect, |
| bool is_active) { |
| const gfx::Insets tab_insets(GetLayoutInsets(TAB)); |
| // If this isn't the foreground tab, don't draw over the toolbar, but do |
| @@ -422,7 +446,7 @@ void PaintTabFill(gfx::Canvas* canvas, |
| // Draw left edge. |
| gfx::ImageSkia tab_l = gfx::ImageSkiaOperations::CreateTiledImage( |
| - *fill_image, x_offset, y_offset, g_mask_images.l_width, size.height()); |
| + fill_image, rect.x(), rect.y(), g_mask_images.l_width, rect.height()); |
| gfx::ImageSkia theme_l = gfx::ImageSkiaOperations::CreateMaskedImage( |
| tab_l, *g_mask_images.image_l); |
| canvas->DrawImageInt( |
| @@ -431,22 +455,108 @@ void PaintTabFill(gfx::Canvas* canvas, |
| // Draw right edge. |
| gfx::ImageSkia tab_r = gfx::ImageSkiaOperations::CreateTiledImage( |
| - *fill_image, x_offset + size.width() - g_mask_images.r_width, y_offset, |
| - g_mask_images.r_width, size.height()); |
| + fill_image, rect.right() - g_mask_images.r_width, rect.y(), |
| + g_mask_images.r_width, rect.height()); |
| gfx::ImageSkia theme_r = gfx::ImageSkiaOperations::CreateMaskedImage( |
| tab_r, *g_mask_images.image_r); |
| canvas->DrawImageInt(theme_r, 0, 0, theme_r.width(), |
| theme_r.height() - toolbar_overlap, |
| - size.width() - theme_r.width(), 0, theme_r.width(), |
| + rect.width() - theme_r.width(), 0, theme_r.width(), |
| theme_r.height() - toolbar_overlap, false); |
| // Draw center. Instead of masking out the top portion we simply skip over it |
| // by incrementing by the top padding, since it's a simple rectangle. |
| - canvas->TileImageInt( |
| - *fill_image, x_offset + g_mask_images.l_width, |
| - y_offset + tab_insets.top(), g_mask_images.l_width, tab_insets.top(), |
| - size.width() - g_mask_images.l_width - g_mask_images.r_width, |
| - size.height() - tab_insets.top() - toolbar_overlap); |
| + rect.Inset(g_mask_images.l_width, tab_insets.top(), g_mask_images.r_width, |
| + toolbar_overlap); |
| + canvas->TileImageInt(fill_image, rect.x(), rect.y(), g_mask_images.l_width, |
| + tab_insets.top(), rect.width(), rect.height()); |
| +} |
| + |
| +void PaintTabBackgroundUsingParams(gfx::Canvas* canvas, |
| + views::GlowHoverController* hc, |
| + const PaintBackgroundParams& params) { |
| + const SkScalar kMinHoverRadius = 16; |
| + const SkScalar radius = |
| + std::max(SkFloatToScalar(params.rect.width() / 4.f), kMinHoverRadius); |
| + const bool draw_hover = !params.is_active && hc; |
| + SkPoint hover_location( |
| + gfx::PointToSkPoint(draw_hover ? hc->location() : gfx::Point())); |
| + const SkColor hover_color = |
| + SkColorSetA(params.toolbar_color, draw_hover ? hc->GetAlpha() : 255); |
| + |
| + if (ui::MaterialDesignController::IsModeMaterial()) { |
| + gfx::ScopedCanvas scoped_canvas(canvas); |
| + const float scale = canvas->UndoDeviceScaleFactor(); |
| + |
| + // Draw the fill. |
| + gfx::Path fill = GetFillPath(scale, params.rect.size()); |
| + SkPaint paint; |
| + paint.setAntiAlias(true); |
| + { |
| + gfx::ScopedCanvas clip_scoper(canvas); |
| + canvas->ClipPath(fill, true); |
| + if (!params.fill_image.isNull()) { |
| + gfx::ScopedCanvas scale_scoper(canvas); |
| + canvas->sk_canvas()->scale(scale, scale); |
| + canvas->TileImageInt(params.fill_image, params.rect.x(), |
| + params.rect.y(), 0, 0, params.rect.width(), |
| + params.rect.height()); |
| + } else { |
| + paint.setColor(params.is_active ? params.toolbar_color |
| + : params.background_color); |
| + canvas->DrawRect( |
| + gfx::ScaleToEnclosingRect(gfx::Rect(params.rect.size()), scale), |
| + paint); |
| + } |
| + if (draw_hover) { |
| + hover_location.scale(SkFloatToScalar(scale)); |
| + DrawHighlight(canvas, hover_location, radius * scale, hover_color); |
| + } |
| + } |
| + |
| + // Draw the stroke. |
| + gfx::Path stroke = GetBorderPath(scale, false, false, params.rect.size()); |
| + Op(stroke, fill, kDifference_SkPathOp, &stroke); |
| + if (!params.is_active) { |
| + // Clip out the bottom line; this will be drawn for us by |
| + // TabStrip::PaintChildren(). |
| + canvas->ClipRect(gfx::RectF(params.rect.width() * scale, |
| + params.rect.height() * scale - 1)); |
|
Greg Levin
2016/08/09 17:28:18
NOTE: Change missed in previous Merge
|
| + } |
| + paint.setColor(params.stroke_color); |
| + canvas->DrawPath(stroke, paint); |
| + } else { |
| + if (draw_hover) { |
| + // Draw everything to a temporary canvas so we can extract an image for |
| + // use in masking the hover glow. |
| + gfx::Canvas background_canvas(params.rect.size(), canvas->image_scale(), |
| + false); |
| + PaintTabFill(&background_canvas, params.fill_image, params.rect, |
| + params.is_active); |
| + gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); |
| + canvas->DrawImageInt(background_image, 0, 0); |
| + |
| + gfx::Canvas hover_canvas(params.rect.size(), canvas->image_scale(), |
| + false); |
| + DrawHighlight(&hover_canvas, hover_location, radius, hover_color); |
| + gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage( |
| + gfx::ImageSkia(hover_canvas.ExtractImageRep()), background_image); |
| + canvas->DrawImageInt(result, 0, 0); |
| + } else { |
| + PaintTabFill(canvas, params.fill_image, params.rect, params.is_active); |
| + } |
| + |
| + // Now draw the stroke, highlights, and shadows around the tab edge. |
| + TabImages* stroke_images = |
| + params.is_active ? &g_active_images : &g_inactive_images; |
| + canvas->DrawImageInt(*stroke_images->image_l, 0, 0); |
| + canvas->TileImageInt( |
| + *stroke_images->image_c, stroke_images->l_width, 0, |
| + params.rect.width() - stroke_images->l_width - stroke_images->r_width, |
| + params.rect.height()); |
| + canvas->DrawImageInt(*stroke_images->image_r, |
| + params.rect.width() - stroke_images->r_width, 0); |
| + } |
| } |
| } // namespace |
| @@ -1484,90 +1594,24 @@ void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* canvas, |
| int fill_id, |
| bool has_custom_image, |
| int y_offset) { |
| - const ui::ThemeProvider* tp = GetThemeProvider(); |
| - const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); |
| - gfx::ImageSkia* fill_image = tp->GetImageSkiaNamed(fill_id); |
| + views::GlowHoverController* hc = |
| + hover_controller_.ShouldDraw() ? &hover_controller_ : nullptr; |
| + gfx::ImageSkia* fill_image = |
| + has_custom_image || !ui::MaterialDesignController::IsModeMaterial() |
| + ? GetThemeProvider()->GetImageSkiaNamed(fill_id) |
| + : nullptr; |
| // The tab image needs to be lined up with the background image |
| // so that it feels partially transparent. These offsets represent the tab |
| // position within the frame background image. |
| - const int x_offset = GetMirroredX() + background_offset_.x(); |
| - |
| - const SkScalar kMinHoverRadius = 16; |
| - const SkScalar radius = |
| - std::max(SkFloatToScalar(width() / 4.f), kMinHoverRadius); |
| - const bool draw_hover = !is_active && hover_controller_.ShouldDraw(); |
| - SkPoint hover_location(gfx::PointToSkPoint(hover_controller_.location())); |
| - const SkColor hover_color = |
| - SkColorSetA(toolbar_color, hover_controller_.GetAlpha()); |
| - |
| - if (ui::MaterialDesignController::IsModeMaterial()) { |
| - gfx::ScopedCanvas scoped_canvas(canvas); |
| - const float scale = canvas->UndoDeviceScaleFactor(); |
| - |
| - // Draw the fill. |
| - gfx::Path fill = GetFillPath(scale, size()); |
| - SkPaint paint; |
| - paint.setAntiAlias(true); |
| - { |
| - gfx::ScopedCanvas clip_scoper(canvas); |
| - canvas->ClipPath(fill, true); |
| - if (has_custom_image) { |
| - gfx::ScopedCanvas scale_scoper(canvas); |
| - canvas->sk_canvas()->scale(scale, scale); |
| - canvas->TileImageInt(*fill_image, x_offset, y_offset, 0, 0, width(), |
| - height()); |
| - } else { |
| - paint.setColor( |
| - is_active ? toolbar_color |
| - : tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); |
| - canvas->DrawRect(gfx::ScaleToEnclosingRect(GetLocalBounds(), scale), |
| - paint); |
| - } |
| - if (draw_hover) { |
| - hover_location.scale(SkFloatToScalar(scale)); |
| - DrawHighlight(canvas, hover_location, radius * scale, hover_color); |
| - } |
| - } |
| - |
| - // Draw the stroke. |
| - gfx::Path stroke = GetBorderPath(scale, false, false, size()); |
| - Op(stroke, fill, kDifference_SkPathOp, &stroke); |
| - if (!is_active) { |
| - // Clip out the bottom line; this will be drawn for us by |
| - // TabStrip::PaintChildren(). |
| - canvas->ClipRect(gfx::RectF(width() * scale, height() * scale - 1)); |
| - } |
| - paint.setColor(controller_->GetToolbarTopSeparatorColor()); |
| - canvas->DrawPath(stroke, paint); |
| - } else { |
| - if (draw_hover) { |
| - // Draw everything to a temporary canvas so we can extract an image for |
| - // use in masking the hover glow. |
| - gfx::Canvas background_canvas(size(), canvas->image_scale(), false); |
| - PaintTabFill(&background_canvas, fill_image, x_offset, y_offset, size(), |
| - is_active); |
| - gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); |
| - canvas->DrawImageInt(background_image, 0, 0); |
| - |
| - gfx::Canvas hover_canvas(size(), canvas->image_scale(), false); |
| - DrawHighlight(&hover_canvas, hover_location, radius, hover_color); |
| - gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage( |
| - gfx::ImageSkia(hover_canvas.ExtractImageRep()), background_image); |
| - canvas->DrawImageInt(result, 0, 0); |
| - } else { |
| - PaintTabFill(canvas, fill_image, x_offset, y_offset, size(), is_active); |
| - } |
| + gfx::Rect rect(GetLocalBounds()); |
| + rect.Offset(GetMirroredX() + background_offset_.x(), y_offset); |
| + PaintBackgroundParams params( |
| + is_active, fill_image, has_custom_image, rect, |
| + controller_->GetToolbarTopSeparatorColor(), |
| + GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR), |
| + GetThemeProvider()->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); |
| - // Now draw the stroke, highlights, and shadows around the tab edge. |
| - TabImages* stroke_images = |
| - is_active ? &g_active_images : &g_inactive_images; |
| - canvas->DrawImageInt(*stroke_images->image_l, 0, 0); |
| - canvas->TileImageInt( |
| - *stroke_images->image_c, stroke_images->l_width, 0, |
| - width() - stroke_images->l_width - stroke_images->r_width, height()); |
| - canvas->DrawImageInt(*stroke_images->image_r, |
| - width() - stroke_images->r_width, 0); |
| - } |
| + PaintTabBackgroundUsingParams(canvas, hc, params); |
| } |
| void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon( |