github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/cmd/mist/assets/qml/views/browser.qml (about) 1 import QtQuick 2.0 2 import QtQuick.Controls 1.0; 3 import QtQuick.Controls.Styles 1.0 4 import QtQuick.Layouts 1.0; 5 import QtWebEngine 1.0 6 import QtWebEngine.experimental 1.0 7 import QtQuick.Window 2.0; 8 9 Rectangle { 10 id: window 11 anchors.fill: parent 12 color: "#00000000" 13 14 property var title: "" 15 property var iconSource: "../browser.png" 16 property var menuItem 17 property var hideUrl: true 18 19 property alias url: webview.url 20 property alias windowTitle: webview.title 21 property alias webView: webview 22 23 property var cleanPath: false 24 property var open: function(url) { 25 if(!window.cleanPath) { 26 var uri = url; 27 if(!/.*\:\/\/.*/.test(uri)) { 28 uri = "http://" + uri; 29 } 30 31 var reg = /(^https?\:\/\/(?:www\.)?)([a-zA-Z0-9_\-]*\.eth)(.*)/ 32 33 if(reg.test(uri)) { 34 uri.replace(reg, function(match, pre, domain, path) { 35 uri = pre; 36 37 var lookup = eth.lookupDomain(domain.substring(0, domain.length - 4)); 38 var ip = []; 39 for(var i = 0, l = lookup.length; i < l; i++) { 40 ip.push(lookup.charCodeAt(i)) 41 } 42 43 if(ip.length != 0) { 44 uri += lookup; 45 } else { 46 uri += domain; 47 } 48 49 uri += path; 50 }); 51 } 52 53 window.cleanPath = true; 54 55 webview.url = uri; 56 57 //uriNav.text = uri.text.replace(/(^https?\:\/\/(?:www\.)?)([a-zA-Z0-9_\-]*\.\w{2,3})(.*)/, "$1$2<span style='color:#CCC'>$3</span>"); 58 uriNav.text = uri; 59 60 } else { 61 // Prevent inf loop. 62 window.cleanPath = false; 63 } 64 } 65 66 function showFullUrlBar(on){ 67 if (on) { 68 //appTitle.visible = false 69 //appDomain.visible = false 70 71 //uriNav.visible = true 72 clickAnywhereOnApp.visible = true 73 74 navBar.state = "fullUrlVisible" 75 } else { 76 //appTitle.visible = true 77 //appDomain.visible = true 78 //uriNav.visible = false 79 clickAnywhereOnApp.visible = false 80 81 navBar.state = "titleVisible" 82 83 } 84 85 } 86 87 Component.onCompleted: { 88 } 89 90 Item { 91 objectName: "root" 92 id: root 93 anchors.fill: parent 94 state: "inspectorShown" 95 96 MouseArea { 97 id: clickAnywhereOnApp 98 z:15 99 //hoverEnabled: true 100 anchors.fill: parent 101 /*hoverEnabled: true*/ 102 103 onClicked: { 104 showFullUrlBar(false); 105 } 106 107 /*Rectangle { 108 anchors.fill: parent 109 color: "#88888888" 110 }*/ 111 } 112 113 RowLayout { 114 id: navBar 115 height: 74 116 z: 20 117 anchors { 118 left: parent.left 119 right: parent.right 120 } 121 122 Button { 123 id: back 124 125 onClicked: { 126 webview.goBack() 127 } 128 129 anchors{ 130 left: parent.left 131 leftMargin: 6 132 } 133 134 style: ButtonStyle { 135 background: Image { 136 source: "../../backButton.png" 137 width: 20 138 height: 30 139 } 140 } 141 } 142 143 Rectangle { 144 id: appInfoPane 145 height: 28 146 color: "#FFFFFF" 147 radius: 6 148 149 150 MouseArea { 151 anchors.fill: parent 152 z: 10 153 hoverEnabled: true 154 155 onEntered: { 156 showFullUrlBar(true); 157 } 158 159 } 160 161 anchors { 162 left: back.right 163 right: parent.right 164 leftMargin: 10 165 rightMargin: 10 166 } 167 168 Text { 169 id: appTitle 170 text: "LOADING" 171 font.bold: true 172 font.capitalization: Font.AllUppercase 173 horizontalAlignment: Text.AlignRight 174 verticalAlignment: Text.AlignVCenter 175 176 anchors { 177 left: parent.left 178 right: parent.horizontalCenter 179 top: parent.top 180 bottom: parent.bottom 181 rightMargin: 10 182 } 183 color: "#928484" 184 } 185 186 Text { 187 id: appDomain 188 text: "loading domain" 189 font.bold: false 190 horizontalAlignment: Text.AlignLeft 191 verticalAlignment: Text.AlignVCenter 192 193 anchors { 194 left: parent.horizontalCenter 195 right: parent.right 196 top: parent.top 197 bottom: parent.bottom 198 leftMargin: 10 199 } 200 color: "#C0AFAF" 201 } 202 203 204 TextField { 205 id: uriNav 206 opacity: 0.0 207 208 anchors { 209 left: parent.left 210 right: parent.right 211 leftMargin: 16 212 } 213 214 horizontalAlignment: Text.AlignHCenter 215 216 style: TextFieldStyle { 217 textColor: "#928484" 218 background: Rectangle { 219 border.width: 0 220 color: "transparent" 221 } 222 } 223 text: webview.url; 224 y: parent.height / 2 - this.height / 2 225 z: 20 226 activeFocusOnPress: true 227 Keys.onReturnPressed: { 228 webview.url = this.text; 229 } 230 /* onFocusedChanged: { 231 if (focused) { 232 //uriNav.selectAll(); 233 } 234 }*/ 235 } 236 237 z:2 238 } 239 240 Rectangle { 241 id: appInfoPaneShadow 242 width: 10 243 height: 30 244 color: "#BDB6B6" 245 radius: 6 246 247 anchors { 248 left: back.right 249 right: parent.right 250 leftMargin:10 251 rightMargin:10 252 top: parent.top 253 topMargin: 23 254 } 255 256 z:1 257 } 258 259 Rectangle { 260 id: navBarBackground 261 anchors.fill: parent 262 gradient: Gradient { 263 GradientStop { position: 0.0; color: "#F6F1F2" } 264 GradientStop { position: 1.0; color: "#DED5D5" } 265 } 266 z:-1 267 } 268 269 states: [ 270 State { 271 name: "fullUrlVisible" 272 PropertyChanges { 273 target: appTitle 274 anchors.rightMargin: -50 275 opacity: 0.0 276 } 277 PropertyChanges { 278 target: appDomain 279 anchors.leftMargin: -50 280 opacity: 0.0 281 } 282 PropertyChanges { 283 target: uriNav 284 anchors.leftMargin: 0 285 opacity: 1.0 286 } 287 }, 288 State { 289 name: "titleVisible" 290 291 PropertyChanges { 292 target: appTitle 293 anchors.rightMargin: 10 294 opacity: 1.0 295 } 296 PropertyChanges { 297 target: appDomain 298 anchors.leftMargin: 10 299 opacity: 1.0 300 } 301 PropertyChanges { 302 target: uriNav 303 anchors.leftMargin: -50 304 opacity: 0.0 305 } 306 } 307 308 ] 309 310 transitions: [ 311 // This adds a transition that defaults to applying to all state changes 312 313 Transition { 314 315 // This applies a default NumberAnimation to any changes a state change makes to x or y properties 316 NumberAnimation { 317 properties: "anchors.leftMargin, anchors.rightMargin, opacity" 318 easing.type: Easing.InOutQuad //Easing.InOutBack 319 duration: 300 320 } 321 } 322 ] 323 324 } 325 326 WebEngineView { 327 objectName: "webView" 328 id: webview 329 experimental.settings.javascriptCanAccessClipboard: true 330 experimental.settings.localContentCanAccessRemoteUrls: true 331 anchors { 332 left: parent.left 333 right: parent.right 334 bottom: parent.bottom 335 top: navBar.bottom 336 } 337 z: 10 338 339 Timer { 340 interval: 500; running: true; repeat: true 341 onTriggered: { 342 webview.runJavaScript("try{document.querySelector('meta[name=badge]').getAttribute('content')}catch(e){}", function(badge) { 343 if (badge) { 344 menuItem.secondaryTitle = badge; 345 } 346 }); 347 } 348 } 349 350 onLoadingChanged: { 351 if (loadRequest.status == WebEngineView.LoadSucceededStatus) { 352 webview.runJavaScript("document.title", function(pageTitle) { 353 menuItem.title = pageTitle; 354 }); 355 356 webView.runJavaScript("try{document.querySelector(\"meta[name='ethereum-dapp-url-bar-style']\").getAttribute(\"content\")}catch(e){}", function(topBarStyle){ 357 if (!topBarStyle) { 358 showFullUrlBar(true); 359 navBarBackground.visible = true; 360 back.visible = true; 361 appInfoPane.anchors.leftMargin = 0; 362 appInfoPaneShadow.anchors.leftMargin = 0; 363 webview.anchors.topMargin = 0; 364 return; 365 } 366 367 if (topBarStyle=="transparent") { 368 // Adjust for a transparent sidebar Dapp 369 navBarBackground.visible = false; 370 back.visible = false; 371 appInfoPane.anchors.leftMargin = -16; 372 appInfoPaneShadow.anchors.leftMargin = -16; 373 webview.anchors.topMargin = -74; 374 webview.runJavaScript("document.querySelector('body').classList.add('ethereum-dapp-url-bar-style-transparent')") 375 376 } else { 377 navBarBackground.visible = true; 378 back.visible = true; 379 appInfoPane.anchors.leftMargin = 0; 380 appInfoPaneShadow.anchors.leftMargin = 0; 381 webview.anchors.topMargin = 0; 382 }; 383 }); 384 385 var cleanTitle = webview.url.toString() 386 var matches = cleanTitle.match(/^[a-z]*\:\/\/([^\/?#]+)(?:[\/?#]|$)/i); 387 var domain = matches && matches[1]; 388 389 if (domain) 390 appDomain.text = domain //webview.url.replace("a", "z") 391 if (webview.title) 392 appTitle.text = webview.title 393 394 showFullUrlBar(false); 395 } 396 } 397 onJavaScriptConsoleMessage: { 398 console.log(sourceID + ":" + lineNumber + ":" + JSON.stringify(message)); 399 } 400 } 401 402 Rectangle { 403 id: sizeGrip 404 color: "gray" 405 visible: false 406 height: 10 407 anchors { 408 left: root.left 409 right: root.right 410 } 411 y: Math.round(root.height * 2 / 3) 412 413 MouseArea { 414 anchors.fill: parent 415 drag.target: sizeGrip 416 drag.minimumY: 0 417 drag.maximumY: root.height 418 drag.axis: Drag.YAxis 419 } 420 } 421 422 WebEngineView { 423 id: inspector 424 visible: false 425 anchors { 426 left: root.left 427 right: root.right 428 top: sizeGrip.bottom 429 bottom: root.bottom 430 } 431 432 } 433 434 states: [ 435 State { 436 name: "inspectorShown" 437 PropertyChanges { 438 target: inspector 439 } 440 } 441 ] 442 } 443 }