Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: Source/web/WebAXObject.cpp

Issue 1185343003: Implements the ability to get and set the caret position and the current selection from anywhere in… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 } 825 }
826 826
827 WebAXRole WebAXObject::role() const 827 WebAXRole WebAXObject::role() const
828 { 828 {
829 if (isDetached()) 829 if (isDetached())
830 return WebAXRoleUnknown; 830 return WebAXRoleUnknown;
831 831
832 return static_cast<WebAXRole>(m_private->roleValue()); 832 return static_cast<WebAXRole>(m_private->roleValue());
833 } 833 }
834 834
835 void WebAXObject::selection(unsigned* anchorId, unsigned* anchorOffset,
836 unsigned* focusId, unsigned* focusOffset) const
837 {
838 if (isDetached()) {
839 *anchorId = 0;
840 *anchorOffset = 0;
841 *focusId = 0;
842 *focusOffset = 0;
843 return;
844 }
845
846 AXObject::AXSelection axSelection = m_private->selection();
847 *anchorId = axSelection.anchorId;
848 *anchorOffset = axSelection.anchorOffset;
849 *focusId = axSelection.focusId;
850 *focusOffset = axSelection.focusOffset;
851 return;
852 }
853
835 unsigned WebAXObject::selectionEnd() const 854 unsigned WebAXObject::selectionEnd() const
836 { 855 {
837 if (isDetached()) 856 if (isDetached())
838 return 0; 857 return 0;
839 858
840 return m_private->selectedTextRange().start + m_private->selectedTextRange() .length; 859 AXObject::AXSelection axSelection = m_private->selectionUnderObject();
860 return axSelection.focusOffset;
841 } 861 }
842 862
843 unsigned WebAXObject::selectionStart() const 863 unsigned WebAXObject::selectionStart() const
844 { 864 {
845 if (isDetached()) 865 if (isDetached())
846 return 0; 866 return 0;
847 867
848 return m_private->selectedTextRange().start; 868 AXObject::AXSelection axSelection = m_private->selectionUnderObject();
869 return axSelection.anchorOffset;
849 } 870 }
850 871
851 unsigned WebAXObject::selectionEndLineNumber() const 872 unsigned WebAXObject::selectionEndLineNumber() const
852 { 873 {
853 if (isDetached()) 874 if (isDetached())
854 return 0; 875 return 0;
855 876
856 VisiblePosition position = m_private->visiblePositionForIndex(selectionEnd() ); 877 VisiblePosition position = m_private->visiblePositionForIndex(selectionEnd() );
857 int lineNumber = m_private->lineForPosition(position); 878 int lineNumber = m_private->lineForPosition(position);
858 if (lineNumber < 0) 879 if (lineNumber < 0)
(...skipping 17 matching lines...) Expand all
876 { 897 {
877 if (!isDetached()) 898 if (!isDetached())
878 m_private->setFocused(on); 899 m_private->setFocused(on);
879 } 900 }
880 901
881 void WebAXObject::setSelectedTextRange(int selectionStart, int selectionEnd) con st 902 void WebAXObject::setSelectedTextRange(int selectionStart, int selectionEnd) con st
882 { 903 {
883 if (isDetached()) 904 if (isDetached())
884 return; 905 return;
885 906
886 m_private->setSelectedTextRange(AXObject::PlainTextRange(selectionStart, sel ectionEnd - selectionStart)); 907 m_private->setSelection(AXObject::AXSelection(selectionStart, selectionEnd)) ;
887 } 908 }
888 909
889 void WebAXObject::setValue(WebString value) const 910 void WebAXObject::setValue(WebString value) const
890 { 911 {
891 if (isDetached()) 912 if (isDetached())
892 return; 913 return;
893 914
894 m_private->setValue(value); 915 m_private->setValue(value);
895 } 916 }
896 917
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 for (size_t i = 0; i < vectorSize; i++) 1527 for (size_t i = 0; i < vectorSize; i++)
1507 offsetsWebVector[i] = offsetsVector[i]; 1528 offsetsWebVector[i] = offsetsVector[i];
1508 offsets.swap(offsetsWebVector); 1529 offsets.swap(offsetsWebVector);
1509 } 1530 }
1510 1531
1511 void WebAXObject::wordBoundaries(WebVector<int>& starts, WebVector<int>& ends) c onst 1532 void WebAXObject::wordBoundaries(WebVector<int>& starts, WebVector<int>& ends) c onst
1512 { 1533 {
1513 if (isDetached()) 1534 if (isDetached())
1514 return; 1535 return;
1515 1536
1516 Vector<AXObject::PlainTextRange> words; 1537 Vector<AXObject::AXSelection> wordBoundaries;
dmazzoni 2015/06/16 17:24:04 Switching this to use AXSelection doesn't make sen
1517 m_private->wordBoundaries(words); 1538 m_private->wordBoundaries(wordBoundaries);
1518 1539
1519 WebVector<int> startsWebVector(words.size()); 1540 WebVector<int> wordStartOffsets(wordBoundaries.size());
1520 WebVector<int> endsWebVector(words.size()); 1541 WebVector<int> wordEndOffsets(wordBoundaries.size());
1521 for (size_t i = 0; i < words.size(); i++) { 1542 for (size_t i = 0; i < wordBoundaries.size(); ++i) {
1522 startsWebVector[i] = words[i].start; 1543 wordStartOffsets[i] = wordBoundaries[i].anchorOffset;
1523 endsWebVector[i] = words[i].start + words[i].length; 1544 wordEndOffsets[i] = wordBoundaries[i].focusOffset;
1524 } 1545 }
1525 starts.swap(startsWebVector); 1546
1526 ends.swap(endsWebVector); 1547 starts.swap(wordStartOffsets);
1548 ends.swap(wordEndOffsets);
1527 } 1549 }
1528 1550
1529 bool WebAXObject::isScrollableContainer() const 1551 bool WebAXObject::isScrollableContainer() const
1530 { 1552 {
1531 if (isDetached()) 1553 if (isDetached())
1532 return false; 1554 return false;
1533 1555
1534 return m_private->isScrollableContainer(); 1556 return m_private->isScrollableContainer();
1535 } 1557 }
1536 1558
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 m_private = object; 1616 m_private = object;
1595 return *this; 1617 return *this;
1596 } 1618 }
1597 1619
1598 WebAXObject::operator WTF::PassRefPtr<AXObject>() const 1620 WebAXObject::operator WTF::PassRefPtr<AXObject>() const
1599 { 1621 {
1600 return m_private.get(); 1622 return m_private.get();
1601 } 1623 }
1602 1624
1603 } // namespace blink 1625 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698