Chromium Code Reviews| 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 |
| 209 LayoutBlock* containing_block = runner->ContainingBlock(); | 203 for (LayoutBlock* containing_block = runner->ContainingBlock(); |
| 210 while (containing_block && !containing_block->IsLayoutView()) { | 204 containing_block && !containing_block->IsLayoutView(); |
| 211 SelectedBlockMap::AddResult result = selected_map.block_map.insert( | 205 containing_block = containing_block->ContainingBlock()) { |
| 212 containing_block, containing_block->GetSelectionState()); | 206 SelectedBlockMap::AddResult result = selected_map.block_map.insert( |
| 213 if (!result.is_new_entry) | 207 containing_block, containing_block->GetSelectionState()); |
| 214 break; | 208 if (!result.is_new_entry) |
| 215 containing_block = containing_block->ContainingBlock(); | 209 break; |
| 216 } | |
| 217 } | 210 } |
| 218 } | 211 } |
| 219 return selected_map; | 212 return selected_map; |
| 220 } | 213 } |
| 221 | 214 |
| 222 // Update the selection status of all LayoutObjects between |start| and |end|. | 215 // Update the selection status of all LayoutObjects between |start| and |end|. |
| 223 static void SetSelectionState(const SelectionPaintRange& range) { | 216 static void SetSelectionState(const SelectionPaintRange& range) { |
| 224 if (range.IsNull()) | 217 if (range.IsNull()) |
| 225 return; | 218 return; |
| 226 | 219 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 237 if (runner != range.StartLayoutObject() && | 230 if (runner != range.StartLayoutObject() && |
| 238 runner != range.EndLayoutObject() && runner->CanBeSelectionLeaf()) | 231 runner != range.EndLayoutObject() && runner->CanBeSelectionLeaf()) |
| 239 runner->SetSelectionStateIfNeeded(SelectionState::kInside); | 232 runner->SetSelectionStateIfNeeded(SelectionState::kInside); |
| 240 } | 233 } |
| 241 } | 234 } |
| 242 | 235 |
| 243 // Set SetSelectionState and ShouldInvalidateSelection flag of LayoutObjects | 236 // Set SetSelectionState and ShouldInvalidateSelection flag of LayoutObjects |
| 244 // comparing them in |new_range| and |old_range|. | 237 // comparing them in |new_range| and |old_range|. |
| 245 static void UpdateLayoutObjectState(const SelectionPaintRange& new_range, | 238 static void UpdateLayoutObjectState(const SelectionPaintRange& new_range, |
| 246 const SelectionPaintRange& old_range) { | 239 const SelectionPaintRange& old_range) { |
| 247 SelectedMap old_selected_map = | 240 SelectedMap old_selected_map = CollectSelectedMap(old_range); |
|
yosin_UTC9
2017/06/14 04:01:15
nit: s/SelectedMap/const SelectedMap&/
| |
| 248 CollectSelectedMap(old_range, CollectSelectedMapOption::kCollectBlock); | |
| 249 | 241 |
| 250 // Now clear the selection. | 242 // Now clear the selection. |
| 251 for (auto layout_object : old_selected_map.object_map.Keys()) | 243 for (auto layout_object : old_selected_map.object_map.Keys()) |
| 252 layout_object->SetSelectionStateIfNeeded(SelectionState::kNone); | 244 layout_object->SetSelectionStateIfNeeded(SelectionState::kNone); |
| 253 | 245 |
| 254 SetSelectionState(new_range); | 246 SetSelectionState(new_range); |
| 255 | 247 |
| 256 // Now that the selection state has been updated for the new objects, walk | 248 // Now that the selection state has been updated for the new objects, walk |
| 257 // them again and put them in the new objects list. | 249 // them again and put them in the new objects list. |
| 258 // TODO(editing-dev): |new_selected_map| doesn't really need to store the | 250 // 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 | 251 // SelectionState, it's just more convenient to have it use the same data |
| 260 // structure as |old_selected_map|. | 252 // structure as |old_selected_map|. |
| 261 SelectedMap new_selected_map = | 253 SelectedMap new_selected_map = CollectSelectedMap(new_range); |
|
yosin_UTC9
2017/06/14 04:01:15
nit: s/SelectedMap/const SelectedMap&/
| |
| 262 CollectSelectedMap(new_range, CollectSelectedMapOption::kCollectBlock); | |
| 263 | 254 |
| 264 // Have any of the old selected objects changed compared to the new selection? | 255 // Have any of the old selected objects changed compared to the new selection? |
| 265 for (const auto& pair : old_selected_map.object_map) { | 256 for (const auto& pair : old_selected_map.object_map) { |
| 266 LayoutObject* obj = pair.key; | 257 LayoutObject* obj = pair.key; |
| 267 SelectionState new_selection_state = obj->GetSelectionState(); | 258 SelectionState new_selection_state = obj->GetSelectionState(); |
| 268 SelectionState old_selection_state = pair.value; | 259 SelectionState old_selection_state = pair.value; |
| 269 if (new_selection_state != old_selection_state || | 260 if (new_selection_state != old_selection_state || |
| 270 (new_range.StartLayoutObject() == obj && | 261 (new_range.StartLayoutObject() == obj && |
| 271 new_range.StartOffset() != old_range.StartOffset()) || | 262 new_range.StartOffset() != old_range.StartOffset()) || |
| 272 (new_range.EndLayoutObject() == obj && | 263 (new_range.EndLayoutObject() == obj && |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 void LayoutSelection::ClearSelection() { | 299 void LayoutSelection::ClearSelection() { |
| 309 // For querying Layer::compositingState() | 300 // For querying Layer::compositingState() |
| 310 // This is correct, since destroying layout objects needs to cause eager paint | 301 // This is correct, since destroying layout objects needs to cause eager paint |
| 311 // invalidations. | 302 // invalidations. |
| 312 DisableCompositingQueryAsserts disabler; | 303 DisableCompositingQueryAsserts disabler; |
| 313 | 304 |
| 314 // Just return if the selection is already empty. | 305 // Just return if the selection is already empty. |
| 315 if (paint_range_.IsNull()) | 306 if (paint_range_.IsNull()) |
| 316 return; | 307 return; |
| 317 | 308 |
| 318 const SelectedMap& old_selected_map = CollectSelectedMap( | 309 for (auto layout_object : paint_range_) { |
| 319 paint_range_, CollectSelectedMapOption::kNotCollectBlock); | |
| 320 // Clear SelectionState and invalidation. | |
| 321 // TODO(yoichio): Iterate with *this directrly. | |
| 322 for (auto layout_object : old_selected_map.object_map.Keys()) { | |
| 323 const SelectionState old_state = layout_object->GetSelectionState(); | 310 const SelectionState old_state = layout_object->GetSelectionState(); |
| 324 layout_object->SetSelectionStateIfNeeded(SelectionState::kNone); | 311 layout_object->SetSelectionStateIfNeeded(SelectionState::kNone); |
| 325 if (layout_object->GetSelectionState() == old_state) | 312 if (layout_object->GetSelectionState() == old_state) |
| 326 continue; | 313 continue; |
| 327 layout_object->SetShouldInvalidateSelection(); | 314 layout_object->SetShouldInvalidateSelection(); |
| 328 } | 315 } |
| 329 | 316 |
| 330 // Reset selection. | 317 // Reset selection. |
| 331 paint_range_ = SelectionPaintRange(); | 318 paint_range_ = SelectionPaintRange(); |
| 332 } | 319 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 | 449 |
| 463 runner->SetShouldInvalidateSelection(); | 450 runner->SetShouldInvalidateSelection(); |
| 464 } | 451 } |
| 465 } | 452 } |
| 466 | 453 |
| 467 DEFINE_TRACE(LayoutSelection) { | 454 DEFINE_TRACE(LayoutSelection) { |
| 468 visitor->Trace(frame_selection_); | 455 visitor->Trace(frame_selection_); |
| 469 } | 456 } |
| 470 | 457 |
| 471 } // namespace blink | 458 } // namespace blink |
| OLD | NEW |