Chromium Code Reviews| 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 2153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2164 HitTestResult result(request, contentsPoint); | 2164 HitTestResult result(request, contentsPoint); |
| 2165 frame->document()->layoutView()->hitTest(result); | 2165 frame->document()->layoutView()->hitTest(result); |
| 2166 | 2166 |
| 2167 if (Node* node = result.innerNode()) | 2167 if (Node* node = result.innerNode()) |
| 2168 return frame->selection().selection().visiblePositionRespectingEditingBo undary(result.localPoint(), node); | 2168 return frame->selection().selection().visiblePositionRespectingEditingBo undary(result.localPoint(), node); |
| 2169 return VisiblePosition(); | 2169 return VisiblePosition(); |
| 2170 } | 2170 } |
| 2171 | 2171 |
| 2172 // TODO(yosin): We should use |associatedLayoutObjectOf()| in "VisibleUnits.cpp" | 2172 // TODO(yosin): We should use |associatedLayoutObjectOf()| in "VisibleUnits.cpp" |
| 2173 // where it takes |LayoutObject| from |Position|. | 2173 // where it takes |LayoutObject| from |Position|. |
| 2174 static LayoutObject* associatedLayoutObjectOf(const Node& node, int offsetInNode ) | 2174 LayoutObject* associatedLayoutObjectOf(const Node& node, int offsetInNode) |
| 2175 { | 2175 { |
| 2176 ASSERT(offsetInNode >= 0); | 2176 ASSERT(offsetInNode >= 0); |
| 2177 LayoutObject* layoutObject = node.layoutObject(); | 2177 LayoutObject* layoutObject = node.layoutObject(); |
| 2178 if (!node.isTextNode() || !layoutObject || !toLayoutText(layoutObject)->isTe xtFragment()) | 2178 if (!node.isTextNode() || !layoutObject || !toLayoutText(layoutObject)->isTe xtFragment()) |
| 2179 return layoutObject; | 2179 return layoutObject; |
| 2180 LayoutTextFragment* layoutTextFragment = toLayoutTextFragment(layoutObject); | 2180 LayoutTextFragment* layoutTextFragment = toLayoutTextFragment(layoutObject); |
| 2181 if (layoutTextFragment->isRemainingTextLayoutObject()) { | 2181 if (!layoutTextFragment->isRemainingTextLayoutObject()) { |
| 2182 if (static_cast<unsigned>(offsetInNode) >= layoutTextFragment->start()) | 2182 // In case of there are no visible characters after first letter, e.g. |
| 2183 return layoutObject; | 2183 // "B\n" |
| 2184 LayoutObject* firstLetterLayoutObject = layoutTextFragment->firstLetterP seudoElement()->layoutObject(); | 2184 ASSERT(static_cast<unsigned>(offsetInNode) <= layoutTextFragment->start( ) + layoutTextFragment->fragmentLength()); |
| 2185 if (!firstLetterLayoutObject) | 2185 return layoutTextFragment; |
| 2186 return nullptr; | |
| 2187 // TODO(yosin): We're not sure when |firstLetterLayoutObject| has | |
| 2188 // multiple child layout object. | |
| 2189 ASSERT(firstLetterLayoutObject->slowFirstChild() == firstLetterLayoutObj ect->slowLastChild()); | |
| 2190 return firstLetterLayoutObject->slowFirstChild(); | |
| 2191 } | 2186 } |
| 2192 // TODO(yosin): We should rename |LayoutTextFramge::length()| instead of | 2187 // In case of |node| contains first-letter only, e.g. <div>"a" "bc"</div> |
| 2193 // |end()|, once |LayoutTextFramge| has it. See http://crbug.com/545789 | 2188 // we have "a" is associated to |LayoutTextFragment| with |
| 2194 ASSERT(static_cast<unsigned>(offsetInNode) <= layoutTextFragment->start() + layoutTextFragment->fragmentLength()); | 2189 // |isRemainingTextLayoutObject()| == true and |fragmentLength()| == 0. |
| 2195 return layoutTextFragment; | 2190 ASSERT(layoutTextFragment->isRemainingTextLayoutObject()); |
|
tkent
2016/01/29 00:56:09
This ASSERT isn't helpful because layoutTextFragme
yosin_UTC9
2016/01/29 03:45:12
Done.
| |
| 2191 if (layoutTextFragment->fragmentLength() && static_cast<unsigned>(offsetInNo de) >= layoutTextFragment->start()) | |
| 2192 return layoutObject; | |
| 2193 LayoutObject* firstLetterLayoutObject = layoutTextFragment->firstLetterPseud oElement()->layoutObject(); | |
|
tkent
2016/01/29 00:56:09
nullptr-check for firstLetterLayoutObject is remov
yosin_UTC9
2016/01/29 03:45:12
Yes, it is intentional. This case should not be ha
| |
| 2194 // TODO(yosin): We're not sure when |firstLetterLayoutObject| has | |
| 2195 // multiple child layout object. | |
| 2196 ASSERT(firstLetterLayoutObject->slowFirstChild() == firstLetterLayoutObject- >slowLastChild()); | |
| 2197 return firstLetterLayoutObject->slowFirstChild(); | |
| 2196 } | 2198 } |
| 2197 | 2199 |
| 2198 int caretMinOffset(const Node* node) | 2200 int caretMinOffset(const Node* node) |
| 2199 { | 2201 { |
| 2200 LayoutObject* layoutObject = associatedLayoutObjectOf(*node, 0); | 2202 LayoutObject* layoutObject = associatedLayoutObjectOf(*node, 0); |
| 2201 return layoutObject ? layoutObject->caretMinOffset() : 0; | 2203 return layoutObject ? layoutObject->caretMinOffset() : 0; |
| 2202 } | 2204 } |
| 2203 | 2205 |
| 2204 int caretMaxOffset(const Node* n) | 2206 int caretMaxOffset(const Node* n) |
| 2205 { | 2207 { |
| (...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3327 { | 3329 { |
| 3328 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); | 3330 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); |
| 3329 } | 3331 } |
| 3330 | 3332 |
| 3331 VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposed Tree& visiblePosition, EditingBoundaryCrossingRule rule) | 3333 VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposed Tree& visiblePosition, EditingBoundaryCrossingRule rule) |
| 3332 { | 3334 { |
| 3333 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePos ition, rule); | 3335 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePos ition, rule); |
| 3334 } | 3336 } |
| 3335 | 3337 |
| 3336 } // namespace blink | 3338 } // namespace blink |
| OLD | NEW |