2 * Copyright (C) 2012 Samsung Electronics
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.
28 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
29 #include "TextSelectionMagnifier.h"
33 #include <Elementary.h>
34 #include <WebCore/IntRect.h>
37 using namespace WebCore;
41 TextSelectionMagnifier::TextSelectionMagnifier(EwkViewImpl* viewImpl)
42 : m_viewImpl(viewImpl)
50 TextSelectionMagnifier::~TextSelectionMagnifier()
53 evas_object_del(m_image);
54 evas_object_del(m_magnifier);
57 void TextSelectionMagnifier::update(const IntPoint& point)
60 Evas_Object* topWidget = elm_object_top_widget_get(elm_object_parent_widget_get(m_viewImpl->view()));
62 topWidget = m_viewImpl->view();
64 m_magnifier = elm_layout_add(topWidget);
65 elm_layout_file_set(m_magnifier, EDJE_DIR"/Magnifier.edj", "magnifier");
68 int viewX, viewY, viewWidth, viewHeight;
69 evas_object_geometry_get(m_viewImpl->view(), &viewX, &viewY, &viewWidth, &viewHeight);
71 float zoomLevel = 1.5f;
72 IntRect rect(point.x() - viewX - (ceil(m_width/zoomLevel)/2), point.y() - viewY - (ceil(m_height/zoomLevel)/2), ceil(m_width/zoomLevel), ceil(m_height/zoomLevel));
79 int overSize = rect.maxX() - (viewX + viewWidth);
81 rect.setX(rect.x() - overSize);
82 overSize = rect.maxY() - (viewY + viewHeight);
84 rect.setY(rect.y() - overSize);
86 RefPtr<WebImage> webImage = m_viewImpl->page()->createSnapshot(rect, zoomLevel);
87 if (!webImage || !webImage->bitmap())
89 RefPtr<cairo_surface_t> cairoSurface = webImage->bitmap()->createCairoSurface();
94 evas_object_del(m_image);
96 m_image = ewk_util_image_from_cairo_surface_add(evas_object_evas_get(m_viewImpl->view()), cairoSurface.get());
97 evas_object_size_hint_min_set(m_image, m_width, m_height);
98 evas_object_resize(m_image, m_width, m_height);
99 evas_object_image_filled_set(m_image, true);
100 evas_object_show(m_image);
102 elm_object_part_content_set(m_magnifier, "swallow", m_image);
103 evas_object_pass_events_set(m_image, EINA_TRUE);
104 evas_object_clip_set(m_image, m_magnifier);
106 evas_object_layer_set(m_magnifier, EVAS_LAYER_MAX);
107 evas_object_layer_set(m_image, EVAS_LAYER_MAX);
110 void TextSelectionMagnifier::show()
115 evas_object_show(m_magnifier);
118 void TextSelectionMagnifier::hide()
123 evas_object_hide(m_magnifier);
126 void TextSelectionMagnifier::move(const IntPoint& point)
128 int viewX, viewY, viewWidth, viewHeight;
129 evas_object_geometry_get(m_viewImpl->view(), &viewX, &viewY, &viewWidth, &viewHeight);
131 int magnfierX, magnfierY, magnfierWidth, magnfierHeight;
132 evas_object_geometry_get(m_magnifier, &magnfierX, &magnfierY, &magnfierWidth, &magnfierHeight);
134 int xPosition = point.x();
135 if (xPosition < (magnfierWidth / 2))
136 xPosition = magnfierWidth / 2;
137 if (xPosition > viewWidth - (magnfierWidth / 2))
138 xPosition = viewWidth - (magnfierWidth / 2);
140 int yPosition = point.y() - 230;
141 if (yPosition < (magnfierHeight / 2))
142 yPosition = magnfierHeight / 2;
143 if (yPosition > viewHeight - (magnfierHeight / 2))
144 yPosition = viewHeight - (magnfierHeight / 2);
146 evas_object_move(m_magnifier, xPosition, yPosition);
149 bool TextSelectionMagnifier::isVisible()
151 return evas_object_visible_get(m_magnifier);
154 } // namespace WebKit
156 #endif // TIZEN_WEBKIT2_TEXT_SELECTION