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

Side by Side Diff: Source/core/editing/FrameSelection.cpp

Issue 988023005: Implementing directional selection strategy in Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressing nits Created 5 years, 8 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
« no previous file with comments | « Source/core/editing/FrameSelection.h ('k') | Source/core/editing/FrameSelectionTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 20 matching lines...) Expand all
31 #include "core/InputTypeNames.h" 31 #include "core/InputTypeNames.h"
32 #include "core/css/StylePropertySet.h" 32 #include "core/css/StylePropertySet.h"
33 #include "core/dom/AXObjectCache.h" 33 #include "core/dom/AXObjectCache.h"
34 #include "core/dom/CharacterData.h" 34 #include "core/dom/CharacterData.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/Element.h" 36 #include "core/dom/Element.h"
37 #include "core/dom/ElementTraversal.h" 37 #include "core/dom/ElementTraversal.h"
38 #include "core/dom/NodeTraversal.h" 38 #include "core/dom/NodeTraversal.h"
39 #include "core/dom/Text.h" 39 #include "core/dom/Text.h"
40 #include "core/editing/Editor.h" 40 #include "core/editing/Editor.h"
41 #include "core/editing/GranularityStrategy.h"
41 #include "core/editing/InputMethodController.h" 42 #include "core/editing/InputMethodController.h"
42 #include "core/editing/RenderedPosition.h" 43 #include "core/editing/RenderedPosition.h"
43 #include "core/editing/SpellChecker.h" 44 #include "core/editing/SpellChecker.h"
44 #include "core/editing/TypingCommand.h" 45 #include "core/editing/TypingCommand.h"
45 #include "core/editing/VisibleUnits.h" 46 #include "core/editing/VisibleUnits.h"
46 #include "core/editing/htmlediting.h" 47 #include "core/editing/htmlediting.h"
47 #include "core/editing/iterators/TextIterator.h" 48 #include "core/editing/iterators/TextIterator.h"
48 #include "core/editing/markup.h" 49 #include "core/editing/markup.h"
49 #include "core/events/Event.h" 50 #include "core/events/Event.h"
50 #include "core/frame/FrameView.h" 51 #include "core/frame/FrameView.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 216
216 newSelection.setIsDirectional(isDirectional); // Adjusting base and extent w ill make newSelection always directional 217 newSelection.setIsDirectional(isDirectional); // Adjusting base and extent w ill make newSelection always directional
217 if (m_selection == newSelection) 218 if (m_selection == newSelection)
218 return; 219 return;
219 220
220 setSelection(newSelection, granularity); 221 setSelection(newSelection, granularity);
221 } 222 }
222 223
223 void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec tionOptions options, CursorAlignOnScroll align, TextGranularity granularity) 224 void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec tionOptions options, CursorAlignOnScroll align, TextGranularity granularity)
224 { 225 {
226 if (m_granularityStrategy && (options & FrameSelection::DoNotClearStrategy) == 0)
227 m_granularityStrategy->Clear();
225 bool closeTyping = options & CloseTyping; 228 bool closeTyping = options & CloseTyping;
226 bool shouldClearTypingStyle = options & ClearTypingStyle; 229 bool shouldClearTypingStyle = options & ClearTypingStyle;
227 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); 230 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options);
228 231
229 VisibleSelection s = validateSelection(newSelection); 232 VisibleSelection s = validateSelection(newSelection);
230 if (shouldAlwaysUseDirectionalSelection(m_frame)) 233 if (shouldAlwaysUseDirectionalSelection(m_frame))
231 s.setIsDirectional(true); 234 s.setIsDirectional(true);
232 235
233 if (!m_frame) { 236 if (!m_frame) {
234 m_selection = s; 237 m_selection = s;
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 m_xPosForVerticalArrowNavigation = x; 1169 m_xPosForVerticalArrowNavigation = x;
1167 } else 1170 } else
1168 x = m_xPosForVerticalArrowNavigation; 1171 x = m_xPosForVerticalArrowNavigation;
1169 1172
1170 return x; 1173 return x;
1171 } 1174 }
1172 1175
1173 void FrameSelection::clear() 1176 void FrameSelection::clear()
1174 { 1177 {
1175 m_granularity = CharacterGranularity; 1178 m_granularity = CharacterGranularity;
1179 if (m_granularityStrategy)
1180 m_granularityStrategy->Clear();
1176 setSelection(VisibleSelection()); 1181 setSelection(VisibleSelection());
1177 } 1182 }
1178 1183
1179 void FrameSelection::prepareForDestruction() 1184 void FrameSelection::prepareForDestruction()
1180 { 1185 {
1181 m_granularity = CharacterGranularity; 1186 m_granularity = CharacterGranularity;
1182 1187
1183 m_caretBlinkTimer.stop(); 1188 m_caretBlinkTimer.stop();
1184 1189
1185 LayoutView* view = m_frame->contentRenderer(); 1190 LayoutView* view = m_frame->contentRenderer();
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 String text = plainText(start.deepEquivalent(), end.deepEquivalent()); 1911 String text = plainText(start.deepEquivalent(), end.deepEquivalent());
1907 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) { 1912 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) {
1908 setSelection(VisibleSelection(start, end), WordGranularity); 1913 setSelection(VisibleSelection(start, end), WordGranularity);
1909 return true; 1914 return true;
1910 } 1915 }
1911 } 1916 }
1912 1917
1913 return false; 1918 return false;
1914 } 1919 }
1915 1920
1916 void FrameSelection::moveRangeSelectionExtent(const VisiblePosition& extentPosit ion, TextGranularity granularity) 1921 GranularityStrategy* FrameSelection::granularityStrategy()
1917 { 1922 {
1918 if (isNone()) 1923 // We do lazy initalization for m_granularityStrategy, because if we
1924 // initialize it right in the constructor - the correct settings may not be
1925 // set yet.
1926 SelectionStrategy strategyType = SelectionStrategy::Character;
1927 Settings* settings = m_frame ? m_frame->settings() : 0;
1928 if (settings && settings->selectionStrategy() == SelectionStrategy::Directio n)
1929 strategyType = SelectionStrategy::Direction;
1930
1931 if (m_granularityStrategy && m_granularityStrategy->GetType() == strategyTyp e)
1932 return m_granularityStrategy.get();
1933
1934 if (strategyType == SelectionStrategy::Direction)
1935 m_granularityStrategy = adoptPtr(new DirectionGranularityStrategy());
1936 else
1937 m_granularityStrategy = adoptPtr(new CharacterGranularityStrategy());
1938 return m_granularityStrategy.get();
1939 }
1940
1941 void FrameSelection::moveRangeSelectionExtent(const VisiblePosition& extentPosit ion)
1942 {
1943 if (isNone() || m_selection.visibleBase() == extentPosition)
1919 return; 1944 return;
1920 1945
1921 const VisiblePosition basePosition = m_selection.isBaseFirst() ? m_selection .visibleStart() : m_selection.visibleEnd(); 1946 VisibleSelection newSelection = granularityStrategy()->updateExtent(extentPo sition, selection());
1922 VisibleSelection newSelection(basePosition, extentPosition); 1947 setSelection(
1923 if (newSelection.isBaseFirst()) 1948 newSelection,
1924 newSelection.setEndRespectingGranularity(granularity); 1949 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSe lection::DoNotClearStrategy | UserTriggered,
1925 else 1950 FrameSelection::AlignCursorOnScrollIfNeeded,
1926 newSelection.setStartRespectingGranularity(granularity); 1951 CharacterGranularity);
1927 if (!newSelection.isRange())
1928 return;
1929
1930 setSelection(newSelection, FrameSelection::CloseTyping | FrameSelection::Cle arTypingStyle | UserTriggered, FrameSelection::AlignCursorOnScrollIfNeeded, gran ularity);
1931 } 1952 }
1932 1953
1933 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, con st VisiblePosition& extentPosition, TextGranularity granularity) 1954 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, con st VisiblePosition& extentPosition, TextGranularity granularity)
1934 { 1955 {
1935 VisibleSelection newSelection(basePosition, extentPosition); 1956 VisibleSelection newSelection(basePosition, extentPosition);
1936 newSelection.expandUsingGranularity(granularity); 1957 newSelection.expandUsingGranularity(granularity);
1937 1958
1938 if (newSelection.isNone()) 1959 if (newSelection.isNone())
1939 return; 1960 return;
1940 1961
1941 setSelection(newSelection, granularity); 1962 setSelection(newSelection, granularity);
1942 } 1963 }
1943 1964
1944 } 1965 }
1945 1966
1946 #ifndef NDEBUG 1967 #ifndef NDEBUG
1947 1968
1948 void showTree(const blink::FrameSelection& sel) 1969 void showTree(const blink::FrameSelection& sel)
1949 { 1970 {
1950 sel.showTreeForThis(); 1971 sel.showTreeForThis();
1951 } 1972 }
1952 1973
1953 void showTree(const blink::FrameSelection* sel) 1974 void showTree(const blink::FrameSelection* sel)
1954 { 1975 {
1955 if (sel) 1976 if (sel)
1956 sel->showTreeForThis(); 1977 sel->showTreeForThis();
1957 } 1978 }
1958 1979
1959 #endif 1980 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/FrameSelection.h ('k') | Source/core/editing/FrameSelectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698