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

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

Issue 2918783002: Extract InlineBox handling from MostForwardCaretPosition() (Closed)
Patch Set: 2017-06-06T13:19:51 Created 3 years, 6 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 2185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2196 if (layout_object->IsText() && 2196 if (layout_object->IsText() &&
2197 ToLayoutText(layout_object)->FirstTextBox()) { 2197 ToLayoutText(layout_object)->FirstTextBox()) {
2198 LayoutText* const text_layout_object = ToLayoutText(layout_object); 2198 LayoutText* const text_layout_object = ToLayoutText(layout_object);
2199 const unsigned text_start_offset = text_layout_object->TextStartOffset(); 2199 const unsigned text_start_offset = text_layout_object->TextStartOffset();
2200 if (current_node != start_node) { 2200 if (current_node != start_node) {
2201 DCHECK(current_pos.AtStartOfNode()); 2201 DCHECK(current_pos.AtStartOfNode());
2202 return PositionTemplate<Strategy>( 2202 return PositionTemplate<Strategy>(
2203 current_node, layout_object->CaretMinOffset() + text_start_offset); 2203 current_node, layout_object->CaretMinOffset() + text_start_offset);
2204 } 2204 }
2205 2205
2206 // Map offset in DOM node to offset in InlineBox. 2206 if (CanBeForwardCaretPosition(text_layout_object,
2207 DCHECK_GE(current_pos.OffsetInLeafNode(), 2207 current_pos.OffsetInLeafNode())) {
2208 static_cast<int>(text_start_offset)); 2208 return current_pos.ComputePosition();
2209 const unsigned text_offset =
2210 current_pos.OffsetInLeafNode() - text_start_offset;
2211 InlineTextBox* last_text_box = text_layout_object->LastTextBox();
2212 for (InlineTextBox* box = text_layout_object->FirstTextBox(); box;
2213 box = box->NextTextBox()) {
2214 if (text_offset <= box->end()) {
2215 if (text_offset >= box->Start())
2216 return current_pos.ComputePosition();
2217 continue;
2218 }
2219
2220 if (box == last_text_box || text_offset != box->Start() + box->Len())
2221 continue;
2222
2223 // The text continues on the next line only if the last text box is not
2224 // on this line and none of the boxes on this line have a larger start
2225 // offset.
2226
2227 bool continues_on_next_line = true;
2228 InlineBox* other_box = box;
2229 while (continues_on_next_line) {
2230 other_box = other_box->NextLeafChild();
2231 if (!other_box)
2232 break;
2233 if (other_box == last_text_box ||
2234 (LineLayoutAPIShim::LayoutObjectFrom(
2235 other_box->GetLineLayoutItem()) == text_layout_object &&
2236 ToInlineTextBox(other_box)->Start() >= text_offset))
2237 continues_on_next_line = false;
2238 }
2239
2240 other_box = box;
2241 while (continues_on_next_line) {
2242 other_box = other_box->PrevLeafChild();
2243 if (!other_box)
2244 break;
2245 if (other_box == last_text_box ||
2246 (LineLayoutAPIShim::LayoutObjectFrom(
2247 other_box->GetLineLayoutItem()) == text_layout_object &&
2248 ToInlineTextBox(other_box)->Start() >= text_offset))
2249 continues_on_next_line = false;
2250 }
2251
2252 if (continues_on_next_line)
2253 return current_pos.ComputePosition();
2254 } 2209 }
2255 } 2210 }
2256 } 2211 }
2257
2258 return last_visible.DeprecatedComputePosition(); 2212 return last_visible.DeprecatedComputePosition();
2259 } 2213 }
2260 2214
2215 // TODO(editing-dev): This function is just moved out from
2216 // |MostForwardCaretPosition()|. We should study this function more and
2217 // name it appropriately. See https://trac.webkit.org/changeset/32438/
2218 // which introduce this.
2219 static bool CanBeForwardCaretPosition(const LayoutText* text_layout_object,
2220 int offset_in_node) {
2221 const unsigned text_start_offset = text_layout_object->TextStartOffset();
2222 DCHECK_GE(offset_in_node, static_cast<int>(text_start_offset));
2223 const unsigned text_offset = offset_in_node - text_start_offset;
2224 InlineTextBox* const last_text_box = text_layout_object->LastTextBox();
2225 for (InlineTextBox* box = text_layout_object->FirstTextBox(); box;
2226 box = box->NextTextBox()) {
2227 if (text_offset <= box->end()) {
2228 if (text_offset >= box->Start())
2229 return true;
2230 continue;
2231 }
2232
2233 if (box == last_text_box || text_offset != box->Start() + box->Len())
2234 continue;
2235
2236 // TODO(yosin): We should move below code fragment into
2237 // |DoesContinueOnNextLine()|. Note: |MostBackwardCaretPosition()| has
2238 // same code fragment except for comparison on |text_offset|.
2239 // Backward: other_box->Start() > text_offset
2240 // Forward: other_box->Start() >= text_offset
2241 // The text continues on the next line only if the last text box is not
2242 // on this line and none of the boxes on this line have a larger start
2243 // offset.
2244 bool continues_on_next_line = true;
2245 InlineBox* other_box = box;
2246 while (continues_on_next_line) {
2247 other_box = other_box->NextLeafChild();
2248 if (!other_box)
2249 break;
2250 if (other_box == last_text_box ||
2251 (LineLayoutAPIShim::LayoutObjectFrom(
2252 other_box->GetLineLayoutItem()) == text_layout_object &&
2253 ToInlineTextBox(other_box)->Start() >= text_offset))
2254 continues_on_next_line = false;
2255 }
2256
2257 other_box = box;
2258 while (continues_on_next_line) {
2259 other_box = other_box->PrevLeafChild();
2260 if (!other_box)
2261 break;
2262 if (other_box == last_text_box ||
2263 (LineLayoutAPIShim::LayoutObjectFrom(
2264 other_box->GetLineLayoutItem()) == text_layout_object &&
2265 ToInlineTextBox(other_box)->Start() >= text_offset))
2266 continues_on_next_line = false;
2267 }
2268
2269 if (continues_on_next_line)
2270 return true;
2271 }
2272 return false;
2273 }
2274
2261 Position MostForwardCaretPosition(const Position& position, 2275 Position MostForwardCaretPosition(const Position& position,
2262 EditingBoundaryCrossingRule rule) { 2276 EditingBoundaryCrossingRule rule) {
2263 return MostForwardCaretPosition<EditingStrategy>(position, rule); 2277 return MostForwardCaretPosition<EditingStrategy>(position, rule);
2264 } 2278 }
2265 2279
2266 PositionInFlatTree MostForwardCaretPosition(const PositionInFlatTree& position, 2280 PositionInFlatTree MostForwardCaretPosition(const PositionInFlatTree& position,
2267 EditingBoundaryCrossingRule rule) { 2281 EditingBoundaryCrossingRule rule) {
2268 return MostForwardCaretPosition<EditingInFlatTreeStrategy>(position, rule); 2282 return MostForwardCaretPosition<EditingInFlatTreeStrategy>(position, rule);
2269 } 2283 }
2270 2284
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
3137 3151
3138 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { 3152 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) {
3139 return EnclosingIntRect(ComputeTextRectTemplate(range)); 3153 return EnclosingIntRect(ComputeTextRectTemplate(range));
3140 } 3154 }
3141 3155
3142 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { 3156 FloatRect ComputeTextFloatRect(const EphemeralRange& range) {
3143 return ComputeTextRectTemplate(range); 3157 return ComputeTextRectTemplate(range);
3144 } 3158 }
3145 3159
3146 } // namespace blink 3160 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698