| 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 // Note about ::first-letter pseudo-element: |
| 2175 // When an element has ::first-letter pseudo-element, first letter characters |
| 2176 // are taken from |Text| node and first letter characters are considered |
| 2177 // as content of <pseudo:first-letter>. |
| 2178 // For following HTML, |
| 2179 // <style>div::first-letter {color: red}</style> |
| 2180 // <div>abc</div> |
| 2181 // we have following layout tree: |
| 2182 // LayoutBlockFlow {DIV} at (0,0) size 784x55 |
| 2183 // LayoutInline {<pseudo:first-letter>} at (0,0) size 22x53 |
| 2184 // LayoutTextFragment (anonymous) at (0,1) size 22x53 |
| 2185 // text run at (0,1) width 22: "a" |
| 2186 // LayoutTextFragment {#text} at (21,30) size 16x17 |
| 2187 // text run at (21,30) width 16: "bc" |
| 2188 // In this case, |Text::layoutObject()| for "abc" returns |LayoutTextFragment| |
| 2189 // containing "bc", and it is called remaining part. |
| 2190 // |
| 2191 // Even if |Text| node contains only first-letter characters, e.g. just "a", |
| 2192 // remaining part of |LayoutTextFragment|, with |fragmentLength()| == 0, is |
| 2193 // appeared in layout tree. |
| 2194 // |
| 2195 // When |Text| node contains only first-letter characters and whitespaces, e.g. |
| 2196 // "B\n", associated |LayoutTextFragment| is first-letter part instead of |
| 2197 // remaining part. |
| 2198 // |
| 2199 // Punctuation characters are considered as first-letter. For "(1)ab", |
| 2200 // "(1)" are first-letter part and "ab" are remaining part. |
| 2201 LayoutObject* associatedLayoutObjectOf(const Node& node, int offsetInNode) |
| 2175 { | 2202 { |
| 2176 ASSERT(offsetInNode >= 0); | 2203 ASSERT(offsetInNode >= 0); |
| 2177 LayoutObject* layoutObject = node.layoutObject(); | 2204 LayoutObject* layoutObject = node.layoutObject(); |
| 2178 if (!node.isTextNode() || !layoutObject || !toLayoutText(layoutObject)->isTe
xtFragment()) | 2205 if (!node.isTextNode() || !layoutObject || !toLayoutText(layoutObject)->isTe
xtFragment()) |
| 2179 return layoutObject; | 2206 return layoutObject; |
| 2180 LayoutTextFragment* layoutTextFragment = toLayoutTextFragment(layoutObject); | 2207 LayoutTextFragment* layoutTextFragment = toLayoutTextFragment(layoutObject); |
| 2181 if (layoutTextFragment->isRemainingTextLayoutObject()) { | 2208 if (!layoutTextFragment->isRemainingTextLayoutObject()) { |
| 2182 if (static_cast<unsigned>(offsetInNode) >= layoutTextFragment->start()) | 2209 ASSERT(static_cast<unsigned>(offsetInNode) <= layoutTextFragment->start(
) + layoutTextFragment->fragmentLength()); |
| 2183 return layoutObject; | 2210 return layoutTextFragment; |
| 2184 LayoutObject* firstLetterLayoutObject = layoutTextFragment->firstLetterP
seudoElement()->layoutObject(); | |
| 2185 if (!firstLetterLayoutObject) | |
| 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 } | 2211 } |
| 2192 // TODO(yosin): We should rename |LayoutTextFramge::length()| instead of | 2212 if (layoutTextFragment->fragmentLength() && static_cast<unsigned>(offsetInNo
de) >= layoutTextFragment->start()) |
| 2193 // |end()|, once |LayoutTextFramge| has it. See http://crbug.com/545789 | 2213 return layoutObject; |
| 2194 ASSERT(static_cast<unsigned>(offsetInNode) <= layoutTextFragment->start() +
layoutTextFragment->fragmentLength()); | 2214 LayoutObject* firstLetterLayoutObject = layoutTextFragment->firstLetterPseud
oElement()->layoutObject(); |
| 2195 return layoutTextFragment; | 2215 // TODO(yosin): We're not sure when |firstLetterLayoutObject| has |
| 2216 // multiple child layout object. |
| 2217 ASSERT(firstLetterLayoutObject->slowFirstChild() == firstLetterLayoutObject-
>slowLastChild()); |
| 2218 return firstLetterLayoutObject->slowFirstChild(); |
| 2196 } | 2219 } |
| 2197 | 2220 |
| 2198 int caretMinOffset(const Node* node) | 2221 int caretMinOffset(const Node* node) |
| 2199 { | 2222 { |
| 2200 LayoutObject* layoutObject = associatedLayoutObjectOf(*node, 0); | 2223 LayoutObject* layoutObject = associatedLayoutObjectOf(*node, 0); |
| 2201 return layoutObject ? layoutObject->caretMinOffset() : 0; | 2224 return layoutObject ? layoutObject->caretMinOffset() : 0; |
| 2202 } | 2225 } |
| 2203 | 2226 |
| 2204 int caretMaxOffset(const Node* n) | 2227 int caretMaxOffset(const Node* n) |
| 2205 { | 2228 { |
| (...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3327 { | 3350 { |
| 3328 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); | 3351 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); |
| 3329 } | 3352 } |
| 3330 | 3353 |
| 3331 VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposed
Tree& visiblePosition, EditingBoundaryCrossingRule rule) | 3354 VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposed
Tree& visiblePosition, EditingBoundaryCrossingRule rule) |
| 3332 { | 3355 { |
| 3333 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePos
ition, rule); | 3356 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePos
ition, rule); |
| 3334 } | 3357 } |
| 3335 | 3358 |
| 3336 } // namespace blink | 3359 } // namespace blink |
| OLD | NEW |