diff options
Diffstat (limited to 'chromium/content/browser/accessibility/browser_accessibility.h')
-rw-r--r-- | chromium/content/browser/accessibility/browser_accessibility.h | 185 |
1 files changed, 65 insertions, 120 deletions
diff --git a/chromium/content/browser/accessibility/browser_accessibility.h b/chromium/content/browser/accessibility/browser_accessibility.h index 1258803e376..17f70caf675 100644 --- a/chromium/content/browser/accessibility/browser_accessibility.h +++ b/chromium/content/browser/accessibility/browser_accessibility.h @@ -12,9 +12,10 @@ #include "base/basictypes.h" #include "base/strings/string16.h" #include "build/build_config.h" -#include "content/common/accessibility_node_data.h" #include "content/common/content_export.h" #include "third_party/WebKit/public/web/WebAXEnums.h" +#include "ui/accessibility/ax_node.h" +#include "ui/accessibility/ax_node_data.h" #if defined(OS_MACOSX) && __OBJC__ @class BrowserAccessibilityCocoa; @@ -24,8 +25,6 @@ namespace content { class BrowserAccessibilityManager; #if defined(OS_WIN) class BrowserAccessibilityWin; -#elif defined(TOOLKIT_GTK) -class BrowserAccessibilityGtk; #endif //////////////////////////////////////////////////////////////////////////////// @@ -48,47 +47,29 @@ class CONTENT_EXPORT BrowserAccessibility { virtual ~BrowserAccessibility(); - // Detach all descendants of this subtree and push all of the node pointers, - // including this node, onto the end of |nodes|. - virtual void DetachTree(std::vector<BrowserAccessibility*>* nodes); + // Called only once, immediately after construction. The constructor doesn't + // take any arguments because in the Windows subclass we use a special + // function to construct a COM object. + virtual void Init(BrowserAccessibilityManager* manager, ui::AXNode* node); - // Perform platform-specific initialization. This can be called multiple times - // during the lifetime of this instance after the members of this base object - // have been reset with new values from the renderer process. - // Child dependent initialization can be done here. - virtual void PostInitialize() {} + // Called after the object is first initialized and again every time + // its data changes. + virtual void OnDataChanged(); + + // Called after an atomic update to the tree finished and this object + // was created or changed in this update. + virtual void OnUpdateFinished() {} // Returns true if this is a native platform-specific object, vs a // cross-platform generic object. virtual bool IsNative() const; - // Initialize the tree structure of this object. - void InitializeTreeStructure( - BrowserAccessibilityManager* manager, - BrowserAccessibility* parent, - int32 renderer_id, - int32 index_in_parent); - - // Initialize this object's data. - void InitializeData(const AccessibilityNodeData& src); - - virtual void SwapChildren(std::vector<BrowserAccessibility*>& children); - - // Update the parent and index in parent if this node has been moved. - void UpdateParent(BrowserAccessibility* parent, int index_in_parent); - - // Update this node's location, leaving everything else the same. - virtual void SetLocation(const gfx::Rect& new_location); + // Called when the location changed. + virtual void OnLocationChanged() const {} // Return true if this object is equal to or a descendant of |ancestor|. bool IsDescendantOf(BrowserAccessibility* ancestor); - // Returns the parent of this object, or NULL if it's the root. - BrowserAccessibility* parent() const { return parent_; } - - // Returns the number of children of this object. - uint32 child_count() const { return children_.size(); } - // Returns true if this is a leaf node on this platform, meaning any // children should not be exposed to this platform's native accessibility // layer. Each platform subclass should implement this itself. @@ -134,14 +115,14 @@ class CONTENT_EXPORT BrowserAccessibility { BrowserAccessibility* BrowserAccessibilityForPoint(const gfx::Point& point); // Marks this object for deletion, releases our reference to it, and - // recursively calls Destroy() on its children. May not delete - // immediately due to reference counting. + // nulls out the pointer to the underlying AXNode. May not delete + // the object immediately due to reference counting. // // Reference counting is used on some platforms because the // operating system may hold onto a reference to a BrowserAccessibility // object even after we're through with it. When a BrowserAccessibility // has had Destroy() called but its reference count is not yet zero, - // queries on this object return failure + // instance_active() returns false and queries on this object return failure. virtual void Destroy(); // Subclasses should override this to support platform reference counting. @@ -154,32 +135,37 @@ class CONTENT_EXPORT BrowserAccessibility { // Accessors // - const std::vector<BrowserAccessibility*>& children() const { - return children_; - } - const std::vector<std::pair<std::string, std::string> >& - html_attributes() const { - return html_attributes_; - } - int32 index_in_parent() const { return index_in_parent_; } - gfx::Rect location() const { return location_; } BrowserAccessibilityManager* manager() const { return manager_; } + bool instance_active() const { return node_ != NULL; } + ui::AXNode* node() const { return node_; } const std::string& name() const { return name_; } const std::string& value() const { return value_; } - int32 renderer_id() const { return renderer_id_; } - int32 role() const { return role_; } - int32 state() const { return state_; } - bool instance_active() const { return instance_active_; } - void set_name(const std::string& name) { name_ = name; } void set_value(const std::string& value) { value_ = value; } + // These access the internal accessibility tree, which doesn't necessarily + // reflect the accessibility tree that should be exposed on each platform. + // Use PlatformChildCount and PlatformGetChild to implement platform + // accessibility APIs. + uint32 InternalChildCount() const; + BrowserAccessibility* InternalGetChild(uint32 child_index) const; + + BrowserAccessibility* GetParent() const; + int32 GetIndexInParent() const; + + int32 GetId() const; + const ui::AXNodeData& GetData() const; + gfx::Rect GetLocation() const; + int32 GetRole() const; + int32 GetState() const; + + typedef std::vector<std::pair<std::string, std::string> > HtmlAttributes; + const HtmlAttributes& GetHtmlAttributes() const; + #if defined(OS_MACOSX) && __OBJC__ BrowserAccessibilityCocoa* ToBrowserAccessibilityCocoa(); #elif defined(OS_WIN) BrowserAccessibilityWin* ToBrowserAccessibilityWin(); -#elif defined(TOOLKIT_GTK) - BrowserAccessibilityGtk* ToBrowserAccessibilityGtk(); #endif // Accessing accessibility attributes: @@ -197,43 +183,37 @@ class CONTENT_EXPORT BrowserAccessibility { // attribute is not present. In addition, strings can be returned as // either std::string or base::string16, for convenience. - bool HasBoolAttribute(AccessibilityNodeData::BoolAttribute attr) const; - bool GetBoolAttribute(AccessibilityNodeData::BoolAttribute attr) const; - bool GetBoolAttribute(AccessibilityNodeData::BoolAttribute attr, - bool* value) const; + bool HasBoolAttribute(ui::AXBoolAttribute attr) const; + bool GetBoolAttribute(ui::AXBoolAttribute attr) const; + bool GetBoolAttribute(ui::AXBoolAttribute attr, bool* value) const; - bool HasFloatAttribute(AccessibilityNodeData::FloatAttribute attr) const; - float GetFloatAttribute(AccessibilityNodeData::FloatAttribute attr) const; - bool GetFloatAttribute(AccessibilityNodeData::FloatAttribute attr, - float* value) const; + bool HasFloatAttribute(ui::AXFloatAttribute attr) const; + float GetFloatAttribute(ui::AXFloatAttribute attr) const; + bool GetFloatAttribute(ui::AXFloatAttribute attr, float* value) const; - bool HasIntAttribute(AccessibilityNodeData::IntAttribute attribute) const; - int GetIntAttribute(AccessibilityNodeData::IntAttribute attribute) const; - bool GetIntAttribute(AccessibilityNodeData::IntAttribute attribute, - int* value) const; + bool HasIntAttribute(ui::AXIntAttribute attribute) const; + int GetIntAttribute(ui::AXIntAttribute attribute) const; + bool GetIntAttribute(ui::AXIntAttribute attribute, int* value) const; bool HasStringAttribute( - AccessibilityNodeData::StringAttribute attribute) const; - const std::string& GetStringAttribute( - AccessibilityNodeData::StringAttribute attribute) const; - bool GetStringAttribute(AccessibilityNodeData::StringAttribute attribute, + ui::AXStringAttribute attribute) const; + const std::string& GetStringAttribute(ui::AXStringAttribute attribute) const; + bool GetStringAttribute(ui::AXStringAttribute attribute, std::string* value) const; - bool GetString16Attribute(AccessibilityNodeData::StringAttribute attribute, + bool GetString16Attribute(ui::AXStringAttribute attribute, base::string16* value) const; base::string16 GetString16Attribute( - AccessibilityNodeData::StringAttribute attribute) const; + ui::AXStringAttribute attribute) const; - bool HasIntListAttribute( - AccessibilityNodeData::IntListAttribute attribute) const; + bool HasIntListAttribute(ui::AXIntListAttribute attribute) const; const std::vector<int32>& GetIntListAttribute( - AccessibilityNodeData::IntListAttribute attribute) const; - bool GetIntListAttribute(AccessibilityNodeData::IntListAttribute attribute, + ui::AXIntListAttribute attribute) const; + bool GetIntListAttribute(ui::AXIntListAttribute attribute, std::vector<int32>* value) const; - void SetStringAttribute( - AccessibilityNodeData::StringAttribute attribute, - const std::string& value); + void SetStringAttribute(ui::AXStringAttribute attribute, + const std::string& value); // Retrieve the value of a html attribute from the attribute map and // returns true if found. @@ -257,7 +237,7 @@ class CONTENT_EXPORT BrowserAccessibility { bool* is_mixed) const; // Returns true if the bit corresponding to the given state enum is 1. - bool HasState(blink::WebAXState state_enum) const; + bool HasState(ui::AXState state_enum) const; // Returns true if this node is an editable text field of any kind. bool IsEditableText() const; @@ -266,56 +246,21 @@ class CONTENT_EXPORT BrowserAccessibility { std::string GetTextRecursive() const; protected: - // Perform platform specific initialization. This can be called multiple times - // during the lifetime of this instance after the members of this base object - // have been reset with new values from the renderer process. - // Perform child independent initialization in this method. - virtual void PreInitialize() {} - BrowserAccessibility(); - // The manager of this tree of accessibility objects; needed for - // global operations like focus tracking. + // The manager of this tree of accessibility objects. BrowserAccessibilityManager* manager_; - // The parent of this object, may be NULL if we're the root object. - BrowserAccessibility* parent_; + // The underlying node. + ui::AXNode* node_; private: - // The index of this within its parent object. - int32 index_in_parent_; - - // The ID of this object in the renderer process. - int32 renderer_id_; - - // The children of this object. - std::vector<BrowserAccessibility*> children_; + // Return the sum of the lengths of all static text descendants, + // including this object if it's static text. + int GetStaticTextLenRecursive() const; - // Accessibility metadata from the renderer std::string name_; std::string value_; - std::vector<std::pair< - AccessibilityNodeData::BoolAttribute, bool> > bool_attributes_; - std::vector<std::pair< - AccessibilityNodeData::FloatAttribute, float> > float_attributes_; - std::vector<std::pair< - AccessibilityNodeData::IntAttribute, int> > int_attributes_; - std::vector<std::pair< - AccessibilityNodeData::StringAttribute, std::string> > string_attributes_; - std::vector<std::pair< - AccessibilityNodeData::IntListAttribute, std::vector<int32> > > - intlist_attributes_; - std::vector<std::pair<std::string, std::string> > html_attributes_; - int32 role_; - int32 state_; - gfx::Rect location_; - - // BrowserAccessibility objects are reference-counted on some platforms. - // When we're done with this object and it's removed from our accessibility - // tree, a client may still be holding onto a pointer to this object, so - // we mark it as inactive so that calls to any of this object's methods - // immediately return failure. - bool instance_active_; private: DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility); |