1 // Copyright 2012 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/tray/actionable_view.h"
7 #include "ash/ash_constants.h"
8 #include "ui/accessibility/ax_view_state.h"
9 #include "ui/gfx/canvas.h"
14 const char ActionableView::kViewClassName
[] = "tray/ActionableView";
16 ActionableView::ActionableView()
17 : has_capture_(false) {
21 ActionableView::~ActionableView() {
24 void ActionableView::OnPaintFocus(gfx::Canvas
* canvas
) {
25 gfx::Rect
rect(GetFocusBounds());
26 rect
.Inset(1, 1, 3, 2);
27 canvas
->DrawSolidFocusRect(rect
, kFocusBorderColor
);
30 gfx::Rect
ActionableView::GetFocusBounds() {
31 return GetLocalBounds();
34 const char* ActionableView::GetClassName() const {
35 return kViewClassName
;
38 bool ActionableView::OnKeyPressed(const ui::KeyEvent
& event
) {
39 if (event
.key_code() == ui::VKEY_SPACE
||
40 event
.key_code() == ui::VKEY_RETURN
) {
41 return PerformAction(event
);
46 bool ActionableView::OnMousePressed(const ui::MouseEvent
& event
) {
47 // Return true so that this view starts capturing the events.
52 void ActionableView::OnMouseReleased(const ui::MouseEvent
& event
) {
53 if (has_capture_
&& GetLocalBounds().Contains(event
.location()))
57 void ActionableView::OnMouseCaptureLost() {
61 void ActionableView::SetAccessibleName(const base::string16
& name
) {
62 accessible_name_
= name
;
65 void ActionableView::GetAccessibleState(ui::AXViewState
* state
) {
66 state
->role
= ui::AX_ROLE_BUTTON
;
67 state
->name
= accessible_name_
;
70 void ActionableView::OnPaint(gfx::Canvas
* canvas
) {
71 View::OnPaint(canvas
);
76 void ActionableView::OnFocus() {
78 // We render differently when focused.
82 void ActionableView::OnBlur() {
84 // We render differently when focused.
88 void ActionableView::OnGestureEvent(ui::GestureEvent
* event
) {
89 if (event
->type() == ui::ET_GESTURE_TAP
&& PerformAction(*event
))