[Title] Implement that a text selection handle can be moved over another text selection handle.
[Issue#] P130401-3601
[Problem] A text selection handle can not be moved another text selection handle.
[Cause] Not implemented.
[Solution] Implement that a text selection handle can be moved over another text selection handle.
Change-Id: I257c66a29e08059d6393c8fb3ecebe459ace46f6
#if ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
, m_selectedHandle(0)
#endif
+ , m_handleMovingDirection(HandleMovingDirectionNormal)
{
ASSERT(viewWidget);
WebCore::IntPoint leftEvasPoint = toEvasTransform.mapPoint(leftRect.minXMaxYCorner());
WebCore::IntPoint rightEvasPoint = toEvasTransform.mapPoint(rightRect.maxXMaxYCorner());
+ TextSelectionHandle* shownLeftHandle = m_leftHandle;
+ TextSelectionHandle* shownRightHandle = m_rightHandle;
+
+ if (m_handleMovingDirection == HandleMovingDirectionReverse) {
+ shownLeftHandle = m_rightHandle;
+ shownRightHandle = m_leftHandle;
+ }
+
EditorState editorState = m_viewImpl->page()->editorState();
if (editorState.isContentEditable) {
- m_leftHandle->hide();
- m_rightHandle->hide();
+ shownLeftHandle->hide();
+ shownRightHandle->hide();
WebCore::IntRect editorRect = editorState.editorRect;
WebCore::IntPoint editorLeftEvasPoint = toEvasTransform.mapPoint(editorRect.location());
evas_object_geometry_get(m_viewImpl->view(), &webViewX, &webViewY, &webViewWidth, &webViewHeight);
if ((editorLeftEvasPoint.x() <= leftEvasPoint.x() && editorLeftEvasPoint.y() <= leftEvasPoint.y())
&& (webViewX <= leftEvasPoint.x() && webViewY <= leftEvasPoint.y())) {
- m_leftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect));
- m_leftHandle->show();
+ shownLeftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect));
+ shownLeftHandle->show();
}
if ((editorRightEvasPoint.x() >= rightEvasPoint.x() && editorRightEvasPoint.y() >= rightEvasPoint.y())
&& ((webViewX + webViewWidth) >= rightEvasPoint.x() && (webViewY <= rightEvasPoint.y() && (webViewY + webViewHeight) >= rightEvasPoint.y()))) {
- m_rightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect));
- m_rightHandle->show();
+ shownRightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect));
+ shownRightHandle->show();
}
} else {
- m_leftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect));
- m_leftHandle->show();
+ shownLeftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect));
+ shownLeftHandle->show();
- m_rightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect));
- m_rightHandle->show();
+ shownRightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect));
+ shownRightHandle->show();
}
}
void TextSelection::setLeftSelectionToEvasPoint(const IntPoint& evasPoint)
{
- m_viewImpl->page()->setLeftSelection(m_viewImpl->transformFromScene().mapPoint(evasPoint));
+ int result = m_viewImpl->page()->setLeftSelection(m_viewImpl->transformFromScene().mapPoint(evasPoint), m_handleMovingDirection);
+ if (result)
+ m_handleMovingDirection = result;
updateHandlers();
}
void TextSelection::setRightSelectionToEvasPoint(const IntPoint& evasPoint)
{
- m_viewImpl->page()->setRightSelection(m_viewImpl->transformFromScene().mapPoint(evasPoint));
+ int result = m_viewImpl->page()->setRightSelection(m_viewImpl->transformFromScene().mapPoint(evasPoint), m_handleMovingDirection);
+ if (result)
+ m_handleMovingDirection = result;
updateHandlers();
}
void TextSelection::handleMouseUp(TextSelectionHandle* /* handle */, const IntPoint& /* position */)
{
+ m_handleMovingDirection = HandleMovingDirectionNormal;
+
hideMagnifier();
+ updateHandlers();
showContextMenu();
}
}
~TextSelection();
+ enum HandleMovingDirection {
+ HandleMovingDirectionNone = 0,
+ HandleMovingDirectionNormal,
+ HandleMovingDirectionReverse,
+ };
+
void update();
bool isTextSelectionDowned() { return m_isTextSelectionDowned; }
void setIsTextSelectionDowned(bool isTextSelectionDowned) { m_isTextSelectionDowned = isTextSelectionDowned; }
#if ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
TextSelectionHandle* m_selectedHandle;
#endif
+ int m_handleMovingDirection;
};
} // namespace WebKit
#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
bool selectClosestWord(const WebCore::IntPoint&);
- bool setLeftSelection(const WebCore::IntPoint&);
- bool setRightSelection(const WebCore::IntPoint&);
+ int setLeftSelection(const WebCore::IntPoint&, const int direction);
+ int setRightSelection(const WebCore::IntPoint&, const int direction);
bool getSelectionHandlers(WebCore::IntRect& leftRect, WebCore::IntRect& rightRect);
String getSelectionText();
bool selectionRangeClear();
return result;
}
-bool WebPageProxy::setLeftSelection(const IntPoint& point)
+int WebPageProxy::setLeftSelection(const IntPoint& point, const int direction)
{
if (!isValid())
- return false;
+ return 0;
- bool result = false;
- process()->sendSync(Messages::WebPage::SetLeftSelection(point), Messages::WebPage::SetLeftSelection::Reply(result), m_pageID);
+ int result = 0;
+ process()->sendSync(Messages::WebPage::SetLeftSelection(point, direction), Messages::WebPage::SetLeftSelection::Reply(result), m_pageID);
return result;
}
-bool WebPageProxy::setRightSelection(const IntPoint& point)
+int WebPageProxy::setRightSelection(const IntPoint& point, const int direction)
{
if (!isValid())
- return false;
+ return 0;
- bool result;
- process()->sendSync(Messages::WebPage::SetRightSelection(point), Messages::WebPage::SetRightSelection::Reply(result), m_pageID);
+ int result = 0;
+ process()->sendSync(Messages::WebPage::SetRightSelection(point, direction), Messages::WebPage::SetRightSelection::Reply(result), m_pageID);
return result;
}
// FIXME: We could genericize these into a DrawingArea client interface. Would that be beneficial?
void drawRect(WebCore::GraphicsContext&, const WebCore::IntRect&);
#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+ enum HandleMovingDirection {
+ HandleMovingDirectionNone = 0,
+ HandleMovingDirectionNormal,
+ HandleMovingDirectionReverse,
+ };
void selectClosestWord(const WebCore::IntPoint&, bool& result);
- void setLeftSelection(const WebCore::IntPoint&, bool& result);
- void setRightSelection(const WebCore::IntPoint&, bool& result);
+ void setLeftSelection(const WebCore::IntPoint&, const int direction, int& result);
+ void setRightSelection(const WebCore::IntPoint&, const int direction, int& result);
void getSelectionHandlers(WebCore::IntRect& leftRect, WebCore::IntRect& rightRect);
void getSelectionText(String& result);
void selectionRangeClear(bool& result);
#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
SelectClosestWord(WebCore::IntPoint point) -> (bool result)
- SetLeftSelection(WebCore::IntPoint point) -> (bool result)
- SetRightSelection(WebCore::IntPoint point) -> (bool result)
+ SetLeftSelection(WebCore::IntPoint point, int direction) -> (int result)
+ SetRightSelection(WebCore::IntPoint point, int direction) -> (int result)
GetSelectionHandlers() -> (WebCore::IntRect leftRect, WebCore::IntRect rightRect)
GetSelectionText() -> (String result)
SelectionRangeClear() -> (bool result)
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;
}
}