| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 SelectedMap() = default; | 179 SelectedMap() = default; |
| 180 SelectedMap(SelectedMap&& other) { | 180 SelectedMap(SelectedMap&& other) { |
| 181 object_map = std::move(other.object_map); | 181 object_map = std::move(other.object_map); |
| 182 block_map = std::move(other.block_map); | 182 block_map = std::move(other.block_map); |
| 183 } | 183 } |
| 184 | 184 |
| 185 private: | 185 private: |
| 186 DISALLOW_COPY_AND_ASSIGN(SelectedMap); | 186 DISALLOW_COPY_AND_ASSIGN(SelectedMap); |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 enum class CollectSelectedMapOption { | 189 static SelectedMap CollectSelectedMap(const SelectionPaintRange& range) { |
| 190 kCollectBlock, | |
| 191 kNotCollectBlock, | |
| 192 }; | |
| 193 | |
| 194 static SelectedMap CollectSelectedMap(const SelectionPaintRange& range, | |
| 195 CollectSelectedMapOption option) { | |
| 196 if (range.IsNull()) | 190 if (range.IsNull()) |
| 197 return SelectedMap(); | 191 return SelectedMap(); |
| 198 | 192 |
| 199 SelectedMap selected_map; | 193 SelectedMap selected_map; |
| 200 | 194 |
| 201 for (LayoutObject* runner : range) { | 195 for (LayoutObject* runner : range) { |
| 202 if (runner->GetSelectionState() == SelectionState::kNone) | 196 if (runner->GetSelectionState() == SelectionState::kNone) |
| 203 continue; | 197 continue; |
| 204 | 198 |
| 205 // Blocks are responsible for painting line gaps and margin gaps. They | 199 // Blocks are responsible for painting line gaps and margin gaps. They |
| 206 // must be examined as well. | 200 // must be examined as well. |
| 207 selected_map.object_map.Set(runner, runner->GetSelectionState()); | 201 selected_map.object_map.Set(runner, runner->GetSelectionState()); |
| 208 if (option == CollectSelectedMapOption::kCollectBlock) { | 202 for (LayoutBlock* containing_block = runner->ContainingBlock(); |
| 209 LayoutBlock* containing_block = runner->ContainingBlock(); | 203 containing_block && !containing_block->IsLayoutView(); |
| 210 while (containing_block && !containing_block->IsLayoutView()) { | 204 containing_block = containing_block->ContainingBlock()) { |
| 211 SelectedBlockMap::AddResult result = selected_map.block_map.insert( | 205 SelectedBlockMap::AddResult result = selected_map.block_map.insert( |
| 212 containing_block, containing_block->GetSelectionState()); | 206 containing_block, containing_block->GetSelectionState()); |
| 213 if (!result.is_new_entry) | 207 if (!result.is_new_entry) |
| 214 break; | 208 break; |
| 215 containing_block = containing_block->ContainingBlock(); | |
| 216 } | |
| 217 } | 209 } |
| 218 } | 210 } |
| 219 return selected_map; | 211 return selected_map; |
| 220 } | 212 } |
| 221 | 213 |
| 222 // Update the selection status of all LayoutObjects between |start| and |end|. | 214 // Update the selection status of all LayoutObjects between |start| and |end|. |
| 223 static void SetSelectionState(const SelectionPaintRange& range) { | 215 static void SetSelectionState(const SelectionPaintRange& range) { |
| 224 if (range.IsNull()) | 216 if (range.IsNull()) |
| 225 return; | 217 return; |
| 226 | 218 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 237 if (runner != range.StartLayoutObject() && | 229 if (runner != range.StartLayoutObject() && |
| 238 runner != range.EndLayoutObject() && runner->CanBeSelectionLeaf()) | 230 runner != range.EndLayoutObject() && runner->CanBeSelectionLeaf()) |
| 239 runner->SetSelectionStateIfNeeded(SelectionState::kInside); | 231 runner->SetSelectionStateIfNeeded(SelectionState::kInside); |
| 240 } | 232 } |
| 241 } | 233 } |
| 242 | 234 |
| 243 // Set SetSelectionState and ShouldInvalidateSelection flag of LayoutObjects | 235 // Set SetSelectionState and ShouldInvalidateSelection flag of LayoutObjects |
| 244 // comparing them in |new_range| and |old_range|. | 236 // comparing them in |new_range| and |old_range|. |
| 245 static void UpdateLayoutObjectState(const SelectionPaintRange& new_range, | 237 static void UpdateLayoutObjectState(const SelectionPaintRange& new_range, |
| 246 const SelectionPaintRange& old_range) { | 238 const SelectionPaintRange& old_range) { |
| 247 SelectedMap old_selected_map = | 239 const SelectedMap& old_selected_map = CollectSelectedMap(old_range); |
| 248 CollectSelectedMap(old_range, CollectSelectedMapOption::kCollectBlock); | |
| 249 | 240 |
| 250 // Now clear the selection. | 241 // Now clear the selection. |
| 251 for (auto layout_object : old_selected_map.object_map.Keys()) | 242 for (auto layout_object : old_selected_map.object_map.Keys()) |
| 252 layout_object->SetSelectionStateIfNeeded(SelectionState::kNone); | 243 layout_object->SetSelectionStateIfNeeded(SelectionState::kNone); |
| 253 | 244 |
| 254 SetSelectionState(new_range); | 245 SetSelectionState(new_range); |
| 255 | 246 |
| 256 // Now that the selection state has been updated for the new objects, walk | 247 // Now that the selection state has been updated for the new objects, walk |
| 257 // them again and put them in the new objects list. | 248 // them again and put them in the new objects list. |
| 258 // TODO(editing-dev): |new_selected_map| doesn't really need to store the | 249 // TODO(editing-dev): |new_selected_map| doesn't really need to store the |
| 259 // SelectionState, it's just more convenient to have it use the same data | 250 // SelectionState, it's just more convenient to have it use the same data |
| 260 // structure as |old_selected_map|. | 251 // structure as |old_selected_map|. |
| 261 SelectedMap new_selected_map = | 252 SelectedMap new_selected_map = CollectSelectedMap(new_range); |
| 262 CollectSelectedMap(new_range, CollectSelectedMapOption::kCollectBlock); | |
| 263 | 253 |
| 264 // Have any of the old selected objects changed compared to the new selection? | 254 // Have any of the old selected objects changed compared to the new selection? |
| 265 for (const auto& pair : old_selected_map.object_map) { | 255 for (const auto& pair : old_selected_map.object_map) { |
| 266 LayoutObject* obj = pair.key; | 256 LayoutObject* obj = pair.key; |
| 267 SelectionState new_selection_state = obj->GetSelectionState(); | 257 SelectionState new_selection_state = obj->GetSelectionState(); |
| 268 SelectionState old_selection_state = pair.value; | 258 SelectionState old_selection_state = pair.value; |
| 269 if (new_selection_state != old_selection_state || | 259 if (new_selection_state != old_selection_state || |
| 270 (new_range.StartLayoutObject() == obj && | 260 (new_range.StartLayoutObject() == obj && |
| 271 new_range.StartOffset() != old_range.StartOffset()) || | 261 new_range.StartOffset() != old_range.StartOffset()) || |
| 272 (new_range.EndLayoutObject() == obj && | 262 (new_range.EndLayoutObject() == obj && |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 448 |
| 459 runner->SetShouldInvalidateSelection(); | 449 runner->SetShouldInvalidateSelection(); |
| 460 } | 450 } |
| 461 } | 451 } |
| 462 | 452 |
| 463 DEFINE_TRACE(LayoutSelection) { | 453 DEFINE_TRACE(LayoutSelection) { |
| 464 visitor->Trace(frame_selection_); | 454 visitor->Trace(frame_selection_); |
| 465 } | 455 } |
| 466 | 456 |
| 467 } // namespace blink | 457 } // namespace blink |
| OLD | NEW |