Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 VisibleSelectionTemplate(const VisibleSelectionTemplate&); | 58 VisibleSelectionTemplate(const VisibleSelectionTemplate&); |
| 59 VisibleSelectionTemplate& operator=(const VisibleSelectionTemplate&); | 59 VisibleSelectionTemplate& operator=(const VisibleSelectionTemplate&); |
| 60 | 60 |
| 61 // Note: |create()| should be used only by |createVisibleSelection| and | 61 // Note: |create()| should be used only by |createVisibleSelection| and |
| 62 // |selectionFromContentsOfNode|. | 62 // |selectionFromContentsOfNode|. |
| 63 // TODO(xiaochengh): Use enum class instead of boolean parameter. | 63 // TODO(xiaochengh): Use enum class instead of boolean parameter. |
| 64 static VisibleSelectionTemplate create( | 64 static VisibleSelectionTemplate create( |
| 65 const PositionTemplate<Strategy>& base, | 65 const PositionTemplate<Strategy>& base, |
| 66 const PositionTemplate<Strategy>& extent, | 66 const PositionTemplate<Strategy>& extent, |
| 67 TextAffinity, | 67 TextAffinity, |
| 68 bool isDirectional); | 68 bool isDirectional, |
| 69 bool isHandleVisible); | |
|
yosin_UTC9
2016/10/07 05:17:59
Please move |isHandleVisible| to |FrameSelection|.
amaralp
2016/10/14 00:53:07
Moved.
| |
| 69 | 70 |
| 70 static VisibleSelectionTemplate selectionFromContentsOfNode(Node*); | 71 static VisibleSelectionTemplate selectionFromContentsOfNode(Node*); |
| 71 | 72 |
| 72 SelectionType getSelectionType() const { return m_selectionType; } | 73 SelectionType getSelectionType() const { return m_selectionType; } |
| 73 | 74 |
| 75 void setIsHandleVisible(bool isHandleVisible) { | |
| 76 m_isHandleVisible = isHandleVisible; | |
| 77 } | |
| 78 bool isHandleVisible() const { return m_isHandleVisible; } | |
| 79 | |
| 74 void setAffinity(TextAffinity affinity) { m_affinity = affinity; } | 80 void setAffinity(TextAffinity affinity) { m_affinity = affinity; } |
| 75 TextAffinity affinity() const { return m_affinity; } | 81 TextAffinity affinity() const { return m_affinity; } |
| 76 | 82 |
| 77 void setBase(const PositionTemplate<Strategy>&); | 83 void setBase(const PositionTemplate<Strategy>&); |
| 78 void setBase(const VisiblePositionTemplate<Strategy>&); | 84 void setBase(const VisiblePositionTemplate<Strategy>&); |
| 79 void setExtent(const PositionTemplate<Strategy>&); | 85 void setExtent(const PositionTemplate<Strategy>&); |
| 80 void setExtent(const VisiblePositionTemplate<Strategy>&); | 86 void setExtent(const VisiblePositionTemplate<Strategy>&); |
| 81 | 87 |
| 82 PositionTemplate<Strategy> base() const { return m_base; } | 88 PositionTemplate<Strategy> base() const { return m_base; } |
| 83 PositionTemplate<Strategy> extent() const { return m_extent; } | 89 PositionTemplate<Strategy> extent() const { return m_extent; } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 void showTreeForThis() const; | 175 void showTreeForThis() const; |
| 170 #endif | 176 #endif |
| 171 static void PrintTo(const VisibleSelectionTemplate&, std::ostream*); | 177 static void PrintTo(const VisibleSelectionTemplate&, std::ostream*); |
| 172 | 178 |
| 173 private: | 179 private: |
| 174 friend class SelectionAdjuster; | 180 friend class SelectionAdjuster; |
| 175 | 181 |
| 176 VisibleSelectionTemplate(const PositionTemplate<Strategy>& base, | 182 VisibleSelectionTemplate(const PositionTemplate<Strategy>& base, |
| 177 const PositionTemplate<Strategy>& extent, | 183 const PositionTemplate<Strategy>& extent, |
| 178 TextAffinity, | 184 TextAffinity, |
| 179 bool isDirectional); | 185 bool isDirectional, |
| 186 bool isHandleVisible); | |
| 180 | 187 |
| 181 void validate(TextGranularity = CharacterGranularity); | 188 void validate(TextGranularity = CharacterGranularity); |
| 182 | 189 |
| 183 // Support methods for validate() | 190 // Support methods for validate() |
| 184 void setBaseAndExtentToDeepEquivalents(); | 191 void setBaseAndExtentToDeepEquivalents(); |
| 185 void adjustSelectionToAvoidCrossingShadowBoundaries(); | 192 void adjustSelectionToAvoidCrossingShadowBoundaries(); |
| 186 void adjustSelectionToAvoidCrossingEditingBoundaries(); | 193 void adjustSelectionToAvoidCrossingEditingBoundaries(); |
| 187 void setEndRespectingGranularity(TextGranularity); | 194 void setEndRespectingGranularity(TextGranularity); |
| 188 void setStartRespectingGranularity(TextGranularity); | 195 void setStartRespectingGranularity(TextGranularity); |
| 189 void updateSelectionType(); | 196 void updateSelectionType(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 210 // Non-directional ignores m_baseIsFirst and selection always extends on shift | 217 // Non-directional ignores m_baseIsFirst and selection always extends on shift |
| 211 // + arrow key. | 218 // + arrow key. |
| 212 bool m_isDirectional : 1; | 219 bool m_isDirectional : 1; |
| 213 | 220 |
| 214 TextGranularity m_granularity; | 221 TextGranularity m_granularity; |
| 215 // |updateIfNeeded()| uses |m_hasTrailingWhitespace| for word granularity. | 222 // |updateIfNeeded()| uses |m_hasTrailingWhitespace| for word granularity. |
| 216 // |m_hasTrailingWhitespace| is set by |appendTrailingWhitespace()|. | 223 // |m_hasTrailingWhitespace| is set by |appendTrailingWhitespace()|. |
| 217 // TODO(yosin): Once we unify start/end and base/extent, we should get rid | 224 // TODO(yosin): Once we unify start/end and base/extent, we should get rid |
| 218 // of |m_hasTrailingWhitespace|. | 225 // of |m_hasTrailingWhitespace|. |
| 219 bool m_hasTrailingWhitespace : 1; | 226 bool m_hasTrailingWhitespace : 1; |
| 227 bool m_isHandleVisible : 1; | |
| 220 }; | 228 }; |
| 221 | 229 |
| 222 extern template class CORE_EXTERN_TEMPLATE_EXPORT | 230 extern template class CORE_EXTERN_TEMPLATE_EXPORT |
| 223 VisibleSelectionTemplate<EditingStrategy>; | 231 VisibleSelectionTemplate<EditingStrategy>; |
| 224 extern template class CORE_EXTERN_TEMPLATE_EXPORT | 232 extern template class CORE_EXTERN_TEMPLATE_EXPORT |
| 225 VisibleSelectionTemplate<EditingInFlatTreeStrategy>; | 233 VisibleSelectionTemplate<EditingInFlatTreeStrategy>; |
| 226 | 234 |
| 227 using VisibleSelection = VisibleSelectionTemplate<EditingStrategy>; | 235 using VisibleSelection = VisibleSelectionTemplate<EditingStrategy>; |
| 228 using VisibleSelectionInFlatTree = | 236 using VisibleSelectionInFlatTree = |
| 229 VisibleSelectionTemplate<EditingInFlatTreeStrategy>; | 237 VisibleSelectionTemplate<EditingInFlatTreeStrategy>; |
| 230 | 238 |
| 231 // TODO(xiaochengh): Introduce builder class to get rid of these overloads. | 239 // TODO(xiaochengh): Introduce builder class to get rid of these overloads. |
| 232 CORE_EXPORT VisibleSelection createVisibleSelection(const Position&, | 240 CORE_EXPORT VisibleSelection |
| 233 TextAffinity, | 241 createVisibleSelection(const Position&, |
| 234 bool isDirectional = false); | 242 TextAffinity, |
| 243 bool isDirectional = false, | |
| 244 bool isHandleVisible = false); | |
| 235 CORE_EXPORT VisibleSelection | 245 CORE_EXPORT VisibleSelection |
| 236 createVisibleSelection(const Position& base, | 246 createVisibleSelection(const Position& base, |
| 237 const Position& extent, | 247 const Position& extent, |
| 238 TextAffinity = SelDefaultAffinity, | 248 TextAffinity = SelDefaultAffinity, |
| 239 bool isDirectional = false); | 249 bool isDirectional = false, |
| 250 bool isHandleVisible = false); | |
| 240 CORE_EXPORT VisibleSelection | 251 CORE_EXPORT VisibleSelection |
| 241 createVisibleSelection(const EphemeralRange&, | 252 createVisibleSelection(const EphemeralRange&, |
| 242 TextAffinity = SelDefaultAffinity, | 253 TextAffinity = SelDefaultAffinity, |
| 243 bool isDirectional = false); | 254 bool isDirectional = false, |
| 244 CORE_EXPORT VisibleSelection createVisibleSelection(const VisiblePosition&, | 255 bool isHandleVisible = false); |
| 245 bool isDirectional = false); | 256 CORE_EXPORT VisibleSelection |
| 246 CORE_EXPORT VisibleSelection createVisibleSelection(const VisiblePosition&, | 257 createVisibleSelection(const VisiblePosition&, |
| 247 const VisiblePosition&, | 258 bool isDirectional = false, |
| 248 bool isDirectional = false); | 259 bool isHandleVisible = false); |
| 249 CORE_EXPORT VisibleSelection createVisibleSelection(const PositionWithAffinity&, | 260 CORE_EXPORT VisibleSelection |
| 250 bool isDirectional = false); | 261 createVisibleSelection(const VisiblePosition&, |
| 262 const VisiblePosition&, | |
| 263 bool isDirectional = false, | |
| 264 bool isHandleVisible = false); | |
| 265 CORE_EXPORT VisibleSelection | |
| 266 createVisibleSelection(const PositionWithAffinity&, | |
| 267 bool isDirectional = false, | |
| 268 bool isHandleVisible = false); | |
| 251 | 269 |
| 252 CORE_EXPORT VisibleSelectionInFlatTree | 270 CORE_EXPORT VisibleSelectionInFlatTree |
| 253 createVisibleSelection(const PositionInFlatTree&, | 271 createVisibleSelection(const PositionInFlatTree&, |
| 254 TextAffinity, | 272 TextAffinity, |
| 255 bool isDirectional = false); | 273 bool isDirectional = false, |
| 274 bool isHandleVisible = false); | |
| 256 CORE_EXPORT VisibleSelectionInFlatTree | 275 CORE_EXPORT VisibleSelectionInFlatTree |
| 257 createVisibleSelection(const PositionInFlatTree& base, | 276 createVisibleSelection(const PositionInFlatTree& base, |
| 258 const PositionInFlatTree& extent, | 277 const PositionInFlatTree& extent, |
| 259 TextAffinity = SelDefaultAffinity, | 278 TextAffinity = SelDefaultAffinity, |
| 260 bool isDirectional = false); | 279 bool isDirectional = false, |
| 280 bool isHandleVisible = false); | |
| 261 CORE_EXPORT VisibleSelectionInFlatTree | 281 CORE_EXPORT VisibleSelectionInFlatTree |
| 262 createVisibleSelection(const EphemeralRangeInFlatTree&, | 282 createVisibleSelection(const EphemeralRangeInFlatTree&, |
| 263 TextAffinity = SelDefaultAffinity, | 283 TextAffinity = SelDefaultAffinity, |
| 264 bool isDirectional = false); | 284 bool isDirectional = false, |
| 285 bool isHandleVisible = false); | |
| 265 CORE_EXPORT VisibleSelectionInFlatTree | 286 CORE_EXPORT VisibleSelectionInFlatTree |
| 266 createVisibleSelection(const VisiblePositionInFlatTree&, | 287 createVisibleSelection(const VisiblePositionInFlatTree&, |
| 267 bool isDirectional = false); | 288 bool isDirectional = false, |
| 289 bool isHandleVisible = false); | |
| 268 CORE_EXPORT VisibleSelectionInFlatTree | 290 CORE_EXPORT VisibleSelectionInFlatTree |
| 269 createVisibleSelection(const VisiblePositionInFlatTree&, | 291 createVisibleSelection(const VisiblePositionInFlatTree&, |
| 270 const VisiblePositionInFlatTree&, | 292 const VisiblePositionInFlatTree&, |
| 271 bool isDirectional = false); | 293 bool isDirectional = false, |
| 294 bool isHandleVisible = false); | |
| 272 CORE_EXPORT VisibleSelectionInFlatTree | 295 CORE_EXPORT VisibleSelectionInFlatTree |
| 273 createVisibleSelection(const PositionInFlatTreeWithAffinity&, | 296 createVisibleSelection(const PositionInFlatTreeWithAffinity&, |
| 274 bool isDirectional = false); | 297 bool isDirectional = false, |
| 298 bool isHandleVisible = false); | |
| 275 | 299 |
| 276 // Callers of these functions should ensure clean layout by themselves and then | 300 // Callers of these functions should ensure clean layout by themselves and then |
| 277 // switch to the proper versions (to be introduced). | 301 // switch to the proper versions (to be introduced). |
| 278 CORE_EXPORT VisibleSelection | 302 CORE_EXPORT VisibleSelection |
| 279 createVisibleSelectionDeprecated(const Position&, | 303 createVisibleSelectionDeprecated(const Position&, |
| 280 TextAffinity, | 304 TextAffinity, |
| 281 bool isDirectional = false); | 305 bool isDirectional = false, |
| 306 bool isHandleVisible = false); | |
| 282 CORE_EXPORT VisibleSelection | 307 CORE_EXPORT VisibleSelection |
| 283 createVisibleSelectionDeprecated(const Position& base, | 308 createVisibleSelectionDeprecated(const Position& base, |
| 284 const Position& extent, | 309 const Position& extent, |
| 285 TextAffinity = SelDefaultAffinity, | 310 TextAffinity = SelDefaultAffinity, |
| 286 bool isDirectional = false); | 311 bool isDirectional = false, |
| 312 bool isHandleVisible = false); | |
| 287 CORE_EXPORT VisibleSelection | 313 CORE_EXPORT VisibleSelection |
| 288 createVisibleSelectionDeprecated(const EphemeralRange&, | 314 createVisibleSelectionDeprecated(const EphemeralRange&, |
| 289 TextAffinity = SelDefaultAffinity, | 315 TextAffinity = SelDefaultAffinity, |
| 290 bool isDirectional = false); | 316 bool isDirectional = false, |
| 317 bool isHandleVisible = false); | |
| 291 CORE_EXPORT VisibleSelection | 318 CORE_EXPORT VisibleSelection |
| 292 createVisibleSelectionDeprecated(const VisiblePosition&, | 319 createVisibleSelectionDeprecated(const VisiblePosition&, |
| 293 bool isDirectional = false); | 320 bool isDirectional = false, |
| 321 bool isHandleVisible = false); | |
| 294 CORE_EXPORT VisibleSelection | 322 CORE_EXPORT VisibleSelection |
| 295 createVisibleSelectionDeprecated(const VisiblePosition&, | 323 createVisibleSelectionDeprecated(const VisiblePosition&, |
| 296 const VisiblePosition&, | 324 const VisiblePosition&, |
| 297 bool isDirectional = false); | 325 bool isDirectional = false, |
| 326 bool isHandleVisible = false); | |
| 298 CORE_EXPORT VisibleSelection | 327 CORE_EXPORT VisibleSelection |
| 299 createVisibleSelectionDeprecated(const PositionWithAffinity&, | 328 createVisibleSelectionDeprecated(const PositionWithAffinity&, |
| 300 bool isDirectional = false); | 329 bool isDirectional = false, |
| 330 bool isHandleVisible = false); | |
| 301 | 331 |
| 302 CORE_EXPORT VisibleSelectionInFlatTree | 332 CORE_EXPORT VisibleSelectionInFlatTree |
| 303 createVisibleSelectionDeprecated(const PositionInFlatTree&, | 333 createVisibleSelectionDeprecated(const PositionInFlatTree&, |
| 304 TextAffinity, | 334 TextAffinity, |
| 305 bool isDirectional = false); | 335 bool isDirectional = false, |
| 336 bool isHandleVisible = false); | |
| 306 CORE_EXPORT VisibleSelectionInFlatTree | 337 CORE_EXPORT VisibleSelectionInFlatTree |
| 307 createVisibleSelectionDeprecated(const PositionInFlatTree& base, | 338 createVisibleSelectionDeprecated(const PositionInFlatTree& base, |
| 308 const PositionInFlatTree& extent, | 339 const PositionInFlatTree& extent, |
| 309 TextAffinity = SelDefaultAffinity, | 340 TextAffinity = SelDefaultAffinity, |
| 310 bool isDirectional = false); | 341 bool isDirectional = false, |
| 342 bool isHandleVisible = false); | |
| 311 CORE_EXPORT VisibleSelectionInFlatTree | 343 CORE_EXPORT VisibleSelectionInFlatTree |
| 312 createVisibleSelectionDeprecated(const EphemeralRangeInFlatTree&, | 344 createVisibleSelectionDeprecated(const EphemeralRangeInFlatTree&, |
| 313 TextAffinity = SelDefaultAffinity, | 345 TextAffinity = SelDefaultAffinity, |
| 314 bool isDirectional = false); | 346 bool isDirectional = false, |
| 347 bool isHandleVisible = false); | |
| 315 CORE_EXPORT VisibleSelectionInFlatTree | 348 CORE_EXPORT VisibleSelectionInFlatTree |
| 316 createVisibleSelectionDeprecated(const VisiblePositionInFlatTree&, | 349 createVisibleSelectionDeprecated(const VisiblePositionInFlatTree&, |
| 317 bool isDirectional = false); | 350 bool isDirectional = false, |
| 351 bool isHandleVisible = false); | |
| 318 CORE_EXPORT VisibleSelectionInFlatTree | 352 CORE_EXPORT VisibleSelectionInFlatTree |
| 319 createVisibleSelectionDeprecated(const VisiblePositionInFlatTree&, | 353 createVisibleSelectionDeprecated(const VisiblePositionInFlatTree&, |
| 320 const VisiblePositionInFlatTree&, | 354 const VisiblePositionInFlatTree&, |
| 321 bool isDirectional = false); | 355 bool isDirectional = false, |
| 356 bool isHandleVisible = false); | |
| 322 CORE_EXPORT VisibleSelectionInFlatTree | 357 CORE_EXPORT VisibleSelectionInFlatTree |
| 323 createVisibleSelectionDeprecated(const PositionInFlatTreeWithAffinity&, | 358 createVisibleSelectionDeprecated(const PositionInFlatTreeWithAffinity&, |
| 324 bool isDirectional = false); | 359 bool isDirectional = false, |
| 360 bool isHandleVisible = false); | |
| 325 | 361 |
| 326 // We don't yet support multi-range selections, so we only ever have one range | 362 // We don't yet support multi-range selections, so we only ever have one range |
| 327 // to return. | 363 // to return. |
| 328 CORE_EXPORT EphemeralRange firstEphemeralRangeOf(const VisibleSelection&); | 364 CORE_EXPORT EphemeralRange firstEphemeralRangeOf(const VisibleSelection&); |
| 329 | 365 |
| 330 // TODO(sof): move more firstRangeOf() uses to be over EphemeralRange instead. | 366 // TODO(sof): move more firstRangeOf() uses to be over EphemeralRange instead. |
| 331 CORE_EXPORT Range* firstRangeOf(const VisibleSelection&); | 367 CORE_EXPORT Range* firstRangeOf(const VisibleSelection&); |
| 332 | 368 |
| 333 CORE_EXPORT std::ostream& operator<<(std::ostream&, const VisibleSelection&); | 369 CORE_EXPORT std::ostream& operator<<(std::ostream&, const VisibleSelection&); |
| 334 CORE_EXPORT std::ostream& operator<<(std::ostream&, | 370 CORE_EXPORT std::ostream& operator<<(std::ostream&, |
| 335 const VisibleSelectionInFlatTree&); | 371 const VisibleSelectionInFlatTree&); |
| 336 | 372 |
| 337 } // namespace blink | 373 } // namespace blink |
| 338 | 374 |
| 339 #ifndef NDEBUG | 375 #ifndef NDEBUG |
| 340 // Outside the WebCore namespace for ease of invocation from gdb. | 376 // Outside the WebCore namespace for ease of invocation from gdb. |
| 341 void showTree(const blink::VisibleSelection&); | 377 void showTree(const blink::VisibleSelection&); |
| 342 void showTree(const blink::VisibleSelection*); | 378 void showTree(const blink::VisibleSelection*); |
| 343 void showTree(const blink::VisibleSelectionInFlatTree&); | 379 void showTree(const blink::VisibleSelectionInFlatTree&); |
| 344 void showTree(const blink::VisibleSelectionInFlatTree*); | 380 void showTree(const blink::VisibleSelectionInFlatTree*); |
| 345 #endif | 381 #endif |
| 346 | 382 |
| 347 #endif // VisibleSelection_h | 383 #endif // VisibleSelection_h |
| OLD | NEW |