1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/tabs/tab_group_highlight.h"
6
7 #include "chrome/browser/ui/layout_constants.h"
8 #include "chrome/browser/ui/tabs/tab_style.h"
9 #include "chrome/browser/ui/views/tabs/tab_group_views.h"
10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/views/background.h"
13 #include "ui/views/view.h"
14
TabGroupHighlight(TabGroupViews * tab_group_views,const tab_groups::TabGroupId & group)15 TabGroupHighlight::TabGroupHighlight(TabGroupViews* tab_group_views,
16 const tab_groups::TabGroupId& group)
17 : tab_group_views_(tab_group_views), group_(group) {}
18
OnPaint(gfx::Canvas * canvas)19 void TabGroupHighlight::OnPaint(gfx::Canvas* canvas) {
20 SkPath path = GetPath();
21 cc::PaintFlags flags;
22 flags.setAntiAlias(true);
23 flags.setStyle(cc::PaintFlags::kFill_Style);
24
25 // Draw two layers to simulate the color of other non-active selected tabs,
26 // which use a similar drawing strategy (see GM2TabStyle::PaintTab()).
27 // This is needed because the group background color alone would be slightly
28 // transparent, so instead it's drawn over the inactive background color.
29 flags.setColor(tab_group_views_->GetTabBackgroundColor());
30 canvas->DrawPath(path, flags);
31
32 flags.setColor(tab_group_views_->GetGroupBackgroundColor());
33 canvas->DrawPath(path, flags);
34 }
35
GetCanProcessEventsWithinSubtree() const36 bool TabGroupHighlight::GetCanProcessEventsWithinSubtree() const {
37 // Don't accept any mouse events, otherwise this will prevent tabs and group
38 // headers from getting clicked.
39 return false;
40 }
41
GetPath() const42 SkPath TabGroupHighlight::GetPath() const {
43 // This path imitates the shape of a tab (see GM2TabStyle::GetPath()). It
44 // doesn't reuse the exact same GetPath() function because it doesn't need
45 // much of the complexity there. Group highlights only appear on group drag,
46 // which is a well-scoped interaction. A dragging group doesn't nestle in with
47 // the tabs around it, so there are no special cases needed when determining
48 // its shape.
49 const int corner_radius = TabStyle::GetCornerRadius();
50
51 SkPath path;
52 path.moveTo(0, bounds().height());
53 path.arcTo(corner_radius, corner_radius, 0, SkPath::kSmall_ArcSize,
54 SkPathDirection::kCCW, corner_radius,
55 bounds().height() - corner_radius);
56 path.lineTo(corner_radius, corner_radius);
57 path.arcTo(corner_radius, corner_radius, 0, SkPath::kSmall_ArcSize,
58 SkPathDirection::kCW, 2 * corner_radius, 0);
59 path.lineTo(bounds().width() - 2 * corner_radius, 0);
60 path.arcTo(corner_radius, corner_radius, 0, SkPath::kSmall_ArcSize,
61 SkPathDirection::kCW, bounds().width() - corner_radius,
62 corner_radius);
63 path.lineTo(bounds().width() - corner_radius,
64 bounds().height() - corner_radius);
65 path.arcTo(corner_radius, corner_radius, 0, SkPath::kSmall_ArcSize,
66 SkPathDirection::kCCW, bounds().width(), bounds().height());
67 path.close();
68
69 return path;
70 }
71