2 * Copyright (C) 2013 Samsung Electronic.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "LinkMagnifier.h"
29 #if ENABLE(TIZEN_LINK_MAGNIFIER)
31 using namespace WebCore;
35 static bool isCandidate(Node* node)
37 if (node->isMouseFocusable() || node->willRespondToMouseClickEvents() || node->willRespondToMouseMoveEvents())
43 static void candidateRect(Node* node, Vector<IntRect>& rects)
45 RenderObject* renderer = node->renderer();
46 FrameView* view = node->document()->frame()->view();
48 IntPoint absolutePoint;
49 absolutePoint = view->convertToContainingWindow(view->convertFromRenderer(renderer, absolutePoint));
51 renderer->addFocusRingRects(rects, absolutePoint);
54 IntRect LinkMagnifier::rect(WebPage* page, const IntPoint& position, const IntSize& area)
56 Frame* frame = page->mainFrame();
60 HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
61 IntPoint hitTestPoint = frame->view()->windowToContents(position);
62 HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(hitTestPoint, true, false, DontHitTestScrollbars, hitType, IntSize(area.width() / 2, area.height() / 2));
63 const HitTestResult::NodeSet& nodeSet(result.rectBasedTestResult());
65 Vector<Node*> wideCandidates;
66 HashSet<Node*> ancestors;
67 HitTestResult::NodeSet::const_iterator nodeIterator = nodeSet.begin();
68 HitTestResult::NodeSet::const_iterator nodeEnd = nodeSet.end();
69 for (; nodeIterator != nodeEnd; ++nodeIterator) {
70 for (Node* node = nodeIterator->get(); node; node = node->parentOrHostNode()) {
71 if (wideCandidates.contains(node))
73 else if (isCandidate(node)) {
74 wideCandidates.append(node);
75 for (node = node->parentOrHostNode(); node; node = node->parentOrHostNode()) {
76 HashSet<Node*>::AddResult addResult = ancestors.add(node);
77 if (!addResult.isNewEntry)
85 Vector<Node*> candidates;
86 size_t size = wideCandidates.size();
87 for (size_t i = 0; i < size; ++i) {
88 if (!ancestors.contains(wideCandidates[i]))
89 candidates.append(wideCandidates[i]);
92 if (candidates.size() <= 1)
95 IntRect candidatesRect;
96 size = candidates.size();
97 for (size_t i = 0; i < size; ++i) {
98 Vector<IntRect> rects;
99 candidateRect(candidates[i], rects);
101 size_t rectSize = rects.size();
102 for (size_t rectsIter = 0; rectsIter < rectSize; rectsIter++)
103 candidatesRect.unite(rects[rectsIter]);
106 return candidatesRect;
109 } // namespace WebKit