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 14 matching lines...) Expand all Loading... | |
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 #include "core/paint/PaintLayer.h" | 31 #include "core/paint/PaintLayer.h" |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
35 SelectionPaintRange::SelectionPaintRange(LayoutObject* start_layout_object, | |
36 int start_offset, | |
37 LayoutObject* end_layout_object, | |
38 int end_offset) | |
39 : start_layout_object_(start_layout_object), | |
40 start_offset_(start_offset), | |
41 end_layout_object_(end_layout_object), | |
42 end_offset_(end_offset) { | |
43 DCHECK(StartLayoutObject()); | |
44 DCHECK(EndLayoutObject()); | |
45 if (StartLayoutObject() == EndLayoutObject()) | |
46 DCHECK_LT(StartOffset(), EndOffset()); | |
47 } | |
48 | |
49 bool SelectionPaintRange::operator==(const SelectionPaintRange& other) const { | |
50 return start_layout_object_ == other.start_layout_object_ && | |
51 start_offset_ == other.start_offset_ && | |
52 end_layout_object_ == other.end_layout_object_ && | |
53 end_offset_ == other.end_offset_; | |
54 } | |
55 bool SelectionPaintRange::operator!=(const SelectionPaintRange& other) const { | |
56 return !(*this == other); | |
57 } | |
58 | |
35 LayoutSelection::LayoutSelection(FrameSelection& frame_selection) | 59 LayoutSelection::LayoutSelection(FrameSelection& frame_selection) |
36 : frame_selection_(&frame_selection), | 60 : frame_selection_(&frame_selection), |
37 has_pending_selection_(false), | 61 has_pending_selection_(false), |
38 selection_start_(nullptr), | 62 paint_range_(SelectionPaintRange()) {} |
39 selection_end_(nullptr), | |
40 selection_start_pos_(-1), | |
41 selection_end_pos_(-1) {} | |
42 | 63 |
43 SelectionInFlatTree LayoutSelection::CalcVisibleSelection( | 64 SelectionInFlatTree LayoutSelection::CalcVisibleSelection( |
44 const VisibleSelectionInFlatTree& original_selection) const { | 65 const VisibleSelectionInFlatTree& original_selection) const { |
45 const PositionInFlatTree& start = original_selection.Start(); | 66 const PositionInFlatTree& start = original_selection.Start(); |
46 const PositionInFlatTree& end = original_selection.end(); | 67 const PositionInFlatTree& end = original_selection.end(); |
47 SelectionType selection_type = original_selection.GetSelectionType(); | 68 SelectionType selection_type = original_selection.GetSelectionType(); |
48 const TextAffinity affinity = original_selection.Affinity(); | 69 const TextAffinity affinity = original_selection.Affinity(); |
49 | 70 |
50 bool paint_block_cursor = | 71 bool paint_block_cursor = |
51 frame_selection_->ShouldShowBlockCursor() && | 72 frame_selection_->ShouldShowBlockCursor() && |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 SelectedMap(SelectedMap&& other) { | 138 SelectedMap(SelectedMap&& other) { |
118 object_map = std::move(other.object_map); | 139 object_map = std::move(other.object_map); |
119 block_map = std::move(other.block_map); | 140 block_map = std::move(other.block_map); |
120 } | 141 } |
121 | 142 |
122 private: | 143 private: |
123 DISALLOW_COPY_AND_ASSIGN(SelectedMap); | 144 DISALLOW_COPY_AND_ASSIGN(SelectedMap); |
124 }; | 145 }; |
125 | 146 |
126 static SelectedMap CollectSelectedMap( | 147 static SelectedMap CollectSelectedMap( |
127 LayoutObject* selection_start, | 148 const SelectionPaintRange& range, |
128 LayoutObject* selection_end, | |
129 int selection_end_pos, | |
130 LayoutSelection::SelectionPaintInvalidationMode | 149 LayoutSelection::SelectionPaintInvalidationMode |
131 block_paint_invalidation_mode) { | 150 block_paint_invalidation_mode) { |
132 SelectedMap selected_map; | 151 SelectedMap selected_map; |
133 | 152 |
134 LayoutObject* const stop = | 153 LayoutObject* const stop = |
135 LayoutObjectAfterPosition(selection_end, selection_end_pos); | 154 LayoutObjectAfterPosition(range.EndLayoutObject(), range.EndOffset()); |
136 for (LayoutObject* runner = selection_start; runner && (runner != stop); | 155 for (LayoutObject* runner = range.StartLayoutObject(); |
137 runner = runner->NextInPreOrder()) { | 156 runner && (runner != stop); runner = runner->NextInPreOrder()) { |
138 if (!runner->CanBeSelectionLeaf() && runner != selection_start && | 157 if (!runner->CanBeSelectionLeaf() && runner != range.StartLayoutObject() && |
139 runner != selection_end) | 158 runner != range.EndLayoutObject()) |
140 continue; | 159 continue; |
141 if (runner->GetSelectionState() == SelectionNone) | 160 if (runner->GetSelectionState() == SelectionNone) |
142 continue; | 161 continue; |
143 | 162 |
144 // Blocks are responsible for painting line gaps and margin gaps. They | 163 // Blocks are responsible for painting line gaps and margin gaps. They |
145 // must be examined as well. | 164 // must be examined as well. |
146 selected_map.object_map.Set(runner, runner->GetSelectionState()); | 165 selected_map.object_map.Set(runner, runner->GetSelectionState()); |
147 if (block_paint_invalidation_mode == | 166 if (block_paint_invalidation_mode == |
148 LayoutSelection::kPaintInvalidationNewXOROld) { | 167 LayoutSelection::kPaintInvalidationNewXOROld) { |
149 LayoutBlock* containing_block = runner->ContainingBlock(); | 168 LayoutBlock* containing_block = runner->ContainingBlock(); |
150 while (containing_block && !containing_block->IsLayoutView()) { | 169 while (containing_block && !containing_block->IsLayoutView()) { |
151 SelectedBlockMap::AddResult result = selected_map.block_map.insert( | 170 SelectedBlockMap::AddResult result = selected_map.block_map.insert( |
152 containing_block, containing_block->GetSelectionState()); | 171 containing_block, containing_block->GetSelectionState()); |
153 if (!result.is_new_entry) | 172 if (!result.is_new_entry) |
154 break; | 173 break; |
155 containing_block = containing_block->ContainingBlock(); | 174 containing_block = containing_block->ContainingBlock(); |
156 } | 175 } |
157 } | 176 } |
158 } | 177 } |
159 return selected_map; | 178 return selected_map; |
160 } | 179 } |
161 | 180 |
162 // Update the selection status of all LayoutObjects between |start| and |end|. | 181 // Update the selection status of all LayoutObjects between |start| and |end|. |
163 static void SetSelectionState(LayoutObject* start, | 182 static void SetSelectionState(const SelectionPaintRange& range) { |
164 LayoutObject* end, | 183 DCHECK(range != SelectionPaintRange()); |
165 int end_pos) { | 184 if (range.StartLayoutObject() == range.EndLayoutObject()) { |
166 if (start && start == end) { | 185 range.StartLayoutObject()->SetSelectionStateIfNeeded(SelectionBoth); |
167 start->SetSelectionStateIfNeeded(SelectionBoth); | |
168 } else { | 186 } else { |
169 if (start) | 187 range.StartLayoutObject()->SetSelectionStateIfNeeded(SelectionStart); |
170 start->SetSelectionStateIfNeeded(SelectionStart); | 188 range.EndLayoutObject()->SetSelectionStateIfNeeded(SelectionEnd); |
171 if (end) | |
172 end->SetSelectionStateIfNeeded(SelectionEnd); | |
173 } | 189 } |
174 | 190 |
175 LayoutObject* const stop = LayoutObjectAfterPosition(end, end_pos); | 191 LayoutObject* const stop = |
176 for (LayoutObject* runner = start; runner && runner != stop; | 192 LayoutObjectAfterPosition(range.EndLayoutObject(), range.EndOffset()); |
177 runner = runner->NextInPreOrder()) { | 193 for (LayoutObject* runner = range.StartLayoutObject(); |
178 if (runner != start && runner != end && runner->CanBeSelectionLeaf()) | 194 runner && runner != stop; runner = runner->NextInPreOrder()) { |
195 if (runner != range.StartLayoutObject() && | |
196 runner != range.EndLayoutObject() && runner->CanBeSelectionLeaf()) | |
179 runner->SetSelectionStateIfNeeded(SelectionInside); | 197 runner->SetSelectionStateIfNeeded(SelectionInside); |
180 } | 198 } |
181 } | 199 } |
182 | 200 |
183 void LayoutSelection::SetSelection( | 201 void LayoutSelection::SetSelection( |
184 LayoutObject* start, | 202 const SelectionPaintRange& new_range, |
185 int start_pos, | |
186 LayoutObject* end, | |
187 int end_pos, | |
188 SelectionPaintInvalidationMode block_paint_invalidation_mode) { | 203 SelectionPaintInvalidationMode block_paint_invalidation_mode) { |
189 DCHECK(start); | 204 DCHECK(new_range != SelectionPaintRange()); |
yosin_UTC9
2017/05/24 09:31:18
I prefer to use |IsNull()| as |EpehemralRange|
yoichio
2017/05/25 02:00:35
Done.
| |
190 DCHECK(end); | |
191 | 205 |
192 // Just return if the selection hasn't changed. | 206 // Just return if the selection hasn't changed. |
193 if (selection_start_ == start && selection_start_pos_ == start_pos && | 207 if (paint_range_ == new_range) |
194 selection_end_ == end && selection_end_pos_ == end_pos) | |
195 return; | 208 return; |
196 | 209 |
197 DCHECK(frame_selection_->GetDocument().GetLayoutView()->GetFrameView()); | 210 DCHECK(frame_selection_->GetDocument().GetLayoutView()->GetFrameView()); |
198 DCHECK(!frame_selection_->GetDocument().NeedsLayoutTreeUpdate()); | 211 DCHECK(!frame_selection_->GetDocument().NeedsLayoutTreeUpdate()); |
199 | 212 |
200 SelectedMap old_selected_map = | 213 SelectedMap old_selected_map = |
201 CollectSelectedMap(selection_start_, selection_end_, selection_end_pos_, | 214 CollectSelectedMap(paint_range_, block_paint_invalidation_mode); |
202 block_paint_invalidation_mode); | |
203 | 215 |
204 // Now clear the selection. | 216 // Now clear the selection. |
205 for (auto layout_object : old_selected_map.object_map.Keys()) | 217 for (auto layout_object : old_selected_map.object_map.Keys()) |
206 layout_object->SetSelectionStateIfNeeded(SelectionNone); | 218 layout_object->SetSelectionStateIfNeeded(SelectionNone); |
207 | 219 |
208 SetSelectionState(start, end, end_pos); | 220 SetSelectionState(new_range); |
209 | 221 |
210 // Now that the selection state has been updated for the new objects, walk | 222 // Now that the selection state has been updated for the new objects, walk |
211 // them again and put them in the new objects list. | 223 // them again and put them in the new objects list. |
212 // TODO(editing-dev): |new_selected_map| doesn't really need to store the | 224 // TODO(editing-dev): |new_selected_map| doesn't really need to store the |
213 // SelectionState, it's just more convenient to have it use the same data | 225 // SelectionState, it's just more convenient to have it use the same data |
214 // structure as |old_selected_map|. | 226 // structure as |old_selected_map|. |
215 SelectedMap new_selected_map = | 227 SelectedMap new_selected_map = |
216 CollectSelectedMap(start, end, end_pos, kPaintInvalidationNewXOROld); | 228 CollectSelectedMap(new_range, kPaintInvalidationNewXOROld); |
217 | 229 |
218 // Have any of the old selected objects changed compared to the new selection? | 230 // Have any of the old selected objects changed compared to the new selection? |
219 for (const auto& pair : old_selected_map.object_map) { | 231 for (const auto& pair : old_selected_map.object_map) { |
220 LayoutObject* obj = pair.key; | 232 LayoutObject* obj = pair.key; |
221 SelectionState new_selection_state = obj->GetSelectionState(); | 233 SelectionState new_selection_state = obj->GetSelectionState(); |
222 SelectionState old_selection_state = pair.value; | 234 SelectionState old_selection_state = pair.value; |
223 if (new_selection_state != old_selection_state || | 235 if (new_selection_state != old_selection_state || |
224 (start == obj && start_pos != selection_start_pos_) || | 236 (new_range.StartLayoutObject() == obj && |
225 (end == obj && end_pos != selection_end_pos_)) { | 237 new_range.StartOffset() != paint_range_.StartOffset()) || |
238 (new_range.EndLayoutObject() == obj && | |
239 new_range.EndOffset() != paint_range_.EndOffset())) { | |
226 obj->SetShouldInvalidateSelection(); | 240 obj->SetShouldInvalidateSelection(); |
227 new_selected_map.object_map.erase(obj); | 241 new_selected_map.object_map.erase(obj); |
228 } | 242 } |
229 } | 243 } |
230 | 244 |
231 // Any new objects that remain were not found in the old objects dict, and so | 245 // Any new objects that remain were not found in the old objects dict, and so |
232 // they need to be updated. | 246 // they need to be updated. |
233 for (auto layout_object : new_selected_map.object_map.Keys()) | 247 for (auto layout_object : new_selected_map.object_map.Keys()) |
234 layout_object->SetShouldInvalidateSelection(); | 248 layout_object->SetShouldInvalidateSelection(); |
235 | 249 |
236 // Have any of the old blocks changed? | 250 // Have any of the old blocks changed? |
237 for (const auto& pair : old_selected_map.block_map) { | 251 for (const auto& pair : old_selected_map.block_map) { |
238 LayoutBlock* block = pair.key; | 252 LayoutBlock* block = pair.key; |
239 SelectionState new_selection_state = block->GetSelectionState(); | 253 SelectionState new_selection_state = block->GetSelectionState(); |
240 SelectionState old_selection_state = pair.value; | 254 SelectionState old_selection_state = pair.value; |
241 if (new_selection_state != old_selection_state) { | 255 if (new_selection_state != old_selection_state) { |
242 block->SetShouldInvalidateSelection(); | 256 block->SetShouldInvalidateSelection(); |
243 new_selected_map.block_map.erase(block); | 257 new_selected_map.block_map.erase(block); |
244 } | 258 } |
245 } | 259 } |
246 | 260 |
247 // Any new blocks that remain were not found in the old blocks dict, and so | 261 // Any new blocks that remain were not found in the old blocks dict, and so |
248 // they need to be updated. | 262 // they need to be updated. |
249 for (auto layout_object : new_selected_map.block_map.Keys()) | 263 for (auto layout_object : new_selected_map.block_map.Keys()) |
250 layout_object->SetShouldInvalidateSelection(); | 264 layout_object->SetShouldInvalidateSelection(); |
251 | 265 |
252 // set selection start and end | 266 paint_range_ = new_range; |
253 selection_start_ = start; | |
254 selection_start_pos_ = start_pos; | |
255 selection_end_ = end; | |
256 selection_end_pos_ = end_pos; | |
257 } | 267 } |
258 | 268 |
259 std::pair<int, int> LayoutSelection::SelectionStartEnd() { | 269 std::pair<int, int> LayoutSelection::SelectionStartEnd() { |
260 Commit(); | 270 Commit(); |
261 return std::make_pair(selection_start_pos_, selection_end_pos_); | 271 return std::make_pair(paint_range_.StartOffset(), paint_range_.EndOffset()); |
262 } | 272 } |
263 | 273 |
264 void LayoutSelection::ClearSelection() { | 274 void LayoutSelection::ClearSelection() { |
265 // For querying Layer::compositingState() | 275 // For querying Layer::compositingState() |
266 // This is correct, since destroying layout objects needs to cause eager paint | 276 // This is correct, since destroying layout objects needs to cause eager paint |
267 // invalidations. | 277 // invalidations. |
268 DisableCompositingQueryAsserts disabler; | 278 DisableCompositingQueryAsserts disabler; |
269 | 279 |
270 // Just return if the selection hasn't changed. | 280 // Just return if the selection is already empty. |
271 if (!selection_start_) { | 281 if (paint_range_ == SelectionPaintRange()) |
272 DCHECK_EQ(selection_end_, nullptr); | |
273 DCHECK_EQ(selection_start_pos_, -1); | |
274 DCHECK_EQ(selection_end_pos_, -1); | |
275 return; | 282 return; |
276 } | |
277 | 283 |
278 const SelectedMap& old_selected_map = | 284 const SelectedMap& old_selected_map = |
279 CollectSelectedMap(selection_start_, selection_end_, selection_end_pos_, | 285 CollectSelectedMap(paint_range_, kPaintInvalidationNewMinusOld); |
280 kPaintInvalidationNewMinusOld); | |
281 // Clear SelectionState and invalidation. | 286 // Clear SelectionState and invalidation. |
282 for (auto layout_object : old_selected_map.object_map.Keys()) { | 287 for (auto layout_object : old_selected_map.object_map.Keys()) { |
283 const SelectionState old_state = layout_object->GetSelectionState(); | 288 const SelectionState old_state = layout_object->GetSelectionState(); |
284 layout_object->SetSelectionStateIfNeeded(SelectionNone); | 289 layout_object->SetSelectionStateIfNeeded(SelectionNone); |
285 if (layout_object->GetSelectionState() == old_state) | 290 if (layout_object->GetSelectionState() == old_state) |
286 continue; | 291 continue; |
287 layout_object->SetShouldInvalidateSelection(); | 292 layout_object->SetShouldInvalidateSelection(); |
288 } | 293 } |
289 | 294 |
290 // Reset selection start and end. | 295 // Reset selection start and end. |
291 selection_start_ = nullptr; | 296 paint_range_ = SelectionPaintRange(); |
292 selection_start_pos_ = -1; | |
293 selection_end_ = nullptr; | |
294 selection_end_pos_ = -1; | |
295 } | 297 } |
296 | 298 |
297 void LayoutSelection::Commit() { | 299 void LayoutSelection::Commit() { |
298 if (!HasPendingSelection()) | 300 if (!HasPendingSelection()) |
299 return; | 301 return; |
300 has_pending_selection_ = false; | 302 has_pending_selection_ = false; |
301 | 303 |
302 const VisibleSelectionInFlatTree& original_selection = | 304 const VisibleSelectionInFlatTree& original_selection = |
303 frame_selection_->ComputeVisibleSelectionInFlatTree(); | 305 frame_selection_->ComputeVisibleSelectionInFlatTree(); |
304 | 306 |
(...skipping 30 matching lines...) Expand all Loading... | |
335 if (start_pos.IsNull() || end_pos.IsNull() || | 337 if (start_pos.IsNull() || end_pos.IsNull() || |
336 selection.VisibleStart().DeepEquivalent() == | 338 selection.VisibleStart().DeepEquivalent() == |
337 selection.VisibleEnd().DeepEquivalent()) | 339 selection.VisibleEnd().DeepEquivalent()) |
338 return; | 340 return; |
339 DCHECK_LE(start_pos, end_pos); | 341 DCHECK_LE(start_pos, end_pos); |
340 LayoutObject* start_layout_object = start_pos.AnchorNode()->GetLayoutObject(); | 342 LayoutObject* start_layout_object = start_pos.AnchorNode()->GetLayoutObject(); |
341 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject(); | 343 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject(); |
342 if (!start_layout_object || !end_layout_object) | 344 if (!start_layout_object || !end_layout_object) |
343 return; | 345 return; |
344 DCHECK(start_layout_object->View() == end_layout_object->View()); | 346 DCHECK(start_layout_object->View() == end_layout_object->View()); |
345 SetSelection(start_layout_object, start_pos.ComputeEditingOffset(), | 347 SetSelection( |
346 end_layout_object, end_pos.ComputeEditingOffset()); | 348 SelectionPaintRange(start_layout_object, start_pos.ComputeEditingOffset(), |
349 end_layout_object, end_pos.ComputeEditingOffset())); | |
347 } | 350 } |
348 | 351 |
349 void LayoutSelection::OnDocumentShutdown() { | 352 void LayoutSelection::OnDocumentShutdown() { |
350 has_pending_selection_ = false; | 353 has_pending_selection_ = false; |
351 selection_start_ = nullptr; | 354 paint_range_ = SelectionPaintRange(); |
352 selection_end_ = nullptr; | |
353 selection_start_pos_ = -1; | |
354 selection_end_pos_ = -1; | |
355 } | 355 } |
356 | 356 |
357 static LayoutRect SelectionRectForLayoutObject(const LayoutObject* object) { | 357 static LayoutRect SelectionRectForLayoutObject(const LayoutObject* object) { |
358 if (!object->IsRooted()) | 358 if (!object->IsRooted()) |
359 return LayoutRect(); | 359 return LayoutRect(); |
360 | 360 |
361 if (!object->CanUpdateSelectionOnRootLineBoxes()) | 361 if (!object->CanUpdateSelectionOnRootLineBoxes()) |
362 return LayoutRect(); | 362 return LayoutRect(); |
363 | 363 |
364 return object->SelectionRectInViewCoordinates(); | 364 return object->SelectionRectInViewCoordinates(); |
365 } | 365 } |
366 | 366 |
367 IntRect LayoutSelection::SelectionBounds() { | 367 IntRect LayoutSelection::SelectionBounds() { |
368 // Now create a single bounding box rect that encloses the whole selection. | 368 // Now create a single bounding box rect that encloses the whole selection. |
369 LayoutRect sel_rect; | 369 LayoutRect sel_rect; |
370 | 370 |
371 typedef HashSet<const LayoutBlock*> VisitedContainingBlockSet; | 371 typedef HashSet<const LayoutBlock*> VisitedContainingBlockSet; |
372 VisitedContainingBlockSet visited_containing_blocks; | 372 VisitedContainingBlockSet visited_containing_blocks; |
373 | 373 |
374 Commit(); | 374 Commit(); |
375 LayoutObject* os = selection_start_; | 375 LayoutObject* os = paint_range_.StartLayoutObject(); |
376 LayoutObject* stop = | 376 LayoutObject* stop = LayoutObjectAfterPosition(paint_range_.EndLayoutObject(), |
377 LayoutObjectAfterPosition(selection_end_, selection_end_pos_); | 377 paint_range_.EndOffset()); |
378 while (os && os != stop) { | 378 while (os && os != stop) { |
379 if ((os->CanBeSelectionLeaf() || os == selection_start_ || | 379 if ((os->CanBeSelectionLeaf() || os == paint_range_.StartLayoutObject() || |
380 os == selection_end_) && | 380 os == paint_range_.EndLayoutObject()) && |
381 os->GetSelectionState() != SelectionNone) { | 381 os->GetSelectionState() != SelectionNone) { |
382 // Blocks are responsible for painting line gaps and margin gaps. They | 382 // Blocks are responsible for painting line gaps and margin gaps. They |
383 // must be examined as well. | 383 // must be examined as well. |
384 sel_rect.Unite(SelectionRectForLayoutObject(os)); | 384 sel_rect.Unite(SelectionRectForLayoutObject(os)); |
385 const LayoutBlock* cb = os->ContainingBlock(); | 385 const LayoutBlock* cb = os->ContainingBlock(); |
386 while (cb && !cb->IsLayoutView()) { | 386 while (cb && !cb->IsLayoutView()) { |
387 sel_rect.Unite(SelectionRectForLayoutObject(cb)); | 387 sel_rect.Unite(SelectionRectForLayoutObject(cb)); |
388 VisitedContainingBlockSet::AddResult add_result = | 388 VisitedContainingBlockSet::AddResult add_result = |
389 visited_containing_blocks.insert(cb); | 389 visited_containing_blocks.insert(cb); |
390 if (!add_result.is_new_entry) | 390 if (!add_result.is_new_entry) |
391 break; | 391 break; |
392 cb = cb->ContainingBlock(); | 392 cb = cb->ContainingBlock(); |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 os = os->NextInPreOrder(); | 396 os = os->NextInPreOrder(); |
397 } | 397 } |
398 | 398 |
399 return PixelSnappedIntRect(sel_rect); | 399 return PixelSnappedIntRect(sel_rect); |
400 } | 400 } |
401 | 401 |
402 void LayoutSelection::InvalidatePaintForSelection() { | 402 void LayoutSelection::InvalidatePaintForSelection() { |
403 LayoutObject* end = | 403 LayoutObject* end = LayoutObjectAfterPosition(paint_range_.EndLayoutObject(), |
404 LayoutObjectAfterPosition(selection_end_, selection_end_pos_); | 404 paint_range_.EndOffset()); |
405 for (LayoutObject* o = selection_start_; o && o != end; | 405 for (LayoutObject* o = paint_range_.StartLayoutObject(); o && o != end; |
406 o = o->NextInPreOrder()) { | 406 o = o->NextInPreOrder()) { |
407 if (!o->CanBeSelectionLeaf() && o != selection_start_ && | 407 if (!o->CanBeSelectionLeaf() && o != paint_range_.StartLayoutObject() && |
408 o != selection_end_) | 408 o != paint_range_.EndLayoutObject()) |
409 continue; | 409 continue; |
410 if (o->GetSelectionState() == SelectionNone) | 410 if (o->GetSelectionState() == SelectionNone) |
411 continue; | 411 continue; |
412 | 412 |
413 o->SetShouldInvalidateSelection(); | 413 o->SetShouldInvalidateSelection(); |
414 } | 414 } |
415 } | 415 } |
416 | 416 |
417 DEFINE_TRACE(LayoutSelection) { | 417 DEFINE_TRACE(LayoutSelection) { |
418 visitor->Trace(frame_selection_); | 418 visitor->Trace(frame_selection_); |
419 } | 419 } |
420 | 420 |
421 } // namespace blink | 421 } // namespace blink |
OLD | NEW |