Merge "Change value of mediaSliderThumHeight" into tizen_2.1
[framework/web/webkit-efl.git] / Source / WebKit2 / WebProcess / WebPage / efl / tizen / LinkMagnifier.cpp
1 /*
2  * Copyright (C) 2013 Samsung Electronic.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25
26 #include "config.h"
27 #include "LinkMagnifier.h"
28
29 #if ENABLE(TIZEN_LINK_MAGNIFIER)
30
31 using namespace WebCore;
32
33 namespace WebKit {
34
35 static bool isCandidate(Node* node)
36 {
37     if (node->isMouseFocusable() || node->willRespondToMouseClickEvents() || node->willRespondToMouseMoveEvents())
38         return true;
39
40     return false;
41 }
42
43 static void candidateRect(Node* node, Vector<IntRect>& rects)
44 {
45     RenderObject* renderer = node->renderer();
46     FrameView* view = node->document()->frame()->view();
47
48     IntPoint absolutePoint;
49     absolutePoint = view->convertToContainingWindow(view->convertFromRenderer(renderer, absolutePoint));
50
51     renderer->addFocusRingRects(rects, absolutePoint);
52 }
53
54 IntRect LinkMagnifier::rect(WebPage* page, const IntPoint& position, const IntSize& area)
55 {
56     Frame* frame = page->mainFrame();
57     if (!frame->view())
58         return IntRect();
59
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());
64
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))
72                 break;
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)
78                         break;
79                 }
80                 break;
81             }
82         }
83     }
84
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]);
90     }
91
92     if (candidates.size() <= 1)
93         return IntRect();
94
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);
100
101         size_t rectSize = rects.size();
102         for (size_t rectsIter = 0; rectsIter < rectSize; rectsIter++)
103             candidatesRect.unite(rects[rectsIter]);
104     }
105
106     return candidatesRect;
107 }
108
109 } // namespace WebKit
110
111 #endif