forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshelf_button.cc
78 lines (64 loc) · 2.76 KB
/
shelf_button.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/shelf_button.h"
#include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_button_delegate.h"
#include "ash/style/default_color_constants.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/views/animation/ink_drop_impl.h"
namespace ash {
ShelfButton::ShelfButton(Shelf* shelf,
ShelfButtonDelegate* shelf_button_delegate)
: Button(Button::PressedCallback()),
shelf_(shelf),
shelf_button_delegate_(shelf_button_delegate) {
DCHECK(shelf_button_delegate_);
SetHideInkDropWhenShowingContextMenu(false);
const AshColorProvider::RippleAttributes ripple_attributes =
AshColorProvider::Get()->GetRippleAttributes();
SetInkDropBaseColor(ripple_attributes.base_color);
SetInkDropVisibleOpacity(ripple_attributes.inkdrop_opacity);
SetFocusBehavior(FocusBehavior::ALWAYS);
SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER);
SetFocusPainter(views::Painter::CreateSolidFocusPainter(
ShelfConfig::Get()->shelf_focus_border_color(), kFocusBorderThickness,
gfx::InsetsF()));
}
ShelfButton::~ShelfButton() = default;
////////////////////////////////////////////////////////////////////////////////
// views::View
const char* ShelfButton::GetClassName() const {
return "ash/ShelfButton";
}
void ShelfButton::AboutToRequestFocusFromTabTraversal(bool reverse) {
shelf_button_delegate_->OnShelfButtonAboutToRequestFocusFromTabTraversal(
this, reverse);
}
// Do not remove this function to avoid unnecessary ChromeVox announcement
// triggered by Button::GetAccessibleNodeData. (See https://crbug.com/932200)
void ShelfButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->role = ax::mojom::Role::kButton;
}
////////////////////////////////////////////////////////////////////////////////
// views::Button
void ShelfButton::NotifyClick(const ui::Event& event) {
// Pressing a shelf button in the auto-hide shelf should not do anything.
// The event can still be received by the auto-hide shelf since we reserved
// a portion of the auto-hide shelf within the screen bounds.
if (!shelf_->IsVisible())
return;
Button::NotifyClick(event);
if (shelf_button_delegate_)
shelf_button_delegate_->ButtonPressed(/*sender=*/this, event, GetInkDrop());
}
std::unique_ptr<views::InkDrop> ShelfButton::CreateInkDrop() {
std::unique_ptr<views::InkDropImpl> ink_drop =
Button::CreateDefaultInkDropImpl();
ink_drop->SetShowHighlightOnHover(false);
return std::move(ink_drop);
}
} // namespace ash