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

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

Issue 1184403004: Templatize extractSelectedText used by FrameSelection function (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
« no previous file with comments | « no previous file | no next file » | 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 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 } 1656 }
1657 target = target->parentOrShadowHostElement(); 1657 target = target->parentOrShadowHostElement();
1658 } 1658 }
1659 m_frame->document()->setFocusedElement(nullptr); 1659 m_frame->document()->setFocusedElement(nullptr);
1660 } 1660 }
1661 1661
1662 if (caretBrowsing) 1662 if (caretBrowsing)
1663 m_frame->page()->focusController().setFocusedElement(0, m_frame); 1663 m_frame->page()->focusController().setFocusedElement(0, m_frame);
1664 } 1664 }
1665 1665
1666 template <typename Strategy>
1667 String extractSelectedTextAlgorithm(const FrameSelection& selection, TextIterato rBehavior behavior)
1668 {
1669 using PositionType = typename Strategy::PositionType;
1670
1671 PositionType start;
1672 PositionType end;
1673 VisibleSelection visibleSelection = selection.selection();
1674 VisibleSelection::normalizePositions(Strategy::selectionStart(visibleSelecti on), Strategy::selectionEnd(visibleSelection), &start, &end);
1675 // We remove '\0' characters because they are not visibly rendered to the us er.
1676 return plainText(start, end, behavior).replace(0, "");
1677 }
1678
1666 static String extractSelectedText(const FrameSelection& selection, TextIteratorB ehavior behavior) 1679 static String extractSelectedText(const FrameSelection& selection, TextIteratorB ehavior behavior)
1667 { 1680 {
1668 // We remove '\0' characters because they are not visibly rendered to the us er. 1681 return extractSelectedTextAlgorithm<VisibleSelection::InDOMTree>(selection, behavior);
1669 return plainText(selection.toNormalizedRange().get(), behavior).replace(0, " ");
1670 } 1682 }
1671 1683
1672 String FrameSelection::selectedHTMLForClipboard() const 1684 String FrameSelection::selectedHTMLForClipboard() const
1673 { 1685 {
1674 return createMarkup(m_selection.toNormalizedRange().get(), AnnotateForInterc hange, ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs); 1686 return createMarkup(m_selection.toNormalizedRange().get(), AnnotateForInterc hange, ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs);
1675 } 1687 }
1676 1688
1677 String FrameSelection::selectedText() const 1689 String FrameSelection::selectedText() const
1678 { 1690 {
1679 return extractSelectedText(*this, TextIteratorDefaultBehavior); 1691 return extractSelectedText(*this, TextIteratorDefaultBehavior);
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 1985
1974 void showTree(const blink::FrameSelection* sel) 1986 void showTree(const blink::FrameSelection* sel)
1975 { 1987 {
1976 if (sel) 1988 if (sel)
1977 sel->showTreeForThis(); 1989 sel->showTreeForThis();
1978 else 1990 else
1979 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); 1991 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n");
1980 } 1992 }
1981 1993
1982 #endif 1994 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698