1 // Copyright 2014 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.
5 #include "ash/system/user/button_from_view.h"
7 #include "ash/ash_constants.h"
8 #include "ash/system/tray/tray_constants.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/views/background.h"
11 #include "ui/views/border.h"
12 #include "ui/views/layout/box_layout.h"
18 // The border color of the user button.
19 const SkColor kBorderColor
= 0xffdcdcdc;
25 ButtonFromView::ButtonFromView(views::View
* content
,
26 views::ButtonListener
* listener
,
27 bool highlight_on_hover
,
28 const gfx::Insets
& tab_frame_inset
)
29 : CustomButton(listener
),
31 highlight_on_hover_(highlight_on_hover
),
32 button_hovered_(false),
34 tab_frame_inset_(tab_frame_inset
) {
35 set_notify_enter_exit_on_child(true);
37 new views::BoxLayout(views::BoxLayout::kHorizontal
, 1, 1, 0));
38 AddChildView(content_
);
40 // Only make it focusable when we are active/interested in clicks.
45 ButtonFromView::~ButtonFromView() {}
47 void ButtonFromView::ForceBorderVisible(bool show
) {
52 void ButtonFromView::OnMouseEntered(const ui::MouseEvent
& event
) {
53 button_hovered_
= true;
57 void ButtonFromView::OnMouseExited(const ui::MouseEvent
& event
) {
58 button_hovered_
= false;
62 void ButtonFromView::OnPaint(gfx::Canvas
* canvas
) {
63 View::OnPaint(canvas
);
65 gfx::Rect
rect(GetLocalBounds());
66 rect
.Inset(tab_frame_inset_
);
67 canvas
->DrawSolidFocusRect(rect
, kFocusBorderColor
);
71 void ButtonFromView::OnFocus() {
73 // Adding focus frame.
77 void ButtonFromView::OnBlur() {
79 // Removing focus frame.
83 void ButtonFromView::ShowActive() {
85 (button_hovered_
&& highlight_on_hover_
) || show_border_
;
86 SkColor border_color
= border_visible
? kBorderColor
: SK_ColorTRANSPARENT
;
87 SetBorder(views::Border::CreateSolidBorder(1, border_color
));
88 if (highlight_on_hover_
) {
89 SkColor background_color
=
90 button_hovered_
? kHoverBackgroundColor
: kBackgroundColor
;
91 content_
->set_background(
92 views::Background::CreateSolidBackground(background_color
));
93 set_background(views::Background::CreateSolidBackground(background_color
));