Bug 1140499 - IPC Proxy for text/char bounds, r=tbsaunde
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Sun, 08 Mar 2015 04:33:57 +0200
changeset 262756 d5f0d1845eccc192bb1731a9402933a72eb2bdef
parent 262755 a6dbd23da5982cc7564367815f6be855c6d2d3f6
child 262757 3d6cd86c1791e3eaed69d7b2b290b42080f99c3c
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs1140499
milestone39.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 1140499 - IPC Proxy for text/char bounds, r=tbsaunde
accessible/atk/nsMaiInterfaceText.cpp
accessible/ipc/DocAccessibleChild.cpp
accessible/ipc/DocAccessibleChild.h
accessible/ipc/PDocAccessible.ipdl
accessible/ipc/ProxyAccessible.cpp
accessible/ipc/ProxyAccessible.h
--- a/accessible/atk/nsMaiInterfaceText.cpp
+++ b/accessible/atk/nsMaiInterfaceText.cpp
@@ -333,56 +333,78 @@ getDefaultAttributesCB(AtkText *aText)
 }
 
 static void
 getCharacterExtentsCB(AtkText *aText, gint aOffset,
                       gint *aX, gint *aY,
                       gint *aWidth, gint *aHeight,
                       AtkCoordType aCoords)
 {
-  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-  if(!accWrap || !aX || !aY || !aWidth || !aHeight)
+  if(!aX || !aY || !aWidth || !aHeight) {
     return;
+  }
 
-  HyperTextAccessible* text = accWrap->AsHyperText();
-  if (!text || !text->IsTextRole())
-    return;
+  nsIntRect rect;
+  uint32_t geckoCoordType;
+  if (aCoords == ATK_XY_SCREEN) {
+    geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
+  } else {
+    geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
+  }
 
-    uint32_t geckoCoordType;
-    if (aCoords == ATK_XY_SCREEN)
-        geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
-    else
-        geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
+  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
+  if (accWrap) {
+    HyperTextAccessible* text = accWrap->AsHyperText();
+    if (!text || !text->IsTextRole()) {
+      return;
+    }
 
-  nsIntRect rect = text->CharBounds(aOffset, geckoCoordType);
+    rect = text->CharBounds(aOffset, geckoCoordType);
+  } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
+    rect = proxy->CharBounds(aOffset, geckoCoordType);
+  } else {
+    return;
+  }
+
   *aX = rect.x;
   *aY = rect.y;
   *aWidth = rect.width;
   *aHeight = rect.height;
 }
 
 static void
 getRangeExtentsCB(AtkText *aText, gint aStartOffset, gint aEndOffset,
                   AtkCoordType aCoords, AtkTextRectangle *aRect)
 {
-  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-  if(!accWrap || !aRect)
+  if (!aRect) {
     return;
+  }
 
-  HyperTextAccessible* text = accWrap->AsHyperText();
-  if (!text || !text->IsTextRole())
-    return;
+  nsIntRect rect;
+  uint32_t geckoCoordType;
+  if (aCoords == ATK_XY_SCREEN) {
+    geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
+  } else {
+    geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
+  }
 
-    uint32_t geckoCoordType;
-    if (aCoords == ATK_XY_SCREEN)
-        geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
-    else
-        geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
+  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
+  if(accWrap) {
+    HyperTextAccessible* text = accWrap->AsHyperText();
+    if (!text || !text->IsTextRole()) {
+      return;
+    }
 
-  nsIntRect rect = text->TextBounds(aStartOffset, aEndOffset, geckoCoordType);
+    rect = text->TextBounds(aStartOffset, aEndOffset, geckoCoordType);
+  } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
+    rect = proxy->TextBounds(aStartOffset, aEndOffset, geckoCoordType);
+  } else {
+    return;
+  }
+
   aRect->x = rect.x;
   aRect->y = rect.y;
   aRect->width = rect.width;
   aRect->height = rect.height;
 }
 
 static gint
 getCharacterCountCB(AtkText *aText)
--- a/accessible/ipc/DocAccessibleChild.cpp
+++ b/accessible/ipc/DocAccessibleChild.cpp
@@ -358,10 +358,39 @@ DocAccessibleChild::RecvDefaultTextAttri
   if (!acc || !acc->IsTextRole()) {
     return true;
   }
 
   nsCOMPtr<nsIPersistentProperties> props = acc->DefaultTextAttributes();
   return PersistentPropertiesToArray(props, aAttributes);
 }
 
+bool
+DocAccessibleChild::RecvTextBounds(const uint64_t& aID,
+                                   const int32_t& aStartOffset,
+                                   const int32_t& aEndOffset,
+                                   const uint32_t& aCoordType,
+                                   nsIntRect* aRetVal)
+{
+  HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
+  if (acc && acc->IsTextRole()) {
+    *aRetVal = acc->TextBounds(aStartOffset, aEndOffset, aCoordType);
+  }
+
+  return true;
+}
+
+bool
+DocAccessibleChild::RecvCharBounds(const uint64_t& aID,
+                                   const int32_t& aOffset,
+                                   const uint32_t& aCoordType,
+                                   nsIntRect* aRetVal)
+{
+  HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
+  if (acc && acc->IsTextRole()) {
+    *aRetVal = acc->CharBounds(aOffset, aCoordType);
+  }
+
+  return true;
+}
+
 }
 }
--- a/accessible/ipc/DocAccessibleChild.h
+++ b/accessible/ipc/DocAccessibleChild.h
@@ -106,16 +106,26 @@ public:
                                   int32_t* aStartOffset,
                                   int32_t* aEndOffset)
     MOZ_OVERRIDE;
 
   virtual bool RecvDefaultTextAttributes(const uint64_t& aID,
                                          nsTArray<Attribute>* aAttributes)
     MOZ_OVERRIDE;
 
+  virtual bool RecvTextBounds(const uint64_t& aID,
+                              const int32_t& aStartOffset,
+                              const int32_t& aEndOffset,
+                              const uint32_t& aCoordType,
+                              nsIntRect* aRetVal) MOZ_OVERRIDE;
+
+  virtual bool RecvCharBounds(const uint64_t& aID,
+                              const int32_t& aOffset,
+                              const uint32_t& aCoordType,
+                              nsIntRect* aRetVal) MOZ_OVERRIDE;
 private:
   bool PersistentPropertiesToArray(nsIPersistentProperties* aProps,
                                    nsTArray<Attribute>* aAttributes);
 
   DocAccessible* mDoc;
 };
 
 }
--- a/accessible/ipc/PDocAccessible.ipdl
+++ b/accessible/ipc/PDocAccessible.ipdl
@@ -1,16 +1,18 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 include protocol PContent;
 
+using struct nsIntRect from "nsRect.h";
+
 namespace mozilla {
 namespace a11y {
 
 struct AccessibleData
 {
   uint64_t ID;
   uint32_t Role;
   uint32_t ChildrenCount;
@@ -78,12 +80,18 @@ child:
 
   prio(high) sync GetTextBeforeOffset(uint64_t aID, int32_t aOffset, int32_t aBoundaryType)
     returns(nsString aText, int32_t aStartOffset, int32_t aEndOffset);
   prio(high) sync CharAt(uint64_t aID, int32_t aOffset) returns(uint16_t aChar);
 
   prio(high) sync TextAttributes(uint64_t aID, bool aIncludeDefAttrs, int32_t aOffset)
     returns(Attribute[] aAttributes, int32_t aStartOffset, int32_t aEndOffset);
   prio(high) sync DefaultTextAttributes(uint64_t aID) returns(Attribute[] aAttributes);
+
+  prio(high) sync TextBounds(uint64_t aID, int32_t aStartOffset, int32_t aEndOffset,
+                             uint32_t aCoordType)
+    returns(nsIntRect aRetVal);
+  prio(high) sync CharBounds(uint64_t aID, int32_t aOffset, uint32_t aCoordType)
+    returns(nsIntRect aRetVal);
 };
 
 }
 }
--- a/accessible/ipc/ProxyAccessible.cpp
+++ b/accessible/ipc/ProxyAccessible.cpp
@@ -238,10 +238,29 @@ ProxyAccessible::TextAttributes(bool aIn
 }
 
 void
 ProxyAccessible::DefaultTextAttributes(nsTArray<Attribute>* aAttrs)
 {
   unused << mDoc->SendDefaultTextAttributes(mID, aAttrs);
 }
 
+nsIntRect
+ProxyAccessible::TextBounds(int32_t aStartOffset, int32_t aEndOffset,
+                            uint32_t aCoordType)
+{
+  nsIntRect rect;
+  unused <<
+    mDoc->SendTextBounds(mID, aStartOffset, aEndOffset, aCoordType, &rect);
+  return rect;
+}
+
+nsIntRect
+ProxyAccessible::CharBounds(int32_t aOffset, uint32_t aCoordType)
+{
+  nsIntRect rect;
+  unused <<
+    mDoc->SendCharBounds(mID, aOffset, aCoordType, &rect);
+  return rect;
+}
+
 }
 }
--- a/accessible/ipc/ProxyAccessible.h
+++ b/accessible/ipc/ProxyAccessible.h
@@ -6,16 +6,17 @@
 
 #ifndef mozilla_a11y_ProxyAccessible_h
 #define mozilla_a11y_ProxyAccessible_h
 
 #include "mozilla/a11y/Role.h"
 #include "nsIAccessibleText.h"
 #include "nsString.h"
 #include "nsTArray.h"
+#include "nsRect.h"
 
 namespace mozilla {
 namespace a11y {
 
 class Attribute;
 class DocAccessibleParent;
 enum class RelationType;
 
@@ -127,16 +128,21 @@ public:
 
   void TextAttributes(bool aIncludeDefAttrs,
                       const int32_t aOffset,
                       nsTArray<Attribute>* aAttributes,
                       int32_t* aStartOffset,
                       int32_t* aEndOffset);
   void DefaultTextAttributes(nsTArray<Attribute>* aAttrs);
 
+  nsIntRect TextBounds(int32_t aStartOffset, int32_t aEndOffset,
+                       uint32_t aCoordType);
+
+  nsIntRect CharBounds(int32_t aOffset, uint32_t aCoordType);
+
   /**
    * Allow the platform to store a pointers worth of data on us.
    */
   uintptr_t GetWrapper() const { return mWrapper; }
   void SetWrapper(uintptr_t aWrapper) { mWrapper = aWrapper; }
 
   /*
    * Return the ID of the accessible being proxied.