Home | History | Annotate | Download | only in browser
      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_ACCESSIBILITY_EVENTS_H_
      6 #define CHROME_BROWSER_ACCESSIBILITY_EVENTS_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 class AccessibilityControlInfo;
     12 class DictionaryValue;
     13 class NotificationType;
     14 class Profile;
     15 
     16 // Use the NotificationService to post the given accessibility
     17 // notification type with AccessibilityControlInfo details to any
     18 // listeners.  Will not send if the profile's pause level is nonzero
     19 // (using profile->PauseAccessibilityEvents).
     20 void SendAccessibilityNotification(
     21     NotificationType type, AccessibilityControlInfo* info);
     22 
     23 // Abstract parent class for accessibility information about a control
     24 // passed to event listeners.
     25 class AccessibilityControlInfo {
     26  public:
     27   virtual ~AccessibilityControlInfo();
     28 
     29   // Serialize this class as a DictionaryValue that can be converted to
     30   // a JavaScript object.
     31   virtual void SerializeToDict(DictionaryValue* dict) const;
     32 
     33   // Return the specific type of this control, which will be one of the
     34   // string constants defined in extension_accessibility_api_constants.h.
     35   virtual const char* type() const = 0;
     36 
     37   Profile* profile() const { return profile_; }
     38 
     39   const std::string& name() const { return name_; }
     40 
     41  protected:
     42   AccessibilityControlInfo(Profile* profile, const std::string& control_name);
     43 
     44   // The profile this control belongs to.
     45   Profile* profile_;
     46 
     47   // The name of the control, like "OK" or "Password".
     48   std::string name_;
     49 };
     50 
     51 // Accessibility information about a window passed to onWindowOpened
     52 // and onWindowClosed event listeners.
     53 class AccessibilityWindowInfo : public AccessibilityControlInfo {
     54  public:
     55   AccessibilityWindowInfo(Profile* profile, const std::string& window_name);
     56 
     57   virtual const char* type() const;
     58 };
     59 
     60 // Accessibility information about a push button passed to onControlFocused
     61 // and onControlAction event listeners.
     62 class AccessibilityButtonInfo : public AccessibilityControlInfo {
     63  public:
     64   AccessibilityButtonInfo(Profile* profile, const std::string& button_name);
     65 
     66   virtual const char* type() const;
     67 };
     68 
     69 // Accessibility information about a hyperlink passed to onControlFocused
     70 // and onControlAction event listeners.
     71 class AccessibilityLinkInfo : public AccessibilityControlInfo {
     72  public:
     73   AccessibilityLinkInfo(Profile* profile, const std::string& link_name);
     74 
     75   virtual const char* type() const;
     76 };
     77 
     78 // Accessibility information about a radio button passed to onControlFocused
     79 // and onControlAction event listeners.
     80 class AccessibilityRadioButtonInfo : public AccessibilityControlInfo {
     81  public:
     82   AccessibilityRadioButtonInfo(Profile* profile,
     83                                const std::string& name,
     84                                bool checked,
     85                                int item_index,
     86                                int item_count);
     87 
     88   virtual const char* type() const;
     89 
     90   virtual void SerializeToDict(DictionaryValue* dict) const;
     91 
     92   void SetChecked(bool checked) { checked_ = checked; }
     93 
     94   int item_index() const { return item_index_; }
     95   int item_count() const { return item_count_; }
     96   bool checked() const { return checked_; }
     97 
     98  private:
     99   bool checked_;
    100   // The 0-based index of this radio button and number of buttons in the group.
    101   int item_index_;
    102   int item_count_;
    103 };
    104 
    105 // Accessibility information about a checkbox passed to onControlFocused
    106 // and onControlAction event listeners.
    107 class AccessibilityCheckboxInfo : public AccessibilityControlInfo {
    108  public:
    109   AccessibilityCheckboxInfo(Profile* profile,
    110                             const std::string& name,
    111                             bool checked);
    112 
    113   virtual const char* type() const;
    114 
    115   virtual void SerializeToDict(DictionaryValue* dict) const;
    116 
    117   void SetChecked(bool checked) { checked_ = checked; }
    118 
    119   bool checked() const { return checked_; }
    120 
    121  private:
    122   bool checked_;
    123 };
    124 
    125 // Accessibility information about a tab passed to onControlFocused
    126 // and onControlAction event listeners.
    127 class AccessibilityTabInfo : public AccessibilityControlInfo {
    128  public:
    129   AccessibilityTabInfo(Profile* profile,
    130                        const std::string& tab_name,
    131                        int tab_index,
    132                        int tab_count);
    133 
    134   virtual const char* type() const;
    135 
    136   virtual void SerializeToDict(DictionaryValue* dict) const;
    137 
    138   void SetTab(int tab_index, std::string tab_name) {
    139     tab_index_ = tab_index;
    140     name_ = tab_name;
    141   }
    142 
    143   int tab_index() const { return tab_index_; }
    144   int tab_count() const { return tab_count_; }
    145 
    146  private:
    147   // The 0-based index of this tab and number of tabs in the group.
    148   int tab_index_;
    149   int tab_count_;
    150 };
    151 
    152 // Accessibility information about a combo box passed to onControlFocused
    153 // and onControlAction event listeners.
    154 class AccessibilityComboBoxInfo : public AccessibilityControlInfo {
    155  public:
    156   AccessibilityComboBoxInfo(Profile* profile,
    157                             const std::string& name,
    158                             const std::string& value,
    159                             int item_index,
    160                             int item_count);
    161 
    162   virtual const char* type() const;
    163 
    164   virtual void SerializeToDict(DictionaryValue* dict) const;
    165 
    166   void SetValue(int item_index, const std::string& value) {
    167     item_index_ = item_index;
    168     value_ = value;
    169   }
    170 
    171   int item_index() const { return item_index_; }
    172   int item_count() const { return item_count_; }
    173   const std::string& value() const { return value_; }
    174 
    175  private:
    176   std::string value_;
    177   // The 0-based index of the current item and the number of total items.
    178   // If the value is not one of the drop-down options, |item_index_| should
    179   // be -1.
    180   int item_index_;
    181   int item_count_;
    182 };
    183 
    184 // Accessibility information about a text box, passed to onControlFocused,
    185 // onControlAction, and onTextChanged event listeners.
    186 class AccessibilityTextBoxInfo : public AccessibilityControlInfo {
    187  public:
    188   AccessibilityTextBoxInfo(Profile* profile,
    189                            const std::string& name,
    190                            bool password);
    191 
    192   virtual const char* type() const;
    193 
    194   virtual void SerializeToDict(DictionaryValue* dict) const;
    195 
    196   void SetValue(
    197       const std::string& value, int selection_start, int selection_end) {
    198     value_ = value;
    199     selection_start_ = selection_start;
    200     selection_end_ = selection_end;
    201   }
    202 
    203   const std::string& value() const { return value_; }
    204   bool password() const { return password_; }
    205   int selection_start() const { return selection_start_; }
    206   int selection_end() const { return selection_end_; }
    207 
    208  private:
    209   std::string value_;
    210   bool password_;
    211   int selection_start_;
    212   int selection_end_;
    213 };
    214 
    215 // Accessibility information about a combo box passed to onControlFocused
    216 // and onControlAction event listeners.
    217 class AccessibilityListBoxInfo : public AccessibilityControlInfo {
    218  public:
    219   AccessibilityListBoxInfo(Profile* profile,
    220                            const std::string& name,
    221                            const std::string& value,
    222                            int item_index,
    223                            int item_count);
    224 
    225   virtual const char* type() const;
    226 
    227   virtual void SerializeToDict(DictionaryValue* dict) const;
    228 
    229   void SetValue(int item_index, std::string value) {
    230     item_index_ = item_index;
    231     value_ = value;
    232   }
    233 
    234   int item_index() const { return item_index_; }
    235   int item_count() const { return item_count_; }
    236   const std::string& value() const { return value_; }
    237 
    238  private:
    239   std::string value_;
    240   // The 0-based index of the current item and the number of total items.
    241   // If the value is not one of the drop-down options, |item_index_| should
    242   // be -1.
    243   int item_index_;
    244   int item_count_;
    245 };
    246 
    247 // Accessibility information about a menu; this class is used by
    248 // onMenuOpened, onMenuClosed, and onControlFocused event listeners.
    249 class AccessibilityMenuInfo : public AccessibilityControlInfo {
    250  public:
    251   AccessibilityMenuInfo(Profile* profile, const std::string& menu_name);
    252 
    253   virtual const char* type() const;
    254 };
    255 
    256 // Accessibility information about a menu item; this class is used by
    257 // onControlFocused event listeners.
    258 class AccessibilityMenuItemInfo : public AccessibilityControlInfo {
    259  public:
    260   AccessibilityMenuItemInfo(Profile* profile,
    261                             const std::string& name,
    262                             bool has_submenu,
    263                             int item_index,
    264                             int item_count);
    265 
    266   virtual const char* type() const;
    267 
    268   virtual void SerializeToDict(DictionaryValue* dict) const;
    269 
    270   int item_index() const { return item_index_; }
    271   int item_count() const { return item_count_; }
    272   bool has_submenu() const { return has_submenu_; }
    273 
    274  private:
    275   bool has_submenu_;
    276   // The 0-based index of the current item and the number of total items.
    277   int item_index_;
    278   int item_count_;
    279 };
    280 
    281 #endif  // CHROME_BROWSER_ACCESSIBILITY_EVENTS_H_
    282