#include <wtf/text/CString.h>
#include <wtf/text/StringBuilder.h>
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+#include "RenderImage.h"
+#endif
+
namespace WebCore {
using namespace std;
*inFixed = allFixed ? EntirelyFixedPosition : (someFixed ? PartiallyFixedPosition : NotFixedPosition);
}
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+void Range::boundingBoxEx(Vector<IntRect>& rects, bool useSelectionHeight, RangeInFixedPosition* inFixed) const
+{
+ Node* startContainer = m_start.container();
+ Node* endContainer = m_end.container();
+
+ if (!startContainer || !endContainer) {
+ if (inFixed)
+ *inFixed = NotFixedPosition;
+ return;
+ }
+
+ bool allFixed = true;
+ bool someFixed = false;
+
+ Node* stopNode = pastLastNode();
+ for (Node* node = firstNode(); node != stopNode; node = node->traverseNextNode()) {
+ RenderObject* r = node->renderer();
+ if (r && r->isText()) {
+ RenderText* renderText = toRenderText(r);
+ int startOffset = node == startContainer ? m_start.offset() : 0;
+ int endOffset = node == endContainer ? m_end.offset() : numeric_limits<int>::max();
+ bool isFixed = false;
+ renderText->absoluteRectsForRange(rects, startOffset, endOffset, useSelectionHeight, &isFixed);
+ allFixed &= isFixed;
+ someFixed |= isFixed;
+ } else if (r && r->isImage()) {
+ RenderImage* renderImage= toRenderImage(r);
+ int startOffset = node == startContainer ? m_start.offset() : 0;
+ int endOffset = node == endContainer ? m_end.offset() : numeric_limits<int>::max();
+ bool isFixed = false;
+ IntRect r = renderImage->absoluteBoundingBoxRect();
+ rects.append(r);
+ allFixed &= isFixed;
+ someFixed |= isFixed;
+ }
+ }
+
+ if (inFixed)
+ *inFixed = allFixed ? EntirelyFixedPosition : (someFixed ? PartiallyFixedPosition : NotFixedPosition);
+}
+#endif
+
void Range::textQuads(Vector<FloatQuad>& quads, bool useSelectionHeight, RangeInFixedPosition* inFixed) const
{
Node* startContainer = m_start.container();
#include "DataObjectTizen.h"
#endif
+#if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
+#include "HTMLImageElement.h"
+#endif
+
using namespace JSC;
using namespace WebCore;
using namespace std;
void WebPage::selectLink(WebCore::IntPoint positionForSelection, bool& result)
{
result = false;
-
Frame* frame = m_page->focusController()->focusedOrMainFrame();
if (!frame)
return;
+
FrameView* frameView = frame->view();
if (!frameView)
return;
HitTestResult hitTestResult = frame->eventHandler()->hitTestResultAtPoint(frameView->windowToContents(positionForSelection), false);
- Element* URLElement = hitTestResult.URLElement();
- if (!URLElement)
- return;
-
RefPtr<Range> range;
- for (Node* childNode = URLElement->firstChild(); childNode; childNode = childNode->traverseNextNode(URLElement)) {
- if (childNode->isTextNode()) {
- if (!range)
- range = VisibleSelection::selectionFromContentsOfNode(childNode).toNormalizedRange();
- else {
- RefPtr<Range> extendedRange = VisibleSelection::selectionFromContentsOfNode(childNode).toNormalizedRange();
- range->setEnd(childNode, extendedRange->endOffset());
+ Element* URLElement = hitTestResult.URLElement();
+ if (URLElement) {
+ for (Node* childNode = URLElement->firstChild(); childNode; childNode = childNode->traverseNextNode(URLElement)) {
+ RenderObject* r = childNode->renderer();
+ if (r && (r->isText() || r->isImage())) {
+ if (!range)
+ range = VisibleSelection::selectionFromContentsOfNode(childNode).toNormalizedRange();
+ else if (!hitTestResult.image()) {
+ RefPtr<Range> extendedRange = VisibleSelection::selectionFromContentsOfNode(childNode).toNormalizedRange();
+ range->setEnd(childNode, extendedRange->endOffset());
+ }
}
}
- }
-
- if (!range)
- range = VisibleSelection::selectionFromContentsOfNode(URLElement).toNormalizedRange();
+ if(!range)
+ range = VisibleSelection::selectionFromContentsOfNode(URLElement).toNormalizedRange();
+ } else
+ range = VisibleSelection::selectionFromContentsOfNode(hitTestResult.innerNonSharedNode()).toNormalizedRange();
WebCore::FrameSelection* frameSelection = frame->selection();
if (!frameSelection)
return;
+
EAffinity affinity = frameSelection->affinity();
frameSelection->setSelectedRange(range.get(), affinity, true);
focusableNode = focusableNode->parentNode();
}
- if (!isFocusRingDrawable)
+ if (!isFocusRingDrawable) {
+ if (node->hasTagName(HTMLNames::imgTag))
+ return getNodeRect(node, node, !hitTestResult.absoluteImageURL().isEmpty());
+
return IntRect();
+ }
return getNodeRect(node, focusableNode, !hitTestResult.absoluteImageURL().isEmpty());
}
result = true;
}
-void WebPage::setLeftSelection(const WebCore::IntPoint& point, bool& result)
+void WebPage::setLeftSelection(const IntPoint& point, bool& result)
{
result = false;
Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
- WebCore::FrameSelection* frameSelection = focusedFrame->selection();
+ FrameSelection* frameSelection = focusedFrame->selection();
if (!frameSelection->isRange())
return;
- WebCore::Node* selectionEndNode = frameSelection->end().deprecatedNode();
+ Node* selectionEndNode = frameSelection->end().deprecatedNode();
if (!selectionEndNode || !selectionEndNode->renderer())
return;
if (!frameView)
return;
- WebCore::IntPoint pos = frameView->windowToContents(point);
- WebCore::IntRect leftRect, rightRect;
+ 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;
- WebCore::IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
+ IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
// here we cheat input field that we actually are just inside of if
if (pos.y() < rect.y() + boundariesWidth)
pos.setY(rect.y() + boundariesWidth);
pos.setY(rect.maxY() - boundariesWidth - 1);
}
- OwnPtr<WebCore::VisiblePosition> position = adoptPtr(new WebCore::VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
- WebCore::Position extent = frameSelection->extent();
+ OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
+ Position extent = frameSelection->extent();
- WebCore::Node* newSelectionStartNode = position->deepEquivalent().deprecatedNode();
+ 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()
- && WebCore::comparePositions(position->deepEquivalent(), extent) < 0) {
+ && comparePositions(position->deepEquivalent(), extent) < 0) {
// 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
// the 'base'/'extent' positions accordingly
- WebCore::VisibleSelection sel(frameSelection->start(), frameSelection->end());
+ VisibleSelection sel(frameSelection->start(), frameSelection->end());
frameSelection->setSelection(sel);
bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
}
-void WebPage::setRightSelection(const WebCore::IntPoint& point, bool& result)
+void WebPage::setRightSelection(const IntPoint& point, bool& result)
{
result = false;
Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
- WebCore::FrameSelection* frameSelection = focusedFrame->selection();
+ FrameSelection* frameSelection = focusedFrame->selection();
if (!frameSelection->isRange())
return;
- WebCore::Node* selectionStartNode = frameSelection->start().deprecatedNode();
+ Node* selectionStartNode = frameSelection->start().deprecatedNode();
if (!selectionStartNode || !selectionStartNode->renderer())
return;
if (!frameView)
return;
- WebCore::IntPoint pos = frameView->windowToContents(point);
+ IntPoint pos = frameView->windowToContents(point);
if (selectionStartNode->rendererIsEditable() && !selectionStartNode->rendererIsRichlyEditable()) {
const int boundariesWidth = 2;
- WebCore::IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
+ IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
// here we cheat input field that we actually are just inside of if
if (pos.y() < rect.y() + boundariesWidth)
pos.setY(rect.y() + boundariesWidth);
pos.setY(rect.maxY() - boundariesWidth - 1);
}
- OwnPtr<WebCore::VisiblePosition> position = adoptPtr(new WebCore::VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
- WebCore::Position base = frameSelection->base();
+ OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
+ Position base = frameSelection->base();
- WebCore::Node* newSelectionEndNode = position->deepEquivalent().deprecatedNode();
+ 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()
- && WebCore::comparePositions(position->deepEquivalent(), base) > 0) {
+ && comparePositions(position->deepEquivalent(), base) > 0) {
// 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
// the 'base'/'extent' positions accordingly
- WebCore::VisibleSelection sel(frameSelection->start(), frameSelection->end());
+ VisibleSelection sel(frameSelection->start(), frameSelection->end());
frameSelection->setSelection(sel);
bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
return;
// Is this check necessary? Leaving it for safety.
- WebCore::RenderView* root = focusedFrame->contentRenderer();
+ RenderView* root = focusedFrame->contentRenderer();
if (!root)
return;
- RefPtr<WebCore::Range> selectedRange = focusedFrame->selection()->toNormalizedRange();
+ RefPtr<Range> selectedRange = focusedFrame->selection()->toNormalizedRange();
- Vector<WebCore::IntRect> rects;
- selectedRange->textRects(rects, true);
+ Vector<IntRect> rects, tempRects;
+ selectedRange->boundingBoxEx(tempRects, true);
+
+ IntRect boundsRect = enclosingIntRect(focusedFrame->selection()->bounds());
+ for (size_t i = 0; i < tempRects.size(); i++) {
+ if (boundsRect.contains(tempRects[i]))
+ rects.append(tempRects[i]);
+ else {
+ tempRects[i].intersect(boundsRect);
+ if (!tempRects[i].isEmpty())
+ rects.append(tempRects[i]);
+ }
+ }
unsigned size = rects.size();
if (size > 0) {
if (size == 1) {
Element* selectionRoot = focusedFrame->selection()->rootEditableElement();
if (selectionRoot) {
- WebCore::IntRect editorRect = focusedFrame->view()->contentsToWindow(selectionRoot->getPixelSnappedRect());
+ IntRect editorRect = focusedFrame->view()->contentsToWindow(selectionRoot->getPixelSnappedRect());
#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
if (m_editorState.editorRect != editorRect) {
result = false;
Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
- WebCore::FrameSelection* frameSelection = focusedFrame->selection();
+ FrameSelection* frameSelection = focusedFrame->selection();
if (frameSelection && frameSelection->isRange() && frameSelection->isContentEditable()) {
- WebCore::VisiblePosition visiblePos(frameSelection->extent());
+ VisiblePosition visiblePos(frameSelection->extent());
if (visiblePos.isNull())
return;
- WebCore::VisibleSelection newSelection = WebCore::VisibleSelection(visiblePos);
- frameSelection->setSelection(newSelection, WebCore::CharacterGranularity);
+ VisibleSelection newSelection = VisibleSelection(visiblePos);
+ frameSelection->setSelection(newSelection, CharacterGranularity);
frameSelection->setCaretBlinkingSuspended(false);
} else
selectionClearAllSelection(m_page->mainFrame());
if (!frame)
return;
- WebCore::FrameSelection* frameSelection = frame->selection();
+ FrameSelection* frameSelection = frame->selection();
if (frameSelection)
frameSelection->clear();
} else if (frame->tree()->nextSibling())
selectionClearAllSelection(frame->tree()->nextSibling());
}
-
#endif
#if ENABLE(TIZEN_LINK_MAGNIFIER)