OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
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 26 matching lines...) Expand all Loading... |
37 #include "core/editing/FrameSelection.h" | 37 #include "core/editing/FrameSelection.h" |
38 #include "core/editing/Position.h" | 38 #include "core/editing/Position.h" |
39 #include "core/editing/PositionIterator.h" | 39 #include "core/editing/PositionIterator.h" |
40 #include "core/editing/RenderedPosition.h" | 40 #include "core/editing/RenderedPosition.h" |
41 #include "core/editing/TextAffinity.h" | 41 #include "core/editing/TextAffinity.h" |
42 #include "core/editing/VisiblePosition.h" | 42 #include "core/editing/VisiblePosition.h" |
43 #include "core/editing/iterators/BackwardsCharacterIterator.h" | 43 #include "core/editing/iterators/BackwardsCharacterIterator.h" |
44 #include "core/editing/iterators/CharacterIterator.h" | 44 #include "core/editing/iterators/CharacterIterator.h" |
45 #include "core/editing/iterators/SimplifiedBackwardsTextIterator.h" | 45 #include "core/editing/iterators/SimplifiedBackwardsTextIterator.h" |
46 #include "core/editing/iterators/TextIterator.h" | 46 #include "core/editing/iterators/TextIterator.h" |
| 47 #include "core/frame/LocalFrame.h" |
| 48 #include "core/frame/Settings.h" |
47 #include "core/html/HTMLBRElement.h" | 49 #include "core/html/HTMLBRElement.h" |
48 #include "core/layout/HitTestRequest.h" | 50 #include "core/layout/HitTestRequest.h" |
49 #include "core/layout/HitTestResult.h" | 51 #include "core/layout/HitTestResult.h" |
50 #include "core/layout/LayoutBlockFlow.h" | 52 #include "core/layout/LayoutBlockFlow.h" |
51 #include "core/layout/LayoutInline.h" | 53 #include "core/layout/LayoutInline.h" |
52 #include "core/layout/LayoutObject.h" | 54 #include "core/layout/LayoutObject.h" |
53 #include "core/layout/LayoutView.h" | 55 #include "core/layout/LayoutView.h" |
54 #include "core/layout/line/InlineIterator.h" | 56 #include "core/layout/line/InlineIterator.h" |
55 #include "core/layout/line/InlineTextBox.h" | 57 #include "core/layout/line/InlineTextBox.h" |
56 #include "core/paint/DeprecatedPaintLayer.h" | 58 #include "core/paint/DeprecatedPaintLayer.h" |
(...skipping 1888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1945 Position mostBackwardCaretPosition(const Position& position, EditingBoundaryCros
singRule rule) | 1947 Position mostBackwardCaretPosition(const Position& position, EditingBoundaryCros
singRule rule) |
1946 { | 1948 { |
1947 return mostBackwardCaretPosition<EditingStrategy>(position, rule); | 1949 return mostBackwardCaretPosition<EditingStrategy>(position, rule); |
1948 } | 1950 } |
1949 | 1951 |
1950 PositionInComposedTree mostBackwardCaretPosition(const PositionInComposedTree& p
osition, EditingBoundaryCrossingRule rule) | 1952 PositionInComposedTree mostBackwardCaretPosition(const PositionInComposedTree& p
osition, EditingBoundaryCrossingRule rule) |
1951 { | 1953 { |
1952 return mostBackwardCaretPosition<EditingInComposedTreeStrategy>(position, ru
le); | 1954 return mostBackwardCaretPosition<EditingInComposedTreeStrategy>(position, ru
le); |
1953 } | 1955 } |
1954 | 1956 |
| 1957 // Returns true if the visually equivalent positions around have different |
| 1958 // editability. A position is considered at editing boundary if one of the |
| 1959 // following is true: |
| 1960 // 1. It is the first position in the node and the next visually equivalent |
| 1961 // position is non editable. |
| 1962 // 2. It is the last position in the node and the previous visually equivalent |
| 1963 // position is non editable. |
| 1964 // 3. It is an editable position and both the next and previous visually |
| 1965 // equivalent positions are both non editable. |
| 1966 template <typename Strategy> |
| 1967 static bool atEditingBoundary(const PositionAlgorithm<Strategy> positions) |
| 1968 { |
| 1969 PositionAlgorithm<Strategy> nextPosition = positions.downstream(CanCrossEdit
ingBoundary); |
| 1970 if (positions.atFirstEditingPositionForNode() && nextPosition.isNotNull() &&
!nextPosition.anchorNode()->hasEditableStyle()) |
| 1971 return true; |
| 1972 |
| 1973 PositionAlgorithm<Strategy> prevPosition = positions.upstream(CanCrossEditin
gBoundary); |
| 1974 if (positions.atLastEditingPositionForNode() && prevPosition.isNotNull() &&
!prevPosition.anchorNode()->hasEditableStyle()) |
| 1975 return true; |
| 1976 |
| 1977 return nextPosition.isNotNull() && !nextPosition.anchorNode()->hasEditableSt
yle() |
| 1978 && prevPosition.isNotNull() && !prevPosition.anchorNode()->hasEditableSt
yle(); |
1955 } | 1979 } |
| 1980 |
| 1981 template <typename Strategy> |
| 1982 static bool isVisuallyEquivalentCandidateAlgorithm(const PositionAlgorithm<Strat
egy>& position) |
| 1983 { |
| 1984 Node* const anchorNode = position.anchorNode(); |
| 1985 if (!anchorNode) |
| 1986 return false; |
| 1987 |
| 1988 LayoutObject* layoutObject = anchorNode->layoutObject(); |
| 1989 if (!layoutObject) |
| 1990 return false; |
| 1991 |
| 1992 if (layoutObject->style()->visibility() != VISIBLE) |
| 1993 return false; |
| 1994 |
| 1995 if (layoutObject->isBR()) { |
| 1996 // TODO(leviw) The condition should be |
| 1997 // m_anchorType == PositionAnchorType::BeforeAnchor, but for now we |
| 1998 // still need to support legacy positions. |
| 1999 if (position.isAfterAnchor()) |
| 2000 return false; |
| 2001 return !position.computeEditingOffset() && !nodeIsUserSelectNone(Strateg
y::parent(*anchorNode)); |
| 2002 } |
| 2003 |
| 2004 if (layoutObject->isText()) |
| 2005 return !nodeIsUserSelectNone(anchorNode) && inRenderedText(position); |
| 2006 |
| 2007 if (layoutObject->isSVG()) { |
| 2008 // We don't consider SVG elements are contenteditable except for |
| 2009 // associated |layoutObject| returns |isText()| true, |
| 2010 // e.g. |LayoutSVGInlineText|. |
| 2011 return false; |
| 2012 } |
| 2013 |
| 2014 if (isRenderedHTMLTableElement(anchorNode) || Strategy::editingIgnoresConten
t(anchorNode)) |
| 2015 return (position.atFirstEditingPositionForNode() || position.atLastEditi
ngPositionForNode()) && !nodeIsUserSelectNone(Strategy::parent(*anchorNode)); |
| 2016 |
| 2017 if (isHTMLHtmlElement(*anchorNode)) |
| 2018 return false; |
| 2019 |
| 2020 if (layoutObject->isLayoutBlockFlow() || layoutObject->isFlexibleBox() || la
youtObject->isLayoutGrid()) { |
| 2021 if (toLayoutBlock(layoutObject)->logicalHeight() || isHTMLBodyElement(*a
nchorNode)) { |
| 2022 if (!hasRenderedNonAnonymousDescendantsWithHeight(layoutObject)) |
| 2023 return position.atFirstEditingPositionForNode() && !nodeIsUserSe
lectNone(anchorNode); |
| 2024 return anchorNode->hasEditableStyle() && !nodeIsUserSelectNone(ancho
rNode) && atEditingBoundary(position); |
| 2025 } |
| 2026 } else { |
| 2027 LocalFrame* frame = anchorNode->document().frame(); |
| 2028 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsi
ngEnabled(); |
| 2029 return (caretBrowsing || anchorNode->hasEditableStyle()) && !nodeIsUserS
electNone(anchorNode) && atEditingBoundary(position); |
| 2030 } |
| 2031 |
| 2032 return false; |
| 2033 } |
| 2034 |
| 2035 bool isVisuallyEquivalentCandidate(const Position& position) |
| 2036 { |
| 2037 return isVisuallyEquivalentCandidateAlgorithm<EditingStrategy>(position); |
| 2038 } |
| 2039 |
| 2040 bool isVisuallyEquivalentCandidate(const PositionInComposedTree& position) |
| 2041 { |
| 2042 return isVisuallyEquivalentCandidateAlgorithm<EditingInComposedTreeStrategy>
(position); |
| 2043 } |
| 2044 |
| 2045 } // namespace blink |
OLD | NEW |