Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / ash / system / tray / actionable_view.cc
blobdc9e9383716515f31110507233c2f0bf6ac27885
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"
11 namespace ash {
12 namespace internal {
14 // static
15 const char ActionableView::kViewClassName[] = "tray/ActionableView";
17 ActionableView::ActionableView()
18 : has_capture_(false) {
19 set_focusable(true);
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);
40 return false;
43 bool ActionableView::OnMousePressed(const ui::MouseEvent& event) {
44 // Return true so that this view starts capturing the events.
45 has_capture_ = true;
46 return true;
49 void ActionableView::OnMouseReleased(const ui::MouseEvent& event) {
50 if (has_capture_ && GetLocalBounds().Contains(event.location()))
51 PerformAction(event);
54 void ActionableView::OnMouseCaptureLost() {
55 has_capture_ = false;
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))
69 event->SetHandled();
72 void ActionableView::GetAccessibleState(ui::AccessibleViewState* state) {
73 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
74 state->name = accessible_name_;
77 } // namespace internal
78 } // namespace ash