~timo-jyrinki/ubuntu/trusty/maliit-framework/fix_qt52

« back to all changes in this revision

Viewing changes to src/windowedsurface.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Sergio Schvezov, Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mfrom: (1.1.2) (1.2.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130723194704-1lsy1kmlda069cea
Tags: 0.99.0+git20130615+97e8335-0ubuntu1
[ Sergio Schvezov ]
* New build from HEAD 97e8335.
* Packaging import from lp:phablet-extras/maliit-framework.

[ Ricardo Salveti de Araujo ]
* debian/control: adding vcs and fixing dependencies
* General package cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* * This file is part of Maliit framework *
2
 
 *
3
 
 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4
 
 * All rights reserved.
5
 
 *
6
 
 * Contact: maliit-discuss@lists.maliit.org
7
 
 *
8
 
 * Copyright (C) 2012 One Laptop per Child Association
9
 
 *
10
 
 * This library is free software; you can redistribute it and/or
11
 
 * modify it under the terms of the GNU Lesser General Public
12
 
 * License version 2.1 as published by the Free Software Foundation
13
 
 * and appearing in the file LICENSE.LGPL included in the packaging
14
 
 * of this file.
15
 
 */
16
 
 
17
 
#include "windowedsurface.h"
18
 
#include "windowedsurface_p.h"
19
 
#include "windowedsurfacefactory_p.h"
20
 
 
21
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
22
 
#include "mimdummyinputcontext.h"
23
 
#endif
24
 
 
25
 
#include "mimapphostedserverlogic.h"
26
 
 
27
 
#include <maliit/plugins/abstractwidgetssurface.h>
28
 
 
29
 
#include <QApplication>
30
 
#include <QDebug>
31
 
#include <QDesktopWidget>
32
 
#include <QGraphicsScene>
33
 
#include <QGraphicsView>
34
 
#include <QGraphicsItem>
35
 
#include <QWidget>
36
 
 
37
 
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
38
 
#include <QGuiApplication>
39
 
#include <QVariant>
40
 
#include <QWindow>
41
 
#include <qpa/qplatformnativeinterface.h>
42
 
#endif
43
 
 
44
 
#ifdef Q_WS_X11
45
 
#include <QX11Info>
46
 
#include <X11/Xlib.h>
47
 
#endif
48
 
 
49
 
using Maliit::Plugins::AbstractSurface;
50
 
 
51
 
namespace Maliit {
52
 
namespace Server {
53
 
 
54
 
namespace {
55
 
    const Qt::WindowFlags g_window_flags =
56
 
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
57
 
    Qt::WindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint
58
 
                    | Qt::WindowDoesNotAcceptFocus);
59
 
#else
60
 
    Qt::WindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
61
 
#endif
62
 
}
63
 
 
64
 
WindowedSurface::WindowedSurface(WindowedSurfaceFactory *factory,
65
 
                                 AbstractSurface::Options options,
66
 
                                 const QSharedPointer<WindowedSurface> &parent,
67
 
                                 QWidget *toplevel)
68
 
    : AbstractSurface(),
69
 
      mFactory(factory),
70
 
      mOptions(options),
71
 
      mParent(parent),
72
 
      mToplevel(toplevel),
73
 
      mActive(false),
74
 
      mVisible(false),
75
 
      mRelativePosition()
76
 
{
77
 
    QWidget *parentWidget = 0;
78
 
    if (parent) {
79
 
        parentWidget = parent->mToplevel.data();
80
 
    }
81
 
    mToplevel->setParent(parentWidget, g_window_flags);
82
 
 
83
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
84
 
    mToplevel->setAttribute(Qt::WA_X11DoNotAcceptFocus);
85
 
#endif
86
 
    mToplevel->setAutoFillBackground(false);
87
 
    mToplevel->setBackgroundRole(QPalette::NoRole);
88
 
 
89
 
    mToplevel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
90
 
 
91
 
    updateVisibility();
92
 
 
93
 
    mToplevel->installEventFilter(this);
94
 
}
95
 
 
96
 
WindowedSurface::~WindowedSurface()
97
 
{
98
 
}
99
 
 
100
 
void WindowedSurface::show()
101
 
{
102
 
    mVisible = true;
103
 
    updateVisibility();
104
 
}
105
 
 
106
 
void WindowedSurface::hide()
107
 
{
108
 
    mVisible = false;
109
 
    updateVisibility();
110
 
}
111
 
 
112
 
QSize WindowedSurface::size() const
113
 
{
114
 
    return mToplevel->size();
115
 
}
116
 
 
117
 
void WindowedSurface::setSize(const QSize &size)
118
 
{
119
 
    if (isWindow()) {
120
 
        // stand-alone Maliit server
121
 
        if (mOptions & PositionCenterBottom) {
122
 
            const QSize desktopSize = QApplication::desktop()->screenGeometry().size();
123
 
 
124
 
            mToplevel->setGeometry(QRect(QPoint((desktopSize.width() - size.width()) / 2,
125
 
                                                desktopSize.height() - size.height()), size));
126
 
        } else {
127
 
            mToplevel->resize(size);
128
 
        }
129
 
    } else {
130
 
        // application-hosted Maliit server
131
 
        mToplevel->resize(size);
132
 
    }
133
 
    mFactory->updateInputMethodArea();
134
 
}
135
 
 
136
 
QPoint WindowedSurface::relativePosition() const
137
 
{
138
 
    return mRelativePosition;
139
 
}
140
 
 
141
 
void WindowedSurface::setRelativePosition(const QPoint &position)
142
 
{
143
 
    mRelativePosition = position;
144
 
    QPoint parentPosition(0, 0);
145
 
    if (mParent) {
146
 
        if (isWindow() && !mParent->isWindow()) {
147
 
            parentPosition = mParent->mapToGlobal(QPoint(0, 0));
148
 
        } else if (!isWindow() && mParent->isWindow()) {
149
 
            // do nothing
150
 
        } else {
151
 
            parentPosition = mParent->mToplevel->pos();
152
 
        }
153
 
    }
154
 
    mToplevel->move(parentPosition + mRelativePosition);
155
 
        mFactory->updateInputMethodArea();
156
 
}
157
 
 
158
 
QSharedPointer<AbstractSurface> WindowedSurface::parent() const
159
 
{
160
 
    return mParent;
161
 
}
162
 
 
163
 
QPoint WindowedSurface::translateEventPosition(const QPoint &eventPosition,
164
 
                                               const QSharedPointer<AbstractSurface> &eventSurface) const
165
 
{
166
 
    if (!eventSurface)
167
 
        return eventPosition;
168
 
 
169
 
    QSharedPointer<WindowedSurface> windowedSurface = qSharedPointerDynamicCast<WindowedSurface>(eventSurface);
170
 
    if (!windowedSurface)
171
 
        return QPoint();
172
 
 
173
 
    return -mToplevel->pos() + eventPosition + windowedSurface->mToplevel->pos();
174
 
}
175
 
 
176
 
void WindowedSurface::setActive(bool active)
177
 
{
178
 
    mActive = active;
179
 
    updateVisibility();
180
 
}
181
 
 
182
 
void WindowedSurface::applicationFocusChanged(WId winId)
183
 
{
184
 
    if (mParent)
185
 
        return;
186
 
#ifdef Q_WS_X11
187
 
    XSetTransientForHint(QX11Info::display(),
188
 
                         mToplevel->window()->effectiveWinId(),
189
 
                         winId);
190
 
#else
191
 
    Q_UNUSED(winId);
192
 
#endif
193
 
}
194
 
 
195
 
QRegion WindowedSurface::inputMethodArea()
196
 
{
197
 
    if (!mToplevel->isVisible())
198
 
        return QRegion();
199
 
 
200
 
    return QRegion(mToplevel->geometry());
201
 
}
202
 
 
203
 
void WindowedSurface::updateVisibility()
204
 
{
205
 
    mToplevel->setVisible(mActive && mVisible);
206
 
    mFactory->updateInputMethodArea();
207
 
}
208
 
 
209
 
bool WindowedSurface::isWindow() const
210
 
{
211
 
    return mToplevel->isWindow();
212
 
}
213
 
 
214
 
QPoint WindowedSurface::mapToGlobal(const QPoint &pos) const
215
 
{
216
 
    return mToplevel->mapToGlobal(pos);
217
 
}
218
 
 
219
 
bool WindowedSurface::eventFilter(QObject *, QEvent *event)
220
 
{
221
 
#ifdef HAVE_WAYLAND
222
 
    if (event->type() == QEvent::WinIdChange) {
223
 
        mSurface = static_cast<struct input_panel_surface *>(mFactory->getInputPanelSurface(mToplevel->windowHandle()));
224
 
        input_panel_surface_set_toplevel(mSurface);
225
 
    }
226
 
#else
227
 
    Q_UNUSED(event);
228
 
#endif
229
 
 
230
 
    return false;
231
 
}
232
 
 
233
 
class GraphicsView : public QGraphicsView
234
 
{
235
 
public:
236
 
    GraphicsView()
237
 
        : QGraphicsView()
238
 
    {
239
 
        setWindowFlags(g_window_flags);
240
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
241
 
        setAttribute(Qt::WA_X11DoNotAcceptFocus);
242
 
#endif
243
 
        // Fixes: MALIIT#194 - Maliit can not input when QML viewer is set to
244
 
        // full screen on QWS without x11
245
 
        setAttribute(Qt::WA_ShowWithoutActivating);
246
 
 
247
 
        setAutoFillBackground(false);
248
 
        setBackgroundRole(QPalette::NoRole);
249
 
        setBackgroundBrush(Qt::transparent);
250
 
 
251
 
        // This is a workaround for non-compositing window managers. Apparently
252
 
        // setting this attribute while using such WMs may cause garbled
253
 
        // painting of VKB.
254
 
#ifndef DISABLE_TRANSLUCENT_BACKGROUND_HINT
255
 
        setAttribute(Qt::WA_TranslucentBackground);
256
 
#endif
257
 
        viewport()->setAutoFillBackground(false);
258
 
    }
259
 
};
260
 
 
261
 
class RootItem
262
 
    : public QGraphicsItem
263
 
{
264
 
private:
265
 
    QRectF m_rect;
266
 
 
267
 
public:
268
 
    explicit RootItem(QGraphicsItem *parent = 0)
269
 
        : QGraphicsItem(parent)
270
 
        , m_rect()
271
 
    {
272
 
        setFlag(QGraphicsItem::ItemHasNoContents);
273
 
    }
274
 
 
275
 
    void setRect(const QRectF &rect)
276
 
    {
277
 
        m_rect = rect;
278
 
    }
279
 
 
280
 
    virtual QRectF boundingRect() const
281
 
    {
282
 
        return m_rect;
283
 
    }
284
 
 
285
 
    virtual void paint(QPainter *,
286
 
                       const QStyleOptionGraphicsItem *,
287
 
                       QWidget *)
288
 
    {}
289
 
};
290
 
 
291
 
class WindowedGraphicsViewSurface : public WindowedSurface, public Maliit::Plugins::AbstractGraphicsViewSurface
292
 
{
293
 
public:
294
 
    WindowedGraphicsViewSurface(WindowedSurfaceFactory *factory, AbstractSurface::Options options,
295
 
                                const QSharedPointer<WindowedSurface> &parent)
296
 
        : WindowedSurface(factory, options, parent, new GraphicsView),
297
 
          AbstractGraphicsViewSurface(),
298
 
          mRoot(0)
299
 
    {
300
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
301
 
        MIMDummyInputContext dummy;
302
 
#endif
303
 
        QGraphicsView *view = static_cast<QGraphicsView*>(mToplevel.data());
304
 
        view->setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
305
 
        view->setOptimizationFlags(QGraphicsView::DontClipPainter | QGraphicsView::DontSavePainterState);
306
 
        view->setFrameShape(QFrame::NoFrame);
307
 
        view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
308
 
        view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
309
 
 
310
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
311
 
        // Calling QGraphicsView::setScene() indirectly calls QWidget::inputContext() on the view.  If there isn't
312
 
        // an input context set on the widget, this calls QApplication::inputContext(), which leads to infinite
313
 
        // recursion if surface creation happens during input method creation and QT_IM_MODULE is set (for example
314
 
        // when embedding maliit-server in the application)
315
 
        view->setInputContext(&dummy);
316
 
#endif
317
 
        QGraphicsScene *scene = new QGraphicsScene(view);
318
 
        view->setScene(scene);
319
 
 
320
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
321
 
        view->setInputContext(0);
322
 
#endif
323
 
    }
324
 
 
325
 
    ~WindowedGraphicsViewSurface() {}
326
 
 
327
 
    QGraphicsScene *scene() const
328
 
    {
329
 
        return view()->scene();
330
 
    }
331
 
 
332
 
    QGraphicsView *view() const
333
 
    {
334
 
        return static_cast<QGraphicsView*>(mToplevel.data());
335
 
    }
336
 
 
337
 
    void show()
338
 
    {
339
 
        WindowedSurface::show();
340
 
 
341
 
        const QRect rect(QPoint(), mToplevel->size());
342
 
 
343
 
        if (not mRoot) {
344
 
            scene()->addItem(mRoot = new RootItem);
345
 
            mRoot->setRect(rect);
346
 
            mRoot->show();
347
 
        }
348
 
    }
349
 
 
350
 
    void setSize(const QSize &size)
351
 
    {
352
 
        WindowedSurface::setSize(size);
353
 
 
354
 
        view()->setSceneRect(QRect(QPoint(), mToplevel->size()));
355
 
        if (mRoot) {
356
 
            mRoot->setRect(QRect(QPoint(), mToplevel->size()));
357
 
        }
358
 
    }
359
 
 
360
 
    void clear()
361
 
    {
362
 
        mRoot = 0;
363
 
        scene()->clear();
364
 
    }
365
 
 
366
 
    QGraphicsItem *root() const
367
 
    {
368
 
        return mRoot;
369
 
    }
370
 
 
371
 
    QWidget *widget() const
372
 
    {
373
 
        return view();
374
 
    }
375
 
 
376
 
private:
377
 
    RootItem *mRoot;
378
 
};
379
 
 
380
 
class WindowedWidgetSurface : public WindowedSurface, public Maliit::Plugins::AbstractWidgetSurface
381
 
{
382
 
public:
383
 
    WindowedWidgetSurface(WindowedSurfaceFactory *factory, AbstractSurface::Options options,
384
 
                          const QSharedPointer<WindowedSurface> &parent)
385
 
        : WindowedSurface(factory, options, parent, new QWidget),
386
 
          AbstractWidgetSurface()
387
 
    {}
388
 
 
389
 
    QWidget* widget() const {
390
 
        return mToplevel.data();
391
 
    }
392
 
};
393
 
 
394
 
#ifdef HAVE_WAYLAND
395
 
namespace {
396
 
 
397
 
void registryGlobal(void *data,
398
 
                    wl_registry *registry,
399
 
                    uint32_t name,
400
 
                    const char *interface,
401
 
                    uint32_t version)
402
 
{
403
 
    WindowedSurfaceFactoryPrivate *d = static_cast<WindowedSurfaceFactoryPrivate *>(data);
404
 
 
405
 
    Q_UNUSED(registry);
406
 
    d->handleRegistryGlobal(name, interface, version);
407
 
}
408
 
 
409
 
void registryGlobalRemove(void *data,
410
 
                          wl_registry *registry,
411
 
                          uint32_t name)
412
 
{
413
 
    WindowedSurfaceFactoryPrivate *d = static_cast<WindowedSurfaceFactoryPrivate *>(data);
414
 
 
415
 
    Q_UNUSED(registry);
416
 
    d->handleRegistryGlobalRemove(name);
417
 
}
418
 
 
419
 
const wl_registry_listener maliit_registry_listener = {
420
 
    registryGlobal,
421
 
    registryGlobalRemove
422
 
};
423
 
 
424
 
void outputGeometry(void *data,
425
 
                    struct wl_output *output,
426
 
                    int32_t x,
427
 
                    int32_t y,
428
 
                    int32_t physical_width,
429
 
                    int32_t physical_height,
430
 
                    int32_t subpixel,
431
 
                    const char *make,
432
 
                    const char *model,
433
 
                    int32_t transform) {
434
 
    WindowedSurfaceFactoryPrivate *d = static_cast<WindowedSurfaceFactoryPrivate *>(data);
435
 
 
436
 
    Q_UNUSED(output);
437
 
    d->handleOutputGeometry(x, y, physical_width, physical_height, subpixel, make,
438
 
                            model, transform);
439
 
}
440
 
 
441
 
void outputMode(void *data,
442
 
                struct wl_output *output,
443
 
                uint32_t flags,
444
 
                int32_t width,
445
 
                int32_t height,
446
 
                int32_t refresh) {
447
 
    WindowedSurfaceFactoryPrivate *d = static_cast<WindowedSurfaceFactoryPrivate *>(data);
448
 
 
449
 
    Q_UNUSED(output);
450
 
    d->handleOutputMode(flags, width, height, refresh);
451
 
}
452
 
 
453
 
const wl_output_listener maliit_output_listener = {
454
 
    outputGeometry,
455
 
    outputMode
456
 
};
457
 
 
458
 
} // unnamed namespace
459
 
#endif
460
 
 
461
 
WindowedSurfaceFactoryPrivate::WindowedSurfaceFactoryPrivate(WindowedSurfaceFactory *factory)
462
 
    : QObject()
463
 
    , q_ptr(factory)
464
 
    , surfaces()
465
 
    , active(false)
466
 
#ifdef HAVE_WAYLAND
467
 
    , registry(0)
468
 
    , output(0)
469
 
    , panel(0)
470
 
    , output_configured(false)
471
 
#endif
472
 
{
473
 
    connect(QApplication::desktop(), SIGNAL(resized(int)),
474
 
            this, SLOT(screenResized(int)));
475
 
 
476
 
#ifdef HAVE_WAYLAND
477
 
    wl_display *display = static_cast<wl_display *>(QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("display"));
478
 
    if (!display) {
479
 
        qCritical() << __PRETTY_FUNCTION__ << "Failed to get a display.";
480
 
        return;
481
 
    }
482
 
    registry = wl_display_get_registry(display);
483
 
    wl_registry_add_listener(registry, &maliit_registry_listener, this);
484
 
    // QtWayland will do dispatching for us.
485
 
#endif
486
 
}
487
 
 
488
 
#ifdef HAVE_WAYLAND
489
 
void WindowedSurfaceFactoryPrivate::handleRegistryGlobal(uint32_t name,
490
 
                                                         const char *interface,
491
 
                                                         uint32_t version)
492
 
{
493
 
    Q_UNUSED(version);
494
 
 
495
 
    if (!strcmp(interface, "input_panel")) {
496
 
        panel = static_cast<input_panel *>(wl_registry_bind(registry, name, &input_panel_interface, 1));
497
 
    } else if (!strcmp(interface, "wl_output")) {
498
 
        if (output) {
499
 
            // Ignoring the event - we already have an output.
500
 
            // TODO: Later we will want to store those outputs as well
501
 
            // to be able to choose where the input method plugin is
502
 
            // shown.
503
 
            return;
504
 
        }
505
 
 
506
 
        output = static_cast<wl_output *>(wl_registry_bind(registry, name, &wl_output_interface, 1));
507
 
        wl_output_add_listener (output, &maliit_output_listener, this);
508
 
    }
509
 
}
510
 
 
511
 
void WindowedSurfaceFactoryPrivate::handleRegistryGlobalRemove(uint32_t name)
512
 
{
513
 
    Q_UNUSED(name);
514
 
}
515
 
 
516
 
void WindowedSurfaceFactoryPrivate::handleOutputGeometry(int32_t x,
517
 
                                                         int32_t y,
518
 
                                                         int32_t physical_width,
519
 
                                                         int32_t physical_height,
520
 
                                                         int32_t subpixel,
521
 
                                                         const char *make,
522
 
                                                         const char *model,
523
 
                                                         int32_t transform)
524
 
{
525
 
    Q_UNUSED(x);
526
 
    Q_UNUSED(y);
527
 
    Q_UNUSED(physical_width);
528
 
    Q_UNUSED(physical_height);
529
 
    Q_UNUSED(subpixel);
530
 
    Q_UNUSED(make);
531
 
    Q_UNUSED(model);
532
 
    Q_UNUSED(transform);
533
 
}
534
 
 
535
 
void WindowedSurfaceFactoryPrivate::handleOutputMode(uint32_t flags,
536
 
                                                     int32_t width,
537
 
                                                     int32_t height,
538
 
                                                     int32_t refresh)
539
 
{
540
 
    Q_UNUSED(width);
541
 
    Q_UNUSED(height);
542
 
    Q_UNUSED(refresh);
543
 
    qDebug() << __PRETTY_FUNCTION__;
544
 
    if ((flags & WL_OUTPUT_MODE_CURRENT) == WL_OUTPUT_MODE_CURRENT) {
545
 
        output_configured = true;
546
 
    }
547
 
}
548
 
#endif
549
 
 
550
 
void WindowedSurfaceFactoryPrivate::screenResized(int)
551
 
{
552
 
    Q_Q(WindowedSurfaceFactory);
553
 
 
554
 
    Q_FOREACH(QWeakPointer<WindowedSurface> weakSurface, surfaces) {
555
 
        QSharedPointer<WindowedSurface> surface = weakSurface.toStrongRef();
556
 
        if (surface) {
557
 
            surface->setSize(surface->size());
558
 
            if (surface->parent()) {
559
 
                surface->setRelativePosition(surface->relativePosition());
560
 
            }
561
 
        }
562
 
    }
563
 
    Q_EMIT q->screenSizeChanged(q->screenSize());
564
 
}
565
 
 
566
 
#ifdef HAVE_WAYLAND
567
 
void *WindowedSurfaceFactory::getInputPanelSurface(QWindow *window)
568
 
{
569
 
    Q_D(WindowedSurfaceFactory);
570
 
 
571
 
    struct wl_surface *surface = static_cast<struct wl_surface *>(QGuiApplication::platformNativeInterface()->nativeResourceForWindow("surface", window));
572
 
 
573
 
    return input_panel_get_input_panel_surface(d->panel, surface);
574
 
}
575
 
#endif
576
 
 
577
 
// Windowed Surface Factory
578
 
 
579
 
WindowedSurfaceFactory::WindowedSurfaceFactory()
580
 
    : AbstractSurfaceFactory()
581
 
    , d_ptr(new WindowedSurfaceFactoryPrivate(this))
582
 
{
583
 
}
584
 
 
585
 
WindowedSurfaceFactory::~WindowedSurfaceFactory()
586
 
{
587
 
}
588
 
 
589
 
QSize WindowedSurfaceFactory::screenSize() const
590
 
{
591
 
    return QApplication::desktop()->screenGeometry().size();
592
 
}
593
 
 
594
 
bool WindowedSurfaceFactory::supported(Maliit::Plugins::AbstractSurface::Options options) const
595
 
{
596
 
    return options & AbstractSurface::TypeGraphicsView;
597
 
}
598
 
 
599
 
namespace {
600
 
 
601
 
QSharedPointer<WindowedSurface> createSurface(WindowedSurfaceFactory *factory,
602
 
                                              AbstractSurface::Options options,
603
 
                                              const QSharedPointer<WindowedSurface> &parent)
604
 
{
605
 
    if (options & Maliit::Plugins::AbstractSurface::TypeGraphicsView) {
606
 
        return QSharedPointer<WindowedSurface>(new WindowedGraphicsViewSurface(factory,
607
 
                                                                               options,
608
 
                                                                               parent));
609
 
    }
610
 
    if (options & Maliit::Plugins::AbstractSurface::TypeWidget) {
611
 
        return QSharedPointer<WindowedSurface>(new WindowedWidgetSurface(factory,
612
 
                                                                         options,
613
 
                                                                         parent));
614
 
    }
615
 
    return QSharedPointer<WindowedSurface>();
616
 
}
617
 
 
618
 
} // unnamed namespace
619
 
 
620
 
QSharedPointer<AbstractSurface> WindowedSurfaceFactory::create(AbstractSurface::Options options,
621
 
                                                               const QSharedPointer<AbstractSurface> &parent)
622
 
{
623
 
    Q_D(WindowedSurfaceFactory);
624
 
 
625
 
    QSharedPointer<WindowedSurface> default_surface_parent(qSharedPointerDynamicCast<WindowedSurface>(parent));
626
 
    QSharedPointer<WindowedSurface> new_surface(createSurface(this, options,
627
 
                                                              default_surface_parent));
628
 
 
629
 
    if (new_surface) {
630
 
        d->surfaces.push_back(new_surface);
631
 
        Q_EMIT surfaceWidgetCreated(new_surface->widget(), options);
632
 
    }
633
 
    return new_surface;
634
 
}
635
 
 
636
 
void WindowedSurfaceFactory::activate()
637
 
{
638
 
    Q_D(WindowedSurfaceFactory);
639
 
 
640
 
    d->active = true;
641
 
 
642
 
    Q_FOREACH(QWeakPointer<WindowedSurface> weakSurface, d->surfaces) {
643
 
        QSharedPointer<WindowedSurface> surface = weakSurface.toStrongRef();
644
 
        if (surface)
645
 
            surface->setActive(true);
646
 
    }
647
 
}
648
 
 
649
 
void WindowedSurfaceFactory::deactivate()
650
 
{
651
 
    Q_D(WindowedSurfaceFactory);
652
 
 
653
 
    d->active = false;
654
 
 
655
 
    Q_FOREACH(QWeakPointer<WindowedSurface> weakSurface, d->surfaces) {
656
 
        QSharedPointer<WindowedSurface> surface = weakSurface.toStrongRef();
657
 
        if (surface)
658
 
            surface->setActive(false);
659
 
    }
660
 
}
661
 
 
662
 
void WindowedSurfaceFactory::applicationFocusChanged(WId winId)
663
 
{
664
 
    Q_D(WindowedSurfaceFactory);
665
 
 
666
 
    Q_FOREACH(QWeakPointer<WindowedSurface> weakSurface, d->surfaces) {
667
 
        QSharedPointer<WindowedSurface> surface = weakSurface.toStrongRef();
668
 
        if (surface) {
669
 
            surface->applicationFocusChanged(winId);
670
 
        }
671
 
    }
672
 
}
673
 
 
674
 
void WindowedSurfaceFactory::updateInputMethodArea()
675
 
{
676
 
    Q_D(WindowedSurfaceFactory);
677
 
 
678
 
    if (!d->active)
679
 
        return;
680
 
 
681
 
    QRegion inputMethodArea;
682
 
 
683
 
    Q_FOREACH(QWeakPointer<WindowedSurface> weakSurface, d->surfaces) {
684
 
        QSharedPointer<WindowedSurface> surface = weakSurface.toStrongRef();
685
 
        if (surface && !surface->parent()) {
686
 
            inputMethodArea |= surface->inputMethodArea();
687
 
        }
688
 
    }
689
 
 
690
 
    Q_EMIT inputMethodAreaChanged(inputMethodArea);
691
 
}
692
 
 
693
 
} // namespace Server
694
 
} // namespace Maliit