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

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: Putting GranularityStrategy into separate files. 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
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();
228 }
225 bool closeTyping = options & CloseTyping; 229 bool closeTyping = options & CloseTyping;
226 bool shouldClearTypingStyle = options & ClearTypingStyle; 230 bool shouldClearTypingStyle = options & ClearTypingStyle;
227 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); 231 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options);
228 232
229 VisibleSelection s = validateSelection(newSelection); 233 VisibleSelection s = validateSelection(newSelection);
234
230 if (shouldAlwaysUseDirectionalSelection(m_frame)) 235 if (shouldAlwaysUseDirectionalSelection(m_frame))
231 s.setIsDirectional(true); 236 s.setIsDirectional(true);
232 237
233 if (!m_frame) { 238 if (!m_frame) {
234 m_selection = s; 239 m_selection = s;
235 return; 240 return;
236 } 241 }
237 242
238 // <http://bugs.webkit.org/show_bug.cgi?id=23464>: Infinite recursion at Fra meSelection::setSelection 243 // <http://bugs.webkit.org/show_bug.cgi?id=23464>: Infinite recursion at Fra meSelection::setSelection
239 // if document->frame() == m_frame we can get into an infinite loop 244 // if document->frame() == m_frame we can get into an infinite loop
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 m_xPosForVerticalArrowNavigation = x; 1171 m_xPosForVerticalArrowNavigation = x;
1167 } else 1172 } else
1168 x = m_xPosForVerticalArrowNavigation; 1173 x = m_xPosForVerticalArrowNavigation;
1169 1174
1170 return x; 1175 return x;
1171 } 1176 }
1172 1177
1173 void FrameSelection::clear() 1178 void FrameSelection::clear()
1174 { 1179 {
1175 m_granularity = CharacterGranularity; 1180 m_granularity = CharacterGranularity;
1181 if (m_granularityStrategy)
1182 m_granularityStrategy->Clear();
1176 setSelection(VisibleSelection()); 1183 setSelection(VisibleSelection());
1177 } 1184 }
1178 1185
1179 void FrameSelection::prepareForDestruction() 1186 void FrameSelection::prepareForDestruction()
1180 { 1187 {
1181 m_granularity = CharacterGranularity; 1188 m_granularity = CharacterGranularity;
1182 1189
1183 m_caretBlinkTimer.stop(); 1190 m_caretBlinkTimer.stop();
1184 1191
1185 LayoutView* view = m_frame->contentRenderer(); 1192 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()); 1913 String text = plainText(start.deepEquivalent(), end.deepEquivalent());
1907 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) { 1914 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) {
1908 setSelection(VisibleSelection(start, end), WordGranularity); 1915 setSelection(VisibleSelection(start, end), WordGranularity);
1909 return true; 1916 return true;
1910 } 1917 }
1911 } 1918 }
1912 1919
1913 return false; 1920 return false;
1914 } 1921 }
1915 1922
1916 void FrameSelection::moveRangeSelectionExtent(const VisiblePosition& extentPosit ion, TextGranularity granularity) 1923 GranularityStrategy* FrameSelection::granularityStrategy()
1917 { 1924 {
1918 if (isNone()) 1925 // We do lazy initalization for m_granularityStrategy, because if we initial ize it
1926 // right in the constructor - the correct settings may not be set yet.
1927 SelectionStrategy strategyType = StrategyCharacter;
1928 Settings* settings = m_frame ? m_frame->settings() : 0;
1929 if (settings && settings->selectionStrategy() == StrategyDirection)
1930 strategyType = StrategyDirection;
1931
1932 if (m_granularityStrategy && m_granularityStrategy->GetType() == strategyTyp e)
1933 return m_granularityStrategy.get();
1934
1935 if (strategyType == StrategyDirection)
1936 m_granularityStrategy = adoptPtr(new DirectionGranularityStrategy());
1937 else
1938 m_granularityStrategy = adoptPtr(new CharacterGranularityStrategy());
1939 return m_granularityStrategy.get();
1940 }
1941
1942 void FrameSelection::moveRangeSelectionExtent(const VisiblePosition& extentPosit ion)
1943 {
1944 const VisiblePosition base = m_selection.visibleBase();
1945
1946 if (isNone() || base == extentPosition)
1919 return; 1947 return;
1920 1948
1921 const VisiblePosition basePosition = m_selection.isBaseFirst() ? m_selection .visibleStart() : m_selection.visibleEnd(); 1949 VisibleSelection newSelection = granularityStrategy()->updateExtent(extentPo sition, selection());
1922 VisibleSelection newSelection(basePosition, extentPosition); 1950 setSelection(
1923 if (newSelection.isBaseFirst()) 1951 newSelection,
1924 newSelection.setEndRespectingGranularity(granularity); 1952 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSe lection::DoNotClearStrategy | UserTriggered,
1925 else 1953 FrameSelection::AlignCursorOnScrollIfNeeded,
1926 newSelection.setStartRespectingGranularity(granularity); 1954 CharacterGranularity);
1927 if (!newSelection.isRange())
1928 return;
1929
1930 setSelection(newSelection, FrameSelection::CloseTyping | FrameSelection::Cle arTypingStyle | UserTriggered, FrameSelection::AlignCursorOnScrollIfNeeded, gran ularity);
1931 } 1955 }
1932 1956
1933 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, con st VisiblePosition& extentPosition, TextGranularity granularity) 1957 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, con st VisiblePosition& extentPosition, TextGranularity granularity)
1934 { 1958 {
1935 VisibleSelection newSelection(basePosition, extentPosition); 1959 VisibleSelection newSelection(basePosition, extentPosition);
1936 newSelection.expandUsingGranularity(granularity); 1960 newSelection.expandUsingGranularity(granularity);
1937 1961
1938 if (newSelection.isNone()) 1962 if (newSelection.isNone())
1939 return; 1963 return;
1940 1964
1941 setSelection(newSelection, granularity); 1965 setSelection(newSelection, granularity);
1942 } 1966 }
1943 1967
1944 } 1968 }
1945 1969
1946 #ifndef NDEBUG 1970 #ifndef NDEBUG
1947 1971
1948 void showTree(const blink::FrameSelection& sel) 1972 void showTree(const blink::FrameSelection& sel)
1949 { 1973 {
1950 sel.showTreeForThis(); 1974 sel.showTreeForThis();
1951 } 1975 }
1952 1976
1953 void showTree(const blink::FrameSelection* sel) 1977 void showTree(const blink::FrameSelection* sel)
1954 { 1978 {
1955 if (sel) 1979 if (sel)
1956 sel->showTreeForThis(); 1980 sel->showTreeForThis();
1957 } 1981 }
1958 1982
1959 #endif 1983 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698