| 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 runner->SetSelectionStateIfNeeded(SelectionInside); | 206 runner->SetSelectionStateIfNeeded(SelectionInside); |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 | 209 |
| 210 void LayoutSelection::SetSelection( | 210 void LayoutSelection::SetSelection( |
| 211 LayoutObject* start, | 211 LayoutObject* start, |
| 212 int start_pos, | 212 int start_pos, |
| 213 LayoutObject* end, | 213 LayoutObject* end, |
| 214 int end_pos, | 214 int end_pos, |
| 215 SelectionPaintInvalidationMode block_paint_invalidation_mode) { | 215 SelectionPaintInvalidationMode block_paint_invalidation_mode) { |
| 216 // This code makes no assumptions as to if the layout tree is up to date or | 216 DCHECK(start); |
| 217 // not and will not try to update it. Currently clearSelection calls this | 217 DCHECK(end); |
| 218 // (intentionally) without updating the layout tree as it doesn't care. | |
| 219 // Other callers may want to force recalc style before calling this. | |
| 220 | |
| 221 // Make sure both our start and end objects are defined. | |
| 222 // Check www.msnbc.com and try clicking around to find the case where this | |
| 223 // happened. | |
| 224 if ((start && !end) || (end && !start)) | |
| 225 return; | |
| 226 | 218 |
| 227 // Just return if the selection hasn't changed. | 219 // Just return if the selection hasn't changed. |
| 228 if (selection_start_ == start && selection_start_pos_ == start_pos && | 220 if (selection_start_ == start && selection_start_pos_ == start_pos && |
| 229 selection_end_ == end && selection_end_pos_ == end_pos) | 221 selection_end_ == end && selection_end_pos_ == end_pos) |
| 230 return; | 222 return; |
| 231 | 223 |
| 232 DCHECK(frame_selection_->GetDocument().GetLayoutView()->GetFrameView()); | 224 DCHECK(frame_selection_->GetDocument().GetLayoutView()->GetFrameView()); |
| 225 DCHECK(!frame_selection_->GetDocument().NeedsLayoutTreeUpdate()); |
| 233 | 226 |
| 234 SelectedMap old_selected_map = | 227 SelectedMap old_selected_map = |
| 235 CollectSelectedMap(selection_start_, selection_end_, selection_end_pos_, | 228 CollectSelectedMap(selection_start_, selection_end_, selection_end_pos_, |
| 236 block_paint_invalidation_mode); | 229 block_paint_invalidation_mode); |
| 237 | 230 |
| 238 // Now clear the selection. | 231 // Now clear the selection. |
| 239 for (auto layout_object : old_selected_map.object_map.Keys()) | 232 for (auto layout_object : old_selected_map.object_map.Keys()) |
| 240 layout_object->SetSelectionStateIfNeeded(SelectionNone); | 233 layout_object->SetSelectionStateIfNeeded(SelectionNone); |
| 241 | 234 |
| 242 SetSelectionState(start, end, end_pos); | 235 SetSelectionState(start, end, end_pos); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 Commit(); | 287 Commit(); |
| 295 return std::make_pair(selection_start_pos_, selection_end_pos_); | 288 return std::make_pair(selection_start_pos_, selection_end_pos_); |
| 296 } | 289 } |
| 297 | 290 |
| 298 void LayoutSelection::ClearSelection() { | 291 void LayoutSelection::ClearSelection() { |
| 299 // For querying Layer::compositingState() | 292 // For querying Layer::compositingState() |
| 300 // This is correct, since destroying layout objects needs to cause eager paint | 293 // This is correct, since destroying layout objects needs to cause eager paint |
| 301 // invalidations. | 294 // invalidations. |
| 302 DisableCompositingQueryAsserts disabler; | 295 DisableCompositingQueryAsserts disabler; |
| 303 | 296 |
| 304 SetSelection(0, -1, 0, -1, kPaintInvalidationNewMinusOld); | 297 // Just return if the selection hasn't changed. |
| 298 if (!selection_start_) { |
| 299 DCHECK_EQ(selection_end_, nullptr); |
| 300 DCHECK_EQ(selection_start_pos_, -1); |
| 301 DCHECK_EQ(selection_end_pos_, -1); |
| 302 return; |
| 303 } |
| 304 |
| 305 const SelectedMap& old_selected_map = |
| 306 CollectSelectedMap(selection_start_, selection_end_, selection_end_pos_, |
| 307 kPaintInvalidationNewMinusOld); |
| 308 // Clear SelectionState and invalidation. |
| 309 for (auto layout_object : old_selected_map.object_map.Keys()) { |
| 310 const SelectionState old_state = layout_object->GetSelectionState(); |
| 311 layout_object->SetSelectionStateIfNeeded(SelectionNone); |
| 312 if (layout_object->GetSelectionState() == old_state) |
| 313 continue; |
| 314 layout_object->SetShouldInvalidateSelection(); |
| 315 } |
| 316 |
| 317 // Reset selection start and end. |
| 318 selection_start_ = nullptr; |
| 319 selection_start_pos_ = -1; |
| 320 selection_end_ = nullptr; |
| 321 selection_end_pos_ = -1; |
| 305 } | 322 } |
| 306 | 323 |
| 307 void LayoutSelection::Commit() { | 324 void LayoutSelection::Commit() { |
| 308 if (!HasPendingSelection()) | 325 if (!HasPendingSelection()) |
| 309 return; | 326 return; |
| 310 has_pending_selection_ = false; | 327 has_pending_selection_ = false; |
| 311 | 328 |
| 312 const VisibleSelectionInFlatTree& original_selection = | 329 const VisibleSelectionInFlatTree& original_selection = |
| 313 frame_selection_->ComputeVisibleSelectionInFlatTree(); | 330 frame_selection_->ComputeVisibleSelectionInFlatTree(); |
| 314 | 331 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 438 |
| 422 o->SetShouldInvalidateSelection(); | 439 o->SetShouldInvalidateSelection(); |
| 423 } | 440 } |
| 424 } | 441 } |
| 425 | 442 |
| 426 DEFINE_TRACE(LayoutSelection) { | 443 DEFINE_TRACE(LayoutSelection) { |
| 427 visitor->Trace(frame_selection_); | 444 visitor->Trace(frame_selection_); |
| 428 } | 445 } |
| 429 | 446 |
| 430 } // namespace blink | 447 } // namespace blink |
| OLD | NEW |