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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 if ((start && !end) || (end && !start)) | 203 if ((start && !end) || (end && !start)) |
204 return; | 204 return; |
205 | 205 |
206 // Just return if the selection hasn't changed. | 206 // Just return if the selection hasn't changed. |
207 if (selection_start_ == start && selection_start_pos_ == start_pos && | 207 if (selection_start_ == start && selection_start_pos_ == start_pos && |
208 selection_end_ == end && selection_end_pos_ == end_pos) | 208 selection_end_ == end && selection_end_pos_ == end_pos) |
209 return; | 209 return; |
210 | 210 |
211 DCHECK(frame_selection_->GetDocument().GetLayoutView()->GetFrameView()); | 211 DCHECK(frame_selection_->GetDocument().GetLayoutView()->GetFrameView()); |
212 | 212 |
213 // Record the old selected objects. These will be used later when we compare | |
214 // against the new selected objects. | |
215 int old_start_pos = selection_start_pos_; | |
216 int old_end_pos = selection_end_pos_; | |
217 | |
218 SelectedMap old_selected_map = | 213 SelectedMap old_selected_map = |
219 CollectSelectedMap(selection_start_, selection_end_, selection_end_pos_, | 214 CollectSelectedMap(selection_start_, selection_end_, selection_end_pos_, |
220 block_paint_invalidation_mode); | 215 block_paint_invalidation_mode); |
221 | 216 |
222 // Now clear the selection. | 217 // Now clear the selection. |
223 for (auto layout_object : old_selected_map.object_map.Keys()) | 218 for (auto layout_object : old_selected_map.object_map.Keys()) |
224 layout_object->SetSelectionStateIfNeeded(SelectionNone); | 219 layout_object->SetSelectionStateIfNeeded(SelectionNone); |
225 | 220 |
226 // set selection start and end | |
227 selection_start_ = start; | |
228 selection_start_pos_ = start_pos; | |
229 selection_end_ = end; | |
230 selection_end_pos_ = end_pos; | |
231 | |
232 // Update the selection status of all objects between m_selectionStart and | 221 // Update the selection status of all objects between m_selectionStart and |
233 // m_selectionEnd | 222 // m_selectionEnd |
234 if (start && start == end) { | 223 if (start && start == end) { |
235 start->SetSelectionStateIfNeeded(SelectionBoth); | 224 start->SetSelectionStateIfNeeded(SelectionBoth); |
236 } else { | 225 } else { |
237 if (start) | 226 if (start) |
238 start->SetSelectionStateIfNeeded(SelectionStart); | 227 start->SetSelectionStateIfNeeded(SelectionStart); |
239 if (end) | 228 if (end) |
240 end->SetSelectionStateIfNeeded(SelectionEnd); | 229 end->SetSelectionStateIfNeeded(SelectionEnd); |
241 } | 230 } |
(...skipping 14 matching lines...) Expand all Loading... |
256 // structure as |old_selected_map|. | 245 // structure as |old_selected_map|. |
257 SelectedMap new_selected_map = | 246 SelectedMap new_selected_map = |
258 CollectSelectedMap(start, end, end_pos, kPaintInvalidationNewXOROld); | 247 CollectSelectedMap(start, end, end_pos, kPaintInvalidationNewXOROld); |
259 | 248 |
260 // Have any of the old selected objects changed compared to the new selection? | 249 // Have any of the old selected objects changed compared to the new selection? |
261 for (const auto& pair : old_selected_map.object_map) { | 250 for (const auto& pair : old_selected_map.object_map) { |
262 LayoutObject* obj = pair.key; | 251 LayoutObject* obj = pair.key; |
263 SelectionState new_selection_state = obj->GetSelectionState(); | 252 SelectionState new_selection_state = obj->GetSelectionState(); |
264 SelectionState old_selection_state = pair.value; | 253 SelectionState old_selection_state = pair.value; |
265 if (new_selection_state != old_selection_state || | 254 if (new_selection_state != old_selection_state || |
266 (selection_start_ == obj && old_start_pos != selection_start_pos_) || | 255 (start == obj && start_pos != selection_start_pos_) || |
267 (selection_end_ == obj && old_end_pos != selection_end_pos_)) { | 256 (end == obj && end_pos != selection_end_pos_)) { |
268 obj->SetShouldInvalidateSelection(); | 257 obj->SetShouldInvalidateSelection(); |
269 new_selected_map.object_map.erase(obj); | 258 new_selected_map.object_map.erase(obj); |
270 } | 259 } |
271 } | 260 } |
272 | 261 |
273 // Any new objects that remain were not found in the old objects dict, and so | 262 // Any new objects that remain were not found in the old objects dict, and so |
274 // they need to be updated. | 263 // they need to be updated. |
275 for (auto layout_object : new_selected_map.object_map.Keys()) | 264 for (auto layout_object : new_selected_map.object_map.Keys()) |
276 layout_object->SetShouldInvalidateSelection(); | 265 layout_object->SetShouldInvalidateSelection(); |
277 | 266 |
278 // Have any of the old blocks changed? | 267 // Have any of the old blocks changed? |
279 for (const auto& pair : old_selected_map.block_map) { | 268 for (const auto& pair : old_selected_map.block_map) { |
280 LayoutBlock* block = pair.key; | 269 LayoutBlock* block = pair.key; |
281 SelectionState new_selection_state = block->GetSelectionState(); | 270 SelectionState new_selection_state = block->GetSelectionState(); |
282 SelectionState old_selection_state = pair.value; | 271 SelectionState old_selection_state = pair.value; |
283 if (new_selection_state != old_selection_state) { | 272 if (new_selection_state != old_selection_state) { |
284 block->SetShouldInvalidateSelection(); | 273 block->SetShouldInvalidateSelection(); |
285 new_selected_map.block_map.erase(block); | 274 new_selected_map.block_map.erase(block); |
286 } | 275 } |
287 } | 276 } |
288 | 277 |
289 // Any new blocks that remain were not found in the old blocks dict, and so | 278 // Any new blocks that remain were not found in the old blocks dict, and so |
290 // they need to be updated. | 279 // they need to be updated. |
291 for (auto layout_object : new_selected_map.block_map.Keys()) | 280 for (auto layout_object : new_selected_map.block_map.Keys()) |
292 layout_object->SetShouldInvalidateSelection(); | 281 layout_object->SetShouldInvalidateSelection(); |
| 282 |
| 283 // set selection start and end |
| 284 selection_start_ = start; |
| 285 selection_start_pos_ = start_pos; |
| 286 selection_end_ = end; |
| 287 selection_end_pos_ = end_pos; |
293 } | 288 } |
294 | 289 |
295 std::pair<int, int> LayoutSelection::SelectionStartEnd() { | 290 std::pair<int, int> LayoutSelection::SelectionStartEnd() { |
296 Commit(); | 291 Commit(); |
297 return std::make_pair(selection_start_pos_, selection_end_pos_); | 292 return std::make_pair(selection_start_pos_, selection_end_pos_); |
298 } | 293 } |
299 | 294 |
300 void LayoutSelection::ClearSelection() { | 295 void LayoutSelection::ClearSelection() { |
301 // For querying Layer::compositingState() | 296 // For querying Layer::compositingState() |
302 // This is correct, since destroying layout objects needs to cause eager paint | 297 // This is correct, since destroying layout objects needs to cause eager paint |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 418 |
424 o->SetShouldInvalidateSelection(); | 419 o->SetShouldInvalidateSelection(); |
425 } | 420 } |
426 } | 421 } |
427 | 422 |
428 DEFINE_TRACE(LayoutSelection) { | 423 DEFINE_TRACE(LayoutSelection) { |
429 visitor->Trace(frame_selection_); | 424 visitor->Trace(frame_selection_); |
430 } | 425 } |
431 | 426 |
432 } // namespace blink | 427 } // namespace blink |
OLD | NEW |