Home | History | Annotate | Download | only in views
      1 // Copyright (c) 2011 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/memory/scoped_ptr.h"
     11 #include "base/task.h"
     12 #include "views/focus/focus_manager.h"
     13 #include "views/view.h"
     14 
     15 namespace views {
     16 class 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.
     23 class 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() OVERRIDE;
     45   virtual bool AcceleratorPressed(const views::Accelerator& accelerator)
     46       OVERRIDE;
     47   virtual void SetVisible(bool flag) OVERRIDE;
     48   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
     49 
     50   // Overridden from views::FocusChangeListener:
     51   virtual void FocusWillChange(View* focused_before,
     52                                View* focused_now) OVERRIDE;
     53 
     54   // Overridden from views::FocusTraversable:
     55   virtual views::FocusSearch* GetFocusSearch() OVERRIDE;
     56   virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE;
     57   virtual View* GetFocusTraversableParentView() OVERRIDE;
     58 
     59  protected:
     60   // A subclass can override this to provide a default focusable child
     61   // other than the first focusable child.
     62   virtual views::View* GetDefaultFocusableChild();
     63 
     64   // Remove pane focus.
     65   virtual void RemovePaneFocus();
     66 
     67   // Select all text in the location bar
     68   virtual void LocationBarSelectAll();
     69 
     70   void RestoreLastFocusedView();
     71 
     72   View* GetFirstFocusableChild();
     73   View* GetLastFocusableChild();
     74 
     75   bool pane_has_focus_;
     76 
     77   ScopedRunnableMethodFactory<AccessiblePaneView> method_factory_;
     78 
     79   // Save the focus manager rather than calling GetFocusManager(),
     80   // so that we can remove focus listeners in the destructor.
     81   views::FocusManager* focus_manager_;
     82 
     83   // Our custom focus search implementation that traps focus in this
     84   // pane and traverses all views that are focusable for accessibility,
     85   // not just those that are normally focusable.
     86   scoped_ptr<views::FocusSearch> focus_search_;
     87 
     88   // Registered accelerators
     89   views::Accelerator home_key_;
     90   views::Accelerator end_key_;
     91   views::Accelerator escape_key_;
     92   views::Accelerator left_key_;
     93   views::Accelerator right_key_;
     94 
     95   // Last focused view that issued this traversal.
     96   int last_focused_view_storage_id_;
     97 
     98   DISALLOW_COPY_AND_ASSIGN(AccessiblePaneView);
     99 };
    100 
    101 #endif  // CHROME_BROWSER_UI_VIEWS_ACCESSIBLE_PANE_VIEW_H_
    102