Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 #include "core/dom/Document.h" | 24 #include "core/dom/Document.h" |
| 25 #include "core/editing/EditingUtilities.h" | 25 #include "core/editing/EditingUtilities.h" |
| 26 #include "core/editing/FrameSelection.h" | 26 #include "core/editing/FrameSelection.h" |
| 27 #include "core/editing/VisiblePosition.h" | 27 #include "core/editing/VisiblePosition.h" |
| 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 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 LayoutSelection::LayoutSelection(FrameSelection& frame_selection) | 34 LayoutSelection::LayoutSelection(FrameSelection& frameSelection) |
|
dcheng
2017/04/11 06:29:14
Nit: mind fixing the name to be frame_selection?
yoichio
2017/04/11 07:23:58
Done.
| |
| 35 : frame_selection_(&frame_selection), has_pending_selection_(false) {} | 35 : frame_selection_(&frameSelection), |
| 36 has_pending_selection_(false), | |
| 37 selection_start_(nullptr), | |
| 38 selection_end_(nullptr), | |
| 39 selection_start_pos_(-1), | |
| 40 selection_end_pos_(-1) {} | |
| 36 | 41 |
| 37 const VisibleSelection& LayoutSelection::GetVisibleSelection() const { | 42 const VisibleSelection& LayoutSelection::GetVisibleSelection() const { |
| 38 return frame_selection_->ComputeVisibleSelectionInDOMTree(); | 43 return frame_selection_->ComputeVisibleSelectionInDOMTree(); |
| 39 } | 44 } |
| 40 | 45 |
| 41 static bool IsSelectionInDocument( | 46 static bool IsSelectionInDocument( |
| 42 const VisibleSelectionInFlatTree& visible_selection, | 47 const VisibleSelectionInFlatTree& visible_selection, |
| 43 const Document& document) { | 48 const Document& document) { |
| 44 const PositionInFlatTree& start = visible_selection.Start(); | 49 const PositionInFlatTree& start = visible_selection.Start(); |
| 45 if (start.IsNotNull() && | 50 if (start.IsNotNull() && |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 return; | 125 return; |
| 121 | 126 |
| 122 // Construct a new VisibleSolution, since visibleSelection() is not | 127 // Construct a new VisibleSolution, since visibleSelection() is not |
| 123 // necessarily valid, and the following steps assume a valid selection. See | 128 // necessarily valid, and the following steps assume a valid selection. See |
| 124 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and | 129 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and |
| 125 // <rdar://problem/10232866>. | 130 // <rdar://problem/10232866>. |
| 126 const VisibleSelectionInFlatTree& selection = | 131 const VisibleSelectionInFlatTree& selection = |
| 127 CreateVisibleSelection(CalcVisibleSelection(original_selection)); | 132 CreateVisibleSelection(CalcVisibleSelection(original_selection)); |
| 128 | 133 |
| 129 if (!selection.IsRange()) { | 134 if (!selection.IsRange()) { |
| 130 layout_view.ClearSelection(); | 135 ClearSelection(); |
| 131 return; | 136 return; |
| 132 } | 137 } |
| 133 | 138 |
| 134 // Use the rightmost candidate for the start of the selection, and the | 139 // Use the rightmost candidate for the start of the selection, and the |
| 135 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. | 140 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. |
| 136 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. | 141 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. |
| 137 // If we pass [foo, 3] as the start of the selection, the selection painting | 142 // If we pass [foo, 3] as the start of the selection, the selection painting |
| 138 // code will think that content on the line containing 'foo' is selected | 143 // code will think that content on the line containing 'foo' is selected |
| 139 // and will fill the gap before 'bar'. | 144 // and will fill the gap before 'bar'. |
| 140 PositionInFlatTree start_pos = selection.Start(); | 145 PositionInFlatTree start_pos = selection.Start(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 152 if (start_pos.IsNull() || end_pos.IsNull() || | 157 if (start_pos.IsNull() || end_pos.IsNull() || |
| 153 selection.VisibleStart().DeepEquivalent() == | 158 selection.VisibleStart().DeepEquivalent() == |
| 154 selection.VisibleEnd().DeepEquivalent()) | 159 selection.VisibleEnd().DeepEquivalent()) |
| 155 return; | 160 return; |
| 156 LayoutObject* start_layout_object = start_pos.AnchorNode()->GetLayoutObject(); | 161 LayoutObject* start_layout_object = start_pos.AnchorNode()->GetLayoutObject(); |
| 157 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject(); | 162 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject(); |
| 158 if (!start_layout_object || !end_layout_object) | 163 if (!start_layout_object || !end_layout_object) |
| 159 return; | 164 return; |
| 160 DCHECK(layout_view == start_layout_object->View()); | 165 DCHECK(layout_view == start_layout_object->View()); |
| 161 DCHECK(layout_view == end_layout_object->View()); | 166 DCHECK(layout_view == end_layout_object->View()); |
| 162 layout_view.SetSelection(start_layout_object, | 167 SetSelection(start_layout_object, start_pos.ComputeEditingOffset(), |
| 163 start_pos.ComputeEditingOffset(), end_layout_object, | 168 end_layout_object, end_pos.ComputeEditingOffset()); |
| 164 end_pos.ComputeEditingOffset()); | 169 } |
| 170 | |
| 171 void LayoutSelection::OnDocumentShutdown() { | |
| 172 has_pending_selection_ = false; | |
| 173 selection_start_ = nullptr; | |
| 174 selection_end_ = nullptr; | |
| 175 selection_start_pos_ = -1; | |
| 176 selection_end_pos_ = -1; | |
| 165 } | 177 } |
| 166 | 178 |
| 167 DEFINE_TRACE(LayoutSelection) { | 179 DEFINE_TRACE(LayoutSelection) { |
| 168 visitor->Trace(frame_selection_); | 180 visitor->Trace(frame_selection_); |
| 169 } | 181 } |
| 170 | 182 |
| 171 } // namespace blink | 183 } // namespace blink |
| OLD | NEW |