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

Side by Side Diff: third_party/WebKit/Source/core/editing/EditingUtilities.cpp

Issue 1409073004: Return EphemeralRange from Editor::findRangeOfString. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Extract text bounds collecting to a function Created 5 years, 1 month 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, 2005, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "core/frame/UseCounter.h" 46 #include "core/frame/UseCounter.h"
47 #include "core/html/HTMLBRElement.h" 47 #include "core/html/HTMLBRElement.h"
48 #include "core/html/HTMLDivElement.h" 48 #include "core/html/HTMLDivElement.h"
49 #include "core/html/HTMLLIElement.h" 49 #include "core/html/HTMLLIElement.h"
50 #include "core/html/HTMLParagraphElement.h" 50 #include "core/html/HTMLParagraphElement.h"
51 #include "core/html/HTMLSpanElement.h" 51 #include "core/html/HTMLSpanElement.h"
52 #include "core/html/HTMLTableCellElement.h" 52 #include "core/html/HTMLTableCellElement.h"
53 #include "core/html/HTMLUListElement.h" 53 #include "core/html/HTMLUListElement.h"
54 #include "core/layout/LayoutObject.h" 54 #include "core/layout/LayoutObject.h"
55 #include "core/layout/LayoutTableCell.h" 55 #include "core/layout/LayoutTableCell.h"
56 #include "core/layout/LayoutText.h"
56 #include "wtf/Assertions.h" 57 #include "wtf/Assertions.h"
57 #include "wtf/StdLibExtras.h" 58 #include "wtf/StdLibExtras.h"
58 #include "wtf/text/StringBuilder.h" 59 #include "wtf/text/StringBuilder.h"
59 60
60 namespace blink { 61 namespace blink {
61 62
62 using namespace HTMLNames; 63 using namespace HTMLNames;
63 64
64 // Atomic means that the node has no children, or has children which are ignored for the 65 // Atomic means that the node has no children, or has children which are ignored for the
65 // purposes of editing. 66 // purposes of editing.
(...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 1674
1674 // if the selection starts just before a paragraph break, skip over it 1675 // if the selection starts just before a paragraph break, skip over it
1675 if (isEndOfParagraph(visiblePosition)) 1676 if (isEndOfParagraph(visiblePosition))
1676 return mostForwardCaretPosition(nextPositionOf(visiblePosition).deepEqui valent()); 1677 return mostForwardCaretPosition(nextPositionOf(visiblePosition).deepEqui valent());
1677 1678
1678 // otherwise, make sure to be at the start of the first selected node, 1679 // otherwise, make sure to be at the start of the first selected node,
1679 // instead of possibly at the end of the last node before the selection 1680 // instead of possibly at the end of the last node before the selection
1680 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 1681 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
1681 } 1682 }
1682 1683
1684 static void absoluteTextBoundsForRange(LayoutText* layoutText, Vector<IntRect>& rects, unsigned startOffset, unsigned endOffset, bool useSelectionHeight, bool* wasFixed)
1685 {
1686 layoutText->absoluteRectsForRange(rects, startOffset, endOffset, useSelectio nHeight, wasFixed);
1687 }
1688
1689 static void absoluteTextBoundsForRange(LayoutText* layoutText, Vector<FloatQuad> & quads, unsigned startOffset, unsigned endOffset, bool useSelectionHeight, bool * wasFixed)
1690 {
1691 layoutText->absoluteQuadsForRange(quads, startOffset, endOffset, useSelectio nHeight, wasFixed);
1692 }
1693
1694 template <typename BoundsType>
1695 void collectTextBoundsInRangeAlgorithm(
yosin_UTC9 2015/11/04 07:11:06 nit: Please add |static|, just in case.
1696 Node* start, int startOffset, Node* end, int endOffset, Node* firstNode, Nod e* stopNode, Node* (*next)(const Node&),
1697 Vector<BoundsType>& textBounds, bool useSelectionHeight, bool* allFixed, boo l* someFixed)
1698 {
1699 ASSERT(start);
1700 ASSERT(end);
1701 ASSERT(next);
1702
1703 bool allFixedLocal = true;
1704 bool someFixedLocal = false;
1705 for (Node* node = firstNode; node != stopNode; node = next(*node)) {
1706 LayoutObject* layoutObject = node->layoutObject();
1707 if (!layoutObject || !layoutObject->isText())
1708 continue;
1709
1710 int textStartOffset = node == start ? startOffset : 0;
1711 int textEndOffset = node == end ? endOffset : std::numeric_limits<int>:: max();
1712 bool isFixed = false;
1713 absoluteTextBoundsForRange(toLayoutText(layoutObject), textBounds, textS tartOffset, textEndOffset, useSelectionHeight, &isFixed);
1714 allFixedLocal &= isFixed;
1715 someFixedLocal |= isFixed;
1716 }
1717
1718 if (allFixed)
1719 *allFixed = allFixedLocal;
1720
1721 if (someFixed)
1722 *someFixed = someFixedLocal;
1723 }
1724
1725 void collectTextBoundsInRange(
1726 Node* start, int startOffset, Node* end, int endOffset, Node* firstNode, Nod e* stopNode, Node* (*next)(const Node&),
1727 Vector<IntRect>& rects, bool useSelectionHeight, bool* allFixed, bool* someF ixed)
1728 {
1729 collectTextBoundsInRangeAlgorithm(start, startOffset, end, endOffset, firstN ode, stopNode, next, rects, useSelectionHeight, allFixed, someFixed);
1730 }
1731
1732 void collectTextBoundsInRange(
1733 Node* start, int startOffset, Node* end, int endOffset, Node* firstNode, Nod e* stopNode, Node* (*next)(const Node&),
1734 Vector<FloatQuad>& quads, bool useSelectionHeight, bool* allFixed, bool* som eFixed)
1735 {
1736 collectTextBoundsInRangeAlgorithm(start, startOffset, end, endOffset, firstN ode, stopNode, next, quads, useSelectionHeight, allFixed, someFixed);
1737 }
1738
1683 } // namespace blink 1739 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698