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 17 matching lines...) Expand all Loading... |
28 #include "core/editing/VisibleUnits.h" | 28 #include "core/editing/VisibleUnits.h" |
29 #include "core/html/TextControlElement.h" | 29 #include "core/html/TextControlElement.h" |
30 #include "core/layout/LayoutView.h" | 30 #include "core/layout/LayoutView.h" |
31 #include "core/paint/PaintLayer.h" | 31 #include "core/paint/PaintLayer.h" |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
35 LayoutSelection::LayoutSelection(FrameSelection& frame_selection) | 35 LayoutSelection::LayoutSelection(FrameSelection& frame_selection) |
36 : frame_selection_(&frame_selection), | 36 : frame_selection_(&frame_selection), |
37 has_pending_selection_(false), | 37 has_pending_selection_(false), |
| 38 force_hide_(false), |
38 selection_start_(nullptr), | 39 selection_start_(nullptr), |
39 selection_end_(nullptr), | 40 selection_end_(nullptr), |
40 selection_start_pos_(-1), | 41 selection_start_pos_(-1), |
41 selection_end_pos_(-1) {} | 42 selection_end_pos_(-1) {} |
42 | 43 |
43 const VisibleSelection& LayoutSelection::GetVisibleSelection() const { | 44 const VisibleSelection& LayoutSelection::GetVisibleSelection() const { |
44 return frame_selection_->ComputeVisibleSelectionInDOMTree(); | 45 return frame_selection_->ComputeVisibleSelectionInDOMTree(); |
45 } | 46 } |
46 | 47 |
47 static bool IsSelectionInDocument( | 48 static bool IsSelectionInDocument( |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 331 |
331 void LayoutSelection::ClearSelection() { | 332 void LayoutSelection::ClearSelection() { |
332 // For querying Layer::compositingState() | 333 // For querying Layer::compositingState() |
333 // This is correct, since destroying layout objects needs to cause eager paint | 334 // This is correct, since destroying layout objects needs to cause eager paint |
334 // invalidations. | 335 // invalidations. |
335 DisableCompositingQueryAsserts disabler; | 336 DisableCompositingQueryAsserts disabler; |
336 | 337 |
337 SetSelection(0, -1, 0, -1, kPaintInvalidationNewMinusOld); | 338 SetSelection(0, -1, 0, -1, kPaintInvalidationNewMinusOld); |
338 } | 339 } |
339 | 340 |
| 341 void LayoutSelection::SetHasPendingSelection(PaintHint hint) { |
| 342 has_pending_selection_ = true; |
| 343 if (hint == PaintHint::kHide) |
| 344 force_hide_ = true; |
| 345 else if (hint == PaintHint::kPaint) |
| 346 force_hide_ = false; |
| 347 } |
| 348 |
340 void LayoutSelection::Commit(LayoutView& layout_view) { | 349 void LayoutSelection::Commit(LayoutView& layout_view) { |
341 if (!HasPendingSelection()) | 350 if (!HasPendingSelection()) |
342 return; | 351 return; |
343 DCHECK(!layout_view.NeedsLayout()); | 352 DCHECK(!layout_view.NeedsLayout()); |
344 has_pending_selection_ = false; | 353 has_pending_selection_ = false; |
345 | 354 |
346 const VisibleSelectionInFlatTree& original_selection = | 355 const VisibleSelectionInFlatTree& original_selection = |
347 frame_selection_->ComputeVisibleSelectionInFlatTree(); | 356 frame_selection_->ComputeVisibleSelectionInFlatTree(); |
348 | 357 |
349 // Skip if pending VisibilePositions became invalid before we reach here. | 358 // Skip if pending VisibilePositions became invalid before we reach here. |
350 if (!IsSelectionInDocument(original_selection, layout_view.GetDocument())) | 359 if (!IsSelectionInDocument(original_selection, layout_view.GetDocument())) |
351 return; | 360 return; |
352 | 361 |
353 // Construct a new VisibleSolution, since visibleSelection() is not | 362 // Construct a new VisibleSolution, since visibleSelection() is not |
354 // necessarily valid, and the following steps assume a valid selection. See | 363 // necessarily valid, and the following steps assume a valid selection. See |
355 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and | 364 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and |
356 // <rdar://problem/10232866>. | 365 // <rdar://problem/10232866>. |
357 const VisibleSelectionInFlatTree& selection = | 366 const VisibleSelectionInFlatTree& selection = |
358 CreateVisibleSelection(CalcVisibleSelection(original_selection)); | 367 CreateVisibleSelection(CalcVisibleSelection(original_selection)); |
359 | 368 |
360 if (!selection.IsRange()) { | 369 if (!selection.IsRange() || force_hide_) { |
361 ClearSelection(); | 370 ClearSelection(); |
362 return; | 371 return; |
363 } | 372 } |
364 | 373 |
365 // Use the rightmost candidate for the start of the selection, and the | 374 // Use the rightmost candidate for the start of the selection, and the |
366 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. | 375 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. |
367 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. | 376 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. |
368 // If we pass [foo, 3] as the start of the selection, the selection painting | 377 // If we pass [foo, 3] as the start of the selection, the selection painting |
369 // code will think that content on the line containing 'foo' is selected | 378 // code will think that content on the line containing 'foo' is selected |
370 // and will fill the gap before 'bar'. | 379 // and will fill the gap before 'bar'. |
(...skipping 18 matching lines...) Expand all Loading... |
389 if (!start_layout_object || !end_layout_object) | 398 if (!start_layout_object || !end_layout_object) |
390 return; | 399 return; |
391 DCHECK(layout_view == start_layout_object->View()); | 400 DCHECK(layout_view == start_layout_object->View()); |
392 DCHECK(layout_view == end_layout_object->View()); | 401 DCHECK(layout_view == end_layout_object->View()); |
393 SetSelection(start_layout_object, start_pos.ComputeEditingOffset(), | 402 SetSelection(start_layout_object, start_pos.ComputeEditingOffset(), |
394 end_layout_object, end_pos.ComputeEditingOffset()); | 403 end_layout_object, end_pos.ComputeEditingOffset()); |
395 } | 404 } |
396 | 405 |
397 void LayoutSelection::OnDocumentShutdown() { | 406 void LayoutSelection::OnDocumentShutdown() { |
398 has_pending_selection_ = false; | 407 has_pending_selection_ = false; |
| 408 force_hide_ = false; |
399 selection_start_ = nullptr; | 409 selection_start_ = nullptr; |
400 selection_end_ = nullptr; | 410 selection_end_ = nullptr; |
401 selection_start_pos_ = -1; | 411 selection_start_pos_ = -1; |
402 selection_end_pos_ = -1; | 412 selection_end_pos_ = -1; |
403 } | 413 } |
404 | 414 |
405 static LayoutRect SelectionRectForLayoutObject(const LayoutObject* object) { | 415 static LayoutRect SelectionRectForLayoutObject(const LayoutObject* object) { |
406 if (!object->IsRooted()) | 416 if (!object->IsRooted()) |
407 return LayoutRect(); | 417 return LayoutRect(); |
408 | 418 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 470 |
461 o->SetShouldInvalidateSelection(); | 471 o->SetShouldInvalidateSelection(); |
462 } | 472 } |
463 } | 473 } |
464 | 474 |
465 DEFINE_TRACE(LayoutSelection) { | 475 DEFINE_TRACE(LayoutSelection) { |
466 visitor->Trace(frame_selection_); | 476 visitor->Trace(frame_selection_); |
467 } | 477 } |
468 | 478 |
469 } // namespace blink | 479 } // namespace blink |
OLD | NEW |