summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/accessible_toolbar_view.h
blob: f892a745c0a50f64275c80b0d7032533c329af0d (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
66
67
68
69
70
71
72
// 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. The last focused view is stored in
  // the ViewStorage with the corresponding |view_storage_id|.
  void InitiateTraversal(int view_storage_id);

  // 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 next accessible view on 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.
  views::View* GetNextAccessibleView(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();

  // Retrieve the focused view from the storage so we can request focus back
  // to it. If |focus_view| is null, we place focus on the default view.
  // |selected_focused_view_| doesn't need to reset here since it will be
  // dealt within the WillLoseFocus method.
  void SetFocusToLastFocusedView();

  // 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_