#ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_H_
#define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_H_
#include <vector>
#include "base/containers/hash_tables.h"
#include "base/memory/scoped_ptr.h"
#include "build/build_config.h"
#include "content/common/content_export.h"
#include "third_party/WebKit/public/web/WebAXEnums.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/gfx/native_widget_types.h"
struct AccessibilityHostMsg_EventParams;
struct AccessibilityHostMsg_LocationChangeParams;
namespace content {
class BrowserAccessibility;
#if defined(OS_ANDROID)
class BrowserAccessibilityManagerAndroid;
#endif
#if defined(OS_WIN)
class BrowserAccessibilityManagerWin;
#endif
class CONTENT_EXPORT BrowserAccessibilityDelegate {
public:
virtual ~BrowserAccessibilityDelegate() {}
virtual void SetAccessibilityFocus(int acc_obj_id) = 0;
virtual void AccessibilityDoDefaultAction(int acc_obj_id) = 0;
virtual void AccessibilityScrollToMakeVisible(
int acc_obj_id, gfx::Rect subfocus) = 0;
virtual void AccessibilityScrollToPoint(
int acc_obj_id, gfx::Point point) = 0;
virtual void AccessibilitySetTextSelection(
int acc_obj_id, int start_offset, int end_offset) = 0;
virtual bool HasFocus() const = 0;
virtual gfx::Rect GetViewBounds() const = 0;
virtual gfx::Point GetLastTouchEventLocation() const = 0;
virtual void FatalAccessibilityTreeError() = 0;
};
class CONTENT_EXPORT BrowserAccessibilityFactory {
public:
virtual ~BrowserAccessibilityFactory() {}
virtual BrowserAccessibility* Create();
};
class CONTENT_EXPORT BrowserAccessibilityManager {
public:
static BrowserAccessibilityManager* Create(
const ui::AXNodeData& src,
BrowserAccessibilityDelegate* delegate,
BrowserAccessibilityFactory* factory = new BrowserAccessibilityFactory());
virtual ~BrowserAccessibilityManager();
void Initialize(const ui::AXNodeData src);
static ui::AXNodeData GetEmptyDocument();
virtual void NotifyAccessibilityEvent(
ui::AXEvent event_type, BrowserAccessibility* node) { }
BrowserAccessibility* GetRoot();
virtual void RemoveNode(BrowserAccessibility* node);
BrowserAccessibility* GetFromRendererID(int32 renderer_id);
virtual void OnWindowFocused();
virtual void OnWindowBlurred();
void GotMouseDown();
void SetFocus(BrowserAccessibility* node, bool notify);
void DoDefaultAction(const BrowserAccessibility& node);
void ScrollToMakeVisible(
const BrowserAccessibility& node, gfx::Rect subfocus);
void ScrollToPoint(
const BrowserAccessibility& node, gfx::Point point);
void SetTextSelection(
const BrowserAccessibility& node, int start_offset, int end_offset);
gfx::Rect GetViewBounds();
void OnAccessibilityEvents(
const std::vector<AccessibilityHostMsg_EventParams>& params);
void OnLocationChanges(
const std::vector<AccessibilityHostMsg_LocationChangeParams>& params);
#if defined(OS_WIN)
BrowserAccessibilityManagerWin* ToBrowserAccessibilityManagerWin();
#endif
#if defined(OS_ANDROID)
BrowserAccessibilityManagerAndroid* ToBrowserAccessibilityManagerAndroid();
#endif
BrowserAccessibility* GetFocus(BrowserAccessibility* root);
bool IsOSKAllowed(const gfx::Rect& bounds);
virtual bool UseRootScrollOffsetsWhenComputingBounds();
BrowserAccessibility* NextInTreeOrder(BrowserAccessibility* node);
BrowserAccessibility* PreviousInTreeOrder(BrowserAccessibility* node);
void UpdateNodesForTesting(
const ui::AXNodeData& node,
const ui::AXNodeData& node2 = ui::AXNodeData(),
const ui::AXNodeData& node3 = ui::AXNodeData(),
const ui::AXNodeData& node4 = ui::AXNodeData(),
const ui::AXNodeData& node5 = ui::AXNodeData(),
const ui::AXNodeData& node6 = ui::AXNodeData(),
const ui::AXNodeData& node7 = ui::AXNodeData());
protected:
BrowserAccessibilityManager(
BrowserAccessibilityDelegate* delegate,
BrowserAccessibilityFactory* factory);
BrowserAccessibilityManager(
const ui::AXNodeData& src,
BrowserAccessibilityDelegate* delegate,
BrowserAccessibilityFactory* factory);
virtual void AddNodeToMap(BrowserAccessibility* node);
virtual void NotifyRootChanged() {}
private:
enum OnScreenKeyboardState {
OSK_DISALLOWED_BECAUSE_TAB_HIDDEN,
OSK_DISALLOWED_BECAUSE_TAB_JUST_APPEARED,
OSK_ALLOWED_WITHIN_FOCUSED_OBJECT,
OSK_ALLOWED
};
bool UpdateNodes(const std::vector<ui::AXNodeData>& nodes);
bool UpdateNode(const ui::AXNodeData& src);
void SetRoot(BrowserAccessibility* root);
BrowserAccessibility* CreateNode(
BrowserAccessibility* parent,
int32 renderer_id,
int32 index_in_parent);
protected:
BrowserAccessibilityDelegate* delegate_;
scoped_ptr<BrowserAccessibilityFactory> factory_;
BrowserAccessibility* root_;
BrowserAccessibility* focus_;
OnScreenKeyboardState osk_state_;
base::hash_map<int32, BrowserAccessibility*> renderer_id_map_;
DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManager);
};
}
#endif