44 |
48 |
45 // ---------------------------------------------------------- |
49 // ---------------------------------------------------------- |
46 |
50 |
47 const qreal KZoomInStep = 1.05; |
51 const qreal KZoomInStep = 1.05; |
48 const qreal KZoomOutStep = 0.95238; |
52 const qreal KZoomOutStep = 0.95238; |
49 |
53 |
50 GWebContentView::GWebContentView(ChromeWidget *chrome, QObject * parent, const QString &objectName) |
54 GWebContentView::GWebContentView(ChromeWidget *chrome, QObject * parent, const QString &objectName) |
51 : ControllableViewBase(parent), |
55 : ControllableViewBase(parent), |
52 m_networkMgr(0), |
56 m_networkMgr(0), |
53 m_chrome(chrome), |
57 m_chrome(chrome), |
54 m_timeLine(0), |
58 m_timeLine(0), |
55 m_zoomIn(false), |
59 m_zoomIn(false), |
56 m_backEnabled(false), |
60 m_backEnabled(false), |
57 m_forwardEnabled(false), |
61 m_forwardEnabled(false), |
|
62 m_sharedPage(0), |
58 m_currentSuperPage(m_superPages.begin()), |
63 m_currentSuperPage(m_superPages.begin()), |
59 m_currentPageIsSuperPage(false), |
64 m_currentPageIsSuperPage(false), |
60 m_timer(NULL) |
65 m_timer(NULL), |
|
66 m_enabled(true) |
61 { |
67 { |
62 setObjectName(objectName); |
68 setObjectName(objectName); |
63 qDebug() << "GWebContentView::GWebContentView: this=" << this; |
69 qDebug() << "GWebContentView::GWebContentView: this=" << this; |
64 QWebPage* page = BrowserPageFactory::openBrowserPage(); |
70 WRT::WrtBrowserContainer* page = BrowserPageFactory::openBrowserPage(); |
65 |
71 |
66 setZoomActions(); |
72 setActions(); |
67 m_widget = new GWebContentViewWidget(parent, this, page); |
73 m_widget = new GWebContentViewWidget(parent, this, page); |
68 #ifndef __gva_no_chrome__ |
74 #ifndef __gva_no_chrome__ |
69 m_jsObject = new GWebContentViewJSObject(this, m_chrome->page()->mainFrame(), objectName); |
75 setJSObject(objectName); |
70 #endif |
76 #endif |
71 m_networkMgr = webWidget()->page()->networkAccessManager(); |
77 m_networkMgr = webWidget()->page()->networkAccessManager(); |
72 |
78 |
73 webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); |
79 webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); |
74 webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); |
80 webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); |
75 |
81 |
76 #ifdef NO_QSTM_GESTURE |
82 #ifdef NO_QSTM_GESTURE |
77 m_touchNavigation = new GWebTouchNavigation(page, m_widget); |
83 m_touchNavigation = new GContentViewTouchNavigation(page, m_widget); |
78 m_touchNavigation->setChromeWidget(m_chrome); |
84 m_touchNavigation->setChromeWidget(m_chrome); |
79 connect(m_touchNavigation, SIGNAL(mouseEvent(QEvent::Type)) , this, SIGNAL(contentViewMouseEvent(QEvent::Type))); |
85 connect(m_touchNavigation, SIGNAL(mouseEvent(QEvent::Type)) , this, SIGNAL(contentViewMouseEvent(QEvent::Type))); |
80 #endif |
86 #endif |
81 WRT::WrtBrowserContainer * wrtPage = static_cast<WRT::WrtBrowserContainer *>(page); |
87 WRT::WrtBrowserContainer * wrtPage = static_cast<WRT::WrtBrowserContainer *>(page); |
82 if(wrtPage) { |
88 if (wrtPage) { |
83 wrtPage->setWebWidget(webWidget()); |
89 wrtPage->setWebWidget(webWidget()); |
84 pageCreated(wrtPage); |
90 pageCreated(wrtPage); |
85 } |
91 } |
86 |
92 |
87 connectAll(); |
93 connectAll(); |
129 |
137 |
130 void GWebContentView::zoomN() |
138 void GWebContentView::zoomN() |
131 { |
139 { |
132 if ((m_value * webWidget()->zoomFactor()) < webWidget()->minimumScale()){ |
140 if ((m_value * webWidget()->zoomFactor()) < webWidget()->minimumScale()){ |
133 if (m_timer && m_timer->isActive()) |
141 if (m_timer && m_timer->isActive()) |
134 bitmapZoomStop(); |
142 bitmapZoomStop(); |
135 }else { |
143 }else { |
136 if (m_timer->isSingleShot()) { |
144 if (m_timer->isSingleShot()) { |
137 m_timer->setSingleShot(false); |
145 m_timer->setSingleShot(false); |
138 m_timer->start(1); |
146 m_timer->start(1); |
139 } |
147 } |
140 webWidget()->setBitmapZoom(m_value * webWidget()->zoomFactor()); |
148 webWidget()->setBitmapZoom(m_value * webWidget()->zoomFactor()); |
141 m_value *= KZoomOutStep; |
149 m_value *= KZoomOutStep; |
142 } |
150 } |
143 } |
151 } |
144 |
152 |
145 void GWebContentView::zoomIn(qreal deltaPercent) |
153 void GWebContentView::zoomIn(qreal deltaPercent) |
146 { |
154 { |
147 Q_UNUSED(deltaPercent) |
155 Q_UNUSED(deltaPercent) |
148 if (webWidget() && webWidget()->isUserScalable()) { |
156 if (webWidget() && webWidget()->isUserScalable()) { |
149 if (m_timer && m_timer->isActive()) { |
157 if (m_timer && m_timer->isActive()) { |
150 if (!m_timer->isSingleShot()) |
158 if (!m_timer->isSingleShot()) |
151 m_value /= KZoomInStep; |
159 m_value /= KZoomInStep; |
152 bitmapZoomStop(); |
160 bitmapZoomStop(); |
153 return; |
161 return; |
154 }else if (!m_timer) |
162 }else if (!m_timer) |
155 m_timer = new QTimer(this); |
163 m_timer = new QTimer(this); |
156 |
164 |
157 m_value = KZoomInStep; |
165 m_value = KZoomInStep; |
158 |
166 |
159 if ((m_value * webWidget()->zoomFactor()) < webWidget()->maximumScale()) { |
167 if ((m_value * webWidget()->zoomFactor()) < webWidget()->maximumScale()) { |
160 webWidget()->createPageSnapShot(); |
168 webWidget()->createPageSnapShot(); |
161 connect(m_timer,SIGNAL(timeout()),this,SLOT(zoomP())); |
169 connect(m_timer,SIGNAL(timeout()),this,SLOT(zoomP())); |
162 zoomP(); |
170 zoomP(); |
163 m_timer->setSingleShot(true); |
171 m_timer->setSingleShot(true); |
205 safe_connect(widget(), SIGNAL(contextEvent(::WebViewEventContext *)), |
213 safe_connect(widget(), SIGNAL(contextEvent(::WebViewEventContext *)), |
206 m_jsObject, SLOT(onContextEvent(::WebViewEventContext *))); |
214 m_jsObject, SLOT(onContextEvent(::WebViewEventContext *))); |
207 QObject::connect(webWidget(), SIGNAL(titleChanged(const QString &)), m_jsObject, SIGNAL(titleChanged(const QString &))); |
215 QObject::connect(webWidget(), SIGNAL(titleChanged(const QString &)), m_jsObject, SIGNAL(titleChanged(const QString &))); |
208 QObject::connect(webWidget(), SIGNAL(loadStarted()), m_jsObject, SIGNAL(loadStarted())); |
216 QObject::connect(webWidget(), SIGNAL(loadStarted()), m_jsObject, SIGNAL(loadStarted())); |
209 QObject::connect(webWidget(), SIGNAL(loadProgress(int)), m_jsObject, SIGNAL(loadProgress(int))); |
217 QObject::connect(webWidget(), SIGNAL(loadProgress(int)), m_jsObject, SIGNAL(loadProgress(int))); |
|
218 QObject::connect(webWidget(), SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int))); |
210 #endif |
219 #endif |
211 QObject::connect(webWidget(), SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
220 QObject::connect(webWidget(), SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
212 QObject::connect(webWidget(), SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
221 QObject::connect(webWidget(), SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
213 QObject::connect(webWidget(), SIGNAL(urlChanged(const QUrl&)), this, SLOT(onUrlChanged(const QUrl&))); |
222 QObject::connect(webWidget(), SIGNAL(urlChanged(const QUrl&)), this, SLOT(onUrlChanged(const QUrl&))); |
214 #ifndef __gva_no_chrome__ |
223 #ifndef __gva_no_chrome__ |
253 |
264 |
254 QWebPage* GWebContentView::wrtPage() { |
265 QWebPage* GWebContentView::wrtPage() { |
255 return m_widget->wrtPage(); |
266 return m_widget->wrtPage(); |
256 } |
267 } |
257 |
268 |
258 void GWebContentView::setZoomActions(){ |
269 void GWebContentView::setActions(){ |
259 |
270 |
260 // Create zoomIn and zoomOut actions */ |
271 QAction* action; |
261 m_actionZoomIn = new QAction("zoomIn", this); |
272 action = m_actions["zoomIn"] = new QAction("zoomIn", this); |
262 m_actionZoomIn->setObjectName("zoomIn"); |
273 action->setObjectName("zoomIn"); |
263 |
274 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn())); |
264 m_actionZoomOut = new QAction("zoomOut", this); |
275 |
265 m_actionZoomOut->setObjectName("zoomOut"); |
276 action = m_actions["zoomOut"] = new QAction("zoomOut", this); |
|
277 action->setObjectName("zoomOut"); |
266 /* Disable zoomOut action initially as we are the the minimum scale */ |
278 /* Disable zoomOut action initially as we are the the minimum scale */ |
267 /* Revisit this to determine whether we can use the change signal to |
279 /* Revisit this to determine whether we can use the change signal to |
268 * set the zoomOut button image initially as well |
280 * set the zoomOut button image initially as well |
269 */ |
281 */ |
270 m_actionZoomOut->setEnabled(false); |
282 action->setEnabled(false); |
271 |
283 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut())); |
272 connect(m_actionZoomIn, SIGNAL(triggered()), this, SLOT(zoomIn())); |
284 |
273 connect(m_actionZoomOut, SIGNAL(triggered()), this, SLOT(zoomOut())); |
285 action = m_actions["zoom"] = new QAction("zoom", this); |
|
286 action->setObjectName("zoom"); |
|
287 |
|
288 |
|
289 action = m_actions["winview"]= new QAction("winview", this); |
|
290 action->setObjectName("winview"); |
|
291 |
|
292 |
|
293 action = m_actions["menu"] = new QAction("menu", this); |
|
294 action->setObjectName("menu"); |
|
295 |
|
296 action = m_actions["mostvisited"] = new QAction("mostvisited", this); |
|
297 action->setObjectName("mostvisited"); |
|
298 |
|
299 action = m_actions["toggletb"] = new QAction("toggletb", this); |
|
300 action->setObjectName("toggletb"); |
|
301 |
274 } |
302 } |
275 |
303 |
276 void GWebContentView::triggerAction(const QString & action) |
304 void GWebContentView::triggerAction(const QString & action) |
277 { |
305 { |
278 qDebug() << "GWebContentView::triggerAction: " << action; |
306 qDebug() << "GWebContentView::triggerAction: " << action; |
279 QWebPage::WebAction webAction; |
307 QWebPage::WebAction webAction; |
280 if(action=="Stop") |
308 if (action=="Stop") |
281 webAction = QWebPage::Stop; |
309 webAction = QWebPage::Stop; |
282 else if (action=="Back") |
310 else if (action=="Back") |
283 webAction = QWebPage::Back; |
311 webAction = QWebPage::Back; |
284 else if(action=="Reload") |
312 else if (action=="Reload") |
285 webAction = QWebPage::Reload; |
313 webAction = QWebPage::Reload; |
286 else if (action=="Forward") |
314 else if (action=="Forward") |
287 webAction = QWebPage::Forward; |
315 webAction = QWebPage::Forward; |
288 else |
316 else |
289 return; |
317 return; |
290 webWidget()->triggerPageAction(webAction); |
318 webWidget()->triggerPageAction(webAction); |
291 } |
319 } |
292 |
320 |
293 void GWebContentView::deactivateZoomActions() |
321 void GWebContentView::deactivateZoomActions() |
294 { |
322 { |
295 m_actionZoomOut->setEnabled(false); |
323 m_actions.value("zoomIn")->setEnabled(false); |
296 m_actionZoomIn->setEnabled(false); |
324 m_actions.value("zoomOut")->setEnabled(false); |
297 } |
325 } |
298 |
326 |
299 void GWebContentView::changeZoomAction(qreal zoom){ |
327 void GWebContentView::changeZoomAction(qreal zoom){ |
300 if(!webWidget()) return; |
328 if (!webWidget()) return; |
301 if(!(webWidget()->isUserScalable() ) ){ |
329 if (!(webWidget()->isUserScalable() ) ){ |
302 deactivateZoomActions(); |
330 deactivateZoomActions(); |
303 } |
331 } |
304 else { |
332 else { |
|
333 QAction * zoomOutAction = m_actions.value("zoomOut"); |
|
334 QAction * zoomInAction = m_actions.value("zoomIn"); |
305 if (zoom <= webWidget()->minimumScale() ) { |
335 if (zoom <= webWidget()->minimumScale() ) { |
306 m_actionZoomOut->setEnabled(false); |
336 zoomOutAction->setEnabled(false); |
307 } |
337 } |
308 else { |
338 else { |
309 m_actionZoomOut->setEnabled(true); |
339 zoomOutAction->setEnabled(true); |
310 } |
340 } |
311 |
341 |
312 if (zoom >= webWidget()->maximumScale() ){ |
342 if (zoom >= webWidget()->maximumScale() ){ |
313 m_actionZoomIn->setEnabled(false); |
343 zoomInAction->setEnabled(false); |
314 } |
344 } |
315 else { |
345 else { |
316 m_actionZoomIn->setEnabled(true); |
346 zoomInAction->setEnabled(true); |
317 } |
347 } |
318 } |
348 } |
319 } |
349 } |
320 |
350 |
321 void GWebContentView::setZoomFactor(qreal factor){ |
351 void GWebContentView::setZoomFactor(qreal factor){ |
322 if(webWidget()) |
352 if (webWidget()) |
323 webWidget()->setZoomFactor(factor); |
353 webWidget()->setZoomFactor(factor); |
324 } |
354 } |
325 |
355 |
326 qreal GWebContentView::getZoomFactor() const { |
356 qreal GWebContentView::getZoomFactor() const { |
327 return webWidgetConst() ? webWidgetConst()->zoomFactor() : 0.0; |
357 return webWidgetConst() ? webWidgetConst()->zoomFactor() : 0.0; |
353 { |
383 { |
354 // Get some of the actions from the page (there are many more available) and build a list |
384 // Get some of the actions from the page (there are many more available) and build a list |
355 // list of them. |
385 // list of them. |
356 |
386 |
357 QList<QAction*> actions; |
387 QList<QAction*> actions; |
|
388 QAction * action = m_actions.value("zoomIn"); |
|
389 |
358 |
390 |
359 /* Add zoomIn and zoomOut actions created earlier*/ |
391 /* Add zoomIn and zoomOut actions created earlier*/ |
360 if(m_actionZoomIn) actions.append(m_actionZoomIn); |
392 if (action) actions.append(action); |
361 if(m_actionZoomOut) actions.append(m_actionZoomOut); |
393 |
|
394 action = m_actions.value("zoomOut"); |
|
395 if (action) actions.append(action); |
362 |
396 |
363 return actions; |
397 return actions; |
364 } |
398 } |
365 |
399 |
366 |
400 |
367 QAction * GWebContentView::getAction(const QString & action) |
401 QAction * GWebContentView::getAction(const QString & action) |
368 { |
402 { |
369 if(action == "zoomIn") |
403 QAction * act = NULL; |
370 return m_actionZoomIn; |
404 if (m_actions.contains(action) ) |
371 if(action == "zoomOut") |
405 act = m_actions.value(action); |
372 return m_actionZoomOut; |
406 |
373 QWebPage::WebAction webAction; |
407 if (!act ) { |
374 if(action == "Back") |
408 WebPageController * pageController = WebPageController::getSingleton(); |
375 webAction = QWebPage::Back; |
409 if (action == "Back") |
376 else if(action == "Forward") |
410 act = pageController->getActionBack(); |
377 webAction = QWebPage::Forward; |
411 else if (action == "Forward") |
378 else if(action == "Stop") |
412 act = pageController->getActionForward(); |
379 webAction = QWebPage::Stop; |
413 else if (action == "Stop") |
380 else if(action == "Reload") |
414 act = pageController->getActionStop(); |
381 webAction = QWebPage::Reload; |
415 else if (action == "Reload") |
382 else return 0; |
416 act = pageController->getActionReload(); |
383 return webWidget()->pageAction(webAction); |
417 |
|
418 } |
|
419 return act; |
384 } |
420 } |
385 |
421 |
386 void GWebContentView::scrollViewBy(int dx, int dy) |
422 void GWebContentView::scrollViewBy(int dx, int dy) |
387 { |
423 { |
388 wrtPage()->mainFrame()->scroll(dx, dy); |
424 wrtPage()->mainFrame()->scroll(dx, dy); |
488 m_timeLine->stop(); |
524 m_timeLine->stop(); |
489 } |
525 } |
490 |
526 |
491 void GWebContentView::updateZoom(qreal delta){ |
527 void GWebContentView::updateZoom(qreal delta){ |
492 Q_UNUSED(delta) |
528 Q_UNUSED(delta) |
493 if(m_zoomIn) |
529 if (m_zoomIn) |
494 zoomBy(0.1); |
530 zoomBy(0.1); |
495 else |
531 else |
496 zoomBy(-0.1); |
532 zoomBy(-0.1); |
497 } |
533 } |
498 |
534 |
499 void GWebContentView::onUrlChanged(const QUrl& url) |
535 void GWebContentView::onUrlChanged(const QUrl& url) |
500 { |
536 { |
501 emit urlChanged(url.toString()); |
537 emit urlChanged(url.toString()); |
502 //NB: Brief hack |
538 //NB: Brief hack |
503 if(url.scheme()=="https") |
539 if (url.scheme()=="https") |
504 emit secureConnection(true); |
540 emit secureConnection(true); |
505 else |
541 else |
506 emit secureConnection(false); |
542 emit secureConnection(false); |
507 } |
543 } |
508 |
544 |
509 GWebPage *GWebContentView::createSuperPage(const QString &name) { |
545 GWebPage *GWebContentView::createSuperPage(const QString &name, bool persist) { |
510 qDebug() << "GWebContentView::createSuperPage: " << name; |
546 qDebug() << "GWebContentView::createSuperPage: " << name; |
511 GWebPage *page = 0; |
547 GWebPage *page = 0; |
512 PageMap::iterator it = m_superPages.find(name); |
548 PageMap::iterator it = m_superPages.find(name); |
513 if(it == m_superPages.end()) { |
549 // If page doesn't exist create a new one. |
514 // Doesn't exist. Create a new one. |
550 if (it == m_superPages.end()) { |
515 page = new GSuperWebPage(0, chrome()); |
551 |
|
552 if (persist || !m_sharedPage){ |
|
553 if (persist) |
|
554 //Implicitly creates a new QWebPage that is owned by the superpage object |
|
555 page = new GSuperWebPage(0, chrome()); |
|
556 |
|
557 else { |
|
558 //Create a shared QWebPage that is owned by this view |
|
559 m_sharedPage = new WebPageWrapper(this, "Superpage javascript error"); |
|
560 page = new GSuperWebPage(m_sharedPage, chrome()); |
|
561 } |
|
562 //No scroll bars |
|
563 page->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); |
|
564 page->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); |
|
565 //No history for super pages |
|
566 page->page()->history()->setMaximumItemCount(0); |
|
567 //Limit page cache usage by super pages |
|
568 //TODO: This needs to be further tested to weigh the costs and benefits. |
|
569 page->page()->settings()->setMaximumPagesInCache(2); |
|
570 //NB: needed? |
|
571 QPalette viewPalette = widget()->palette(); |
|
572 viewPalette.setBrush(QPalette::Base, Qt::white); |
|
573 page->page()->setPalette(viewPalette); |
|
574 } else { |
|
575 //Reuse the shared QWebPage |
|
576 page = new GSuperWebPage(m_sharedPage, chrome()); |
|
577 } |
|
578 //Export the superpage to JS |
516 page->setParent(jsObject()); |
579 page->setParent(jsObject()); |
517 page->setObjectName(name); |
580 page->setObjectName(name); |
518 |
|
519 // Add it to the superpage list. |
581 // Add it to the superpage list. |
520 m_superPages[name] = page; |
582 m_superPages[name] = page; |
521 if(m_superPages.count() == 1) { |
583 if (m_superPages.count() == 1) { |
522 // This is the only superpage, make it current. |
584 // This is the only superpage, make it current. |
523 m_currentSuperPage = m_superPages.find(name); |
585 m_currentSuperPage = m_superPages.find(name); |
524 } |
586 } |
525 |
|
526 //NB: Here's how to set default webview backgound color |
|
527 page->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); |
|
528 page->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); |
|
529 QPalette viewPalette = widget()->palette(); |
|
530 viewPalette.setBrush(QPalette::Base, Qt::white); |
|
531 //viewPalette.setColor(QPalette::Window, Qt::transparent); |
|
532 page->page()->setPalette(viewPalette); |
|
533 //m_view->setPalette(viewPalette); |
|
534 } |
587 } |
535 else { |
588 else { |
536 qDebug() << "GWebContentView::createPage: page already exists: " << name; |
589 qDebug() << "GWebContentView::createPage: page already exists: " << name; |
537 } |
590 } |
538 return page; |
591 return page; |
539 } |
592 } |
540 |
593 |
541 void GWebContentView::destroySuperPage(const QString &name) { |
594 void GWebContentView::destroySuperPage(const QString &name) { |
542 qDebug() << "GWebContentView::destroySuperPage: " << name; |
595 qDebug() << "GWebContentView::destroySuperPage: " << name; |
543 if(!m_superPages.contains(name)) return; |
596 if (!m_superPages.contains(name)) return; |
544 |
597 |
545 GWebPage *page = m_superPages.take(name); |
598 GWebPage *page = m_superPages.take(name); |
546 if(page) { |
599 //This will destroy any QWebPage owned by the super page. The shared page is not |
547 delete page; |
600 //owned by the super page and will be deleted when the GWebContentView is deleted. |
|
601 if (page){ |
|
602 delete page; |
548 } |
603 } |
549 } |
604 } |
550 |
605 |
551 void GWebContentView::setCurrentSuperPage(const QString &name) { |
606 void GWebContentView::setCurrentSuperPage(const QString &name) { |
552 PageMap::iterator it = m_superPages.find(name); |
607 PageMap::iterator it = m_superPages.find(name); |
553 if(it != m_superPages.end()) { |
608 if (it != m_superPages.end()) { |
554 m_currentSuperPage = it; |
609 m_currentSuperPage = it; |
555 } |
610 } |
556 else { |
611 else { |
557 qDebug() << "GWebContentView::setCurrentSuperPage: not found: " << name; |
612 qDebug() << "GWebContentView::setCurrentSuperPage: not found: " << name; |
558 } |
613 } |
559 } |
614 } |
560 |
615 |
561 bool GWebContentView::isSuperPage(const QString &name){ |
616 bool GWebContentView::isSuperPage(const QString &name){ |
562 PageMap::iterator it = m_superPages.find(name); |
617 PageMap::iterator it = m_superPages.find(name); |
563 if(it != m_superPages.end()) { |
618 if (it != m_superPages.end()) { |
564 return true; |
619 return true; |
565 } |
620 } |
566 qDebug() << "GWebContentView::superPage: not found: " << name; |
621 qDebug() << "GWebContentView::superPage: not found: " << name; |
567 return false; |
622 return false; |
568 } |
623 } |
569 |
624 |
570 |
625 |
571 GWebPage * GWebContentView::superPage(const QString &name) { |
626 GWebPage * GWebContentView::superPage(const QString &name) { |
572 PageMap::iterator it = m_superPages.find(name); |
627 PageMap::iterator it = m_superPages.find(name); |
573 if(it != m_superPages.end()) { |
628 if (it != m_superPages.end()) { |
574 return it.value(); |
629 return it.value(); |
575 } |
630 } |
576 qDebug() << "GWebContentView::superPage: not found: " << name; |
631 qDebug() << "GWebContentView::superPage: not found: " << name; |
577 return 0; |
632 return 0; |
578 } |
633 } |
579 |
634 |
580 void GWebContentView::showSuperPage(const QString &name) { |
635 void GWebContentView::showSuperPage(const QString &name) { |
581 setCurrentSuperPage(name); |
636 setCurrentSuperPage(name); |
582 qDebug() << "GWebContentView::showSuperPage: " << currentSuperPage(); |
637 qDebug() << "GWebContentView::showSuperPage: " << currentSuperPage(); |
583 m_currentPageIsSuperPage = true; |
638 m_currentPageIsSuperPage = true; |
584 webWidget()->setPage(currentSuperPage()->page()); |
639 webWidget()->setPage(currentSuperPage()->page()); |
585 m_touchNavigation->setPage(webWidget()->page()); |
640 m_touchNavigation->setPage(webWidget()->page()); |
|
641 m_touchNavigation->setWantSlideViewCalls(false); |
586 webWidget()->page()->setPreferredContentsSize(webWidget()->size().toSize()); |
642 webWidget()->page()->setPreferredContentsSize(webWidget()->size().toSize()); |
587 } |
643 } |
588 |
644 |
589 void GWebContentView::showNormalPage() { |
645 void GWebContentView::showNormalPage() { |
590 if(webWidget()) { |
646 if (webWidget()) { |
591 webWidget()->showNormalPage(); |
647 webWidget()->showNormalPage(); |
592 webWidget()->setViewportSize(); |
648 webWidget()->setViewportSize(); |
593 m_touchNavigation->setPage(currentPage()); |
649 m_touchNavigation->setPage(currentPage()); |
|
650 m_touchNavigation->setWantSlideViewCalls(true); |
|
651 //TODO: Further testing is needed to show if the following is a net benefit. |
|
652 if (m_currentPageIsSuperPage && (currentSuperPage()->page() == m_sharedPage)){ |
|
653 //Clear contents of shared page to free resources. This should save |
|
654 //memory for big pages, but at the performance cost of loading an empty page. |
|
655 //An alternative is to delete the shared page every time and reallocate it when |
|
656 //a super page is loaded. |
|
657 currentSuperPage()->page()->mainFrame()->setHtml(QString()); |
|
658 } |
594 m_currentPageIsSuperPage =false; |
659 m_currentPageIsSuperPage =false; |
595 } |
660 } |
596 } |
661 } |
597 |
662 |
598 QObjectList GWebContentView::getSuperPages() { |
663 QObjectList GWebContentView::getSuperPages() { |
599 QObjectList *result = new QObjectList; |
664 QObjectList *result = new QObjectList; |
600 foreach(GVA::GWebPage *page, m_superPages) { |
665 foreach(GVA::GWebPage *page, m_superPages) { |
601 result->append(page); |
666 result->append(page); |
602 } |
667 } |
610 } |
675 } |
611 |
676 |
612 void GWebContentView::onLoadStarted() |
677 void GWebContentView::onLoadStarted() |
613 { |
678 { |
614 //qDebug() << "GWebContentView::onLoadStarted: " << QTime::currentTime(); |
679 //qDebug() << "GWebContentView::onLoadStarted: " << QTime::currentTime(); |
615 #if defined(__gva_no_chrome__) || defined(NO_RESIZE_ON_LOAD) |
680 #if defined(__gva_no_chrome__) || defined(NO_RESIZE_ON_LOAD) |
616 m_widget->onLoadStarted(); |
681 m_widget->onLoadStarted(); |
617 #endif |
682 #endif |
618 emit loadStarted(); |
683 emit loadStarted(); |
619 } |
684 } |
620 |
685 |
621 void GWebContentView::onLoadFinished(bool ok) |
686 void GWebContentView::onLoadFinished(bool ok) |
622 { |
687 { |
623 //qDebug() << "GWebContentView::onLoadFinished: " << QTime::currentTime(); |
688 //qDebug() << "GWebContentView::onLoadFinished: " << QTime::currentTime(); |
624 emit loadFinished(ok); |
689 emit loadFinished(ok); |
625 //NB: page manager functions really |
690 //NB: page manager functions really |
626 if(!m_backEnabled && currentPage()->history()->canGoBack()){ |
691 if (!m_backEnabled && currentPage()->history()->canGoBack()){ |
627 m_backEnabled = true; |
692 m_backEnabled = true; |
628 emit backEnabled(true); |
693 emit backEnabled(true); |
629 } |
694 } |
630 else if (m_backEnabled && !currentPage()->history()->canGoBack()){ |
695 else if (m_backEnabled && !currentPage()->history()->canGoBack()){ |
631 m_backEnabled = false; |
696 m_backEnabled = false; |
632 emit backEnabled(false); |
697 emit backEnabled(false); |
633 } |
698 } |
634 if(!m_forwardEnabled && currentPage()->history()->canGoForward()){ |
699 if (!m_forwardEnabled && currentPage()->history()->canGoForward()){ |
635 m_forwardEnabled = true; |
700 m_forwardEnabled = true; |
636 emit forwardEnabled(true); |
701 emit forwardEnabled(true); |
637 } |
702 } |
638 else if (m_forwardEnabled && !currentPage()->history()->canGoForward()){ |
703 else if (m_forwardEnabled && !currentPage()->history()->canGoForward()){ |
639 m_forwardEnabled = false; |
704 m_forwardEnabled = false; |
640 emit forwardEnabled(false); |
705 emit forwardEnabled(false); |
641 } |
706 } |
642 |
707 |
643 // Set focus to the Web View so that text boxes have the focus (BR-994) |
708 // Set focus to the Web View so that text boxes have the focus (BR-994) |
644 m_widget->setFocus(); |
709 m_widget->setFocus(); |
645 |
710 |
646 #if defined(__gva_no_chrome__) || defined(NO_RESIZE_ON_LOAD) |
711 #if defined(__gva_no_chrome__) || defined(NO_RESIZE_ON_LOAD) |
647 m_widget->onLoadFinished(); |
712 m_widget->onLoadFinished(); |