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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 exploring_backwards = !next && (next != stop); | 119 exploring_backwards = !next && (next != stop); |
| 120 if (exploring_backwards) { | 120 if (exploring_backwards) { |
| 121 next = stop->PreviousInPreOrder(); | 121 next = stop->PreviousInPreOrder(); |
| 122 continue_exploring = next && !next->IsLayoutView(); | 122 continue_exploring = next && !next->IsLayoutView(); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 return next; | 126 return next; |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Objects each have a single selection rect to examine. | |
| 130 using SelectedObjectMap = HashMap<LayoutObject*, SelectionState>; | |
| 131 // Blocks contain selected objects and fill gaps between them, either on the | |
| 132 // left, right, or in between lines and blocks. | |
| 133 // In order to get the visual rect right, we have to examine left, middle, and | |
| 134 // right rects individually, since otherwise the union of those rects might | |
| 135 // remain the same even when changes have occurred. | |
| 136 using SelectedBlockMap = HashMap<LayoutBlock*, SelectionState>; | |
| 137 using SelectedMap = std::pair<SelectedObjectMap, SelectedBlockMap>; | |
| 138 | |
| 129 void LayoutSelection::SetSelection( | 139 void LayoutSelection::SetSelection( |
| 130 LayoutObject* start, | 140 LayoutObject* start, |
| 131 int start_pos, | 141 int start_pos, |
| 132 LayoutObject* end, | 142 LayoutObject* end, |
| 133 int end_pos, | 143 int end_pos, |
| 134 SelectionPaintInvalidationMode block_paint_invalidation_mode) { | 144 SelectionPaintInvalidationMode block_paint_invalidation_mode) { |
| 135 // This code makes no assumptions as to if the layout tree is up to date or | 145 // This code makes no assumptions as to if the layout tree is up to date or |
| 136 // not and will not try to update it. Currently clearSelection calls this | 146 // not and will not try to update it. Currently clearSelection calls this |
| 137 // (intentionally) without updating the layout tree as it doesn't care. | 147 // (intentionally) without updating the layout tree as it doesn't care. |
| 138 // Other callers may want to force recalc style before calling this. | 148 // Other callers may want to force recalc style before calling this. |
| 139 | 149 |
| 140 // Make sure both our start and end objects are defined. | 150 // Make sure both our start and end objects are defined. |
| 141 // Check www.msnbc.com and try clicking around to find the case where this | 151 // Check www.msnbc.com and try clicking around to find the case where this |
| 142 // happened. | 152 // happened. |
| 143 if ((start && !end) || (end && !start)) | 153 if ((start && !end) || (end && !start)) |
| 144 return; | 154 return; |
| 145 | 155 |
| 146 // Just return if the selection hasn't changed. | 156 // Just return if the selection hasn't changed. |
| 147 if (selection_start_ == start && selection_start_pos_ == start_pos && | 157 if (selection_start_ == start && selection_start_pos_ == start_pos && |
| 148 selection_end_ == end && selection_end_pos_ == end_pos) | 158 selection_end_ == end && selection_end_pos_ == end_pos) |
| 149 return; | 159 return; |
| 150 | 160 |
| 151 // Record the old selected objects. These will be used later when we compare | 161 // Record the old selected objects. These will be used later when we compare |
| 152 // against the new selected objects. | 162 // against the new selected objects. |
| 153 int old_start_pos = selection_start_pos_; | 163 int old_start_pos = selection_start_pos_; |
| 154 int old_end_pos = selection_end_pos_; | 164 int old_end_pos = selection_end_pos_; |
| 155 | 165 |
| 156 // Objects each have a single selection rect to examine. | 166 SelectedMap old_selected_map; |
| 157 typedef HashMap<LayoutObject*, SelectionState> SelectedObjectMap; | |
| 158 SelectedObjectMap old_selected_objects; | |
| 159 // FIXME: |newSelectedObjects| doesn't really need to store the | |
| 160 // SelectionState, it's just more convenient to have it use the same data | |
| 161 // structure as |oldSelectedObjects|. | |
| 162 SelectedObjectMap new_selected_objects; | |
| 163 | |
| 164 // Blocks contain selected objects and fill gaps between them, either on the | |
| 165 // left, right, or in between lines and blocks. | |
| 166 // In order to get the visual rect right, we have to examine left, middle, and | |
| 167 // right rects individually, since otherwise the union of those rects might | |
| 168 // remain the same even when changes have occurred. | |
| 169 typedef HashMap<LayoutBlock*, SelectionState> SelectedBlockMap; | |
| 170 SelectedBlockMap old_selected_blocks; | |
| 171 // FIXME: |newSelectedBlocks| doesn't really need to store the SelectionState, | |
| 172 // it's just more convenient to have it use the same data structure as | |
| 173 // |oldSelectedBlocks|. | |
| 174 SelectedBlockMap new_selected_blocks; | |
| 175 | |
| 176 LayoutObject* os = selection_start_; | 167 LayoutObject* os = selection_start_; |
| 177 LayoutObject* stop = | 168 LayoutObject* stop = |
| 178 LayoutObjectAfterPosition(selection_end_, selection_end_pos_); | 169 LayoutObjectAfterPosition(selection_end_, selection_end_pos_); |
| 179 bool exploring_backwards = false; | 170 bool exploring_backwards = false; |
| 180 bool continue_exploring = os && (os != stop); | 171 bool continue_exploring = os && (os != stop); |
| 181 while (continue_exploring) { | 172 while (continue_exploring) { |
| 182 if ((os->CanBeSelectionLeaf() || os == selection_start_ || | 173 if ((os->CanBeSelectionLeaf() || os == selection_start_ || |
| 183 os == selection_end_) && | 174 os == selection_end_) && |
| 184 os->GetSelectionState() != SelectionNone) { | 175 os->GetSelectionState() != SelectionNone) { |
| 185 // Blocks are responsible for painting line gaps and margin gaps. They | 176 // Blocks are responsible for painting line gaps and margin gaps. They |
| 186 // must be examined as well. | 177 // must be examined as well. |
| 187 old_selected_objects.Set(os, os->GetSelectionState()); | 178 old_selected_map.first.Set(os, os->GetSelectionState()); |
| 188 if (block_paint_invalidation_mode == kPaintInvalidationNewXOROld) { | 179 if (block_paint_invalidation_mode == kPaintInvalidationNewXOROld) { |
| 189 LayoutBlock* cb = os->ContainingBlock(); | 180 LayoutBlock* cb = os->ContainingBlock(); |
| 190 while (cb && !cb->IsLayoutView()) { | 181 while (cb && !cb->IsLayoutView()) { |
| 191 SelectedBlockMap::AddResult result = | 182 SelectedBlockMap::AddResult result = |
| 192 old_selected_blocks.insert(cb, cb->GetSelectionState()); | 183 old_selected_map.second.insert(cb, cb->GetSelectionState()); |
| 193 if (!result.is_new_entry) | 184 if (!result.is_new_entry) |
| 194 break; | 185 break; |
| 195 cb = cb->ContainingBlock(); | 186 cb = cb->ContainingBlock(); |
| 196 } | 187 } |
| 197 } | 188 } |
| 198 } | 189 } |
| 199 | 190 |
| 200 os = GetNextOrPrevLayoutObjectBasedOnDirection(os, stop, continue_exploring, | 191 os = GetNextOrPrevLayoutObjectBasedOnDirection(os, stop, continue_exploring, |
| 201 exploring_backwards); | 192 exploring_backwards); |
| 202 } | 193 } |
| 203 | 194 |
| 204 // Now clear the selection. | 195 // Now clear the selection. |
| 205 SelectedObjectMap::iterator old_objects_end = old_selected_objects.end(); | 196 SelectedObjectMap::iterator old_objects_end = old_selected_map.first.end(); |
| 206 for (SelectedObjectMap::iterator i = old_selected_objects.begin(); | 197 for (SelectedObjectMap::iterator i = old_selected_map.first.begin(); |
| 207 i != old_objects_end; ++i) | 198 i != old_objects_end; ++i) |
| 208 i->key->SetSelectionStateIfNeeded(SelectionNone); | 199 i->key->SetSelectionStateIfNeeded(SelectionNone); |
| 209 | 200 |
| 210 // set selection start and end | 201 // set selection start and end |
| 211 selection_start_ = start; | 202 selection_start_ = start; |
| 212 selection_start_pos_ = start_pos; | 203 selection_start_pos_ = start_pos; |
| 213 selection_end_ = end; | 204 selection_end_ = end; |
| 214 selection_end_pos_ = end_pos; | 205 selection_end_pos_ = end_pos; |
| 215 | 206 |
| 216 // Update the selection status of all objects between m_selectionStart and | 207 // Update the selection status of all objects between m_selectionStart and |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 228 stop = LayoutObjectAfterPosition(end, end_pos); | 219 stop = LayoutObjectAfterPosition(end, end_pos); |
| 229 | 220 |
| 230 while (o && o != stop) { | 221 while (o && o != stop) { |
| 231 if (o != start && o != end && o->CanBeSelectionLeaf()) | 222 if (o != start && o != end && o->CanBeSelectionLeaf()) |
| 232 o->SetSelectionStateIfNeeded(SelectionInside); | 223 o->SetSelectionStateIfNeeded(SelectionInside); |
| 233 o = o->NextInPreOrder(); | 224 o = o->NextInPreOrder(); |
| 234 } | 225 } |
| 235 | 226 |
| 236 // Now that the selection state has been updated for the new objects, walk | 227 // Now that the selection state has been updated for the new objects, walk |
| 237 // them again and put them in the new objects list. | 228 // them again and put them in the new objects list. |
| 229 // FIXME: |new_selected_map| doesn't really need to store the | |
|
yosin_UTC9
2017/05/10 09:04:22
nit: s/FIXME/TODO(editing-dev)/
| |
| 230 // SelectionState, it's just more convenient to have it use the same data | |
| 231 // structure as |old_selected_map|. | |
| 232 SelectedMap new_selected_map; | |
| 238 o = start; | 233 o = start; |
| 239 exploring_backwards = false; | 234 exploring_backwards = false; |
| 240 continue_exploring = o && (o != stop); | 235 continue_exploring = o && (o != stop); |
| 241 while (continue_exploring) { | 236 while (continue_exploring) { |
| 242 if ((o->CanBeSelectionLeaf() || o == start || o == end) && | 237 if ((o->CanBeSelectionLeaf() || o == start || o == end) && |
| 243 o->GetSelectionState() != SelectionNone) { | 238 o->GetSelectionState() != SelectionNone) { |
| 244 new_selected_objects.Set(o, o->GetSelectionState()); | 239 new_selected_map.first.Set(o, o->GetSelectionState()); |
| 245 LayoutBlock* cb = o->ContainingBlock(); | 240 LayoutBlock* cb = o->ContainingBlock(); |
| 246 while (cb && !cb->IsLayoutView()) { | 241 while (cb && !cb->IsLayoutView()) { |
| 247 SelectedBlockMap::AddResult result = | 242 SelectedBlockMap::AddResult result = |
| 248 new_selected_blocks.insert(cb, cb->GetSelectionState()); | 243 new_selected_map.second.insert(cb, cb->GetSelectionState()); |
| 249 if (!result.is_new_entry) | 244 if (!result.is_new_entry) |
| 250 break; | 245 break; |
| 251 cb = cb->ContainingBlock(); | 246 cb = cb->ContainingBlock(); |
| 252 } | 247 } |
| 253 } | 248 } |
| 254 | 249 |
| 255 o = GetNextOrPrevLayoutObjectBasedOnDirection(o, stop, continue_exploring, | 250 o = GetNextOrPrevLayoutObjectBasedOnDirection(o, stop, continue_exploring, |
| 256 exploring_backwards); | 251 exploring_backwards); |
| 257 } | 252 } |
| 258 | 253 |
| 259 // TODO(yoichio): DCHECK(frame_selection_->,,,->GetFrameView()); | 254 // TODO(yoichio): DCHECK(frame_selection_->,,,->GetFrameView()); |
| 260 if (!frame_selection_->GetDocument().GetLayoutView()->GetFrameView()) | 255 if (!frame_selection_->GetDocument().GetLayoutView()->GetFrameView()) |
| 261 return; | 256 return; |
| 262 | 257 |
| 263 // Have any of the old selected objects changed compared to the new selection? | 258 // Have any of the old selected objects changed compared to the new selection? |
| 264 for (SelectedObjectMap::iterator i = old_selected_objects.begin(); | 259 for (SelectedObjectMap::iterator i = old_selected_map.first.begin(); |
| 265 i != old_objects_end; ++i) { | 260 i != old_objects_end; ++i) { |
| 266 LayoutObject* obj = i->key; | 261 LayoutObject* obj = i->key; |
| 267 SelectionState new_selection_state = obj->GetSelectionState(); | 262 SelectionState new_selection_state = obj->GetSelectionState(); |
| 268 SelectionState old_selection_state = i->value; | 263 SelectionState old_selection_state = i->value; |
| 269 if (new_selection_state != old_selection_state || | 264 if (new_selection_state != old_selection_state || |
| 270 (selection_start_ == obj && old_start_pos != selection_start_pos_) || | 265 (selection_start_ == obj && old_start_pos != selection_start_pos_) || |
| 271 (selection_end_ == obj && old_end_pos != selection_end_pos_)) { | 266 (selection_end_ == obj && old_end_pos != selection_end_pos_)) { |
| 272 obj->SetShouldInvalidateSelection(); | 267 obj->SetShouldInvalidateSelection(); |
| 273 new_selected_objects.erase(obj); | 268 new_selected_map.first.erase(obj); |
| 274 } | 269 } |
| 275 } | 270 } |
| 276 | 271 |
| 277 // Any new objects that remain were not found in the old objects dict, and so | 272 // Any new objects that remain were not found in the old objects dict, and so |
| 278 // they need to be updated. | 273 // they need to be updated. |
| 279 SelectedObjectMap::iterator new_objects_end = new_selected_objects.end(); | 274 SelectedObjectMap::iterator new_objects_end = new_selected_map.first.end(); |
| 280 for (SelectedObjectMap::iterator i = new_selected_objects.begin(); | 275 for (SelectedObjectMap::iterator i = new_selected_map.first.begin(); |
| 281 i != new_objects_end; ++i) | 276 i != new_objects_end; ++i) |
| 282 i->key->SetShouldInvalidateSelection(); | 277 i->key->SetShouldInvalidateSelection(); |
| 283 | 278 |
| 284 // Have any of the old blocks changed? | 279 // Have any of the old blocks changed? |
| 285 SelectedBlockMap::iterator old_blocks_end = old_selected_blocks.end(); | 280 SelectedBlockMap::iterator old_blocks_end = old_selected_map.second.end(); |
| 286 for (SelectedBlockMap::iterator i = old_selected_blocks.begin(); | 281 for (SelectedBlockMap::iterator i = old_selected_map.second.begin(); |
| 287 i != old_blocks_end; ++i) { | 282 i != old_blocks_end; ++i) { |
| 288 LayoutBlock* block = i->key; | 283 LayoutBlock* block = i->key; |
| 289 SelectionState new_selection_state = block->GetSelectionState(); | 284 SelectionState new_selection_state = block->GetSelectionState(); |
| 290 SelectionState old_selection_state = i->value; | 285 SelectionState old_selection_state = i->value; |
| 291 if (new_selection_state != old_selection_state) { | 286 if (new_selection_state != old_selection_state) { |
| 292 block->SetShouldInvalidateSelection(); | 287 block->SetShouldInvalidateSelection(); |
| 293 new_selected_blocks.erase(block); | 288 new_selected_map.second.erase(block); |
| 294 } | 289 } |
| 295 } | 290 } |
| 296 | 291 |
| 297 // Any new blocks that remain were not found in the old blocks dict, and so | 292 // Any new blocks that remain were not found in the old blocks dict, and so |
| 298 // they need to be updated. | 293 // they need to be updated. |
| 299 SelectedBlockMap::iterator new_blocks_end = new_selected_blocks.end(); | 294 SelectedBlockMap::iterator new_blocks_end = new_selected_map.second.end(); |
| 300 for (SelectedBlockMap::iterator i = new_selected_blocks.begin(); | 295 for (SelectedBlockMap::iterator i = new_selected_map.second.begin(); |
| 301 i != new_blocks_end; ++i) | 296 i != new_blocks_end; ++i) |
| 302 i->key->SetShouldInvalidateSelection(); | 297 i->key->SetShouldInvalidateSelection(); |
| 303 } | 298 } |
| 304 | 299 |
| 305 std::pair<int, int> LayoutSelection::SelectionStartEnd() { | 300 std::pair<int, int> LayoutSelection::SelectionStartEnd() { |
| 306 Commit(); | 301 Commit(); |
| 307 return std::make_pair(selection_start_pos_, selection_end_pos_); | 302 return std::make_pair(selection_start_pos_, selection_end_pos_); |
| 308 } | 303 } |
| 309 | 304 |
| 310 void LayoutSelection::ClearSelection() { | 305 void LayoutSelection::ClearSelection() { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 | 437 |
| 443 o->SetShouldInvalidateSelection(); | 438 o->SetShouldInvalidateSelection(); |
| 444 } | 439 } |
| 445 } | 440 } |
| 446 | 441 |
| 447 DEFINE_TRACE(LayoutSelection) { | 442 DEFINE_TRACE(LayoutSelection) { |
| 448 visitor->Trace(frame_selection_); | 443 visitor->Trace(frame_selection_); |
| 449 } | 444 } |
| 450 | 445 |
| 451 } // namespace blink | 446 } // namespace blink |
| OLD | NEW |