[go: nahoru, domu]

blob: e20212d3a39d19c647cc19525add7fc4cd52babb [file] [log] [blame]
Sammie Quon9b911f2f2017-12-15 02:53:151// Copyright 2017 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 "ash/shelf/back_button.h"
6
Sammie Quon6970d572020-03-13 23:18:407#include "ash/keyboard/keyboard_util.h"
Sammie Quon9b911f2f2017-12-15 02:53:158#include "ash/resources/vector_icons/vector_icons.h"
Manu Cornetd9d5b6c2019-07-22 19:01:459#include "ash/shelf/shelf.h"
10#include "ash/shelf/shelf_focus_cycler.h"
Sammie Quon9b911f2f2017-12-15 02:53:1511#include "ash/strings/grit/ash_strings.h"
Yulun Wu0ff63932020-08-27 00:27:2712#include "ash/style/ash_color_provider.h"
mincha0be38742019-11-12 19:18:2313#include "ash/wm/window_state.h"
Sammie Quon6970d572020-03-13 23:18:4014#include "ash/wm/window_util.h"
Andrew Xua903f922019-11-07 20:39:4415#include "base/metrics/user_metrics.h"
16#include "base/metrics/user_metrics_action.h"
Sammie Quon9b911f2f2017-12-15 02:53:1517#include "ui/aura/window.h"
18#include "ui/aura/window_tree_host.h"
19#include "ui/base/l10n/l10n_util.h"
Sammie Quon9b911f2f2017-12-15 02:53:1520#include "ui/gfx/canvas.h"
21#include "ui/gfx/paint_vector_icon.h"
Sammie Quon9b911f2f2017-12-15 02:53:1522#include "ui/views/widget/widget.h"
23
24namespace ash {
25
Manu Cornetc0066332019-02-20 19:26:0326// static
27const char BackButton::kViewClassName[] = "ash/BackButton";
28
Manu Cornetd9d5b6c2019-07-22 19:01:4529BackButton::BackButton(Shelf* shelf) : ShelfControlButton(shelf, this) {
Sammie Quon9b911f2f2017-12-15 02:53:1530 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_BACK_BUTTON_TITLE));
Allen Bauereac9b922020-10-23 22:56:5431 SetFlipCanvasOnPaintForRTLUI(true);
Sammie Quon9b911f2f2017-12-15 02:53:1532}
33
Alex Newcomer4601bb02019-10-31 00:37:3934BackButton::~BackButton() {}
Sammie Quon9b911f2f2017-12-15 02:53:1535
Toni Barzic71ebb6fd2020-05-29 17:16:5336void BackButton::HandleLocaleChange() {
37 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_BACK_BUTTON_TITLE));
38 TooltipTextChanged();
39}
40
Sammie Quon9b911f2f2017-12-15 02:53:1541void BackButton::PaintButtonContents(gfx::Canvas* canvas) {
42 // Use PaintButtonContents instead of SetImage so the icon gets drawn at
43 // |GetCenterPoint| coordinates instead of always in the center.
Yulun Wu0ff63932020-08-27 00:27:2744 gfx::ImageSkia img = CreateVectorIcon(
Yulun Wu687f9292021-02-09 22:43:2845 kShelfBackIcon,
46 AshColorProvider::Get()->GetContentLayerColor(
47 AshColorProvider::ContentLayerType::kButtonIconColor));
Sammie Quon9b911f2f2017-12-15 02:53:1548 canvas->DrawImageInt(img, GetCenterPoint().x() - img.width() / 2,
49 GetCenterPoint().y() - img.height() / 2);
50}
51
Manu Cornetc0066332019-02-20 19:26:0352const char* BackButton::GetClassName() const {
53 return kViewClassName;
54}
55
Jan Wilken Dörrie85285b02021-03-11 23:38:4756std::u16string BackButton::GetTooltipText(const gfx::Point& p) const {
Manu Cornete11c3c352019-07-31 06:13:4157 return GetAccessibleName();
58}
59
Manu Cornetd9d5b6c2019-07-22 19:01:4560void BackButton::OnShelfButtonAboutToRequestFocusFromTabTraversal(
61 ShelfButton* button,
62 bool reverse) {
63 DCHECK_EQ(button, this);
64 if (!reverse) {
65 // We're trying to focus this button by advancing from the last view of
66 // the shelf. Let the focus manager advance to the status area instead.
Manu Cornete11c3c352019-07-31 06:13:4167 shelf()->shelf_focus_cycler()->FocusOut(reverse,
68 SourceView::kShelfNavigationView);
Manu Cornetd9d5b6c2019-07-22 19:01:4569 }
70}
71
72void BackButton::ButtonPressed(views::Button* sender,
73 const ui::Event& event,
74 views::InkDrop* ink_drop) {
Andrew Xua903f922019-11-07 20:39:4475 base::RecordAction(base::UserMetricsAction("AppList_BackButtonPressed"));
76
Sammie Quon6970d572020-03-13 23:18:4077 if (keyboard_util::CloseKeyboardIfActive())
78 return;
79
80 if (window_util::ShouldMinimizeTopWindowOnBack()) {
81 auto* top_window = window_util::GetTopWindow();
82 DCHECK(top_window);
83 WindowState::Get(top_window)->Minimize();
84 return;
mincha0be38742019-11-12 19:18:2385 }
Sammie Quon6970d572020-03-13 23:18:4086
87 window_util::SendBackKeyEvent(
88 GetWidget()->GetNativeWindow()->GetRootWindow());
Manu Cornetd9d5b6c2019-07-22 19:01:4589}
90
Yulun Wu8924cebb2021-01-12 20:23:2891void BackButton::OnThemeChanged() {
92 ShelfControlButton::OnThemeChanged();
93 SchedulePaint();
94}
95
Sammie Quon9b911f2f2017-12-15 02:53:1596} // namespace ash