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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 | 102 |
103 current_ = nullptr; | 103 current_ = nullptr; |
104 return *this; | 104 return *this; |
105 } | 105 } |
106 | 106 |
107 LayoutSelection::LayoutSelection(FrameSelection& frame_selection) | 107 LayoutSelection::LayoutSelection(FrameSelection& frame_selection) |
108 : frame_selection_(&frame_selection), | 108 : frame_selection_(&frame_selection), |
109 has_pending_selection_(false), | 109 has_pending_selection_(false), |
110 paint_range_(SelectionPaintRange()) {} | 110 paint_range_(SelectionPaintRange()) {} |
111 | 111 |
112 static SelectionInFlatTree CalcSelection( | 112 static VisibleSelectionInFlatTree CalcSelection( |
113 const VisibleSelectionInFlatTree& original_selection, | 113 const FrameSelection& frame_selection) { |
114 bool should_show_blok_cursor) { | 114 const VisibleSelectionInFlatTree& original_selection = |
115 const PositionInFlatTree& start = original_selection.Start(); | 115 frame_selection.ComputeVisibleSelectionInFlatTree(); |
116 const PositionInFlatTree& end = original_selection.End(); | |
117 SelectionType selection_type = original_selection.GetSelectionType(); | |
118 const TextAffinity affinity = original_selection.Affinity(); | |
119 | 116 |
120 bool paint_block_cursor = | 117 const bool paint_block_cursor = |
yosin_UTC9
2017/06/23 03:53:50
Could you move this expression into function?
yoichio
2017/06/23 04:27:15
I don't understand. This expression is used only h
yosin_UTC9
2017/06/23 04:46:11
It is noisy for reading code focusing CalcSelectio
yoichio
2017/06/23 05:01:01
O.K. Done.
| |
121 should_show_blok_cursor && | 118 frame_selection.ShouldShowBlockCursor() && |
122 selection_type == SelectionType::kCaretSelection && | 119 original_selection.GetSelectionType() == SelectionType::kCaretSelection && |
yosin_UTC9
2017/06/23 04:46:11
original_selection.IsCaret()
| |
123 !IsLogicalEndOfLine(CreateVisiblePosition(end, affinity)); | 120 !IsLogicalEndOfLine(CreateVisiblePosition(original_selection.End(), |
124 if (EnclosingTextControl(start.ComputeContainerNode())) { | 121 original_selection.Affinity())); |
125 // TODO(yosin) We should use |PositionMoveType::CodePoint| to avoid | 122 if (!paint_block_cursor) |
126 // ending paint at middle of character. | 123 return original_selection; |
127 PositionInFlatTree end_position = | |
128 paint_block_cursor ? NextPositionOf(original_selection.Extent(), | |
129 PositionMoveType::kCodeUnit) | |
130 : end; | |
131 return SelectionInFlatTree::Builder() | |
132 .SetBaseAndExtent(start, end_position) | |
133 .Build(); | |
134 } | |
135 | 124 |
136 const VisiblePositionInFlatTree& visible_start = CreateVisiblePosition( | 125 // TODO(editing-dev): We should consider BIDI. |
yosin_UTC9
2017/06/23 03:53:50
Could you explain more about this?
NextPositionOf(
yoichio
2017/06/23 04:27:15
Understood. This works already.
| |
137 start, selection_type == SelectionType::kRangeSelection | 126 const PositionInFlatTree end_position = NextPositionOf( |
138 ? TextAffinity::kDownstream | 127 original_selection.Extent(), PositionMoveType::kGraphemeCluster); |
139 : affinity); | 128 return CreateVisibleSelection( |
140 if (visible_start.IsNull()) | 129 SelectionInFlatTree::Builder() |
141 return SelectionInFlatTree(); | 130 .SetBaseAndExtent(original_selection.Start(), end_position) |
142 if (paint_block_cursor) { | 131 .Build()); |
143 const VisiblePositionInFlatTree visible_extent = NextPositionOf( | |
144 CreateVisiblePosition(end, affinity), kCanSkipOverEditingBoundary); | |
145 if (visible_extent.IsNull()) | |
146 return SelectionInFlatTree(); | |
147 SelectionInFlatTree::Builder builder; | |
148 builder.Collapse(visible_start.ToPositionWithAffinity()); | |
149 builder.Extend(visible_extent.DeepEquivalent()); | |
150 return builder.Build(); | |
151 } | |
152 const VisiblePositionInFlatTree visible_end = CreateVisiblePosition( | |
153 end, selection_type == SelectionType::kRangeSelection | |
154 ? TextAffinity::kUpstream | |
155 : affinity); | |
156 if (visible_end.IsNull()) | |
157 return SelectionInFlatTree(); | |
158 SelectionInFlatTree::Builder builder; | |
159 builder.Collapse(visible_start.ToPositionWithAffinity()); | |
160 builder.Extend(visible_end.DeepEquivalent()); | |
161 return builder.Build(); | |
162 } | 132 } |
163 | 133 |
164 | |
165 | |
166 // Objects each have a single selection rect to examine. | 134 // Objects each have a single selection rect to examine. |
167 using SelectedObjectMap = HashMap<LayoutObject*, SelectionState>; | 135 using SelectedObjectMap = HashMap<LayoutObject*, SelectionState>; |
168 // Blocks contain selected objects and fill gaps between them, either on the | 136 // Blocks contain selected objects and fill gaps between them, either on the |
169 // left, right, or in between lines and blocks. | 137 // left, right, or in between lines and blocks. |
170 // In order to get the visual rect right, we have to examine left, middle, and | 138 // In order to get the visual rect right, we have to examine left, middle, and |
171 // right rects individually, since otherwise the union of those rects might | 139 // right rects individually, since otherwise the union of those rects might |
172 // remain the same even when changes have occurred. | 140 // remain the same even when changes have occurred. |
173 using SelectedBlockMap = HashMap<LayoutBlock*, SelectionState>; | 141 using SelectedBlockMap = HashMap<LayoutBlock*, SelectionState>; |
174 struct SelectedMap { | 142 struct SelectedMap { |
175 STACK_ALLOCATED(); | 143 STACK_ALLOCATED(); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 paint_range_ = SelectionPaintRange(); | 285 paint_range_ = SelectionPaintRange(); |
318 } | 286 } |
319 | 287 |
320 static SelectionPaintRange CalcSelectionPaintRange( | 288 static SelectionPaintRange CalcSelectionPaintRange( |
321 const FrameSelection& frame_selection) { | 289 const FrameSelection& frame_selection) { |
322 const SelectionInDOMTree& selection_in_dom = | 290 const SelectionInDOMTree& selection_in_dom = |
323 frame_selection.GetSelectionInDOMTree(); | 291 frame_selection.GetSelectionInDOMTree(); |
324 if (selection_in_dom.IsNone()) | 292 if (selection_in_dom.IsNone()) |
325 return SelectionPaintRange(); | 293 return SelectionPaintRange(); |
326 | 294 |
327 const VisibleSelectionInFlatTree& original_selection = | 295 const VisibleSelectionInFlatTree& selection = CalcSelection(frame_selection); |
328 frame_selection.ComputeVisibleSelectionInFlatTree(); | |
329 // Construct a new VisibleSolution, since visibleSelection() is not | |
330 // necessarily valid, and the following steps assume a valid selection. See | |
331 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and | |
332 // <rdar://problem/10232866>. | |
333 const SelectionInFlatTree& new_selection = CalcSelection( | |
334 original_selection, frame_selection.ShouldShowBlockCursor()); | |
335 const VisibleSelectionInFlatTree& selection = | |
336 CreateVisibleSelection(new_selection); | |
337 | |
338 if (!selection.IsRange() || frame_selection.IsHidden()) | 296 if (!selection.IsRange() || frame_selection.IsHidden()) |
339 return SelectionPaintRange(); | 297 return SelectionPaintRange(); |
340 | 298 |
341 DCHECK(!selection.IsNone()); | 299 DCHECK(!selection.IsNone()); |
342 const PositionInFlatTree start_pos = selection.Start(); | 300 const PositionInFlatTree start_pos = selection.Start(); |
343 const PositionInFlatTree end_pos = selection.End(); | 301 const PositionInFlatTree end_pos = selection.End(); |
344 DCHECK_LE(start_pos, end_pos); | 302 DCHECK_LE(start_pos, end_pos); |
345 LayoutObject* start_layout_object = start_pos.AnchorNode()->GetLayoutObject(); | 303 LayoutObject* start_layout_object = start_pos.AnchorNode()->GetLayoutObject(); |
346 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject(); | 304 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject(); |
347 DCHECK(start_layout_object); | 305 DCHECK(start_layout_object); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 | 373 |
416 runner->SetShouldInvalidateSelection(); | 374 runner->SetShouldInvalidateSelection(); |
417 } | 375 } |
418 } | 376 } |
419 | 377 |
420 DEFINE_TRACE(LayoutSelection) { | 378 DEFINE_TRACE(LayoutSelection) { |
421 visitor->Trace(frame_selection_); | 379 visitor->Trace(frame_selection_); |
422 } | 380 } |
423 | 381 |
424 } // namespace blink | 382 } // namespace blink |
OLD | NEW |