summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/accessible_toolbar_view.h
blob: 2827ba519363c1adaf4932f20f6c0cc548e77cb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_VIEWS_ACCESSIBLE_TOOLBAR_VIEW_H_
#define CHROME_BROWSER_VIEWS_ACCESSIBLE_TOOLBAR_VIEW_H_

#include "views/view.h"

// This class provides keyboard access to any view that extends it by intiating
// ALT+SHIFT+T. And once you press TAB or SHIFT-TAB, it will traverse all the
// toolbars within Chrome. Child views are traversed in the order they were
// added.

class AccessibleToolbarView : public views::View {
 public:
  AccessibleToolbarView();
  virtual ~AccessibleToolbarView();

  // Initiate the traversal on the toolbar.
  void InitiateTraversal();

  // Overridden from views::View:
  virtual void DidGainFocus();
  virtual void WillLoseFocus();
  virtual bool OnKeyPressed(const views::KeyEvent& e);
  virtual bool OnKeyReleased(const views::KeyEvent& e);
  virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e);
  virtual void ShowContextMenu(int x, int y, bool is_mouse_gesture);
  virtual void RequestFocus();
  virtual bool GetAccessibleName(std::wstring* name);
  virtual bool GetAccessibleRole(AccessibilityTypes::Role* role);
  virtual void SetAccessibleName(const std::wstring& name);
  virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
  virtual View* GetAccFocusedChildView() { return selected_focused_view_; }

 protected:
  // Returns the index of the next view of the toolbar, starting from the given
  // view index. |forward| when true means it will navigate from left to right,
  // and vice versa when false. If |view_index| is -1 the first accessible child
  // is returned.
  int GetNextAccessibleViewIndex(int view_index, bool forward);

  // Invoked from GetNextAccessibleViewIndex to determine if |view| can be
  // traversed to. Default implementation returns true, override to return false
  // for views you don't want reachable.
  virtual bool IsAccessibleViewTraversable(views::View* view);

 private:
  // Sets the focus to the currently |acc_focused_view_| view.
  void SetFocusToAccessibleView();

  // Storage of strings needed for accessibility.
  std::wstring accessible_name_;

  // Selected child view currently having accessibility focus.
  views::View* selected_focused_view_;

  // Last focused view that issued this traversal.
  int last_focused_view_storage_id_;

  DISALLOW_COPY_AND_ASSIGN(AccessibleToolbarView);
};

#endif  // CHROME_BROWSER_VIEWS_ACCESSIBLE_TOOLBAR_VIEW_H_