Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(881)

Side by Side Diff: ash/system/user/button_from_view.cc

Issue 2099793002: mash: Migrate some system user files to common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ash/system/user/button_from_view.h"
6
7 #include "ash/common/ash_constants.h"
8 #include "ash/common/system/tray/tray_constants.h"
9 #include "ash/common/system/tray/tray_utils.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "ui/accessibility/ax_view_state.h"
13 #include "ui/gfx/canvas.h"
14 #include "ui/views/background.h"
15 #include "ui/views/border.h"
16 #include "ui/views/layout/box_layout.h"
17
18 namespace ash {
19
20 namespace {
21
22 // The border color of the user button.
23 const SkColor kBorderColor = 0xffdcdcdc;
24
25 } // namespace
26
27 namespace tray {
28
29 ButtonFromView::ButtonFromView(views::View* content,
30 views::ButtonListener* listener,
31 bool highlight_on_hover,
32 const gfx::Insets& tab_frame_inset)
33 : CustomButton(listener),
34 content_(content),
35 highlight_on_hover_(highlight_on_hover),
36 button_hovered_(false),
37 show_border_(false),
38 tab_frame_inset_(tab_frame_inset) {
39 set_notify_enter_exit_on_child(true);
40 SetLayoutManager(
41 new views::BoxLayout(views::BoxLayout::kHorizontal, 1, 1, 0));
42 AddChildView(content_);
43 ShowActive();
44 // Only make it focusable when we are active/interested in clicks.
45 if (listener)
46 SetFocusForPlatform();
47 }
48
49 ButtonFromView::~ButtonFromView() {}
50
51 void ButtonFromView::ForceBorderVisible(bool show) {
52 show_border_ = show;
53 ShowActive();
54 }
55
56 void ButtonFromView::OnMouseEntered(const ui::MouseEvent& event) {
57 button_hovered_ = true;
58 ShowActive();
59 }
60
61 void ButtonFromView::OnMouseExited(const ui::MouseEvent& event) {
62 button_hovered_ = false;
63 ShowActive();
64 }
65
66 void ButtonFromView::OnPaint(gfx::Canvas* canvas) {
67 View::OnPaint(canvas);
68 if (HasFocus()) {
69 gfx::Rect rect(GetLocalBounds());
70 rect.Inset(tab_frame_inset_);
71 canvas->DrawSolidFocusRect(rect, kFocusBorderColor);
72 }
73 }
74
75 void ButtonFromView::OnFocus() {
76 View::OnFocus();
77 // Adding focus frame.
78 SchedulePaint();
79 }
80
81 void ButtonFromView::OnBlur() {
82 View::OnBlur();
83 // Removing focus frame.
84 SchedulePaint();
85 }
86
87 void ButtonFromView::GetAccessibleState(ui::AXViewState* state) {
88 state->role = ui::AX_ROLE_BUTTON;
89 std::vector<base::string16> labels;
90 for (int i = 0; i < child_count(); ++i)
91 GetAccessibleLabelFromDescendantViews(child_at(i), labels);
92 state->name = base::JoinString(labels, base::ASCIIToUTF16(" "));
93 }
94
95 void ButtonFromView::ShowActive() {
96 bool border_visible =
97 (button_hovered_ && highlight_on_hover_) || show_border_;
98 SkColor border_color = border_visible ? kBorderColor : SK_ColorTRANSPARENT;
99 SetBorder(views::Border::CreateSolidBorder(1, border_color));
100 if (highlight_on_hover_) {
101 SkColor background_color =
102 button_hovered_ ? kHoverBackgroundColor : kBackgroundColor;
103 content_->set_background(
104 views::Background::CreateSolidBackground(background_color));
105 set_background(views::Background::CreateSolidBackground(background_color));
106 }
107 SchedulePaint();
108 }
109
110 } // namespace tray
111 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698