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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 } | 126 } |
127 | 127 |
128 // Objects each have a single selection rect to examine. | 128 // Objects each have a single selection rect to examine. |
129 using SelectedObjectMap = HashMap<LayoutObject*, SelectionState>; | 129 using SelectedObjectMap = HashMap<LayoutObject*, SelectionState>; |
130 // Blocks contain selected objects and fill gaps between them, either on the | 130 // Blocks contain selected objects and fill gaps between them, either on the |
131 // left, right, or in between lines and blocks. | 131 // left, right, or in between lines and blocks. |
132 // In order to get the visual rect right, we have to examine left, middle, and | 132 // In order to get the visual rect right, we have to examine left, middle, and |
133 // right rects individually, since otherwise the union of those rects might | 133 // right rects individually, since otherwise the union of those rects might |
134 // remain the same even when changes have occurred. | 134 // remain the same even when changes have occurred. |
135 using SelectedBlockMap = HashMap<LayoutBlock*, SelectionState>; | 135 using SelectedBlockMap = HashMap<LayoutBlock*, SelectionState>; |
136 using SelectedMap = std::pair<SelectedObjectMap, SelectedBlockMap>; | 136 struct SelectedMap { |
137 STACK_ALLOCATED(); | |
138 | |
139 SelectedMap() {} | |
140 SelectedMap(SelectedMap&& other) { | |
141 swap(first, other.first); | |
yosin_UTC9
2017/05/12 02:09:45
nit: s/swap/std::swap/
or
|first = std::move(other
yoichio
2017/05/12 04:37:39
Done.
| |
142 swap(second, other.second); | |
yosin_UTC9
2017/05/12 02:09:45
nit: s/swap/std::swap/
second = std::move(other.se
yoichio
2017/05/12 04:37:39
Done.
| |
143 } | |
144 SelectedObjectMap first; | |
yosin_UTC9
2017/05/12 02:09:45
nit: s/first/object_map/ or another instead of |fi
yoichio
2017/05/12 04:37:39
Done.
| |
145 SelectedBlockMap second; | |
yosin_UTC9
2017/05/12 02:09:45
nit: s/second/block_map/ or another instead of |se
yoichio
2017/05/12 04:37:39
Done.
| |
146 | |
147 private: | |
148 DISALLOW_COPY_AND_ASSIGN(SelectedMap); | |
149 }; | |
150 | |
151 static SelectedMap CollectSelectedMap( | |
152 LayoutObject* selection_start, | |
153 LayoutObject* selection_end, | |
154 int selection_end_pos, | |
155 LayoutSelection::SelectionPaintInvalidationMode | |
156 block_paint_invalidation_mode = | |
157 LayoutSelection::kPaintInvalidationNewXOROld) { | |
158 SelectedMap selected_map; | |
159 LayoutObject* os = selection_start; | |
yosin_UTC9
2017/05/12 02:09:45
nit: s/os/runner/ or another meaning full name.
yoichio
2017/05/12 04:37:39
Done.
| |
160 LayoutObject* stop = | |
161 LayoutObjectAfterPosition(selection_end, selection_end_pos); | |
162 bool exploring_backwards = false; | |
163 bool continue_exploring = os && (os != stop); | |
164 while (continue_exploring) { | |
165 if ((os->CanBeSelectionLeaf() || os == selection_start || | |
166 os == selection_end) && | |
167 os->GetSelectionState() != SelectionNone) { | |
168 // Blocks are responsible for painting line gaps and margin gaps. They | |
169 // must be examined as well. | |
170 selected_map.first.Set(os, os->GetSelectionState()); | |
171 if (block_paint_invalidation_mode == | |
172 LayoutSelection::kPaintInvalidationNewXOROld) { | |
173 LayoutBlock* cb = os->ContainingBlock(); | |
yosin_UTC9
2017/05/12 02:09:45
nit: s/cb/containing_block/
yoichio
2017/05/12 04:37:39
Done.
| |
174 while (cb && !cb->IsLayoutView()) { | |
175 SelectedBlockMap::AddResult result = | |
176 selected_map.second.insert(cb, cb->GetSelectionState()); | |
177 if (!result.is_new_entry) | |
178 break; | |
179 cb = cb->ContainingBlock(); | |
180 } | |
181 } | |
182 } | |
183 | |
184 os = GetNextOrPrevLayoutObjectBasedOnDirection(os, stop, continue_exploring, | |
185 exploring_backwards); | |
186 } | |
187 return selected_map; | |
188 } | |
137 | 189 |
138 void LayoutSelection::SetSelection( | 190 void LayoutSelection::SetSelection( |
139 LayoutObject* start, | 191 LayoutObject* start, |
140 int start_pos, | 192 int start_pos, |
141 LayoutObject* end, | 193 LayoutObject* end, |
142 int end_pos, | 194 int end_pos, |
143 SelectionPaintInvalidationMode block_paint_invalidation_mode) { | 195 SelectionPaintInvalidationMode block_paint_invalidation_mode) { |
144 // This code makes no assumptions as to if the layout tree is up to date or | 196 // This code makes no assumptions as to if the layout tree is up to date or |
145 // not and will not try to update it. Currently clearSelection calls this | 197 // not and will not try to update it. Currently clearSelection calls this |
146 // (intentionally) without updating the layout tree as it doesn't care. | 198 // (intentionally) without updating the layout tree as it doesn't care. |
(...skipping 10 matching lines...) Expand all Loading... | |
157 selection_end_ == end && selection_end_pos_ == end_pos) | 209 selection_end_ == end && selection_end_pos_ == end_pos) |
158 return; | 210 return; |
159 | 211 |
160 DCHECK(frame_selection_->GetDocument().GetLayoutView()->GetFrameView()); | 212 DCHECK(frame_selection_->GetDocument().GetLayoutView()->GetFrameView()); |
161 | 213 |
162 // Record the old selected objects. These will be used later when we compare | 214 // Record the old selected objects. These will be used later when we compare |
163 // against the new selected objects. | 215 // against the new selected objects. |
164 int old_start_pos = selection_start_pos_; | 216 int old_start_pos = selection_start_pos_; |
165 int old_end_pos = selection_end_pos_; | 217 int old_end_pos = selection_end_pos_; |
166 | 218 |
167 SelectedMap old_selected_map; | 219 SelectedMap old_selected_map = |
168 LayoutObject* os = selection_start_; | 220 CollectSelectedMap(selection_start_, selection_end_, selection_end_pos_, |
169 LayoutObject* stop = | 221 block_paint_invalidation_mode); |
170 LayoutObjectAfterPosition(selection_end_, selection_end_pos_); | |
171 bool exploring_backwards = false; | |
172 bool continue_exploring = os && (os != stop); | |
173 while (continue_exploring) { | |
174 if ((os->CanBeSelectionLeaf() || os == selection_start_ || | |
175 os == selection_end_) && | |
176 os->GetSelectionState() != SelectionNone) { | |
177 // Blocks are responsible for painting line gaps and margin gaps. They | |
178 // must be examined as well. | |
179 old_selected_map.first.Set(os, os->GetSelectionState()); | |
180 if (block_paint_invalidation_mode == kPaintInvalidationNewXOROld) { | |
181 LayoutBlock* cb = os->ContainingBlock(); | |
182 while (cb && !cb->IsLayoutView()) { | |
183 SelectedBlockMap::AddResult result = | |
184 old_selected_map.second.insert(cb, cb->GetSelectionState()); | |
185 if (!result.is_new_entry) | |
186 break; | |
187 cb = cb->ContainingBlock(); | |
188 } | |
189 } | |
190 } | |
191 | |
192 os = GetNextOrPrevLayoutObjectBasedOnDirection(os, stop, continue_exploring, | |
193 exploring_backwards); | |
194 } | |
195 | 222 |
196 // Now clear the selection. | 223 // Now clear the selection. |
197 SelectedObjectMap::iterator old_objects_end = old_selected_map.first.end(); | 224 SelectedObjectMap::iterator old_objects_end = old_selected_map.first.end(); |
198 for (SelectedObjectMap::iterator i = old_selected_map.first.begin(); | 225 for (SelectedObjectMap::iterator i = old_selected_map.first.begin(); |
199 i != old_objects_end; ++i) | 226 i != old_objects_end; ++i) |
200 i->key->SetSelectionStateIfNeeded(SelectionNone); | 227 i->key->SetSelectionStateIfNeeded(SelectionNone); |
201 | 228 |
202 // set selection start and end | 229 // set selection start and end |
203 selection_start_ = start; | 230 selection_start_ = start; |
204 selection_start_pos_ = start_pos; | 231 selection_start_pos_ = start_pos; |
205 selection_end_ = end; | 232 selection_end_ = end; |
206 selection_end_pos_ = end_pos; | 233 selection_end_pos_ = end_pos; |
207 | 234 |
208 // Update the selection status of all objects between m_selectionStart and | 235 // Update the selection status of all objects between m_selectionStart and |
209 // m_selectionEnd | 236 // m_selectionEnd |
210 if (start && start == end) { | 237 if (start && start == end) { |
211 start->SetSelectionStateIfNeeded(SelectionBoth); | 238 start->SetSelectionStateIfNeeded(SelectionBoth); |
212 } else { | 239 } else { |
213 if (start) | 240 if (start) |
214 start->SetSelectionStateIfNeeded(SelectionStart); | 241 start->SetSelectionStateIfNeeded(SelectionStart); |
215 if (end) | 242 if (end) |
216 end->SetSelectionStateIfNeeded(SelectionEnd); | 243 end->SetSelectionStateIfNeeded(SelectionEnd); |
217 } | 244 } |
218 | 245 |
219 LayoutObject* o = start; | 246 LayoutObject* o = start; |
220 stop = LayoutObjectAfterPosition(end, end_pos); | 247 LayoutObject* stop = LayoutObjectAfterPosition(end, end_pos); |
yosin_UTC9
2017/05/12 02:09:45
Can we make |LayoutObject* stop|?
yoichio
2017/05/12 04:37:39
Done.
| |
221 | 248 |
222 while (o && o != stop) { | 249 while (o && o != stop) { |
223 if (o != start && o != end && o->CanBeSelectionLeaf()) | 250 if (o != start && o != end && o->CanBeSelectionLeaf()) |
224 o->SetSelectionStateIfNeeded(SelectionInside); | 251 o->SetSelectionStateIfNeeded(SelectionInside); |
225 o = o->NextInPreOrder(); | 252 o = o->NextInPreOrder(); |
226 } | 253 } |
227 | 254 |
228 // Now that the selection state has been updated for the new objects, walk | 255 // Now that the selection state has been updated for the new objects, walk |
229 // them again and put them in the new objects list. | 256 // them again and put them in the new objects list. |
230 // FIXME: |new_selected_map| doesn't really need to store the | 257 // TODO(editing-dev): |new_selected_map| doesn't really need to store the |
231 // SelectionState, it's just more convenient to have it use the same data | 258 // SelectionState, it's just more convenient to have it use the same data |
232 // structure as |old_selected_map|. | 259 // structure as |old_selected_map|. |
233 SelectedMap new_selected_map; | 260 SelectedMap new_selected_map = CollectSelectedMap(start, end, end_pos); |
234 o = start; | |
235 exploring_backwards = false; | |
236 continue_exploring = o && (o != stop); | |
237 while (continue_exploring) { | |
238 if ((o->CanBeSelectionLeaf() || o == start || o == end) && | |
239 o->GetSelectionState() != SelectionNone) { | |
240 new_selected_map.first.Set(o, o->GetSelectionState()); | |
241 LayoutBlock* cb = o->ContainingBlock(); | |
242 while (cb && !cb->IsLayoutView()) { | |
243 SelectedBlockMap::AddResult result = | |
244 new_selected_map.second.insert(cb, cb->GetSelectionState()); | |
245 if (!result.is_new_entry) | |
246 break; | |
247 cb = cb->ContainingBlock(); | |
248 } | |
249 } | |
250 | |
251 o = GetNextOrPrevLayoutObjectBasedOnDirection(o, stop, continue_exploring, | |
252 exploring_backwards); | |
253 } | |
254 | 261 |
255 // Have any of the old selected objects changed compared to the new selection? | 262 // Have any of the old selected objects changed compared to the new selection? |
256 for (SelectedObjectMap::iterator i = old_selected_map.first.begin(); | 263 for (SelectedObjectMap::iterator i = old_selected_map.first.begin(); |
257 i != old_objects_end; ++i) { | 264 i != old_objects_end; ++i) { |
258 LayoutObject* obj = i->key; | 265 LayoutObject* obj = i->key; |
259 SelectionState new_selection_state = obj->GetSelectionState(); | 266 SelectionState new_selection_state = obj->GetSelectionState(); |
260 SelectionState old_selection_state = i->value; | 267 SelectionState old_selection_state = i->value; |
261 if (new_selection_state != old_selection_state || | 268 if (new_selection_state != old_selection_state || |
262 (selection_start_ == obj && old_start_pos != selection_start_pos_) || | 269 (selection_start_ == obj && old_start_pos != selection_start_pos_) || |
263 (selection_end_ == obj && old_end_pos != selection_end_pos_)) { | 270 (selection_end_ == obj && old_end_pos != selection_end_pos_)) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 | 432 |
426 o->SetShouldInvalidateSelection(); | 433 o->SetShouldInvalidateSelection(); |
427 } | 434 } |
428 } | 435 } |
429 | 436 |
430 DEFINE_TRACE(LayoutSelection) { | 437 DEFINE_TRACE(LayoutSelection) { |
431 visitor->Trace(frame_selection_); | 438 visitor->Trace(frame_selection_); |
432 } | 439 } |
433 | 440 |
434 } // namespace blink | 441 } // namespace blink |
OLD | NEW |