1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
// Copyright (C) 2015-2016 Canonical Ltd.
4
// This library is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU Lesser General Public
6
// License as published by the Free Software Foundation; either
7
// version 2.1 of the License, or (at your option) any later version.
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// Lesser General Public License for more details.
14
// You should have received a copy of the GNU Lesser General Public
15
// License along with this library; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
#include "oxide_qt_touch_handle_drawable.h"
20
#include "qt/core/glue/oxide_qt_touch_handle_drawable_proxy.h"
22
#include "oxide_qt_web_view.h"
29
TouchHandleDrawable::TouchHandleDrawable(const WebView* view)
32
TouchHandleDrawable::~TouchHandleDrawable() {}
34
void TouchHandleDrawable::SetProxy(TouchHandleDrawableProxy* proxy) {
38
void TouchHandleDrawable::SetEnabled(bool enabled) {
40
proxy_->SetEnabled(enabled);
44
void TouchHandleDrawable::SetOrientation(
45
ui::TouchHandleOrientation orientation,
47
bool mirror_horizontal) {
49
TouchHandleDrawableProxy::Orientation o;
50
switch (orientation) {
51
case ui::TouchHandleOrientation::LEFT:
52
o = TouchHandleDrawableProxy::Left;
54
case ui::TouchHandleOrientation::CENTER:
55
o = TouchHandleDrawableProxy::Center;
57
case ui::TouchHandleOrientation::RIGHT:
58
o = TouchHandleDrawableProxy::Right;
60
case ui::TouchHandleOrientation::UNDEFINED:
61
o = TouchHandleDrawableProxy::Undefined;
66
proxy_->SetOrientation(o, mirror_vertical, mirror_horizontal);
70
void TouchHandleDrawable::SetOrigin(const gfx::PointF& origin) {
72
const float dpr = view_->GetDeviceScaleFactor();
73
const int y_offset = view_->GetLocationBarContentOffsetPix();
74
proxy_->SetOrigin(QPointF(origin.x() * dpr, origin.y() * dpr + y_offset));
78
void TouchHandleDrawable::SetAlpha(float alpha) {
80
proxy_->SetAlpha(alpha);
84
gfx::RectF TouchHandleDrawable::GetVisibleBounds() const {
89
const float dpr = view_->GetDeviceScaleFactor();
90
const int y_offset = view_->GetLocationBarContentOffsetPix();
91
QRectF bounds = proxy_->GetVisibleBounds();
92
return gfx::RectF(bounds.x() / dpr, (bounds.y() - y_offset) / dpr,
93
bounds.width() / dpr, bounds.height() / dpr);
96
float TouchHandleDrawable::GetDrawableHorizontalPaddingRatio() const {
101
return proxy_->GetDrawableHorizontalPaddingRatio();