| 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 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1831 | 1831 |
| 1832 void FrameSelection::didChangeVisibleSelection() | 1832 void FrameSelection::didChangeVisibleSelection() |
| 1833 { | 1833 { |
| 1834 ASSERT(m_observingVisibleSelection); | 1834 ASSERT(m_observingVisibleSelection); |
| 1835 // Invalidate the logical range when the underlying VisibleSelection has cha
nged. | 1835 // Invalidate the logical range when the underlying VisibleSelection has cha
nged. |
| 1836 m_logicalRange = nullptr; | 1836 m_logicalRange = nullptr; |
| 1837 m_selection.clearChangeObserver(); | 1837 m_selection.clearChangeObserver(); |
| 1838 m_observingVisibleSelection = false; | 1838 m_observingVisibleSelection = false; |
| 1839 } | 1839 } |
| 1840 | 1840 |
| 1841 VisibleSelection FrameSelection::validateSelection(const VisibleSelection& selec
tion) |
| 1842 { |
| 1843 if (!m_frame || selection.isNone()) |
| 1844 return selection; |
| 1845 |
| 1846 Position base = selection.base(); |
| 1847 Position extent = selection.extent(); |
| 1848 bool isBaseValid = base.document() == m_frame->document(); |
| 1849 bool isExtentValid = extent.document() == m_frame->document(); |
| 1850 |
| 1851 if (isBaseValid && isExtentValid) |
| 1852 return selection; |
| 1853 |
| 1854 VisibleSelection newSelection; |
| 1855 if (isBaseValid) { |
| 1856 newSelection.setWithoutValidation(base, base); |
| 1857 return newSelection; |
| 1858 } |
| 1859 if (isExtentValid) { |
| 1860 newSelection.setWithoutValidation(extent, extent); |
| 1861 return newSelection; |
| 1862 } |
| 1863 return newSelection; |
| 1864 } |
| 1865 |
| 1841 void FrameSelection::startObservingVisibleSelectionChange() | 1866 void FrameSelection::startObservingVisibleSelectionChange() |
| 1842 { | 1867 { |
| 1843 ASSERT(!m_observingVisibleSelection); | 1868 ASSERT(!m_observingVisibleSelection); |
| 1844 m_selection.setChangeObserver(*this); | 1869 m_selection.setChangeObserver(*this); |
| 1845 m_observingVisibleSelection = true; | 1870 m_observingVisibleSelection = true; |
| 1846 } | 1871 } |
| 1847 | 1872 |
| 1848 void FrameSelection::stopObservingVisibleSelectionChangeIfNecessary() | 1873 void FrameSelection::stopObservingVisibleSelectionChangeIfNecessary() |
| 1849 { | 1874 { |
| 1850 if (m_observingVisibleSelection) { | 1875 if (m_observingVisibleSelection) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1886 sel.showTreeForThis(); | 1911 sel.showTreeForThis(); |
| 1887 } | 1912 } |
| 1888 | 1913 |
| 1889 void showTree(const WebCore::FrameSelection* sel) | 1914 void showTree(const WebCore::FrameSelection* sel) |
| 1890 { | 1915 { |
| 1891 if (sel) | 1916 if (sel) |
| 1892 sel->showTreeForThis(); | 1917 sel->showTreeForThis(); |
| 1893 } | 1918 } |
| 1894 | 1919 |
| 1895 #endif | 1920 #endif |
| OLD | NEW |