1 // 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/login/ui/login_button.h"
6
7 #include <utility>
8
9 #include "ash/login/ui/views_utils.h"
10 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
11 #include "ui/views/animation/ink_drop_highlight.h"
12
13 namespace ash {
14
15 namespace {
16
17 // Color of the ink drop ripple.
18 constexpr SkColor kInkDropRippleColor = SkColorSetARGB(0x0F, 0xFF, 0xFF, 0xFF);
19
20 // Color of the ink drop highlight.
21 constexpr SkColor kInkDropHighlightColor =
22 SkColorSetARGB(0x14, 0xFF, 0xFF, 0xFF);
23
24 } // namespace
25
LoginButton(PressedCallback callback)26 LoginButton::LoginButton(PressedCallback callback)
27 : views::ImageButton(std::move(callback)) {
28 SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER);
29 SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
30 SetInkDropMode(InkDropMode::ON);
31 SetHasInkDropActionOnClick(true);
32
33 SetInstallFocusRingOnFocus(true);
34 login_views_utils::ConfigureRectFocusRingCircleInkDrop(this, focus_ring(),
35 base::nullopt);
36 }
37
38 LoginButton::~LoginButton() = default;
39
CreateInkDropRipple() const40 std::unique_ptr<views::InkDropRipple> LoginButton::CreateInkDropRipple() const {
41 gfx::Point center = GetLocalBounds().CenterPoint();
42 const int radius = GetInkDropRadius();
43 gfx::Rect bounds(center.x() - radius, center.y() - radius, radius * 2,
44 radius * 2);
45
46 return std::make_unique<views::FloodFillInkDropRipple>(
47 size(), GetLocalBounds().InsetsFrom(bounds),
48 GetInkDropCenterBasedOnLastEvent(), kInkDropRippleColor,
49 1.f /*visible_opacity*/);
50 }
51
CreateInkDropHighlight() const52 std::unique_ptr<views::InkDropHighlight> LoginButton::CreateInkDropHighlight()
53 const {
54 return std::make_unique<views::InkDropHighlight>(gfx::SizeF(size()),
55 kInkDropHighlightColor);
56 }
57
GetInkDropRadius() const58 int LoginButton::GetInkDropRadius() const {
59 return std::min(GetLocalBounds().width(), GetLocalBounds().height()) / 2;
60 }
61
62 } // namespace ash
63