AccessibilitySidebarView.js 3.9 KB

123456789101112131415161718192021222324252627
  1. export default class AccessibilitySidebarView extends UI.ThrottledWidget{constructor(){super();this._node=null;this._axNode=null;this._skipNextPullNode=false;this._sidebarPaneStack=UI.viewManager.createStackLocation();this._breadcrumbsSubPane=new Accessibility.AXBreadcrumbsPane(this);this._sidebarPaneStack.showView(this._breadcrumbsSubPane);this._ariaSubPane=new Accessibility.ARIAAttributesPane();this._sidebarPaneStack.showView(this._ariaSubPane);this._axNodeSubPane=new Accessibility.AXNodeSubPane();this._sidebarPaneStack.showView(this._axNodeSubPane);this._sidebarPaneStack.widget().show(this.element);UI.context.addFlavorChangeListener(SDK.DOMNode,this._pullNode,this);this._pullNode();}
  2. node(){return this._node;}
  3. axNode(){return this._axNode;}
  4. setNode(node,fromAXTree){this._skipNextPullNode=!!fromAXTree;this._node=node;this.update();}
  5. accessibilityNodeCallback(axNode){if(!axNode){return;}
  6. this._axNode=axNode;if(axNode.isDOMNode()){this._sidebarPaneStack.showView(this._ariaSubPane,this._axNodeSubPane);}else{this._sidebarPaneStack.removeView(this._ariaSubPane);}
  7. if(this._axNodeSubPane){this._axNodeSubPane.setAXNode(axNode);}
  8. if(this._breadcrumbsSubPane){this._breadcrumbsSubPane.setAXNode(axNode);}}
  9. doUpdate(){const node=this.node();this._axNodeSubPane.setNode(node);this._ariaSubPane.setNode(node);this._breadcrumbsSubPane.setNode(node);if(!node){return Promise.resolve();}
  10. const accessibilityModel=node.domModel().target().model(Accessibility.AccessibilityModel);accessibilityModel.clear();return accessibilityModel.requestPartialAXTree(node).then(()=>{this.accessibilityNodeCallback(accessibilityModel.axNodeForDOMNode(node));});}
  11. wasShown(){super.wasShown();this.doUpdate();SDK.targetManager.addModelListener(SDK.DOMModel,SDK.DOMModel.Events.AttrModified,this._onAttrChange,this);SDK.targetManager.addModelListener(SDK.DOMModel,SDK.DOMModel.Events.AttrRemoved,this._onAttrChange,this);SDK.targetManager.addModelListener(SDK.DOMModel,SDK.DOMModel.Events.CharacterDataModified,this._onNodeChange,this);SDK.targetManager.addModelListener(SDK.DOMModel,SDK.DOMModel.Events.ChildNodeCountUpdated,this._onNodeChange,this);}
  12. willHide(){SDK.targetManager.removeModelListener(SDK.DOMModel,SDK.DOMModel.Events.AttrModified,this._onAttrChange,this);SDK.targetManager.removeModelListener(SDK.DOMModel,SDK.DOMModel.Events.AttrRemoved,this._onAttrChange,this);SDK.targetManager.removeModelListener(SDK.DOMModel,SDK.DOMModel.Events.CharacterDataModified,this._onNodeChange,this);SDK.targetManager.removeModelListener(SDK.DOMModel,SDK.DOMModel.Events.ChildNodeCountUpdated,this._onNodeChange,this);}
  13. _pullNode(){if(this._skipNextPullNode){this._skipNextPullNode=false;return;}
  14. this.setNode(UI.context.flavor(SDK.DOMNode));}
  15. _onAttrChange(event){if(!this.node()){return;}
  16. const node=event.data.node;if(this.node()!==node){return;}
  17. this.update();}
  18. _onNodeChange(event){if(!this.node()){return;}
  19. const node=event.data;if(this.node()!==node){return;}
  20. this.update();}}
  21. export class AccessibilitySubPane extends UI.SimpleView{constructor(name){super(name);this._axNode=null;this.registerRequiredCSS('accessibility/accessibilityProperties.css');}
  22. setAXNode(axNode){}
  23. node(){return this._node;}
  24. setNode(node){this._node=node;}
  25. createInfo(textContent,className){const classNameOrDefault=className||'gray-info-message';const info=this.element.createChild('div',classNameOrDefault);info.textContent=textContent;return info;}
  26. createTreeOutline(){const treeOutline=new UI.TreeOutlineInShadow();treeOutline.registerRequiredCSS('accessibility/accessibilityNode.css');treeOutline.registerRequiredCSS('accessibility/accessibilityProperties.css');treeOutline.registerRequiredCSS('object_ui/objectValue.css');treeOutline.element.classList.add('hidden');treeOutline.hideOverflow();this.element.appendChild(treeOutline.element);return treeOutline;}}
  27. self.Accessibility=self.Accessibility||{};Accessibility=Accessibility||{};Accessibility.AccessibilitySidebarView=AccessibilitySidebarView;Accessibility.AccessibilitySubPane=AccessibilitySubPane;