OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 216 |
217 setSelection(newSelection, granularity); | 217 setSelection(newSelection, granularity); |
218 } | 218 } |
219 | 219 |
220 void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec
tionOptions options, CursorAlignOnScroll align, TextGranularity granularity) | 220 void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec
tionOptions options, CursorAlignOnScroll align, TextGranularity granularity) |
221 { | 221 { |
222 bool closeTyping = options & CloseTyping; | 222 bool closeTyping = options & CloseTyping; |
223 bool shouldClearTypingStyle = options & ClearTypingStyle; | 223 bool shouldClearTypingStyle = options & ClearTypingStyle; |
224 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); | 224 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); |
225 | 225 |
226 VisibleSelection s = newSelection; | 226 VisibleSelection s = validateSelection(newSelection); |
227 if (shouldAlwaysUseDirectionalSelection(m_frame)) | 227 if (shouldAlwaysUseDirectionalSelection(m_frame)) |
228 s.setIsDirectional(true); | 228 s.setIsDirectional(true); |
229 | 229 |
230 if (!m_frame) { | 230 if (!m_frame) { |
231 m_selection = s; | 231 m_selection = s; |
232 return; | 232 return; |
233 } | 233 } |
234 | 234 |
235 // <http://bugs.webkit.org/show_bug.cgi?id=23464>: Infinite recursion at Fra
meSelection::setSelection | 235 // <http://bugs.webkit.org/show_bug.cgi?id=23464>: Infinite recursion at Fra
meSelection::setSelection |
236 // if document->frame() == m_frame we can get into an infinite loop | 236 // if document->frame() == m_frame we can get into an infinite loop |
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1841 | 1841 |
1842 void FrameSelection::didChangeVisibleSelection() | 1842 void FrameSelection::didChangeVisibleSelection() |
1843 { | 1843 { |
1844 ASSERT(m_observingVisibleSelection); | 1844 ASSERT(m_observingVisibleSelection); |
1845 // Invalidate the logical range when the underlying VisibleSelection has cha
nged. | 1845 // Invalidate the logical range when the underlying VisibleSelection has cha
nged. |
1846 m_logicalRange = nullptr; | 1846 m_logicalRange = nullptr; |
1847 m_selection.clearChangeObserver(); | 1847 m_selection.clearChangeObserver(); |
1848 m_observingVisibleSelection = false; | 1848 m_observingVisibleSelection = false; |
1849 } | 1849 } |
1850 | 1850 |
| 1851 VisibleSelection FrameSelection::validateSelection(const VisibleSelection& selec
tion) |
| 1852 { |
| 1853 if (!m_frame || selection.isNone()) |
| 1854 return selection; |
| 1855 |
| 1856 Position base = selection.base(); |
| 1857 Position extent = selection.extent(); |
| 1858 bool isBaseValid = base.document() == m_frame->document(); |
| 1859 bool isExtentValid = extent.document() == m_frame->document(); |
| 1860 |
| 1861 if (isBaseValid && isExtentValid) |
| 1862 return selection; |
| 1863 |
| 1864 VisibleSelection newSelection; |
| 1865 if (isBaseValid) { |
| 1866 newSelection.setWithoutValidation(base, base); |
| 1867 } else if (isExtentValid) { |
| 1868 newSelection.setWithoutValidation(extent, extent); |
| 1869 } |
| 1870 return newSelection; |
| 1871 } |
| 1872 |
1851 void FrameSelection::startObservingVisibleSelectionChange() | 1873 void FrameSelection::startObservingVisibleSelectionChange() |
1852 { | 1874 { |
1853 ASSERT(!m_observingVisibleSelection); | 1875 ASSERT(!m_observingVisibleSelection); |
1854 m_selection.setChangeObserver(*this); | 1876 m_selection.setChangeObserver(*this); |
1855 m_observingVisibleSelection = true; | 1877 m_observingVisibleSelection = true; |
1856 } | 1878 } |
1857 | 1879 |
1858 void FrameSelection::stopObservingVisibleSelectionChangeIfNecessary() | 1880 void FrameSelection::stopObservingVisibleSelectionChangeIfNecessary() |
1859 { | 1881 { |
1860 if (m_observingVisibleSelection) { | 1882 if (m_observingVisibleSelection) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1896 sel.showTreeForThis(); | 1918 sel.showTreeForThis(); |
1897 } | 1919 } |
1898 | 1920 |
1899 void showTree(const blink::FrameSelection* sel) | 1921 void showTree(const blink::FrameSelection* sel) |
1900 { | 1922 { |
1901 if (sel) | 1923 if (sel) |
1902 sel->showTreeForThis(); | 1924 sel->showTreeForThis(); |
1903 } | 1925 } |
1904 | 1926 |
1905 #endif | 1927 #endif |
OLD | NEW |