ProfilePolicyConnectorFactory: Refactoring from Profile to BrowserContext.
[chromium-blink-merge.git] / ash / system / user / button_from_view.cc
blob34f5099f0b57a6921d9afdd0515b8dea441c469e
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"
14 namespace ash {
16 namespace {
18 // The border color of the user button.
19 const SkColor kBorderColor = 0xffdcdcdc;
21 } // namespace
23 namespace tray {
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),
30 content_(content),
31 highlight_on_hover_(highlight_on_hover),
32 button_hovered_(false),
33 show_border_(false),
34 tab_frame_inset_(tab_frame_inset) {
35 set_notify_enter_exit_on_child(true);
36 SetLayoutManager(
37 new views::BoxLayout(views::BoxLayout::kHorizontal, 1, 1, 0));
38 AddChildView(content_);
39 ShowActive();
40 // Only make it focusable when we are active/interested in clicks.
41 if (listener)
42 SetFocusable(true);
45 ButtonFromView::~ButtonFromView() {}
47 void ButtonFromView::ForceBorderVisible(bool show) {
48 show_border_ = show;
49 ShowActive();
52 void ButtonFromView::OnMouseEntered(const ui::MouseEvent& event) {
53 button_hovered_ = true;
54 ShowActive();
57 void ButtonFromView::OnMouseExited(const ui::MouseEvent& event) {
58 button_hovered_ = false;
59 ShowActive();
62 void ButtonFromView::OnPaint(gfx::Canvas* canvas) {
63 View::OnPaint(canvas);
64 if (HasFocus()) {
65 gfx::Rect rect(GetLocalBounds());
66 rect.Inset(tab_frame_inset_);
67 canvas->DrawSolidFocusRect(rect, kFocusBorderColor);
71 void ButtonFromView::OnFocus() {
72 View::OnFocus();
73 // Adding focus frame.
74 SchedulePaint();
77 void ButtonFromView::OnBlur() {
78 View::OnBlur();
79 // Removing focus frame.
80 SchedulePaint();
83 void ButtonFromView::ShowActive() {
84 bool border_visible =
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));
95 SchedulePaint();
98 } // namespace tray
99 } // namespace ash