summaryrefslogtreecommitdiffstats
path: root/src/core/touch_selection_menu_controller.cpp
blob: 98481baf0207a78fbd03f7c19418690526556c06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "touch_selection_controller_client_qt.h"
#include "touch_selection_menu_controller.h"

namespace QtWebEngineCore {

TouchSelectionMenuController::TouchSelectionMenuController(TouchSelectionControllerClientQt *touchSelectionControllerClient)
    : m_touchSelectionControllerClient(touchSelectionControllerClient)
{
}

TouchSelectionMenuController::~TouchSelectionMenuController()
{
}

int TouchSelectionMenuController::buttonCount()
{
    // Context menu should be always available
    return qPopulationCount(static_cast<quint8>(availableActions())) + 1;
}

bool TouchSelectionMenuController::isCommandEnabled(TouchSelectionMenuController::TouchSelectionCommandFlag command)
{
    return m_touchSelectionControllerClient->IsCommandIdEnabled(static_cast<int>(command));
}

void TouchSelectionMenuController::cut()
{
    m_touchSelectionControllerClient->ExecuteCommand(static_cast<int>(Cut), 0);
}

void TouchSelectionMenuController::copy()
{
    m_touchSelectionControllerClient->ExecuteCommand(static_cast<int>(Copy), 0);
}

void TouchSelectionMenuController::paste()
{
    m_touchSelectionControllerClient->ExecuteCommand(static_cast<int>(Paste), 0);
}

void TouchSelectionMenuController::runContextMenu()
{
    return m_touchSelectionControllerClient->RunContextMenu();
}

TouchSelectionMenuController::TouchSelectionCommandFlags TouchSelectionMenuController::availableActions()
{
    TouchSelectionCommandFlags availableActions;

    if (m_touchSelectionControllerClient->IsCommandIdEnabled(Cut)) {
        availableActions |= TouchSelectionMenuController::Cut;
    }
    if (m_touchSelectionControllerClient->IsCommandIdEnabled(Copy)) {
        availableActions |= TouchSelectionMenuController::Copy;
    }
    if (m_touchSelectionControllerClient->IsCommandIdEnabled(Paste)) {
        availableActions |= TouchSelectionMenuController::Paste;
    }

    return availableActions;
}

} // namespace QtWebEngineCore