Bug 1074736 - selection_rect_list should consider multiple range. r=mdas
☠☠ backed out by 35de551b2727 ☠ ☠
authorMorris Tseng <mtseng@mozilla.com>
Wed, 22 Oct 2014 20:03:00 +0200
changeset 212218 141ea70b1caf6bf42a2ac2e1c359de7ed9a93a02
parent 212217 8a799dd8a11c147a6fbe21d6a9ec2873a2961af2
child 212219 b1ab04e807c344a621225b97d58f0b3591d50772
push id9560
push userkwierso@gmail.com
push dateFri, 24 Oct 2014 22:09:23 +0000
treeherderfx-team@c70f62375f7d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmdas
bugs1074736
milestone36.0a1
Bug 1074736 - selection_rect_list should consider multiple range. r=mdas
testing/marionette/client/marionette/selection.py
--- a/testing/marionette/client/marionette/selection.py
+++ b/testing/marionette/client/marionette/selection.py
@@ -68,40 +68,48 @@ class SelectionManager(object):
             cmd = '''var len = arguments[0].value.length;
                   arguments[0].setSelectionRange(len, len);'''
         else:
             cmd = '''var sel = window.getSelection();
                   sel.collapse(arguments[0].lastChild, arguments[0].lastChild.length);'''
 
         self.element.marionette.execute_script(cmd, script_args=[self.element])
 
-    def selection_rect_list(self):
-        '''Return the selection's DOMRectList object.
+    def selection_rect_list(self, idx):
+        '''Return the selection's DOMRectList object for the range at given idx.
 
-        If the element is either <input> or <textarea>, return the selection's
-        DOMRectList within the element. Otherwise, return the DOMRectList of the
-        current selection.
+        If the element is either <input> or <textarea>, return the DOMRectList of
+        the range at given idx of the selection within the element. Otherwise,
+        return the DOMRectList of the of the range at given idx of current selection.
 
         '''
         cmd = self.js_selection_cmd() +\
-            '''return sel.getRangeAt(0).getClientRects();'''
+            '''return sel.getRangeAt(%d).getClientRects();''' % idx
+        return self.element.marionette.execute_script(cmd, script_args=[self.element])
+
+    def range_count(self):
+        '''Get selection's range count'''
+        cmd = self.js_selection_cmd() +\
+            '''return sel.rangeCount;'''
         return self.element.marionette.execute_script(cmd, script_args=[self.element])
 
     def _selection_location_helper(self, location_type):
         '''Return the start and end location of the selection in the element.
 
         Return a tuple containing two pairs of (x, y) coordinates of the start
         and end locations in the element. The coordinates are relative to the
         top left-hand corner of the element. Both ltr and rtl directions are
         considered.
 
         '''
-        rect_list = self.selection_rect_list()
-        list_length = rect_list['length']
-        first_rect, last_rect = rect_list['0'], rect_list[str(list_length - 1)]
+        range_count = self.range_count();
+        first_rect_list = self.selection_rect_list(0)
+        last_rect_list = self.selection_rect_list(range_count - 1)
+        last_list_length = last_rect_list['length']
+        first_rect, last_rect = first_rect_list['0'], last_rect_list[str(last_list_length - 1)]
         origin_x, origin_y = self.element.location['x'], self.element.location['y']
 
         if self.element.get_attribute('dir') == 'rtl':  # such as Arabic
             start_pos, end_pos = 'right', 'left'
         else:
             start_pos, end_pos = 'left', 'right'
 
         # Calculate y offset according to different needs.