void SelectionModifier::willBeModified(EAlteration alter, SelectionDirection direction) { if (alter != FrameSelection::AlterationExtend) return; Position start = m_selection.start(); Position end = m_selection.end(); bool baseIsStart = true; if (m_selection.isDirectional()) { // Make base and extent match start and end so we extend the user-visible // selection. This only matters for cases where base and extend point to // different positions than start and end (e.g. after a double-click to // select a word). if (m_selection.isBaseFirst()) baseIsStart = true; else baseIsStart = false; } else { switch (direction) { case DirectionRight: if (directionOfSelection() == LTR) baseIsStart = true; else baseIsStart = false; break; case DirectionForward: baseIsStart = true; break; case DirectionLeft: if (directionOfSelection() == LTR) baseIsStart = false; else baseIsStart = true; break; case DirectionBackward: baseIsStart = false; break; } } if (baseIsStart) { m_selection.setBase(start); m_selection.setExtent(end); } else { m_selection.setBase(end); m_selection.setExtent(start); } }
VisiblePosition SelectionEditor::modifyMovingLeft(TextGranularity granularity) { VisiblePosition pos; switch (granularity) { case CharacterGranularity: if (m_selection.isRange()) { if (directionOfSelection() == LTR) pos = createVisiblePosition(m_selection.start(), m_selection.affinity()); else pos = createVisiblePosition(m_selection.end(), m_selection.affinity()); } else { pos = leftPositionOf(createVisiblePosition(m_selection.extent(), m_selection.affinity())); } break; case WordGranularity: { bool skipsSpaceWhenMovingRight = frame() && frame()->editor().behavior().shouldSkipSpaceWhenMovingRight(); pos = leftWordPosition(createVisiblePosition(m_selection.extent(), m_selection.affinity()), skipsSpaceWhenMovingRight); break; } case SentenceGranularity: case LineGranularity: case ParagraphGranularity: case SentenceBoundary: case ParagraphBoundary: case DocumentBoundary: // FIXME: Implement all of the above. pos = modifyMovingBackward(granularity); break; case LineBoundary: pos = leftBoundaryOfLine(startForPlatform(), directionOfEnclosingBlock()); break; } return pos; }