[orca] Grab focus on entries when setting focus mode; ont when positioning caret



commit 092c28b1c85e44510605df5ebc92d66e2f6ec859
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Sun Feb 28 12:54:27 2016 -0500

    Grab focus on entries when setting focus mode; ont when positioning caret
    
    Doing the latter can trigger popups and events we don't want in browse mode.

 src/orca/scripts/web/script.py           |    8 ++++-
 src/orca/scripts/web/script_utilities.py |   45 ++++++++++++++++++------------
 2 files changed, 34 insertions(+), 19 deletions(-)
---
diff --git a/src/orca/scripts/web/script.py b/src/orca/scripts/web/script.py
index 1560138..7694a00 100644
--- a/src/orca/scripts/web/script.py
+++ b/src/orca/scripts/web/script.py
@@ -962,8 +962,8 @@ class Script(default.Script):
         self._focusModeIsSticky = True
 
     def togglePresentationMode(self, inputEvent):
+        [obj, characterOffset] = self.utilities.getCaretContext()
         if self._inFocusMode:
-            [obj, characterOffset] = self.utilities.getCaretContext()
             try:
                 parentRole = obj.parent.getRole()
             except:
@@ -975,6 +975,12 @@ class Script(default.Script):
 
             self.presentMessage(messages.MODE_BROWSE)
         else:
+            if not self.utilities.grabFocusWhenSettingCaret(obj) \
+               and (self._lastCommandWasCaretNav \
+                    or self._lastCommandWasStructNav \
+                    or inputEvent):
+                self.utilities.grabFocus(obj)
+
             self.presentMessage(messages.MODE_FOCUS)
         self._inFocusMode = not self._inFocusMode
         self._focusModeIsSticky = False
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index 12d8699..07e7f16 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -236,6 +236,31 @@ class Utilities(script_utilities.Utilities):
 
         return None
 
+    def grabFocusWhenSettingCaret(self, obj):
+        try:
+            role = obj.getRole()
+            state = obj.getState()
+        except:
+            msg = "WEB: Exception getting role and state for %s" % obj
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return False
+
+        # To avoid triggering popup lists.
+        if role == pyatspi.ROLE_ENTRY:
+            return False
+
+        return state.contains(pyatspi.STATE_FOCUSABLE)
+
+    def grabFocus(self, obj):
+        try:
+            obj.queryComponent().grabFocus()
+        except NotImplementedError:
+            msg = "WEB: %s does not implement the component interface" % obj
+            debug.println(debug.LEVEL_INFO, msg, True)
+        except:
+            msg = "WEB: Exception grabbing focus on %s" % obj
+            debug.println(debug.LEVEL_INFO, msg, True)
+
     def setCaretPosition(self, obj, offset):
         if self._script.flatReviewContext:
             self._script.toggleFlatReviewMode()
@@ -245,25 +270,9 @@ class Utilities(script_utilities.Utilities):
         if self._script.focusModeIsSticky():
             return
 
-        try:
-            state = obj.getState()
-        except:
-            msg = "WEB: Exception getting state for %s" % obj
-            debug.println(debug.LEVEL_INFO, msg, True)
-            return
-
         orca.setLocusOfFocus(None, obj, notifyScript=False)
-        if state.contains(pyatspi.STATE_FOCUSABLE):
-            try:
-                obj.queryComponent().grabFocus()
-            except NotImplementedError:
-                msg = "WEB: %s does not implement the component interface" % obj
-                debug.println(debug.LEVEL_INFO, msg, True)
-                return
-            except:
-                msg = "WEB: Exception grabbing focus on %s" % obj
-                debug.println(debug.LEVEL_INFO, msg, True)
-                return
+        if self.grabFocusWhenSettingCaret(obj):
+            self.grabFocus(obj)
 
         text = self.queryNonEmptyText(obj)
         if text:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]