~uriboni/webbrowser-app/tab-context-menu

« back to all changes in this revision

Viewing changes to src/app/webbrowser/AddressBar.qml

  • Committer: CI Train Bot
  • Author(s): Olivier Tilloy, Ugo Riboni
  • Date: 2015-08-11 11:18:30 UTC
  • mfrom: (985.6.52 uriboni-find-in-page)
  • Revision ID: ci-train-bot@canonical.com-20150811111830-o328zwwobjvumevy
Implement the "Find in Page" feature.
This bumps the runtime dependency on liboxideqt-qmlplugin to 1.8. Fixes: #1312260
Approved by: Riccardo Padovani

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import QtQuick 2.4
20
20
import Ubuntu.Components 1.3
21
21
import Ubuntu.Components.Popups 1.3
22
 
import com.canonical.Oxide 1.0 as Oxide
 
22
import com.canonical.Oxide 1.8 as Oxide
23
23
import ".."
24
24
import "urlManagement.js" as UrlManagement
25
25
 
40
40
    property bool canSimplifyText: true
41
41
    property bool editing: false
42
42
    property bool showFavicon: true
 
43
    property bool findInPageMode: false
 
44
    property var findController: null
43
45
 
44
46
    property var securityStatus: null
45
47
 
57
59
        textField.selectAll()
58
60
    }
59
61
 
 
62
    Binding {
 
63
        target: findController
 
64
        property: "text"
 
65
        value: findInPageMode ? textField.text : ""
 
66
    }
 
67
 
60
68
    TextField {
61
69
        id: textField
62
70
        objectName: "addressBarTextField"
68
76
 
69
77
            width: iconsRow.width + units.gu(1)
70
78
            height: units.gu(2)
 
79
            visible: !findInPageMode
71
80
 
72
81
            Row {
73
82
                id: iconsRow
179
188
            }
180
189
        }
181
190
 
182
 
        secondaryItem: MouseArea {
183
 
            id: bookmarkToggle
184
 
            objectName: "bookmarkToggle"
185
 
 
 
191
        secondaryItem: Row {
186
192
            height: textField.height
187
 
            width: visible ? height : 0
188
 
 
189
 
            visible: internal.idle && addressbar.actualUrl.toString()
190
 
 
191
 
            Icon {
192
 
                height: parent.height - units.gu(2)
193
 
                width: height
194
 
                anchors.centerIn: parent
195
 
 
196
 
                name: addressbar.bookmarked ? "starred" : "non-starred"
197
 
                color: addressbar.bookmarked ? UbuntuColors.orange : UbuntuColors.darkGrey
 
193
 
 
194
            Label {
 
195
                objectName: "findInPageCounter"
 
196
                anchors.verticalCenter: parent.verticalCenter
 
197
                fontSize: "x-small"
 
198
                color: UbuntuColors.darkGrey
 
199
                opacity: findController && findController.count > 0 ? 1.0 : 0.6
 
200
                visible: findInPageMode
 
201
 
 
202
                // TRANSLATORS: %2 refers to the total number of find in page results and %1 to the highlighted result
 
203
                text: i18n.tr("%1/%2").arg(current).arg(count)
 
204
                property int current: findController ? findController.current : 0
 
205
                property int count: findController ? findController.count : 0
198
206
            }
199
207
 
200
 
            onClicked: addressbar.bookmarked = !addressbar.bookmarked
201
 
 
202
 
            Item {
203
 
                id: bookmarkTogglePlaceHolderItem
204
 
                anchors.fill: parent
 
208
            MouseArea {
 
209
                id: bookmarkToggle
 
210
                objectName: "bookmarkToggle"
 
211
 
 
212
                height: parent.height
 
213
                width: visible ? height : 0
 
214
 
 
215
                visible: !findInPageMode && internal.idle && addressbar.actualUrl.toString()
 
216
 
 
217
                Icon {
 
218
                    height: parent.height - units.gu(2)
 
219
                    width: height
 
220
                    anchors.centerIn: parent
 
221
 
 
222
                    name: addressbar.bookmarked ? "starred" : "non-starred"
 
223
                    color: addressbar.bookmarked ? UbuntuColors.orange : UbuntuColors.darkGrey
 
224
                }
 
225
 
 
226
                onClicked: addressbar.bookmarked = !addressbar.bookmarked
 
227
 
 
228
                Item {
 
229
                    id: bookmarkTogglePlaceHolderItem
 
230
                    anchors.fill: parent
 
231
                }
205
232
            }
206
233
        }
207
234
 
209
236
        color: UbuntuColors.darkGrey
210
237
        inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhUrlCharactersOnly
211
238
 
212
 
        placeholderText: i18n.tr("search or enter an address")
 
239
        placeholderText: findInPageMode ? i18n.tr("find in page")
 
240
                                        : i18n.tr("search or enter an address")
213
241
 
214
242
        // Work around the "fix" for http://pad.lv/1089370 which
215
243
        // unsets focus on the TextField when it becomes invisible
224
252
        highlighted: true
225
253
 
226
254
        onAccepted: if (!internal.idle) internal.validate()
 
255
 
 
256
        Keys.onReturnPressed: {
 
257
            if (!findInPageMode) {
 
258
                accepted()
 
259
            } else if (event.modifiers & Qt.ShiftModifier) {
 
260
                findController.previous()
 
261
            } else {
 
262
                findController.next()
 
263
            }
 
264
        }
227
265
    }
228
266
 
229
267
    // Make sure that all the text is selected at the first click
233
271
            leftMargin: icons.width
234
272
            rightMargin: bookmarkToggle.width
235
273
        }
 
274
 
236
275
        enabled: !addressbar.activeFocus
237
276
        onClicked: {
238
277
            textField.forceActiveFocus()
309
348
    }
310
349
 
311
350
    onEditingChanged: {
 
351
        if (findInPageMode) return
312
352
        if (editing && internal.simplified) {
313
353
            text = actualUrl
314
354
            internal.simplified = false
324
364
    }
325
365
 
326
366
    onCanSimplifyTextChanged: {
327
 
        if (editing) return
 
367
        if (editing || findInPageMode) return
328
368
        if (canSimplifyText && !loading && actualUrl.toString()) {
329
369
            text = internal.simplifyUrl(actualUrl)
330
370
            internal.simplified = true
335
375
    }
336
376
 
337
377
    onActualUrlChanged: {
338
 
        if (editing && actualUrl.toString()) return
 
378
        if ((editing && actualUrl.toString()) || findInPageMode) return
339
379
        if (canSimplifyText) {
340
380
            text = internal.simplifyUrl(actualUrl)
341
381
            internal.simplified = true
346
386
    }
347
387
 
348
388
    onRequestedUrlChanged: {
349
 
        if (editing) return
 
389
        if (editing || findInPageMode) return
350
390
        if (canSimplifyText) {
351
391
            text = internal.simplifyUrl(requestedUrl)
352
392
            internal.simplified = true
356
396
        }
357
397
    }
358
398
 
 
399
    onFindInPageModeChanged: {
 
400
        if (findInPageMode) return
 
401
        if (canSimplifyText) {
 
402
            text = internal.simplifyUrl(actualUrl)
 
403
            internal.simplified = true
 
404
        } else {
 
405
            text = actualUrl
 
406
            internal.simplified = false
 
407
        }
 
408
    }
 
409
 
359
410
    function showSecurityCertificateDetails() {
360
411
        if (!internal.securityCertificateDetails) {
361
412
            internal.securityCertificateDetails = PopupUtils.open(Qt.resolvedUrl("SecurityCertificatePopover.qml"), certificatePopoverPositioner, {"securityStatus": securityStatus})