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 16 matching lines...) Expand all Loading... | |
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& frame_selection) |
35 : frame_selection_(&frame_selection), | 35 : frame_selection_(&frame_selection), |
36 has_pending_selection_(false), | 36 has_pending_selection_(false), |
37 force_hide_(false), | |
37 selection_start_(nullptr), | 38 selection_start_(nullptr), |
38 selection_end_(nullptr), | 39 selection_end_(nullptr), |
39 selection_start_pos_(-1), | 40 selection_start_pos_(-1), |
40 selection_end_pos_(-1) {} | 41 selection_end_pos_(-1) {} |
41 | 42 |
42 const VisibleSelection& LayoutSelection::GetVisibleSelection() const { | 43 const VisibleSelection& LayoutSelection::GetVisibleSelection() const { |
43 return frame_selection_->ComputeVisibleSelectionInDOMTree(); | 44 return frame_selection_->ComputeVisibleSelectionInDOMTree(); |
44 } | 45 } |
45 | 46 |
46 static bool IsSelectionInDocument( | 47 static bool IsSelectionInDocument( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 ? TextAffinity::kUpstream | 105 ? TextAffinity::kUpstream |
105 : affinity); | 106 : affinity); |
106 if (visible_end.IsNull()) | 107 if (visible_end.IsNull()) |
107 return SelectionInFlatTree(); | 108 return SelectionInFlatTree(); |
108 SelectionInFlatTree::Builder builder; | 109 SelectionInFlatTree::Builder builder; |
109 builder.Collapse(visible_start.ToPositionWithAffinity()); | 110 builder.Collapse(visible_start.ToPositionWithAffinity()); |
110 builder.Extend(visible_end.DeepEquivalent()); | 111 builder.Extend(visible_end.DeepEquivalent()); |
111 return builder.Build(); | 112 return builder.Build(); |
112 } | 113 } |
113 | 114 |
115 void LayoutSelection::SetHasPendingSelection(PaintHint hint) { | |
116 has_pending_selection_ = true; | |
117 if (hint == PaintHint::kHide) | |
yosin_UTC9
2017/04/13 09:31:50
How about
if (hint == PaintHint::kKeep)
return;
hugoh_UTC2
2017/04/14 01:34:47
Acknowledged. Semantically the same so this is a m
yosin_UTC9
2017/04/14 02:29:16
Blink prefers early-return style, though.
| |
118 force_hide_ = true; | |
119 else if (hint == PaintHint::kPaint) | |
120 force_hide_ = false; | |
121 } | |
122 | |
114 void LayoutSelection::Commit(LayoutView& layout_view) { | 123 void LayoutSelection::Commit(LayoutView& layout_view) { |
115 if (!HasPendingSelection()) | 124 if (!HasPendingSelection()) |
116 return; | 125 return; |
117 DCHECK(!layout_view.NeedsLayout()); | 126 DCHECK(!layout_view.NeedsLayout()); |
118 has_pending_selection_ = false; | 127 has_pending_selection_ = false; |
119 | 128 |
120 const VisibleSelectionInFlatTree& original_selection = | 129 const VisibleSelectionInFlatTree& original_selection = |
121 frame_selection_->ComputeVisibleSelectionInFlatTree(); | 130 frame_selection_->ComputeVisibleSelectionInFlatTree(); |
122 | 131 |
123 // Skip if pending VisibilePositions became invalid before we reach here. | 132 // Skip if pending VisibilePositions became invalid before we reach here. |
124 if (!IsSelectionInDocument(original_selection, layout_view.GetDocument())) | 133 if (!IsSelectionInDocument(original_selection, layout_view.GetDocument())) |
125 return; | 134 return; |
126 | 135 |
127 // Construct a new VisibleSolution, since visibleSelection() is not | 136 // Construct a new VisibleSolution, since visibleSelection() is not |
128 // necessarily valid, and the following steps assume a valid selection. See | 137 // necessarily valid, and the following steps assume a valid selection. See |
129 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and | 138 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and |
130 // <rdar://problem/10232866>. | 139 // <rdar://problem/10232866>. |
131 const VisibleSelectionInFlatTree& selection = | 140 const VisibleSelectionInFlatTree& selection = |
132 CreateVisibleSelection(CalcVisibleSelection(original_selection)); | 141 CreateVisibleSelection(CalcVisibleSelection(original_selection)); |
133 | 142 |
134 if (!selection.IsRange()) { | 143 if (!selection.IsRange() || force_hide_) { |
135 ClearSelection(); | 144 ClearSelection(); |
136 return; | 145 return; |
137 } | 146 } |
138 | 147 |
139 // Use the rightmost candidate for the start of the selection, and the | 148 // Use the rightmost candidate for the start of the selection, and the |
140 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. | 149 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. |
141 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. | 150 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. |
142 // If we pass [foo, 3] as the start of the selection, the selection painting | 151 // If we pass [foo, 3] as the start of the selection, the selection painting |
143 // code will think that content on the line containing 'foo' is selected | 152 // code will think that content on the line containing 'foo' is selected |
144 // and will fill the gap before 'bar'. | 153 // and will fill the gap before 'bar'. |
(...skipping 18 matching lines...) Expand all Loading... | |
163 if (!start_layout_object || !end_layout_object) | 172 if (!start_layout_object || !end_layout_object) |
164 return; | 173 return; |
165 DCHECK(layout_view == start_layout_object->View()); | 174 DCHECK(layout_view == start_layout_object->View()); |
166 DCHECK(layout_view == end_layout_object->View()); | 175 DCHECK(layout_view == end_layout_object->View()); |
167 SetSelection(start_layout_object, start_pos.ComputeEditingOffset(), | 176 SetSelection(start_layout_object, start_pos.ComputeEditingOffset(), |
168 end_layout_object, end_pos.ComputeEditingOffset()); | 177 end_layout_object, end_pos.ComputeEditingOffset()); |
169 } | 178 } |
170 | 179 |
171 void LayoutSelection::OnDocumentShutdown() { | 180 void LayoutSelection::OnDocumentShutdown() { |
172 has_pending_selection_ = false; | 181 has_pending_selection_ = false; |
182 force_hide_ = false; | |
173 selection_start_ = nullptr; | 183 selection_start_ = nullptr; |
174 selection_end_ = nullptr; | 184 selection_end_ = nullptr; |
175 selection_start_pos_ = -1; | 185 selection_start_pos_ = -1; |
176 selection_end_pos_ = -1; | 186 selection_end_pos_ = -1; |
177 } | 187 } |
178 | 188 |
179 DEFINE_TRACE(LayoutSelection) { | 189 DEFINE_TRACE(LayoutSelection) { |
180 visitor->Trace(frame_selection_); | 190 visitor->Trace(frame_selection_); |
181 } | 191 } |
182 | 192 |
183 } // namespace blink | 193 } // namespace blink |
OLD | NEW |