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