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