Changeset 40738 in webkit
- Timestamp:
- Feb 6, 2009 4:04:48 PM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r40737 r40738 1 2009-02-06 Eric Seidel <eric@webkit.org> 2 3 Reviewed by Justin Garcia. 4 5 Minor refactoring and cleanup to Selection code 6 https://bugs.webkit.org/show_bug.cgi?id=23774 7 8 No functional changes, thus no tests. 9 10 * editing/Editor.cpp: 11 (WebCore::Editor::applyStyle): 12 (WebCore::Editor::applyParagraphStyle): 13 * editing/Selection.cpp: 14 (WebCore::Selection::Selection): 15 (WebCore::Selection::setBaseAndExtentToDeepEquivalents): 16 (WebCore::Selection::setStartAndEndFromBaseAndExtentRespectingGranularity): 17 (WebCore::Selection::updateSelectionType): 18 (WebCore::Selection::validate): 19 (WebCore::Selection::setWithoutValidation): 20 (WebCore::Selection::adjustSelectionToAvoidCrossingEditingBoundaries): 21 * editing/Selection.h: 22 (WebCore::Selection::): 23 (WebCore::Selection::selectionType): 24 (WebCore::Selection::extent): 25 (WebCore::Selection::isNone): 26 (WebCore::Selection::isCaret): 27 (WebCore::Selection::isRange): 28 (WebCore::Selection::isCaretOrRange): 29 * editing/SelectionController.h: 30 (WebCore::SelectionController::selectionType): 31 * editing/TypingCommand.cpp: 32 (WebCore::TypingCommand::deleteKeyPressed): 33 (WebCore::TypingCommand::forwardDeleteKeyPressed): 34 * page/Frame.cpp: 35 (WebCore::Frame::revealSelection): 36 1 37 2009-02-06 Dimitri Glazkov <dglazkov@chromium.org> 2 38 -
trunk/WebCore/editing/Editor.cpp
r40675 r40738 711 711 void Editor::applyStyle(CSSStyleDeclaration* style, EditAction editingAction) 712 712 { 713 switch (m_frame->selection()->s tate()) {714 case Selection::N ONE:713 switch (m_frame->selection()->selectionType()) { 714 case Selection::NoSelection: 715 715 // do nothing 716 716 break; 717 case Selection::C ARET:717 case Selection::CaretSelection: 718 718 m_frame->computeAndSetTypingStyle(style, editingAction); 719 719 break; 720 case Selection::R ANGE:720 case Selection::RangeSelection: 721 721 if (m_frame->document() && style) 722 722 applyCommand(ApplyStyleCommand::create(m_frame->document(), style, editingAction)); … … 732 732 void Editor::applyParagraphStyle(CSSStyleDeclaration* style, EditAction editingAction) 733 733 { 734 switch (m_frame->selection()->s tate()) {735 case Selection::N ONE:734 switch (m_frame->selection()->selectionType()) { 735 case Selection::NoSelection: 736 736 // do nothing 737 737 break; 738 case Selection::C ARET:739 case Selection::R ANGE:738 case Selection::CaretSelection: 739 case Selection::RangeSelection: 740 740 if (m_frame->document() && style) 741 741 applyCommand(ApplyStyleCommand::create(m_frame->document(), style, editingAction, ApplyStyleCommand::ForceBlockProperties)); -
trunk/WebCore/editing/Selection.cpp
r39831 r40738 44 44 : m_affinity(DOWNSTREAM) 45 45 , m_granularity(CharacterGranularity) 46 , m_s tate(NONE)46 , m_selectionType(NoSelection) 47 47 , m_baseIsFirst(true) 48 48 { … … 239 239 } 240 240 241 void Selection:: validate()241 void Selection::setBaseAndExtentToDeepEquivalents() 242 242 { 243 243 // Move the selection to rendered positions, if possible. … … 260 260 m_extent = m_base; 261 261 m_baseIsFirst = true; 262 } else {262 } else 263 263 m_baseIsFirst = comparePositions(m_base, m_extent) <= 0; 264 } 265 264 } 265 266 void Selection::setStartAndEndFromBaseAndExtentRespectingGranularity() 267 { 266 268 if (m_baseIsFirst) { 267 269 m_start = m_base; … … 272 274 } 273 275 274 // Expand the selection if requested.275 276 switch (m_granularity) { 276 277 case CharacterGranularity: … … 386 387 if (m_end.isNull()) 387 388 m_end = m_start; 388 389 adjustForEditableContent(); 390 391 // adjust the state 389 } 390 391 void Selection::updateSelectionType() 392 { 392 393 if (m_start.isNull()) { 393 394 ASSERT(m_end.isNull()); 394 m_state = NONE; 395 396 // enforce downstream affinity if not caret, as affinity only 397 // makes sense for caret 395 m_selectionType = NoSelection; 396 } else if (m_start == m_end || m_start.upstream() == m_end.upstream()) { 397 m_selectionType = CaretSelection; 398 } else 399 m_selectionType = RangeSelection; 400 401 // Affinity only makes sense for a caret 402 if (m_selectionType != CaretSelection) 398 403 m_affinity = DOWNSTREAM; 399 } else if (m_start == m_end || m_start.upstream() == m_end.upstream()) { 400 m_state = CARET; 401 } else { 402 m_state = RANGE; 403 404 // enforce downstream affinity if not caret, as affinity only 405 // makes sense for caret 406 m_affinity = DOWNSTREAM; 407 404 } 405 406 void Selection::validate() 407 { 408 setBaseAndExtentToDeepEquivalents(); 409 setStartAndEndFromBaseAndExtentRespectingGranularity(); 410 adjustSelectionToAvoidCrossingEditingBoundaries(); 411 updateSelectionType(); 412 413 if (selectionType() == RangeSelection) { 408 414 // "Constrain" the selection to be the smallest equivalent range of nodes. 409 415 // This is a somewhat arbitrary choice, but experience shows that it is … … 442 448 m_end = base; 443 449 } 444 m_s tate = RANGE;445 } 446 447 void Selection::adjust ForEditableContent()450 m_selectionType = RangeSelection; 451 } 452 453 void Selection::adjustSelectionToAvoidCrossingEditingBoundaries() 448 454 { 449 455 if (m_base.isNull() || m_start.isNull() || m_end.isNull()) … … 506 512 } 507 513 VisiblePosition previous(p); 508 514 509 515 if (previous.isNull()) { 516 // The selection crosses an Editing boundary. This is a 517 // programmer error in the editing code. Happy debugging! 510 518 ASSERT_NOT_REACHED(); 511 519 m_base = Position(); … … 535 543 536 544 if (next.isNull()) { 545 // The selection crosses an Editing boundary. This is a 546 // programmer error in the editing code. Happy debugging! 537 547 ASSERT_NOT_REACHED(); 538 548 m_base = Position(); -
trunk/WebCore/editing/Selection.h
r38735 r40738 38 38 class Selection { 39 39 public: 40 enum EState { NONE, CARET, RANGE }; 41 enum EDirection { FORWARD, BACKWARD, RIGHT, LEFT }; 40 enum SelectionType { NoSelection, CaretSelection, RangeSelection }; 42 41 43 42 Selection(); … … 53 52 static Selection selectionFromContentsOfNode(Node*); 54 53 55 EState state() const { return m_state; }54 SelectionType selectionType() const { return m_selectionType; } 56 55 57 56 void setAffinity(EAffinity affinity) { m_affinity = affinity; } … … 64 63 65 64 Position base() const { return m_base; } 66 Position extent() const { return m_extent; } 65 Position extent() const { return m_extent; } 67 66 Position start() const { return m_start; } 68 67 Position end() const { return m_end; } … … 71 70 VisiblePosition visibleEnd() const { return VisiblePosition(m_end, isRange() ? UPSTREAM : affinity()); } 72 71 73 bool isNone() const { return s tate() == NONE; }74 bool isCaret() const { return s tate() == CARET; }75 bool isRange() const { return s tate() == RANGE; }76 bool isCaretOrRange() const { return s tate() != NONE; }72 bool isNone() const { return selectionType() == NoSelection; } 73 bool isCaret() const { return selectionType() == CaretSelection; } 74 bool isRange() const { return selectionType() == RangeSelection; } 75 bool isCaretOrRange() const { return selectionType() != NoSelection; } 77 76 78 77 bool isBaseFirst() const { return m_baseIsFirst; } … … 101 100 private: 102 101 void validate(); 103 void adjustForEditableContent();104 102 105 Position m_base; // base position for the selection 106 Position m_extent; // extent position for the selection 107 Position m_start; // start position for the selection 108 Position m_end; // end position for the selection 103 // Support methods for validate() 104 void setBaseAndExtentToDeepEquivalents(); 105 void setStartAndEndFromBaseAndExtentRespectingGranularity(); 106 void adjustSelectionToAvoidCrossingEditingBoundaries(); 107 void updateSelectionType(); 109 108 110 EAffinity m_affinity; // the upstream/downstream affinity of the caret 111 TextGranularity m_granularity; // granularity of start/end selection 109 Position m_base; // Where the first click happened 110 Position m_extent; // Where the end click happened 111 Position m_start; // Leftmost position when expanded to respect granularity 112 Position m_end; // Rightmost position when expanded to respect granularity 113 114 EAffinity m_affinity; // the upstream/downstream affinity of the caret 115 TextGranularity m_granularity; // granularity of start/end selection 112 116 113 117 // these are cached, can be recalculated by validate() 114 EState m_state; // the state of the selection118 SelectionType m_selectionType; // None, Caret, Range 115 119 bool m_baseIsFirst; // true if base is before the extent 116 120 }; -
trunk/WebCore/editing/SelectionController.h
r39069 r40738 68 68 bool contains(const IntPoint&); 69 69 70 Selection:: EState state() const { return m_sel.state(); }70 Selection::SelectionType selectionType() const { return m_sel.selectionType(); } 71 71 72 72 EAffinity affinity() const { return m_sel.affinity(); } -
trunk/WebCore/editing/TypingCommand.cpp
r40710 r40738 374 374 Selection selectionAfterUndo; 375 375 376 switch (endingSelection().s tate()) {377 case Selection::R ANGE:376 switch (endingSelection().selectionType()) { 377 case Selection::RangeSelection: 378 378 selectionToDelete = endingSelection(); 379 379 selectionAfterUndo = selectionToDelete; 380 380 break; 381 case Selection::C ARET: {381 case Selection::CaretSelection: { 382 382 if (breakOutOfEmptyMailBlockquotedParagraph()) { 383 383 typingAddedToOpenCommand(); … … 432 432 break; 433 433 } 434 case Selection::N ONE:434 case Selection::NoSelection: 435 435 ASSERT_NOT_REACHED(); 436 436 break; … … 456 456 Selection selectionAfterUndo; 457 457 458 switch (endingSelection().s tate()) {459 case Selection::R ANGE:458 switch (endingSelection().selectionType()) { 459 case Selection::RangeSelection: 460 460 selectionToDelete = endingSelection(); 461 461 selectionAfterUndo = selectionToDelete; 462 462 break; 463 case Selection::C ARET: {463 case Selection::CaretSelection: { 464 464 m_smartDelete = false; 465 465 … … 510 510 break; 511 511 } 512 case Selection::N ONE:512 case Selection::NoSelection: 513 513 ASSERT_NOT_REACHED(); 514 514 break; -
trunk/WebCore/page/Frame.cpp
r40473 r40738 1251 1251 } 1252 1252 1253 // FIXME: should this go in SelectionController?1254 1253 void Frame::revealSelection(const RenderLayer::ScrollAlignment& alignment) const 1255 1254 { 1256 1255 IntRect rect; 1257 1258 switch (selection()->s tate()) {1259 case Selection::N ONE:1256 1257 switch (selection()->selectionType()) { 1258 case Selection::NoSelection: 1260 1259 return; 1261 1262 case Selection::CARET: 1260 case Selection::CaretSelection: 1263 1261 rect = selection()->absoluteCaretBounds(); 1264 1262 break; 1265 1266 case Selection::RANGE: 1263 case Selection::RangeSelection: 1267 1264 rect = enclosingIntRect(selectionBounds(false)); 1268 1265 break; … … 1270 1267 1271 1268 Position start = selection()->start(); 1272 1273 1269 ASSERT(start.node()); 1274 1270 if (start.node() && start.node()->renderer()) { … … 1276 1272 // the selection rect could intersect more than just that. 1277 1273 // See <rdar://problem/4799899>. 1278 if (RenderLayer *layer = start.node()->renderer()->enclosingLayer())1274 if (RenderLayer* layer = start.node()->renderer()->enclosingLayer()) 1279 1275 layer->scrollRectToVisible(rect, false, alignment, alignment); 1280 1276 }
Note: See TracChangeset
for help on using the changeset viewer.