| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ash/system/tray/actionable_view.h" | |
| 6 | |
| 7 #include "ash/common/ash_constants.h" | |
| 8 #include "ui/accessibility/ax_view_state.h" | |
| 9 #include "ui/gfx/canvas.h" | |
| 10 | |
| 11 namespace ash { | |
| 12 | |
| 13 // static | |
| 14 const char ActionableView::kViewClassName[] = "tray/ActionableView"; | |
| 15 | |
| 16 ActionableView::ActionableView() | |
| 17 : has_capture_(false) { | |
| 18 SetFocusBehavior(FocusBehavior::ALWAYS); | |
| 19 } | |
| 20 | |
| 21 ActionableView::~ActionableView() { | |
| 22 } | |
| 23 | |
| 24 void ActionableView::OnPaintFocus(gfx::Canvas* canvas) { | |
| 25 gfx::Rect rect(GetFocusBounds()); | |
| 26 rect.Inset(1, 1, 3, 2); | |
| 27 canvas->DrawSolidFocusRect(rect, kFocusBorderColor); | |
| 28 } | |
| 29 | |
| 30 gfx::Rect ActionableView::GetFocusBounds() { | |
| 31 return GetLocalBounds(); | |
| 32 } | |
| 33 | |
| 34 const char* ActionableView::GetClassName() const { | |
| 35 return kViewClassName; | |
| 36 } | |
| 37 | |
| 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); | |
| 42 } | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 bool ActionableView::OnMousePressed(const ui::MouseEvent& event) { | |
| 47 // Return true so that this view starts capturing the events. | |
| 48 has_capture_ = true; | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 void ActionableView::OnMouseReleased(const ui::MouseEvent& event) { | |
| 53 if (has_capture_ && GetLocalBounds().Contains(event.location())) | |
| 54 PerformAction(event); | |
| 55 } | |
| 56 | |
| 57 void ActionableView::OnMouseCaptureLost() { | |
| 58 has_capture_ = false; | |
| 59 } | |
| 60 | |
| 61 void ActionableView::SetAccessibleName(const base::string16& name) { | |
| 62 accessible_name_ = name; | |
| 63 } | |
| 64 | |
| 65 void ActionableView::GetAccessibleState(ui::AXViewState* state) { | |
| 66 state->role = ui::AX_ROLE_BUTTON; | |
| 67 state->name = accessible_name_; | |
| 68 } | |
| 69 | |
| 70 void ActionableView::OnPaint(gfx::Canvas* canvas) { | |
| 71 View::OnPaint(canvas); | |
| 72 if (HasFocus()) | |
| 73 OnPaintFocus(canvas); | |
| 74 } | |
| 75 | |
| 76 void ActionableView::OnFocus() { | |
| 77 View::OnFocus(); | |
| 78 // We render differently when focused. | |
| 79 SchedulePaint(); | |
| 80 } | |
| 81 | |
| 82 void ActionableView::OnBlur() { | |
| 83 View::OnBlur(); | |
| 84 // We render differently when focused. | |
| 85 SchedulePaint(); | |
| 86 } | |
| 87 | |
| 88 void ActionableView::OnGestureEvent(ui::GestureEvent* event) { | |
| 89 if (event->type() == ui::ET_GESTURE_TAP && PerformAction(*event)) | |
| 90 event->SetHandled(); | |
| 91 } | |
| 92 | |
| 93 } // namespace ash | |
| OLD | NEW |