result = true;
}
-void WebPage::setLeftSelection(const IntPoint& point, bool& result)
+void WebPage::setLeftSelection(const IntPoint& point, const int direction, int& result)
{
- result = false;
+ result = HandleMovingDirectionNone;
Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
FrameSelection* frameSelection = focusedFrame->selection();
IntPoint pos = frameView->windowToContents(point);
IntRect leftRect, rightRect;
getSelectionHandlers(leftRect, rightRect);
- if ((rightRect.y() + rightRect.height()) < pos.y())
- pos.setY(rightRect.y() + (rightRect.height()/2));
if (selectionEndNode->rendererIsEditable() && !selectionEndNode->rendererIsRichlyEditable()) {
const int boundariesWidth = 2;
}
OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
+ Position base = frameSelection->base();
Position extent = frameSelection->extent();
Node* newSelectionStartNode = position->deepEquivalent().deprecatedNode();
// both start and end nodes should be in the same area type: both should be editable or both should be not editable
// Check if the new position is before the extent's position
if (newSelectionStartNode
- && selectionEndNode->isContentEditable() == newSelectionStartNode->isContentEditable()
- && comparePositions(position->deepEquivalent(), extent) < 0) {
+ && selectionEndNode->isContentEditable() == newSelectionStartNode->isContentEditable()) {
// Change the 'base' and 'extent' positions to 'start' and 'end' positions.
// We do it, because without this, the other modification of the selection
// would destroy the 'start' and/or 'end' positions and set them to
bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
focusedFrame->view()->setProhibitsScrolling(true);
- frameSelection->setBase(*position);
+ if (direction == HandleMovingDirectionNormal) {
+ if (comparePositions(position->deepEquivalent(), extent) < 0) {
+ frameSelection->setBase(*position);
+ result = HandleMovingDirectionNormal;
+ } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
+ frameSelection->setExtent(*position);
+ frameSelection->setBase(extent);
+ result = HandleMovingDirectionReverse;
+ }
+ } else if (direction == HandleMovingDirectionReverse) {
+ if (comparePositions(position->deepEquivalent(), base) > 0) {
+ frameSelection->setExtent(*position);
+ result = HandleMovingDirectionReverse;
+ } else if (comparePositions(position->deepEquivalent(), base) < 0) {
+ frameSelection->setBase(*position);
+ frameSelection->setExtent(base);
+ result = HandleMovingDirectionNormal;
+ }
+ }
focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
// This forces webkit to show selection
// m_coreFrame->invalidateSelection();
-
- result = true;
}
}
-
-void WebPage::setRightSelection(const IntPoint& point, bool& result)
+void WebPage::setRightSelection(const IntPoint& point, const int direction, int& result)
{
- result = false;
+ result = HandleMovingDirectionNone;
Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
FrameSelection* frameSelection = focusedFrame->selection();
OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
Position base = frameSelection->base();
+ Position extent = frameSelection->extent();
Node* newSelectionEndNode = position->deepEquivalent().deprecatedNode();
// both start and end nodes should be in the same area type: both should be editable or both should be not editable
// Check if the new position is after the base's position
if (newSelectionEndNode
- && selectionStartNode->isContentEditable() == newSelectionEndNode->isContentEditable()
- && comparePositions(position->deepEquivalent(), base) > 0) {
+ && selectionStartNode->isContentEditable() == newSelectionEndNode->isContentEditable()) {
// Change the 'base' and 'extent' positions to 'start' and 'end' positions.
// We do it, because without this, the other modifications of the selection
// would destroy the 'start' and/or 'end' positions and set them to
bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
focusedFrame->view()->setProhibitsScrolling(true);
- frameSelection->setExtent(*position);
+ if (direction == HandleMovingDirectionNormal) {
+ if (comparePositions(position->deepEquivalent(), base) > 0) {
+ frameSelection->setExtent(*position);
+ result = HandleMovingDirectionNormal;
+ } else if (comparePositions(position->deepEquivalent(), base) < 0) {
+ frameSelection->setBase(*position);
+ frameSelection->setExtent(base);
+ result = HandleMovingDirectionReverse;
+ }
+ } else if (direction == HandleMovingDirectionReverse) {
+ if (comparePositions(position->deepEquivalent(), extent) < 0) {
+ frameSelection->setBase(*position);
+ result = HandleMovingDirectionReverse;
+ } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
+ frameSelection->setExtent(*position);
+ frameSelection->setBase(extent);
+ result = HandleMovingDirectionNormal;
+ }
+ }
focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
-
- result = true;
}
}