1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "wrtbrowsercontainer.h" |
|
19 #include "HistoryFlowView.h" |
|
20 |
|
21 #include "WindowFlowView.h" |
|
22 #include "webpagecontroller.h" |
|
23 #include "actionjsobject.h" |
|
24 #include "bedrockprovisioning.h" |
|
25 #include "chromejsobject.h" |
|
26 #include "chromesnippet.h" |
|
27 #include "chromeview.h" |
|
28 #include "chromewidget.h" |
|
29 #include "controllableview.h" |
|
30 #include "BookmarksManager.h" |
|
31 #include "utilities.h" |
|
32 #include "viewcontroller.h" |
|
33 #include "webcontentview.h" |
|
34 #include "webnavigation.h" |
|
35 #include "viewstack.h" |
|
36 #include "ZoomMetaData.h" |
|
37 #include "LocaleDelegate.h" |
|
38 #include "devicedelegate.h" |
|
39 #include <assert.h> |
|
40 |
|
41 #include <QtGui> |
|
42 #include "qwebview.h" |
|
43 #include "qwebframe.h" |
|
44 #include "qwebhistory.h" |
|
45 |
|
46 #include <QProcessEnvironment> |
|
47 |
|
48 #ifdef USE_DOWNLOAD_MANAGER |
|
49 #include <QNetworkAccessManager> |
|
50 #include <QNetworkProxy> |
|
51 #include "downloadcontroller.h" |
|
52 #endif |
|
53 |
|
54 #ifdef USE_STATEMACHINE |
|
55 Q_SCRIPT_DECLARE_QMETAOBJECT(ChromeView, QWidget *) |
|
56 #endif |
|
57 |
|
58 static QBrush s_backgroundBrush(QColor(0,0,0)); |
|
59 |
|
60 ChromeView::ChromeView(QWidget * parent = 0) |
|
61 : QGraphicsView(parent) |
|
62 { |
|
63 init(ChromeView::getChromePath()); |
|
64 } |
|
65 |
|
66 ChromeView::ChromeView(const QString chromeUrl, QWidget * parent = 0) |
|
67 : QGraphicsView(parent) |
|
68 { |
|
69 init(chromeUrl); |
|
70 } |
|
71 |
|
72 void ChromeView::init(const QString chromeUrl) |
|
73 { |
|
74 m_graphicsScene = new QGraphicsScene; // probably should be created by owner... |
|
75 m_chromeWidget = 0; |
|
76 m_viewController = 0; |
|
77 m_js = 0; |
|
78 m_mainWidget = 0; |
|
79 m_displayMode = DisplayModePortrait; |
|
80 m_chromeUrl = chromeUrl; |
|
81 m_splashScreen = 0; |
|
82 m_navigation = 0; |
|
83 m_downloadController = 0; |
|
84 |
|
85 qDebug() << "ChromeView::ChromeView: " << chromeUrl; |
|
86 setBackgroundBrush(s_backgroundBrush); |
|
87 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
88 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
89 |
|
90 setScene(m_graphicsScene); |
|
91 |
|
92 showSplashScreen(); |
|
93 |
|
94 m_mainWidget = new QGraphicsWidget(); |
|
95 m_graphicsScene->addItem(m_mainWidget); |
|
96 |
|
97 setViewportUpdateMode(QGraphicsView::FullViewportUpdate); |
|
98 |
|
99 // Create the "chrome" javascript object. |
|
100 m_js = new ChromeJSObject(this); |
|
101 |
|
102 // Create the chrome overlay. |
|
103 m_chromeWidget = new ChromeWidget(this, m_mainWidget, "snippets"); |
|
104 QTimer::singleShot(0, this, SLOT(connectAll())); |
|
105 m_localeDelegate = new LocaleDelegate(this); |
|
106 m_deviceDelegate = new DeviceDelegate(); |
|
107 |
|
108 ActionJSObject::initClass(); |
|
109 |
|
110 initViewController(); |
|
111 |
|
112 setObjectName("ChromeView"); |
|
113 setStyleSheet("QGraphicsView#ChromeView {margin:0; border: 0; padding:0;}"); |
|
114 |
|
115 safe_connect(m_chromeWidget, SIGNAL(delegateLink(const QUrl&)), WebPageController::getSingleton(), SLOT(currentLoad(const QUrl&))); |
|
116 safe_connect(WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer*)), this, SLOT(pageCreated(WRT::WrtBrowserContainer*))); |
|
117 safe_connect(WebPageController::getSingleton(), SIGNAL(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)), this, SLOT(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*))); |
|
118 } |
|
119 |
|
120 void ChromeView::initViewController() { |
|
121 // Create content view manager/factory. |
|
122 m_viewController = new ViewController(0, m_graphicsScene); |
|
123 ViewStack::getSingleton()->setViewController(m_viewController); |
|
124 ViewStack::getSingleton()->setChromeView(this); |
|
125 |
|
126 safe_connect(m_viewController, SIGNAL(currentViewChanging()), this, SLOT(contentViewChanging())); |
|
127 safe_connect(m_viewController, SIGNAL(currentViewChanged()), this, SLOT(setContentView())); |
|
128 |
|
129 // Setup view class factory. |
|
130 m_viewController->subscribe(WebContentView::Type(), WebContentView::createNew); |
|
131 m_viewController->subscribe(WRT::WindowFlowView::Type(), WRT::WindowFlowView::createNew); |
|
132 m_viewController->subscribe(WRT::HistoryFlowView::Type(), WRT::HistoryFlowView::createNew); |
|
133 |
|
134 |
|
135 // Create window view |
|
136 m_viewController->createView(WRT::WindowFlowView::Type()); |
|
137 |
|
138 /* |
|
139 // Create the goAnywhereview view. |
|
140 WRT::GoAnywhereView *goAnywhereView = |
|
141 static_cast<WRT::GoAnywhereView *>(m_viewController->createView(WRT::GoAnywhereView::Type())); |
|
142 */ |
|
143 // Create the history view. |
|
144 WRT::HistoryFlowView *historyView = |
|
145 static_cast<WRT::HistoryFlowView *>(m_viewController->createView(WRT::HistoryFlowView::Type())); |
|
146 |
|
147 |
|
148 historyView->setChromeFrame(m_chromeWidget->chromePage()->mainFrame()); |
|
149 // Create the web view. |
|
150 WebContentView *webContentView = |
|
151 static_cast<WebContentView *>(m_viewController->createView(WebContentView::Type())); |
|
152 webContentView->hide(); |
|
153 |
|
154 m_viewController->setCurrent(webContentView); |
|
155 WRT::WrtBrowserContainer* pg = WebPageController::getSingleton()->currentPage(); |
|
156 pg->setWebWidget(webContentView->widget()); |
|
157 m_navigation = new WebNavigation(pg,webContentView->widget()); |
|
158 |
|
159 #ifdef USE_DOWNLOAD_MANAGER |
|
160 QWebPage * wrtPage = webContentView->wrtPage(); |
|
161 QNetworkAccessManager * accessManager = wrtPage->networkAccessManager(); |
|
162 QNetworkProxy proxy = accessManager->proxy(); |
|
163 |
|
164 m_downloadController = new DownloadController("Bedrock Browser", proxy); |
|
165 if (!m_downloadController->handlePage(wrtPage)) { |
|
166 qDebug() << "DownloadController::handlePage failed for" << wrtPage; |
|
167 } |
|
168 |
|
169 connect(m_downloadController, SIGNAL(downloadCreated(Download*)), |
|
170 m_js, SLOT(downloadCreated(Download*))); |
|
171 |
|
172 connect(m_downloadController, SIGNAL(downloadStarted(Download*)), |
|
173 m_js, SLOT(downloadStarted(Download*))); |
|
174 |
|
175 connect(m_downloadController, SIGNAL(downloadProgress(Download*)), |
|
176 m_js, SLOT(downloadProgress(Download*))); |
|
177 |
|
178 connect(m_downloadController, SIGNAL(downloadFinished(Download*)), |
|
179 m_js, SLOT(downloadFinished(Download*))); |
|
180 |
|
181 connect(m_downloadController, SIGNAL(downloadPaused(Download*, const QString &)), |
|
182 m_js, SLOT(downloadPaused(Download*, const QString &))); |
|
183 |
|
184 connect(m_downloadController, SIGNAL(downloadCancelled(Download*, const QString &)), |
|
185 m_js, SLOT(downloadCancelled(Download*, const QString &))); |
|
186 |
|
187 connect(m_downloadController, SIGNAL(downloadFailed(Download*, const QString &)), |
|
188 m_js, SLOT(downloadFailed(Download*, const QString &))); |
|
189 |
|
190 connect(m_downloadController, SIGNAL(downloadNetworkLoss(Download*, const QString &)), |
|
191 m_js, SLOT(downloadNetworkLoss(Download*, const QString &))); |
|
192 |
|
193 connect(m_downloadController, SIGNAL(downloadError(Download*, const QString &)), |
|
194 m_js, SLOT(downloadError(Download*, const QString &))); |
|
195 #endif |
|
196 } |
|
197 |
|
198 |
|
199 bool ChromeView::viewportEvent(QEvent* event) |
|
200 { |
|
201 return QGraphicsView::viewportEvent(event); |
|
202 } |
|
203 |
|
204 void ChromeView::contentViewChanging(){ |
|
205 //Remove the current content view |
|
206 if(m_viewController && m_viewController->currentView()) { |
|
207 m_viewController->currentView()->widget()->disconnect(this); |
|
208 } |
|
209 } |
|
210 |
|
211 void ChromeView::saveToHistory(bool ok) |
|
212 { |
|
213 if(ok){ |
|
214 WRT::WrtBrowserContainer * currPage = WebPageController::getSingleton()->currentPage(); |
|
215 Q_ASSERT(currPage); |
|
216 Q_ASSERT(!currPage->mainFrame()->url().isEmpty()); |
|
217 //WRT::BookmarksManager::getSingleton()->addHistory(currPage->mainFrame()->url(), |
|
218 // currPage->mainFrame()->title(), |
|
219 // currPage->mainFrame()->icon()); |
|
220 |
|
221 } |
|
222 } |
|
223 |
|
224 |
|
225 void ChromeView::loadContentView() |
|
226 { |
|
227 if(m_viewController) m_viewController->showContent("webView"); |
|
228 //toggleVisibility("UrlSearchChromeId"); |
|
229 //toggleVisibility("HistoryViewToolbarId"); |
|
230 //toggleVisibility("WebViewToolbarId"); |
|
231 } |
|
232 |
|
233 void ChromeView::loadUrltoCurrentPage(const QUrl & url) |
|
234 { |
|
235 WRT::WrtBrowserContainer * activePage = WebPageController::getSingleton()->currentPage(); |
|
236 |
|
237 if(activePage) { |
|
238 activePage->mainFrame()->load(url); |
|
239 } |
|
240 } |
|
241 |
|
242 void ChromeView::setContentView(){ |
|
243 connectContentView(); |
|
244 } |
|
245 |
|
246 void ChromeView::connectContentView(){ |
|
247 ControllableView *view = m_viewController ? m_viewController->currentView() : 0; |
|
248 if(!view) return; |
|
249 |
|
250 QGraphicsWidget *contentWidget = view->widget(); |
|
251 assert(contentWidget); |
|
252 |
|
253 contentWidget->setGeometry(geometry()); |
|
254 |
|
255 safe_connect(m_chromeWidget, SIGNAL(dragStarted()), m_viewController, SLOT(freezeView())); |
|
256 safe_connect(m_chromeWidget, SIGNAL(dragFinished()), m_viewController, SLOT(unfreezeView())); |
|
257 |
|
258 contentWidget->setFocus(); |
|
259 updateGeometry(); |
|
260 parentWidget()->updateGeometry(); |
|
261 } |
|
262 |
|
263 void ChromeView::connectAll(){ |
|
264 //Connect content signals |
|
265 connectContentView(); |
|
266 //NB: Revisit this to avoid signal spaghetti |
|
267 //When the chrome widget finishes loading and initialization of snippets, JS emits loadComplete |
|
268 safe_connect(m_chromeWidget, SIGNAL(loadComplete()), m_js, SIGNAL(loadComplete())); |
|
269 safe_connect(m_chromeWidget, SIGNAL(loadComplete()), this, SLOT(chromeLoaded())); |
|
270 //When the widget resizes the view port, invoke update of the current view geometry. NB: this signal could also be handled by |
|
271 //the viewstack directly which would, for example, allow it to resize all views, not just the current view. |
|
272 safe_connect(m_chromeWidget, SIGNAL(viewPortResize(QRect)), this, SLOT(updateContentGeometry(QRect))); |
|
273 //Also, JS emits its version of this signal |
|
274 safe_connect(this, SIGNAL(viewPortResize(int, int, int, int)), m_js, SIGNAL(viewPortResize(int, int, int, int))); |
|
275 //Create the JS API |
|
276 safe_connect(m_chromeWidget->chromePage()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(injectJSObjects())); |
|
277 |
|
278 safe_connect(WebPageController::getSingleton(), SIGNAL(loadFinished(bool)), this, |
|
279 SLOT(saveToHistory(bool))); |
|
280 |
|
281 //Load the chrome contents from the default location |
|
282 reloadChrome(); |
|
283 } |
|
284 |
|
285 ChromeView::~ChromeView() |
|
286 { |
|
287 delete m_navigation; |
|
288 delete m_chromeWidget; |
|
289 delete m_js; |
|
290 if(m_splashScreen) delete m_splashScreen; |
|
291 |
|
292 //Deleting the scene will delete m_mainWidget. |
|
293 //Deleting m_mainWidget will also delete any graphics items that the chromeWidget has |
|
294 //added to the m_mainWidget. |
|
295 |
|
296 //Content views are not owned by the chrome view; this allows the application to manage |
|
297 //its content windows independently of the chrome. |
|
298 |
|
299 if(m_viewController) { |
|
300 delete m_viewController; |
|
301 ViewStack::getSingleton()->setViewController(NULL); |
|
302 } |
|
303 delete m_graphicsScene; |
|
304 |
|
305 #ifdef USE_DOWNLOAD_MANAGER |
|
306 if (m_downloadController) { |
|
307 delete m_downloadController; |
|
308 } |
|
309 #endif |
|
310 |
|
311 delete m_localeDelegate; |
|
312 delete m_deviceDelegate; |
|
313 } |
|
314 |
|
315 ChromeWidget * ChromeView::getChromeWidget(){ |
|
316 return m_chromeWidget; |
|
317 } |
|
318 |
|
319 void ChromeView::updateViewPort(){ |
|
320 assert (m_chromeWidget); |
|
321 m_chromeWidget->updateViewPort(); |
|
322 } |
|
323 |
|
324 void ChromeView::setViewPort(QRect viewPort){ |
|
325 assert (m_chromeWidget); |
|
326 m_chromeWidget->setViewPort(viewPort); |
|
327 } |
|
328 |
|
329 void ChromeView::loadChrome(const QString &url){ |
|
330 qDebug() << "ChromeView::loadChrome: " << url; |
|
331 m_chromeUrl = url; |
|
332 if(m_chromeWidget) { |
|
333 m_chromeWidget->setChromeUrl(url); |
|
334 } |
|
335 } |
|
336 |
|
337 void ChromeView::reloadChrome(){ |
|
338 loadChrome(m_chromeUrl); |
|
339 } |
|
340 |
|
341 void ChromeView::show(const QString& id, int x, int y){ |
|
342 assert(m_chromeWidget); |
|
343 m_chromeWidget->show(id, x, y); |
|
344 } |
|
345 |
|
346 void ChromeView::show(const QString& id){ |
|
347 assert(m_chromeWidget); |
|
348 m_chromeWidget->show(id); |
|
349 } |
|
350 |
|
351 |
|
352 void ChromeView::hide(const QString& id){ |
|
353 assert(m_chromeWidget); |
|
354 m_chromeWidget->hide(id); |
|
355 } |
|
356 |
|
357 |
|
358 void ChromeView::toggleVisibility(const QString& id){ |
|
359 assert(m_chromeWidget); |
|
360 m_chromeWidget->toggleVisibility(id); |
|
361 } |
|
362 |
|
363 void ChromeView::setLocation(const QString& id, int x, int y){ |
|
364 assert(m_chromeWidget); |
|
365 m_chromeWidget->setLocation(id, x, y); |
|
366 } |
|
367 |
|
368 void ChromeView::setAnchor(const QString& id, const QString& anchor){ |
|
369 assert(m_chromeWidget); |
|
370 m_chromeWidget->setAnchor(id, anchor); |
|
371 } |
|
372 |
|
373 void ChromeView::toggleAttention(const QString& id){ |
|
374 assert(m_chromeWidget); |
|
375 m_chromeWidget->toggleAttention(id); |
|
376 } |
|
377 |
|
378 void ChromeView::setVisibilityAnimator(const QString& elementId, const QString & animatorName){ |
|
379 assert(m_chromeWidget); |
|
380 m_chromeWidget->setVisibilityAnimator(elementId, animatorName); |
|
381 } |
|
382 |
|
383 void ChromeView::setAttentionAnimator(const QString& elementId, const QString & animatorName){ |
|
384 assert(m_chromeWidget); |
|
385 m_chromeWidget->setAttentionAnimator(elementId, animatorName); |
|
386 } |
|
387 |
|
388 //Animated "flips" between the current view an a chrome snippet |
|
389 // TO DO: needs updating or removal. |
|
390 void ChromeView::flipFromCurrentView(const QString& toId){ |
|
391 assert(m_chromeWidget); |
|
392 |
|
393 // TBD |
|
394 |
|
395 ChromeSnippet *snippet = m_chromeWidget->getSnippet(toId); |
|
396 if(snippet) |
|
397 snippet->show(true); |
|
398 } |
|
399 |
|
400 void ChromeView::flipToCurrentView(const QString& fromId){ |
|
401 Q_UNUSED(fromId) |
|
402 |
|
403 // TBD |
|
404 |
|
405 if(m_viewController && m_viewController->currentView()) |
|
406 m_viewController->currentView()->show(); |
|
407 } |
|
408 |
|
409 ControllableView *ChromeView::currentContentView() { |
|
410 return m_viewController ? m_viewController->currentView() : 0; |
|
411 } |
|
412 |
|
413 ControllableView *ChromeView::contentView(const QString & type) { |
|
414 return m_viewController ? m_viewController->getView(type) : 0; |
|
415 } |
|
416 |
|
417 void ChromeView::loadStarted(){ // slot |
|
418 //qDebug() << "ChromeView::loadStarted: "; |
|
419 //m_viewController->currentView()->setCursor(Qt::BusyCursor); |
|
420 } |
|
421 |
|
422 void ChromeView::loadFinished(bool ok){ // slot |
|
423 Q_UNUSED(ok) |
|
424 //qDebug() << "ChromeView::loadFinished: " << m_viewController->currentView()->url(); |
|
425 //m_viewController->currentView()->setCursor(Qt::ArrowCursor); |
|
426 } |
|
427 |
|
428 void ChromeView::updateSceneSize(const QSize &size) { |
|
429 QRectF sceneRect = m_graphicsScene->sceneRect(); |
|
430 qDebug() << "ChromeView::updateSceneSize: sceneRect=" << sceneRect << " new size=" << size; |
|
431 m_graphicsScene->setSceneRect(sceneRect.x(), sceneRect.y(), size.width(), size.height()); |
|
432 } |
|
433 |
|
434 void ChromeView::resizeEvent(QResizeEvent *e){ |
|
435 qDebug() << "ChromeView::resizeEvent: " << e->size(); |
|
436 QRect rect(QPoint(0,0), e->size()); |
|
437 |
|
438 displayModeChangeStart(); |
|
439 |
|
440 updateChildGeometries(rect); |
|
441 updateDisplayMode(); |
|
442 updateSceneSize(rect.size()); |
|
443 |
|
444 if(m_splashScreen) { |
|
445 m_splashScreen->setGeometry(rect); |
|
446 } |
|
447 } |
|
448 |
|
449 void ChromeView::resizeScrollArea(QResizeEvent *e){ |
|
450 qDebug() << "ChromeView::resizeScrollArea: " << e; |
|
451 QRect rect(QPoint(0,0), e->size()); |
|
452 |
|
453 updateChildGeometries(rect); |
|
454 updateDisplayMode(); |
|
455 |
|
456 QGraphicsView::setGeometry(rect); |
|
457 updateSceneSize(rect.size()); |
|
458 } |
|
459 |
|
460 void ChromeView::updateDisplayMode() { |
|
461 if(width() > height()) |
|
462 setDisplayMode(DisplayModeLandscape); |
|
463 else |
|
464 setDisplayMode(DisplayModePortrait); |
|
465 } |
|
466 |
|
467 void ChromeView::setDisplayMode(DisplayMode mode) { |
|
468 qDebug() << "ChromeView::setDisplayMode: " << mode; |
|
469 if(mode != m_displayMode){ |
|
470 m_displayMode = mode; |
|
471 m_js->displayModeChanged(m_displayMode); |
|
472 QString newMode = ( (mode == DisplayModeLandscape) ? "Landscape" : "Portrait" ); |
|
473 m_viewController->currentView()->displayModeChanged(newMode); |
|
474 } |
|
475 } |
|
476 |
|
477 void ChromeView::displayModeChangeStart() { |
|
478 DisplayMode mode = DisplayModePortrait; |
|
479 |
|
480 if(width() > height()) |
|
481 { |
|
482 mode = DisplayModeLandscape; |
|
483 } |
|
484 if (mode != m_displayMode) { |
|
485 m_js->displayModeChangeStart(mode); |
|
486 } |
|
487 } |
|
488 |
|
489 void ChromeView::updateChildGeometries(const QRect &rect){ |
|
490 m_mainWidget->setGeometry(rect); |
|
491 updateContentGeometry(rect); |
|
492 if(m_chromeWidget) |
|
493 m_chromeWidget->setGeometry(rect); |
|
494 } |
|
495 |
|
496 void ChromeView::updateContentGeometry(const QRect &rect) { |
|
497 if(m_viewController && m_viewController->currentView()) |
|
498 m_viewController->currentView()->widget()->setGeometry(rect); |
|
499 emit viewPortResize(rect.x(), rect.y(), rect.width(), rect.height()); |
|
500 } |
|
501 |
|
502 |
|
503 QRect ChromeView::contentViewGeometry() const { |
|
504 if(m_viewController && m_viewController->currentView()) |
|
505 return m_viewController->currentView()->widget()->geometry().toRect(); |
|
506 return QRect(); |
|
507 } |
|
508 |
|
509 void ChromeView::setBackgroundColor(const QColor &color){ |
|
510 s_backgroundBrush.setColor(color); |
|
511 } |
|
512 |
|
513 void ChromeView::injectJSObjects() { // slot |
|
514 //qDebug() << "ChromeView::injectJSObjects"; |
|
515 injectJSObject(m_chromeWidget->jsObject()); |
|
516 injectJSObject(m_js); |
|
517 injectJSObject(m_viewController); |
|
518 injectJSObject(WebPageController::getSingleton()); |
|
519 injectJSObject(WRT::BookmarksManager::getSingleton()); |
|
520 injectJSObject(ViewStack::getSingleton()); |
|
521 injectJSObject(m_localeDelegate); |
|
522 injectJSObject(m_deviceDelegate); |
|
523 if(m_viewController) |
|
524 m_viewController->setChromeFrame(m_chromeWidget->chromePage()->mainFrame()); |
|
525 } |
|
526 |
|
527 void ChromeView::injectJSObject(QObject *object) { |
|
528 if(object) { |
|
529 m_chromeWidget->chromePage()->mainFrame()->addToJavaScriptWindowObject(object->objectName(), object); |
|
530 } |
|
531 } |
|
532 |
|
533 void ChromeView::chromeLoaded() { // slot |
|
534 if(m_splashScreen) { |
|
535 // Remove splashscreen now that the chrome is ready. |
|
536 delete m_splashScreen; |
|
537 m_splashScreen = 0; |
|
538 } |
|
539 |
|
540 // foreach(QGraphicsItem *child, m_mainWidget->childItems()){ |
|
541 // qDebug() << " m_mainWidget child: " << child ; |
|
542 // } |
|
543 // |
|
544 // foreach(QObject *objChild, children()){ |
|
545 // qDebug() << " ChromeView child: " << objChild; |
|
546 // } |
|
547 // |
|
548 // foreach(QGraphicsItem *item, m_graphicsScene->items()){ |
|
549 // qDebug() << " graphics items: " << item; |
|
550 // } |
|
551 } |
|
552 |
|
553 void ChromeView::pageCreated(WRT::WrtBrowserContainer* newPage) { |
|
554 |
|
555 /* save the page snapshot before changing the current page to the new page*/ |
|
556 WRT::WrtBrowserContainer * currPage = WebPageController::getSingleton()->currentPage(); |
|
557 QWebHistoryItem item = currPage->history()->currentItem(); |
|
558 currPage->savePageDataToHistoryItem(currPage->mainFrame(), &item); |
|
559 |
|
560 WebContentView * cv ; |
|
561 if(m_viewController) { |
|
562 cv = static_cast<WebContentView *>(m_viewController->getView("webView")); |
|
563 } |
|
564 if(cv) { |
|
565 // When new windows are created from window view, as the content is emoty, we should disable |
|
566 // zoom actions. Set the user-scalable to false and also init the other zoom params |
|
567 // so that even if we change to windows view again without loading a page we are safe. |
|
568 // In the code-driven window usecase, this will be overwritten when the page is loaded and setViewportSize is invoked |
|
569 newPage->setPageZoomMetaData(cv->webView()->defaultZoomData()); |
|
570 |
|
571 |
|
572 /* Set the new page as the current page */ |
|
573 WebPageController::getSingleton()->setCurrentPage(newPage); |
|
574 |
|
575 /* Set the web widget- this one is responsible for webnavigation etc */ |
|
576 newPage->setWebWidget( cv->webView()); |
|
577 |
|
578 //connect current page main frame's initialLayoutCompleted with WebContentWidget' setViewportSize SLOT |
|
579 connect(WebPageController::getSingleton()->currentPage()->mainFrame(), SIGNAL(initialLayoutCompleted()), cv->webView(), SLOT(setViewportSize())); |
|
580 |
|
581 #ifdef USE_DOWNLOAD_MANAGER |
|
582 if (!m_downloadController->handlePage(newPage)) { |
|
583 qDebug() << "DownloadController::handlePage failed for" << newPage; |
|
584 } |
|
585 #endif |
|
586 } |
|
587 |
|
588 } |
|
589 |
|
590 void ChromeView::updateWebPage(WRT::WrtBrowserContainer* pg) |
|
591 { |
|
592 if(!m_viewController) return; |
|
593 |
|
594 WebContentView* cv = static_cast<WebContentView *>(m_viewController->getView("webView")); |
|
595 WebContentWidget* w = cv->webView(); |
|
596 w->setPage(pg); |
|
597 if(pg) |
|
598 { |
|
599 // Disconnect this signal to avoid multiple connections - it is being connected in setWebWidget |
|
600 disconnect(w, SIGNAL(pageZoomMetaDataChange(QWebFrame*, ZoomMetaData)), pg, SLOT(pageZoomMetaDataChange(QWebFrame*, ZoomMetaData))); |
|
601 |
|
602 pg->setWebWidget(w); |
|
603 |
|
604 // Change navigation also to the current page |
|
605 m_navigation->setPage(pg); |
|
606 |
|
607 } |
|
608 } |
|
609 |
|
610 void ChromeView::pageChanged(WRT::WrtBrowserContainer* oldPage, WRT::WrtBrowserContainer* newPage) { |
|
611 |
|
612 Q_UNUSED(oldPage) |
|
613 updateWebPage(newPage); |
|
614 |
|
615 // Set new page zoom info |
|
616 changeContentViewZoomInfo(newPage); |
|
617 } |
|
618 |
|
619 |
|
620 void ChromeView::changeContentViewZoomInfo(WRT::WrtBrowserContainer* newPage){ |
|
621 |
|
622 if(m_viewController) { |
|
623 WebContentView * cv = static_cast<WebContentView *>(m_viewController->getView("webView")); |
|
624 |
|
625 // Copy the new page zoom info into cv |
|
626 cv->webView()->setPageZoomMetaData(newPage->pageZoomMetaData()); |
|
627 |
|
628 if (cv->webView()->isUserScalable()) { |
|
629 cv->webView()->setZoomFactor(newPage->mainFrame()->zoomFactor()); |
|
630 } |
|
631 else { |
|
632 // Need to call setPageZoomFactor instead of setZoomFactor because setZoomFactor |
|
633 // will not do anything is user-scalable is false. But we need to |
|
634 // ensure that the correct zoom factor is applied as there is a possibility |
|
635 // that we might have been on another page earlier |
|
636 cv->webView()->setPageZoomFactor(newPage->mainFrame()->zoomFactor()); |
|
637 |
|
638 } |
|
639 } |
|
640 } |
|
641 |
|
642 // TODO: INVESTIGATE: Is this needed anymore since we handle pageChanged now |
|
643 void ChromeView::setViewofCurrentPage() { |
|
644 updateWebPage(WebPageController::getSingleton()->currentPage()); |
|
645 } |
|
646 |
|
647 |
|
648 QString ChromeView::getChromeBaseDir() { |
|
649 QString chromeBaseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory"); |
|
650 return chromeBaseDir; |
|
651 } |
|
652 |
|
653 QString ChromeView::getChromePath() { |
|
654 |
|
655 QString chromeFile = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartUpChrome"); |
|
656 QString baseDir = getChromeBaseDir(); |
|
657 QString chromePath = baseDir + chromeFile; |
|
658 qDebug() << chromePath; |
|
659 return chromePath; |
|
660 } |
|
661 |
|
662 void ChromeView::showSplashScreen() { |
|
663 |
|
664 QString splashImage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("SplashImage"); |
|
665 QString baseDir = getChromeBaseDir(); |
|
666 QString imagePath = baseDir + splashImage; |
|
667 |
|
668 if(!imagePath.isNull()) { |
|
669 m_splashScreen = new QLabel(parentWidget()); |
|
670 m_splashScreen->setStyleSheet("background-color: #000"); |
|
671 m_splashScreen->setPixmap(QPixmap(imagePath)); |
|
672 if(m_splashScreen->pixmap()->isNull()) { |
|
673 qDebug() << "ChromeView::chromeLoaded: ERROR splashscreen creation failed. " << imagePath; |
|
674 } |
|
675 else { |
|
676 m_splashScreen->show(); |
|
677 } |
|
678 } |
|
679 } |
|