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); |
yosin_UTC9
2017/05/23 05:29:05
Nice! (^_^)b
| |
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 SelectedMap old_selected_map = | |
yosin_UTC9
2017/05/23 05:29:05
nit: s/SelectedMap/const SelectedMap&/
yoichio
2017/05/23 05:43:07
Done.
| |
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) | |
yosin_UTC9
2017/05/23 05:29:05
nit: early-continue style is better.
if (layoutOb
yoichio
2017/05/23 05:43:07
Done.
| |
313 layout_object->SetShouldInvalidateSelection(); | |
314 } | |
315 | |
316 // Reset selection start and end. | |
317 selection_start_ = nullptr; | |
yosin_UTC9
2017/05/23 05:29:05
Q: do you have a plan to introduce object represen
yoichio
2017/05/23 05:43:07
I consider having SelectionInFlatTree instead of h
| |
318 selection_start_pos_ = -1; | |
319 selection_end_ = nullptr; | |
320 selection_end_pos_ = -1; | |
305 } | 321 } |
306 | 322 |
307 void LayoutSelection::Commit() { | 323 void LayoutSelection::Commit() { |
308 if (!HasPendingSelection()) | 324 if (!HasPendingSelection()) |
309 return; | 325 return; |
310 has_pending_selection_ = false; | 326 has_pending_selection_ = false; |
311 | 327 |
312 const VisibleSelectionInFlatTree& original_selection = | 328 const VisibleSelectionInFlatTree& original_selection = |
313 frame_selection_->ComputeVisibleSelectionInFlatTree(); | 329 frame_selection_->ComputeVisibleSelectionInFlatTree(); |
314 | 330 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 | 437 |
422 o->SetShouldInvalidateSelection(); | 438 o->SetShouldInvalidateSelection(); |
423 } | 439 } |
424 } | 440 } |
425 | 441 |
426 DEFINE_TRACE(LayoutSelection) { | 442 DEFINE_TRACE(LayoutSelection) { |
427 visitor->Trace(frame_selection_); | 443 visitor->Trace(frame_selection_); |
428 } | 444 } |
429 | 445 |
430 } // namespace blink | 446 } // namespace blink |
OLD | NEW |