| 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), | |
| 39 selection_start_(nullptr), | 38 selection_start_(nullptr), |
| 40 selection_end_(nullptr), | 39 selection_end_(nullptr), |
| 41 selection_start_pos_(-1), | 40 selection_start_pos_(-1), |
| 42 selection_end_pos_(-1) {} | 41 selection_end_pos_(-1) {} |
| 43 | 42 |
| 44 SelectionInFlatTree LayoutSelection::CalcVisibleSelection( | 43 SelectionInFlatTree LayoutSelection::CalcVisibleSelection( |
| 45 const VisibleSelectionInFlatTree& original_selection) const { | 44 const VisibleSelectionInFlatTree& original_selection) const { |
| 46 const PositionInFlatTree& start = original_selection.Start(); | 45 const PositionInFlatTree& start = original_selection.Start(); |
| 47 const PositionInFlatTree& end = original_selection.end(); | 46 const PositionInFlatTree& end = original_selection.end(); |
| 48 SelectionType selection_type = original_selection.GetSelectionType(); | 47 SelectionType selection_type = original_selection.GetSelectionType(); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 308 |
| 310 void LayoutSelection::ClearSelection() { | 309 void LayoutSelection::ClearSelection() { |
| 311 // For querying Layer::compositingState() | 310 // For querying Layer::compositingState() |
| 312 // This is correct, since destroying layout objects needs to cause eager paint | 311 // This is correct, since destroying layout objects needs to cause eager paint |
| 313 // invalidations. | 312 // invalidations. |
| 314 DisableCompositingQueryAsserts disabler; | 313 DisableCompositingQueryAsserts disabler; |
| 315 | 314 |
| 316 SetSelection(0, -1, 0, -1, kPaintInvalidationNewMinusOld); | 315 SetSelection(0, -1, 0, -1, kPaintInvalidationNewMinusOld); |
| 317 } | 316 } |
| 318 | 317 |
| 319 void LayoutSelection::SetHasPendingSelection(PaintHint hint) { | |
| 320 has_pending_selection_ = true; | |
| 321 if (hint == PaintHint::kHide) | |
| 322 force_hide_ = true; | |
| 323 else if (hint == PaintHint::kPaint) | |
| 324 force_hide_ = false; | |
| 325 } | |
| 326 | |
| 327 void LayoutSelection::Commit() { | 318 void LayoutSelection::Commit() { |
| 328 if (!HasPendingSelection()) | 319 if (!HasPendingSelection()) |
| 329 return; | 320 return; |
| 330 has_pending_selection_ = false; | 321 has_pending_selection_ = false; |
| 331 | 322 |
| 332 const VisibleSelectionInFlatTree& original_selection = | 323 const VisibleSelectionInFlatTree& original_selection = |
| 333 frame_selection_->ComputeVisibleSelectionInFlatTree(); | 324 frame_selection_->ComputeVisibleSelectionInFlatTree(); |
| 334 | 325 |
| 335 // Construct a new VisibleSolution, since visibleSelection() is not | 326 // Construct a new VisibleSolution, since visibleSelection() is not |
| 336 // necessarily valid, and the following steps assume a valid selection. See | 327 // necessarily valid, and the following steps assume a valid selection. See |
| 337 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and | 328 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and |
| 338 // <rdar://problem/10232866>. | 329 // <rdar://problem/10232866>. |
| 339 const VisibleSelectionInFlatTree& selection = | 330 const VisibleSelectionInFlatTree& selection = |
| 340 CreateVisibleSelection(CalcVisibleSelection(original_selection)); | 331 CreateVisibleSelection(CalcVisibleSelection(original_selection)); |
| 341 | 332 |
| 342 if (!selection.IsRange() || force_hide_) { | 333 if (!selection.IsRange() || frame_selection_->IsHidden()) { |
| 343 ClearSelection(); | 334 ClearSelection(); |
| 344 return; | 335 return; |
| 345 } | 336 } |
| 346 | 337 |
| 347 // Use the rightmost candidate for the start of the selection, and the | 338 // Use the rightmost candidate for the start of the selection, and the |
| 348 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. | 339 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. |
| 349 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. | 340 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. |
| 350 // If we pass [foo, 3] as the start of the selection, the selection painting | 341 // If we pass [foo, 3] as the start of the selection, the selection painting |
| 351 // code will think that content on the line containing 'foo' is selected | 342 // code will think that content on the line containing 'foo' is selected |
| 352 // and will fill the gap before 'bar'. | 343 // and will fill the gap before 'bar'. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 370 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject(); | 361 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject(); |
| 371 if (!start_layout_object || !end_layout_object) | 362 if (!start_layout_object || !end_layout_object) |
| 372 return; | 363 return; |
| 373 DCHECK(start_layout_object->View() == end_layout_object->View()); | 364 DCHECK(start_layout_object->View() == end_layout_object->View()); |
| 374 SetSelection(start_layout_object, start_pos.ComputeEditingOffset(), | 365 SetSelection(start_layout_object, start_pos.ComputeEditingOffset(), |
| 375 end_layout_object, end_pos.ComputeEditingOffset()); | 366 end_layout_object, end_pos.ComputeEditingOffset()); |
| 376 } | 367 } |
| 377 | 368 |
| 378 void LayoutSelection::OnDocumentShutdown() { | 369 void LayoutSelection::OnDocumentShutdown() { |
| 379 has_pending_selection_ = false; | 370 has_pending_selection_ = false; |
| 380 force_hide_ = false; | |
| 381 selection_start_ = nullptr; | 371 selection_start_ = nullptr; |
| 382 selection_end_ = nullptr; | 372 selection_end_ = nullptr; |
| 383 selection_start_pos_ = -1; | 373 selection_start_pos_ = -1; |
| 384 selection_end_pos_ = -1; | 374 selection_end_pos_ = -1; |
| 385 } | 375 } |
| 386 | 376 |
| 387 static LayoutRect SelectionRectForLayoutObject(const LayoutObject* object) { | 377 static LayoutRect SelectionRectForLayoutObject(const LayoutObject* object) { |
| 388 if (!object->IsRooted()) | 378 if (!object->IsRooted()) |
| 389 return LayoutRect(); | 379 return LayoutRect(); |
| 390 | 380 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 432 |
| 443 o->SetShouldInvalidateSelection(); | 433 o->SetShouldInvalidateSelection(); |
| 444 } | 434 } |
| 445 } | 435 } |
| 446 | 436 |
| 447 DEFINE_TRACE(LayoutSelection) { | 437 DEFINE_TRACE(LayoutSelection) { |
| 448 visitor->Trace(frame_selection_); | 438 visitor->Trace(frame_selection_); |
| 449 } | 439 } |
| 450 | 440 |
| 451 } // namespace blink | 441 } // namespace blink |
| OLD | NEW |