OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008 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 1934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1945 for (CompositeEditCommand* command = this; command; | 1945 for (CompositeEditCommand* command = this; command; |
1946 command = command->parent()) { | 1946 command = command->parent()) { |
1947 if (UndoStep* undoStep = command->undoStep()) { | 1947 if (UndoStep* undoStep = command->undoStep()) { |
1948 DCHECK(command->isTopLevelCommand()); | 1948 DCHECK(command->isTopLevelCommand()); |
1949 undoStep->setEndingSelection(selection); | 1949 undoStep->setEndingSelection(selection); |
1950 } | 1950 } |
1951 command->m_endingSelection = selection; | 1951 command->m_endingSelection = selection; |
1952 } | 1952 } |
1953 } | 1953 } |
1954 | 1954 |
1955 void CompositeEditCommand::shrinkEndingSelectionToFitBody() { | |
yosin_UTC9
2017/03/17 10:04:11
I would like this function as local function and f
| |
1956 Position start = endingSelection().visibleStart().deepEquivalent(); | |
1957 Position end = endingSelection().visibleEnd().deepEquivalent(); | |
1958 if (start.isNull() || start.isOrphan() || end.isNull() || end.isOrphan()) | |
1959 return; | |
1960 HTMLElement* body = start.document()->body(); | |
1961 if (!body) | |
1962 return; | |
1963 Position bodyStart(body, PositionAnchorType::BeforeChildren); | |
1964 Position bodyEnd(body, PositionAnchorType::AfterChildren); | |
1965 bool needsToShrink = false; | |
1966 | |
1967 if (start < bodyStart) { | |
1968 start = bodyStart; | |
1969 needsToShrink = true; | |
1970 } | |
1971 if (end < bodyStart) { | |
1972 end = bodyStart; | |
1973 needsToShrink = true; | |
1974 } | |
1975 if (bodyEnd < start) { | |
1976 start = bodyEnd; | |
1977 needsToShrink = true; | |
1978 } | |
1979 if (bodyEnd < end) { | |
1980 end = bodyEnd; | |
1981 needsToShrink = true; | |
1982 } | |
1983 if (!needsToShrink) | |
1984 return; | |
1985 SelectionInDOMTree::Builder builder; | |
1986 builder.collapse(start); | |
1987 builder.extend(end); | |
1988 builder.setIsDirectional(endingSelection().isDirectional()); | |
1989 setEndingSelection(builder.build()); | |
1990 } | |
1991 | |
1955 void CompositeEditCommand::setParent(CompositeEditCommand* parent) { | 1992 void CompositeEditCommand::setParent(CompositeEditCommand* parent) { |
1956 EditCommand::setParent(parent); | 1993 EditCommand::setParent(parent); |
1957 if (!parent) | 1994 if (!parent) |
1958 return; | 1995 return; |
1959 m_startingSelection = parent->m_endingSelection; | 1996 m_startingSelection = parent->m_endingSelection; |
1960 m_endingSelection = parent->m_endingSelection; | 1997 m_endingSelection = parent->m_endingSelection; |
1961 } | 1998 } |
1962 | 1999 |
1963 DEFINE_TRACE(CompositeEditCommand) { | 2000 DEFINE_TRACE(CompositeEditCommand) { |
1964 visitor->trace(m_commands); | 2001 visitor->trace(m_commands); |
1965 visitor->trace(m_startingSelection); | 2002 visitor->trace(m_startingSelection); |
1966 visitor->trace(m_endingSelection); | 2003 visitor->trace(m_endingSelection); |
1967 visitor->trace(m_undoStep); | 2004 visitor->trace(m_undoStep); |
1968 EditCommand::trace(visitor); | 2005 EditCommand::trace(visitor); |
1969 } | 2006 } |
1970 | 2007 |
1971 } // namespace blink | 2008 } // namespace blink |
OLD | NEW |