Bug 1187740 - Handle proxies in mozHTMLAccessible r=tbsaunde
authorLorien Hu <lorien@lorienhu.com>
Wed, 05 Aug 2015 21:55:15 -0400
changeset 288133 b4b5caf0208e81ad7f1375e61be72cc6778bebde
parent 288132 e323de7f0ac981ec884bed04a6d093490c5510e3
child 288134 28ec449865beb04a7744e8361cc7a85313e89d29
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs1187740
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1187740 - Handle proxies in mozHTMLAccessible r=tbsaunde
accessible/ipc/DocAccessibleChild.cpp
accessible/ipc/DocAccessibleChild.h
accessible/ipc/PDocAccessible.ipdl
accessible/ipc/ProxyAccessible.cpp
accessible/ipc/ProxyAccessible.h
accessible/mac/mozHTMLAccessible.mm
--- a/accessible/ipc/DocAccessibleChild.cpp
+++ b/accessible/ipc/DocAccessibleChild.cpp
@@ -346,16 +346,26 @@ DocAccessibleChild::RecvARIARoleAtom(con
       roleAtom->ToString(*aRole);
     }
   }
 
   return true;
 }
 
 bool
+DocAccessibleChild::RecvGetLevelInternal(const uint64_t& aID, int32_t* aLevel)
+{
+  Accessible* acc = IdToAccessible(aID);
+  if (acc) {
+    *aLevel = acc->GetLevelInternal();
+  }
+  return true;
+}
+
+bool
 DocAccessibleChild::RecvCaretLineNumber(const uint64_t& aID, int32_t* aLineNumber)
 {
   HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
   *aLineNumber = acc && acc->IsTextRole() ? acc->CaretLineNumber() : 0;
   return true;
 }
 
 bool
@@ -1822,16 +1832,29 @@ DocAccessibleChild::RecvDocType(const ui
   if (acc && acc->IsDoc()) {
     acc->AsDoc()->DocType(*aType);
   }
 
   return true;
 }
 
 bool
+DocAccessibleChild::RecvTitle(const uint64_t& aID,
+                            nsString* aTitle)
+{
+  Accessible* acc = IdToAccessible(aID);
+  if (acc) {
+    mozilla::ErrorResult rv;
+    acc->GetContent()->GetTextContent(*aTitle, rv);
+  }
+
+  return true;
+}
+
+bool
 DocAccessibleChild::RecvURL(const uint64_t& aID,
                             nsString* aURL)
 {
   Accessible* acc = IdToAccessible(aID);
   if (acc && acc->IsDoc()) {
     acc->AsDoc()->URL(*aURL);
   }
 
--- a/accessible/ipc/DocAccessibleChild.h
+++ b/accessible/ipc/DocAccessibleChild.h
@@ -89,16 +89,18 @@ public:
     override;
 
   virtual bool RecvIsSearchbox(const uint64_t& aID, bool* aRetVal) override;
 
   virtual bool RecvLandmarkRole(const uint64_t& aID, nsString* aLandmark) override;
 
   virtual bool RecvARIARoleAtom(const uint64_t& aID, nsString* aRole) override;
 
+  virtual bool RecvGetLevelInternal(const uint64_t& aID, int32_t* aLevel) override;
+
   virtual bool RecvAttributes(const uint64_t& aID,
                               nsTArray<Attribute> *aAttributes) override;
 
   virtual bool RecvCaretLineNumber(const uint64_t& aID, int32_t* aLineNumber)
     override;
   virtual bool RecvCaretOffset(const uint64_t& aID, int32_t* aOffset)
     override;
   virtual bool RecvSetCaretOffset(const uint64_t& aID, const int32_t& aOffset,
@@ -449,16 +451,17 @@ public:
                                 const uint32_t& aWhich,
                                 uint64_t* aChild,
                                 bool* aOk) override;
 
   virtual bool RecvBounds(const uint64_t& aID, nsIntRect* aRect) override;
 
   virtual bool RecvLanguage(const uint64_t& aID, nsString* aLocale) override;
   virtual bool RecvDocType(const uint64_t& aID, nsString* aType) override;
+  virtual bool RecvTitle(const uint64_t& aID, nsString* aTitle) override;
   virtual bool RecvURL(const uint64_t& aID, nsString* aURL) override;
   virtual bool RecvMimeType(const uint64_t& aID, nsString* aMime) override;
   virtual bool RecvURLDocTypeMimeType(const uint64_t& aID,
                                       nsString* aURL,
                                       nsString* aDocType,
                                       nsString* aMimeType) override;
 private:
 
--- a/accessible/ipc/PDocAccessible.ipdl
+++ b/accessible/ipc/PDocAccessible.ipdl
@@ -80,16 +80,17 @@ child:
   prio(high) sync Description(uint64_t aID) returns(nsString desc);
   prio(high) sync Attributes(uint64_t aID) returns(Attribute[] attributes);
   prio(high) sync RelationByType(uint64_t aID, uint32_t aRelationType)
     returns(uint64_t[] targets);
   prio(high) sync Relations(uint64_t aID) returns(RelationTargets[] relations);
   prio(high) sync IsSearchbox(uint64_t aID) returns(bool retval);
   prio(high) sync LandmarkRole(uint64_t aID) returns(nsString landmark);
   prio(high) sync ARIARoleAtom(uint64_t aID) returns(nsString role);
+  prio(high) sync GetLevelInternal(uint64_t aID) returns(int32_t aLevel);
 
   // AccessibleText
 
   // TextSubstring is getText in IDL.
   prio(high) sync CaretLineNumber(uint64_t aID) returns(int32_t aLineNumber);
   prio(high) sync CaretOffset(uint64_t aID) returns(int32_t aOffset);
   prio(high) sync SetCaretOffset(uint64_t aID, int32_t aOffset) returns (bool aValid);
   prio(high) sync CharacterCount(uint64_t aID) returns(int32_t aCount);
@@ -232,15 +233,16 @@ child:
   prio(high) sync FocusedChild(uint64_t aID)
     returns(uint64_t aChild, bool aOk);
   prio(high) sync ChildAtPoint(uint64_t aID, int32_t aX, int32_t aY, uint32_t aWhich)
     returns(uint64_t aChild, bool aOk);
   prio(high) sync Bounds(uint64_t aID) returns(nsIntRect aRect);
 
   prio(high) sync Language(uint64_t aID) returns(nsString aLocale);
   prio(high) sync DocType(uint64_t aID) returns(nsString aType);
+  prio(high) sync Title(uint64_t aID) returns(nsString aTitle);
   prio(high) sync URL(uint64_t aID) returns(nsString aURL);
   prio(high) sync MimeType(uint64_t aID) returns(nsString aMime);
   prio(high) sync URLDocTypeMimeType(uint64_t aID) returns(nsString aURL, nsString aDocType, nsString aMimeType);
 };
 
 }
 }
--- a/accessible/ipc/ProxyAccessible.cpp
+++ b/accessible/ipc/ProxyAccessible.cpp
@@ -187,16 +187,24 @@ nsIAtom*
 ProxyAccessible::ARIARoleAtom() const
 {
   nsString role;
   unused << mDoc->SendARIARoleAtom(mID, &role);
   return NS_GetStaticAtom(role);
 }
 
 int32_t
+ProxyAccessible::GetLevelInternal()
+{
+  int32_t level = 0;
+  unused << mDoc->SendGetLevelInternal(mID, &level);
+  return level;
+}
+
+int32_t
 ProxyAccessible::CaretLineNumber()
 {
   int32_t line = -1;
   unused << mDoc->SendCaretOffset(mID, &line);
   return line;
 }
 
 int32_t
@@ -1025,16 +1033,22 @@ ProxyAccessible::Language(nsString& aLoc
 
 void
 ProxyAccessible::DocType(nsString& aType)
 {
   unused << mDoc->SendDocType(mID, &aType);
 }
 
 void
+ProxyAccessible::Title(nsString& aTitle)
+{
+  unused << mDoc->SendTitle(mID, &aTitle);
+}
+
+void
 ProxyAccessible::URL(nsString& aURL)
 {
   unused << mDoc->SendURL(mID, &aURL);
 }
 
 void
 ProxyAccessible::MimeType(nsString aMime)
 {
--- a/accessible/ipc/ProxyAccessible.h
+++ b/accessible/ipc/ProxyAccessible.h
@@ -122,16 +122,18 @@ public:
                  nsTArray<nsTArray<ProxyAccessible*>>* aTargetSets) const;
 
   bool IsSearchbox() const;
 
   nsIAtom* LandmarkRole() const;
 
   nsIAtom* ARIARoleAtom() const;
 
+  int32_t GetLevelInternal();
+
   int32_t CaretLineNumber();
   int32_t CaretOffset();
   bool SetCaretOffset(int32_t aOffset);
 
   int32_t CharacterCount();
   int32_t SelectionCount();
 
   /**
@@ -305,16 +307,17 @@ public:
   void TakeFocus();
   ProxyAccessible* FocusedChild();
   ProxyAccessible* ChildAtPoint(int32_t aX, int32_t aY,
                                 Accessible::EWhichChildAtPoint aWhichChild);
   nsIntRect Bounds();
 
   void Language(nsString& aLocale);
   void DocType(nsString& aType);
+  void Title(nsString& aTitle);
   void URL(nsString& aURL);
   void MimeType(nsString aMime);
   void URLDocTypeMimeType(nsString& aURL, nsString& aDocType,
                           nsString& aMimeType);
 
   /**
    * Allow the platform to store a pointers worth of data on us.
    */
--- a/accessible/mac/mozHTMLAccessible.mm
+++ b/accessible/mac/mozHTMLAccessible.mm
@@ -12,113 +12,127 @@
 
 #import "nsCocoaUtils.h"
 
 @implementation mozHeadingAccessible
 
 - (NSString*)title
 {
   nsAutoString title;
-  mozilla::ErrorResult rv;
-  // XXX use the flattening API when there are available
-  // see bug 768298
-  [self getGeckoAccessible]->GetContent()->GetTextContent(title, rv);
+  if (AccessibleWrap* accWrap = [self getGeckoAccessible]) {
+    mozilla::ErrorResult rv;
+    // XXX use the flattening API when there are available
+    // see bug 768298
+    accWrap->GetContent()->GetTextContent(title, rv);
+  } else if (ProxyAccessible* proxy = [self getProxyAccessible]) {
+    proxy->Title(title);
+  }
 
   return nsCocoaUtils::ToNSString(title);
 }
 
 - (id)value
 {
-  AccessibleWrap* accWrap = [self getGeckoAccessible];
+  uint32_t level = 0;
+  if (AccessibleWrap* accWrap = [self getGeckoAccessible]) {
+    level = accWrap->GetLevelInternal();
+  } else if (ProxyAccessible* proxy = [self getProxyAccessible]) {
+    level = proxy->GetLevelInternal();
+  }
 
-  if (!accWrap || !accWrap->IsHyperText())
-    return nil;
-
-  uint32_t level = accWrap->AsHyperText()->GetLevelInternal();
   return [NSNumber numberWithInt:level];
 }
 
 @end
 
 @interface mozLinkAccessible ()
 -(NSURL*)url;
 @end
 
 @implementation mozLinkAccessible
 
 - (NSArray*)accessibilityAttributeNames
 {
   // if we're expired, we don't support any attributes.
-  if (![self getGeckoAccessible])
+  if (![self getGeckoAccessible] && ![self getProxyAccessible])
     return [NSArray array];
-  
+
   static NSMutableArray* attributes = nil;
-  
+
   if (!attributes) {
     attributes = [[super accessibilityAttributeNames] mutableCopy];
     [attributes addObject:NSAccessibilityURLAttribute];
   }
 
   return attributes;
 }
 
 - (id)accessibilityAttributeValue:(NSString *)attribute
 {
   if ([attribute isEqualToString:NSAccessibilityURLAttribute])
     return [self url];
 
   return [super accessibilityAttributeValue:attribute];
 }
 
-- (NSArray*)accessibilityActionNames 
+- (NSArray*)accessibilityActionNames
 {
     // if we're expired, we don't support any attributes.
-  if (![self getGeckoAccessible])
+  if (![self getGeckoAccessible] && ![self getProxyAccessible])
     return [NSArray array];
 
   static NSArray* actionNames = nil;
 
   if (!actionNames) {
     actionNames = [[NSArray alloc] initWithObjects:NSAccessibilityPressAction,
                                    nil];
   }
 
   return actionNames;
 }
 
-- (void)accessibilityPerformAction:(NSString*)action 
+- (void)accessibilityPerformAction:(NSString*)action
 {
   AccessibleWrap* accWrap = [self getGeckoAccessible];
-
-  if (!accWrap)
+  ProxyAccessible* proxy = [self getProxyAccessible];
+  if (!accWrap && !proxy) {
     return;
+  }
 
-  if ([action isEqualToString:NSAccessibilityPressAction])
-    accWrap->DoAction(0);
-  else
-    [super accessibilityPerformAction:action];
+  if ([action isEqualToString:NSAccessibilityPressAction]) {
+    if (accWrap) {
+      accWrap->DoAction(0);
+    } else if (proxy) {
+      proxy->DoAction(0);
+    }
+    return;
+  }
+
+  [super accessibilityPerformAction:action];
+
 }
 
 - (NSString*)customDescription
 {
   return @"";
 }
 
 - (NSString*)value
 {
   return @"";
 }
 
 - (NSURL*)url
 {
-  if (![self getGeckoAccessible] || [self getGeckoAccessible]->IsDefunct())
-    return nil;
-
   nsAutoString value;
-  [self getGeckoAccessible]->Value(value);
+  if (AccessibleWrap* accWrap = [self getGeckoAccessible]) {
+    accWrap->Value(value);
+  } else if (ProxyAccessible* proxy = [self getProxyAccessible]) {
+    proxy->Value(value);
+  }
 
   NSString* urlString = value.IsEmpty() ? nil : nsCocoaUtils::ToNSString(value);
   if (!urlString)
     return nil;
 
   return [NSURL URLWithString:urlString];
 }