accessible_pane_view.h revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2010 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#ifndef CHROME_BROWSER_UI_VIEWS_ACCESSIBLE_PANE_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_ACCESSIBLE_PANE_VIEW_H_ 7#pragma once 8 9#include "base/hash_tables.h" 10#include "base/scoped_ptr.h" 11#include "base/task.h" 12#include "views/focus/focus_manager.h" 13#include "views/view.h" 14 15namespace views { 16class FocusSearch; 17} 18 19// This class provides keyboard access to any view that extends it, typically 20// a toolbar. The user sets focus to a control in this view by pressing 21// F6 to traverse all panes, or by pressing a shortcut that jumps directly 22// to this pane. 23class AccessiblePaneView : public views::View, 24 public views::FocusChangeListener, 25 public views::FocusTraversable { 26 public: 27 AccessiblePaneView(); 28 virtual ~AccessiblePaneView(); 29 30 // Set focus to the pane with complete keyboard access. 31 // Focus will be restored to the ViewStorage with id |view_storage_id| 32 // if the user escapes. If |initial_focus| is not NULL, that control will get 33 // the initial focus, if it's enabled and focusable. Returns true if 34 // the pane was able to receive focus. 35 virtual bool SetPaneFocus(int view_storage_id, View* initial_focus); 36 37 // Set focus to the pane with complete keyboard access, with the 38 // focus initially set to the default child. Focus will be restored 39 // to the ViewStorage with id |view_storage_id| if the user escapes. 40 // Returns true if the pane was able to receive focus. 41 virtual bool SetPaneFocusAndFocusDefault(int view_storage_id); 42 43 // Overridden from views::View: 44 virtual FocusTraversable* GetPaneFocusTraversable(); 45 virtual bool AcceleratorPressed(const views::Accelerator& accelerator); 46 virtual void SetVisible(bool flag); 47 virtual AccessibilityTypes::Role GetAccessibleRole(); 48 49 // Overridden from views::FocusChangeListener: 50 virtual void FocusWillChange(View* focused_before, 51 View* focused_now); 52 53 // Overridden from views::FocusTraversable: 54 virtual views::FocusSearch* GetFocusSearch(); 55 virtual FocusTraversable* GetFocusTraversableParent(); 56 virtual View* GetFocusTraversableParentView(); 57 58 protected: 59 // A subclass can override this to provide a default focusable child 60 // other than the first focusable child. 61 virtual views::View* GetDefaultFocusableChild(); 62 63 // Remove pane focus. 64 virtual void RemovePaneFocus(); 65 66 // Select all text in the location bar 67 virtual void LocationBarSelectAll(); 68 69 void RestoreLastFocusedView(); 70 71 View* GetFirstFocusableChild(); 72 View* GetLastFocusableChild(); 73 74 bool pane_has_focus_; 75 76 ScopedRunnableMethodFactory<AccessiblePaneView> method_factory_; 77 78 // Save the focus manager rather than calling GetFocusManager(), 79 // so that we can remove focus listeners in the destructor. 80 views::FocusManager* focus_manager_; 81 82 // Our custom focus search implementation that traps focus in this 83 // pane and traverses all views that are focusable for accessibility, 84 // not just those that are normally focusable. 85 scoped_ptr<views::FocusSearch> focus_search_; 86 87 // Registered accelerators 88 views::Accelerator home_key_; 89 views::Accelerator end_key_; 90 views::Accelerator escape_key_; 91 views::Accelerator left_key_; 92 views::Accelerator right_key_; 93 94 // Last focused view that issued this traversal. 95 int last_focused_view_storage_id_; 96 97 DISALLOW_COPY_AND_ASSIGN(AccessiblePaneView); 98}; 99 100#endif // CHROME_BROWSER_UI_VIEWS_ACCESSIBLE_PANE_VIEW_H_ 101