OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights |
4 * reserved. | 4 * reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 SelectedMap selected_map; | 175 SelectedMap selected_map; |
176 | 176 |
177 LayoutObject* const stop = | 177 LayoutObject* const stop = |
178 LayoutObjectAfterPosition(range.EndLayoutObject(), range.EndOffset()); | 178 LayoutObjectAfterPosition(range.EndLayoutObject(), range.EndOffset()); |
179 for (LayoutObject* runner = range.StartLayoutObject(); | 179 for (LayoutObject* runner = range.StartLayoutObject(); |
180 runner && (runner != stop); runner = runner->NextInPreOrder()) { | 180 runner && (runner != stop); runner = runner->NextInPreOrder()) { |
181 if (!runner->CanBeSelectionLeaf() && runner != range.StartLayoutObject() && | 181 if (!runner->CanBeSelectionLeaf() && runner != range.StartLayoutObject() && |
182 runner != range.EndLayoutObject()) | 182 runner != range.EndLayoutObject()) |
183 continue; | 183 continue; |
184 if (runner->GetSelectionState() == SelectionNone) | 184 if (runner->GetSelectionState() == SelectionState::kNone) |
185 continue; | 185 continue; |
186 | 186 |
187 // Blocks are responsible for painting line gaps and margin gaps. They | 187 // Blocks are responsible for painting line gaps and margin gaps. They |
188 // must be examined as well. | 188 // must be examined as well. |
189 selected_map.object_map.Set(runner, runner->GetSelectionState()); | 189 selected_map.object_map.Set(runner, runner->GetSelectionState()); |
190 if (option == CollectSelectedMapOption::kCollectBlock) { | 190 if (option == CollectSelectedMapOption::kCollectBlock) { |
191 LayoutBlock* containing_block = runner->ContainingBlock(); | 191 LayoutBlock* containing_block = runner->ContainingBlock(); |
192 while (containing_block && !containing_block->IsLayoutView()) { | 192 while (containing_block && !containing_block->IsLayoutView()) { |
193 SelectedBlockMap::AddResult result = selected_map.block_map.insert( | 193 SelectedBlockMap::AddResult result = selected_map.block_map.insert( |
194 containing_block, containing_block->GetSelectionState()); | 194 containing_block, containing_block->GetSelectionState()); |
195 if (!result.is_new_entry) | 195 if (!result.is_new_entry) |
196 break; | 196 break; |
197 containing_block = containing_block->ContainingBlock(); | 197 containing_block = containing_block->ContainingBlock(); |
198 } | 198 } |
199 } | 199 } |
200 } | 200 } |
201 return selected_map; | 201 return selected_map; |
202 } | 202 } |
203 | 203 |
204 // Update the selection status of all LayoutObjects between |start| and |end|. | 204 // Update the selection status of all LayoutObjects between |start| and |end|. |
205 static void SetSelectionState(const SelectionPaintRange& range) { | 205 static void SetSelectionState(const SelectionPaintRange& range) { |
206 if (range.IsNull()) | 206 if (range.IsNull()) |
207 return; | 207 return; |
208 | 208 |
209 if (range.StartLayoutObject() == range.EndLayoutObject()) { | 209 if (range.StartLayoutObject() == range.EndLayoutObject()) { |
210 range.StartLayoutObject()->SetSelectionStateIfNeeded(SelectionBoth); | 210 range.StartLayoutObject()->SetSelectionStateIfNeeded( |
| 211 SelectionState::kStartAndEnd); |
211 } else { | 212 } else { |
212 range.StartLayoutObject()->SetSelectionStateIfNeeded(SelectionStart); | 213 range.StartLayoutObject()->SetSelectionStateIfNeeded( |
213 range.EndLayoutObject()->SetSelectionStateIfNeeded(SelectionEnd); | 214 SelectionState::kStart); |
| 215 range.EndLayoutObject()->SetSelectionStateIfNeeded(SelectionState::kEnd); |
214 } | 216 } |
215 | 217 |
216 LayoutObject* const stop = | 218 LayoutObject* const stop = |
217 LayoutObjectAfterPosition(range.EndLayoutObject(), range.EndOffset()); | 219 LayoutObjectAfterPosition(range.EndLayoutObject(), range.EndOffset()); |
218 for (LayoutObject* runner = range.StartLayoutObject(); | 220 for (LayoutObject* runner = range.StartLayoutObject(); |
219 runner && runner != stop; runner = runner->NextInPreOrder()) { | 221 runner && runner != stop; runner = runner->NextInPreOrder()) { |
220 if (runner != range.StartLayoutObject() && | 222 if (runner != range.StartLayoutObject() && |
221 runner != range.EndLayoutObject() && runner->CanBeSelectionLeaf()) | 223 runner != range.EndLayoutObject() && runner->CanBeSelectionLeaf()) |
222 runner->SetSelectionStateIfNeeded(SelectionInside); | 224 runner->SetSelectionStateIfNeeded(SelectionState::kInside); |
223 } | 225 } |
224 } | 226 } |
225 | 227 |
226 // Set SetSelectionState and ShouldInvalidateSelection flag of LayoutObjects | 228 // Set SetSelectionState and ShouldInvalidateSelection flag of LayoutObjects |
227 // comparing them in |new_range| and |old_range|. | 229 // comparing them in |new_range| and |old_range|. |
228 static void UpdateLayoutObjectState(const SelectionPaintRange& new_range, | 230 static void UpdateLayoutObjectState(const SelectionPaintRange& new_range, |
229 const SelectionPaintRange& old_range) { | 231 const SelectionPaintRange& old_range) { |
230 SelectedMap old_selected_map = | 232 SelectedMap old_selected_map = |
231 CollectSelectedMap(old_range, CollectSelectedMapOption::kCollectBlock); | 233 CollectSelectedMap(old_range, CollectSelectedMapOption::kCollectBlock); |
232 | 234 |
233 // Now clear the selection. | 235 // Now clear the selection. |
234 for (auto layout_object : old_selected_map.object_map.Keys()) | 236 for (auto layout_object : old_selected_map.object_map.Keys()) |
235 layout_object->SetSelectionStateIfNeeded(SelectionNone); | 237 layout_object->SetSelectionStateIfNeeded(SelectionState::kNone); |
236 | 238 |
237 SetSelectionState(new_range); | 239 SetSelectionState(new_range); |
238 | 240 |
239 // Now that the selection state has been updated for the new objects, walk | 241 // Now that the selection state has been updated for the new objects, walk |
240 // them again and put them in the new objects list. | 242 // them again and put them in the new objects list. |
241 // TODO(editing-dev): |new_selected_map| doesn't really need to store the | 243 // TODO(editing-dev): |new_selected_map| doesn't really need to store the |
242 // SelectionState, it's just more convenient to have it use the same data | 244 // SelectionState, it's just more convenient to have it use the same data |
243 // structure as |old_selected_map|. | 245 // structure as |old_selected_map|. |
244 SelectedMap new_selected_map = | 246 SelectedMap new_selected_map = |
245 CollectSelectedMap(new_range, CollectSelectedMapOption::kCollectBlock); | 247 CollectSelectedMap(new_range, CollectSelectedMapOption::kCollectBlock); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 298 |
297 // Just return if the selection is already empty. | 299 // Just return if the selection is already empty. |
298 if (paint_range_.IsNull()) | 300 if (paint_range_.IsNull()) |
299 return; | 301 return; |
300 | 302 |
301 const SelectedMap& old_selected_map = CollectSelectedMap( | 303 const SelectedMap& old_selected_map = CollectSelectedMap( |
302 paint_range_, CollectSelectedMapOption::kNotCollectBlock); | 304 paint_range_, CollectSelectedMapOption::kNotCollectBlock); |
303 // Clear SelectionState and invalidation. | 305 // Clear SelectionState and invalidation. |
304 for (auto layout_object : old_selected_map.object_map.Keys()) { | 306 for (auto layout_object : old_selected_map.object_map.Keys()) { |
305 const SelectionState old_state = layout_object->GetSelectionState(); | 307 const SelectionState old_state = layout_object->GetSelectionState(); |
306 layout_object->SetSelectionStateIfNeeded(SelectionNone); | 308 layout_object->SetSelectionStateIfNeeded(SelectionState::kNone); |
307 if (layout_object->GetSelectionState() == old_state) | 309 if (layout_object->GetSelectionState() == old_state) |
308 continue; | 310 continue; |
309 layout_object->SetShouldInvalidateSelection(); | 311 layout_object->SetShouldInvalidateSelection(); |
310 } | 312 } |
311 | 313 |
312 // Reset selection. | 314 // Reset selection. |
313 paint_range_ = SelectionPaintRange(); | 315 paint_range_ = SelectionPaintRange(); |
314 } | 316 } |
315 | 317 |
316 void LayoutSelection::Commit() { | 318 void LayoutSelection::Commit() { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 Commit(); | 402 Commit(); |
401 if (paint_range_.IsNull()) | 403 if (paint_range_.IsNull()) |
402 return IntRect(); | 404 return IntRect(); |
403 | 405 |
404 LayoutObject* os = paint_range_.StartLayoutObject(); | 406 LayoutObject* os = paint_range_.StartLayoutObject(); |
405 LayoutObject* stop = LayoutObjectAfterPosition(paint_range_.EndLayoutObject(), | 407 LayoutObject* stop = LayoutObjectAfterPosition(paint_range_.EndLayoutObject(), |
406 paint_range_.EndOffset()); | 408 paint_range_.EndOffset()); |
407 while (os && os != stop) { | 409 while (os && os != stop) { |
408 if ((os->CanBeSelectionLeaf() || os == paint_range_.StartLayoutObject() || | 410 if ((os->CanBeSelectionLeaf() || os == paint_range_.StartLayoutObject() || |
409 os == paint_range_.EndLayoutObject()) && | 411 os == paint_range_.EndLayoutObject()) && |
410 os->GetSelectionState() != SelectionNone) { | 412 os->GetSelectionState() != SelectionState::kNone) { |
411 // Blocks are responsible for painting line gaps and margin gaps. They | 413 // Blocks are responsible for painting line gaps and margin gaps. They |
412 // must be examined as well. | 414 // must be examined as well. |
413 sel_rect.Unite(SelectionRectForLayoutObject(os)); | 415 sel_rect.Unite(SelectionRectForLayoutObject(os)); |
414 const LayoutBlock* cb = os->ContainingBlock(); | 416 const LayoutBlock* cb = os->ContainingBlock(); |
415 while (cb && !cb->IsLayoutView()) { | 417 while (cb && !cb->IsLayoutView()) { |
416 sel_rect.Unite(SelectionRectForLayoutObject(cb)); | 418 sel_rect.Unite(SelectionRectForLayoutObject(cb)); |
417 VisitedContainingBlockSet::AddResult add_result = | 419 VisitedContainingBlockSet::AddResult add_result = |
418 visited_containing_blocks.insert(cb); | 420 visited_containing_blocks.insert(cb); |
419 if (!add_result.is_new_entry) | 421 if (!add_result.is_new_entry) |
420 break; | 422 break; |
(...skipping 11 matching lines...) Expand all Loading... |
432 if (paint_range_.IsNull()) | 434 if (paint_range_.IsNull()) |
433 return; | 435 return; |
434 | 436 |
435 LayoutObject* end = LayoutObjectAfterPosition(paint_range_.EndLayoutObject(), | 437 LayoutObject* end = LayoutObjectAfterPosition(paint_range_.EndLayoutObject(), |
436 paint_range_.EndOffset()); | 438 paint_range_.EndOffset()); |
437 for (LayoutObject* o = paint_range_.StartLayoutObject(); o && o != end; | 439 for (LayoutObject* o = paint_range_.StartLayoutObject(); o && o != end; |
438 o = o->NextInPreOrder()) { | 440 o = o->NextInPreOrder()) { |
439 if (!o->CanBeSelectionLeaf() && o != paint_range_.StartLayoutObject() && | 441 if (!o->CanBeSelectionLeaf() && o != paint_range_.StartLayoutObject() && |
440 o != paint_range_.EndLayoutObject()) | 442 o != paint_range_.EndLayoutObject()) |
441 continue; | 443 continue; |
442 if (o->GetSelectionState() == SelectionNone) | 444 if (o->GetSelectionState() == SelectionState::kNone) |
443 continue; | 445 continue; |
444 | 446 |
445 o->SetShouldInvalidateSelection(); | 447 o->SetShouldInvalidateSelection(); |
446 } | 448 } |
447 } | 449 } |
448 | 450 |
449 DEFINE_TRACE(LayoutSelection) { | 451 DEFINE_TRACE(LayoutSelection) { |
450 visitor->Trace(frame_selection_); | 452 visitor->Trace(frame_selection_); |
451 } | 453 } |
452 | 454 |
453 } // namespace blink | 455 } // namespace blink |
OLD | NEW |