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/base/accessibility/accessible_view_state.h"
9 #include "ui/gfx/canvas.h"
15 const char ActionableView::kViewClassName
[] = "tray/ActionableView";
17 ActionableView::ActionableView()
18 : has_capture_(false) {
22 ActionableView::~ActionableView() {
25 void ActionableView::DrawBorder(gfx::Canvas
* canvas
, const gfx::Rect
& bounds
) {
26 gfx::Rect rect
= bounds
;
27 rect
.Inset(1, 1, 3, 3);
28 canvas
->DrawRect(rect
, kFocusBorderColor
);
31 const char* ActionableView::GetClassName() const {
32 return kViewClassName
;
35 bool ActionableView::OnKeyPressed(const ui::KeyEvent
& event
) {
36 if (event
.key_code() == ui::VKEY_SPACE
||
37 event
.key_code() == ui::VKEY_RETURN
) {
38 return PerformAction(event
);
43 bool ActionableView::OnMousePressed(const ui::MouseEvent
& event
) {
44 // Return true so that this view starts capturing the events.
49 void ActionableView::OnMouseReleased(const ui::MouseEvent
& event
) {
50 if (has_capture_
&& GetLocalBounds().Contains(event
.location()))
54 void ActionableView::OnMouseCaptureLost() {
58 void ActionableView::SetAccessibleName(const base::string16
& name
) {
59 accessible_name_
= name
;
62 void ActionableView::OnPaintFocusBorder(gfx::Canvas
* canvas
) {
63 if (HasFocus() && (focusable() || IsAccessibilityFocusable()))
64 DrawBorder(canvas
, GetLocalBounds());
67 void ActionableView::OnGestureEvent(ui::GestureEvent
* event
) {
68 if (event
->type() == ui::ET_GESTURE_TAP
&& PerformAction(*event
))
72 void ActionableView::GetAccessibleState(ui::AccessibleViewState
* state
) {
73 state
->role
= ui::AccessibilityTypes::ROLE_PUSHBUTTON
;
74 state
->name
= accessible_name_
;
77 } // namespace internal