Beispiel #1
0
bool CachedNode::Clip(const WebCore::IntRect& outer, WebCore::IntRect* inner,
    WTF::Vector<WebCore::IntRect>* rings)
{
    if (outer.contains(*inner))
        return true;
//    DBG_NAV_LOGD("outer:{%d,%d,%d,%d} does not contain inner:{%d,%d,%d,%d}",
//        outer.x(), outer.y(), outer.width(), outer.height(),
//        inner->x(), inner->y(), inner->width(), inner->height());
    bool intersects = outer.intersects(*inner);
    size_t size = intersects ? rings->size() : 0;
    *inner = WebCore::IntRect(0, 0, 0, 0);
    if (intersects) {
        WebCore::IntRect * const start = rings->begin();
        WebCore::IntRect* ring = start + size - 1;
        do {
            ring->intersect(outer);
            if (ring->isEmpty()) {
                if ((size_t) (ring - start) != --size)
                    *ring = start[size];
            } else
                inner->unite(*ring);
        } while (ring-- != start);
    }
    rings->shrink(size);
//    DBG_NAV_LOGD("size:%d", size);
    return size != 0;
}
void SelectionHandler::setSelection(WebCore::IntPoint start, WebCore::IntPoint end)
{
    m_selectionActive = true;

    ASSERT(m_webPage && m_webPage->mainFrame() && m_webPage->mainFrame()->selection());
    Frame* frame = m_webPage->mainFrame();
    ASSERT(frame);

#if SHOWDEBUG_SELECTIONHANDLER
    Olympia::Platform::log(Olympia::Platform::LogLevelInfo, "SelectionHandler::setSelection adjusted points %d, %d, %d, %d", start.x(), start.y(), end.x(), end.y());
#endif

    bool selectionIsValid = true;
    VisibleSelection newSelection(frame->visiblePositionForPoint(start), frame->visiblePositionForPoint(end));

    // Validate the new points to avoid crossing frame or editing boundaries.
    if (m_webPage->mainFrame() != m_webPage->focusedOrMainFrame() && m_webPage->focusedOrMainFrame()->ownerRenderer()) {
        // Current focus frame is not the main frame, it must be a subframe.
        WebCore::IntRect subframeRect = m_webPage->focusedOrMainFrame()->ownerRenderer()->absoluteContentBox();
        if (!subframeRect.contains(start) || !subframeRect.contains(end)) {
            // Requested selection points are outside of current frame.
            selectionIsValid = false;
        }
    }
    // Check whether selection is occurring inside of an input field.  Do not handle as
    // an else if, an input field may be active inside of a subframe.
    if (m_webPage->m_inputHandler->isInputMode() && !selectionIsContainedByAnchorNode(newSelection)) {
        // Requested selection points are not contained within the anchor node (input field).
        selectionIsValid = false;
    }

    if (selectionIsValid) {
        frame->selection()->setSelection(newSelection);

#if SHOWDEBUG_SELECTIONHANDLER
        Olympia::Platform::log(Olympia::Platform::LogLevelInfo, "SelectionHandler::setSelection selection points valid, selection updated");
#endif
    }

    // Need to manually trigger notification as response to change.
    // This needs to be set even if no selection change occurs to ensure client has accurate
    // selection points.
    selectionPositionChanged();
}
		static bool WouldBeTrappedInElement(const WebCore::IntRect& rect, const WebCore::IntPoint& point, EA::WebKit::JumpDirection direction)
		{
			// If we're not inside, don't worry
			if (rect.contains(point))
			{
				typedef WebCore::IntPoint Vector2D;

				const WebCore::IntPoint centre = Average( rect.minXMaxYCorner(), rect.maxXMinYCorner() );

				Vector2D pointToCentre = Subtract(centre,point);
				Vector2D forward;

				switch (direction)
				{
				// note these are 'backward
				case EA::WebKit::JumpUp:		forward = Vector2D(0,-100); break;
				case EA::WebKit::JumpDown:		forward = Vector2D(0,100); break;
				case EA::WebKit::JumpLeft:		forward = Vector2D(-100,0); break;
				case EA::WebKit::JumpRight:		forward = Vector2D(100,0); break;
				}

				// Basically, if the centre is behind us, don't jump there
				if (DotProduct(forward,pointToCentre) < 0)
				{
					return false;
				}
				else
				{
					/*printf("(%d,%d) Trapped Inside Element (%d,%d)->(%d,%d): forward=(%d,%d) pointToCentre=(%d,%d) dot=%d\n",
						point.x(),
						point.y(),
						rect.bottomLeft().x(),
						rect.bottomLeft().y(),
						rect.topRight().x(),
						rect.topRight().y(),
						forward.x(),
						forward.y(),
						pointToCentre.x(),
						pointToCentre.y(),
						DotProduct(forward,pointToCentre)
						);*/
					return true;
				}
			}
			else
			{
				return false;
			}
		}