~osomon/oxide/override-touchUngrabEvent

« back to all changes in this revision

Viewing changes to qt/core/browser/oxide_qt_touch_handle_drawable.cc

  • Committer: Olivier Tilloy
  • Date: 2016-01-12 11:46:34 UTC
  • mfrom: (1272.2.38 touch-selection-api)
  • Revision ID: olivier.tilloy@canonical.com-20160112114634-u1t78baa0u4hfoha
Add a touch selection API, to allow embedders to display handles for resizing the current selection, and contextual actions for it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim:expandtab:shiftwidth=2:tabstop=2:
 
2
// Copyright (C) 2015-2016 Canonical Ltd.
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
 
 
18
#include "oxide_qt_touch_handle_drawable.h"
 
19
 
 
20
#include "qt/core/glue/oxide_qt_touch_handle_drawable_proxy.h"
 
21
 
 
22
#include "oxide_qt_web_view.h"
 
23
 
 
24
#include <QPointF>
 
25
 
 
26
namespace oxide {
 
27
namespace qt {
 
28
 
 
29
TouchHandleDrawable::TouchHandleDrawable(const WebView* view)
 
30
    : view_(view) {}
 
31
 
 
32
TouchHandleDrawable::~TouchHandleDrawable() {}
 
33
 
 
34
void TouchHandleDrawable::SetProxy(TouchHandleDrawableProxy* proxy) {
 
35
  proxy_.reset(proxy);
 
36
}
 
37
 
 
38
void TouchHandleDrawable::SetEnabled(bool enabled) {
 
39
  if (proxy_) {
 
40
    proxy_->SetEnabled(enabled);
 
41
  }
 
42
}
 
43
 
 
44
void TouchHandleDrawable::SetOrientation(
 
45
    ui::TouchHandleOrientation orientation,
 
46
    bool mirror_vertical,
 
47
    bool mirror_horizontal) {
 
48
  if (proxy_) {
 
49
    TouchHandleDrawableProxy::Orientation o;
 
50
    switch (orientation) {
 
51
      case ui::TouchHandleOrientation::LEFT:
 
52
        o = TouchHandleDrawableProxy::Left;
 
53
        break;
 
54
      case ui::TouchHandleOrientation::CENTER:
 
55
        o = TouchHandleDrawableProxy::Center;
 
56
        break;
 
57
      case ui::TouchHandleOrientation::RIGHT:
 
58
        o = TouchHandleDrawableProxy::Right;
 
59
        break;
 
60
      case ui::TouchHandleOrientation::UNDEFINED:
 
61
        o = TouchHandleDrawableProxy::Undefined;
 
62
        break;
 
63
      default:
 
64
        Q_UNREACHABLE();
 
65
    }
 
66
    proxy_->SetOrientation(o, mirror_vertical, mirror_horizontal);
 
67
  }
 
68
}
 
69
 
 
70
void TouchHandleDrawable::SetOrigin(const gfx::PointF& origin) {
 
71
  if (proxy_) {
 
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));
 
75
  }
 
76
}
 
77
 
 
78
void TouchHandleDrawable::SetAlpha(float alpha) {
 
79
  if (proxy_) {
 
80
    proxy_->SetAlpha(alpha);
 
81
  }
 
82
}
 
83
 
 
84
gfx::RectF TouchHandleDrawable::GetVisibleBounds() const {
 
85
  if (!proxy_) {
 
86
    return gfx::RectF();
 
87
  }
 
88
 
 
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);
 
94
}
 
95
 
 
96
float TouchHandleDrawable::GetDrawableHorizontalPaddingRatio() const {
 
97
  if (!proxy_) {
 
98
    return 0.0f;
 
99
  }
 
100
 
 
101
  return proxy_->GetDrawableHorizontalPaddingRatio();
 
102
}
 
103
 
 
104
} // namespace qt
 
105
} // namespace oxide