28 #include "GWebContentView.h" |
28 #include "GWebContentView.h" |
29 #include "mostvisitedsnippet.h" |
29 #include "mostvisitedsnippet.h" |
30 #include "webpagecontroller.h" |
30 #include "webpagecontroller.h" |
31 #include "ViewController.h" |
31 #include "ViewController.h" |
32 #include "ChromeEffect.h" |
32 #include "ChromeEffect.h" |
33 |
33 #include "qstmgestureevent.h" |
|
34 |
|
35 #if defined(Q_WS_MAEMO_5) || defined(BROWSER_LAYOUT_TENONE) |
|
36 #include "ScaleNinePainter.h" |
|
37 #endif |
34 |
38 |
35 #include <QTimeLine> |
39 #include <QTimeLine> |
36 #include <QDebug> |
40 #include <QDebug> |
37 |
41 |
38 #define TOOLBAR_MARGIN 4 |
42 #define TOOLBAR_MARGIN 4 |
39 #define TOOLBAR_ANIMATION_DURATION 200 |
43 #define TOOLBAR_ANIMATION_DURATION 200 |
40 #define TOOLBAR_INACTIVITY_DURATION 5000 |
44 #define TOOLBAR_INACTIVITY_DURATION 5000 |
41 |
45 |
42 namespace GVA { |
46 namespace GVA { |
43 |
47 |
44 ToolbarFadeAnimator::ToolbarFadeAnimator(): m_timeLine(NULL) |
48 ToolbarFadeAnimator::ToolbarFadeAnimator(): m_timeLine(NULL) { |
45 { |
49 |
46 } |
50 } |
47 |
51 |
48 |
52 |
49 ToolbarFadeAnimator::~ToolbarFadeAnimator() { |
53 ToolbarFadeAnimator::~ToolbarFadeAnimator() { |
50 |
54 |
79 //qDebug() << __PRETTY_FUNCTION__ ; |
83 //qDebug() << __PRETTY_FUNCTION__ ; |
80 m_timeLine->stop(); |
84 m_timeLine->stop(); |
81 } |
85 } |
82 |
86 |
83 void ToolbarFadeAnimator::valueChange(qreal step) { |
87 void ToolbarFadeAnimator::valueChange(qreal step) { |
|
88 |
84 emit updateVisibility(step); |
89 emit updateVisibility(step); |
85 } |
90 } |
86 |
91 |
87 ContentToolbarChromeItem::ContentToolbarChromeItem(ChromeSnippet* snippet, QGraphicsItem* parent) |
92 ContentToolbarChromeItem::ContentToolbarChromeItem(ChromeSnippet* snippet, QGraphicsItem* parent) |
88 : ToolbarChromeItem(snippet, parent), |
93 : ToolbarChromeItem(snippet, parent), |
|
94 #if defined(Q_WS_MAEMO_5) || defined(BROWSER_LAYOUT_TENONE) |
|
95 m_backgroundPainter(0), |
|
96 m_backgroundPixmap(0), |
|
97 m_backgroundDirty(true), |
|
98 #else |
89 m_background(NULL), |
99 m_background(NULL), |
|
100 #endif |
90 m_state(CONTENT_TOOLBAR_STATE_FULL), |
101 m_state(CONTENT_TOOLBAR_STATE_FULL), |
91 m_autoHideToolbar(true), |
102 m_autoHideToolbar(true), |
92 m_timerState(CONTENT_TOOLBAR_TIMER_STATE_ALLOW) |
103 m_timerState(CONTENT_TOOLBAR_TIMER_STATE_ALLOW) |
93 { |
104 { |
94 |
105 |
103 if (m_autoHideToolbar ) { |
114 if (m_autoHideToolbar ) { |
104 connect(m_snippet->chrome(), SIGNAL(chromeComplete()), this, SLOT(onChromeComplete())); |
115 connect(m_snippet->chrome(), SIGNAL(chromeComplete()), this, SLOT(onChromeComplete())); |
105 } |
116 } |
106 |
117 |
107 setFlags(QGraphicsItem::ItemDoesntPropagateOpacityToChildren); |
118 setFlags(QGraphicsItem::ItemDoesntPropagateOpacityToChildren); |
108 |
119 |
109 } |
120 #ifdef Q_WS_MAEMO_5 |
110 |
121 m_backgroundPainter = new ScaleNinePainter( |
111 ContentToolbarChromeItem::~ContentToolbarChromeItem() |
122 ":/toolbar/toolBar_bkg_topLeft.png", |
112 { |
123 ":/toolbar/toolBar_bkg_topMiddle.png", |
|
124 ":/toolbar/toolBar_bkg_topRight.png", |
|
125 "", |
|
126 ":/toolbar/toolBar_bkg_middleMiddle.png", |
|
127 "", |
|
128 ":/toolbar/toolBar_bkg_bottomLeft.png", |
|
129 ":/toolbar/toolBar_bkg_bottomMiddle.png", |
|
130 ":/toolbar/toolBar_bkg_bottomRight.png" |
|
131 ); |
|
132 #endif |
|
133 |
|
134 #ifdef BROWSER_LAYOUT_TENONE |
|
135 m_backgroundPainter = new ScaleNinePainter( |
|
136 ":/toolbar/toolBar_bkg_topLeft.png", |
|
137 ":/toolbar/toolBar_bkg_topMiddle.png", |
|
138 ":/toolbar/toolBar_bkg_topRight.png", |
|
139 "", |
|
140 "", |
|
141 "", |
|
142 ":/toolbar/toolBar_bkg_bottomLeft.png", |
|
143 ":/toolbar/toolBar_bkg_bottomMiddle.png", |
|
144 ":/toolbar/toolBar_bkg_bottomRight.png" |
|
145 ); |
|
146 #endif |
|
147 } |
|
148 |
|
149 ContentToolbarChromeItem::~ContentToolbarChromeItem() { |
|
150 |
|
151 #if defined(Q_WS_MAEMO_5) || defined(BROWSER_LAYOUT_TENONE) |
|
152 delete m_backgroundPainter; |
|
153 delete m_backgroundPixmap; |
|
154 #else |
113 if (m_background ) |
155 if (m_background ) |
114 delete m_background; |
156 delete m_background; |
|
157 #endif |
115 delete m_inactivityTimer; |
158 delete m_inactivityTimer; |
116 |
159 |
117 delete m_animator; |
160 delete m_animator; |
118 |
161 |
119 } |
162 } |
120 |
163 |
121 void ContentToolbarChromeItem::resizeEvent(QGraphicsSceneResizeEvent * ev) |
164 void ContentToolbarChromeItem::resizeEvent(QGraphicsSceneResizeEvent * ev) { |
122 { |
165 |
123 //qDebug() << __PRETTY_FUNCTION__ << boundingRect(); |
166 //qDebug() << __PRETTY_FUNCTION__ << boundingRect(); |
124 ToolbarChromeItem::resizeEvent(ev); |
167 ToolbarChromeItem::resizeEvent(ev); |
125 addFullBackground(); |
168 addFullBackground(); |
126 |
169 #if defined(Q_WS_MAEMO_5) || defined(BROWSER_LAYOUT_TENONE) |
127 } |
170 m_backgroundDirty = true; |
128 |
171 #endif |
129 void ContentToolbarChromeItem::mousePressEvent(QGraphicsSceneMouseEvent * ev) |
172 } |
130 { |
173 |
|
174 void ContentToolbarChromeItem::mousePressEvent(QGraphicsSceneMouseEvent * ev) { |
131 // If we are not in full state, ignore the event. Once igonre, none of the |
175 // If we are not in full state, ignore the event. Once igonre, none of the |
132 // other mouse events are received until the next mouse press |
176 // other mouse events are received until the next mouse press |
133 if (m_state == CONTENT_TOOLBAR_STATE_PARTIAL ) { |
177 if (m_state == CONTENT_TOOLBAR_STATE_PARTIAL ) { |
134 ev->ignore(); |
178 ev->ignore(); |
135 } |
179 } |
165 switch (m_state) { |
209 switch (m_state) { |
166 case CONTENT_TOOLBAR_STATE_PARTIAL: |
210 case CONTENT_TOOLBAR_STATE_PARTIAL: |
167 ToolbarChromeItem::paint(painter, opt, widget); |
211 ToolbarChromeItem::paint(painter, opt, widget); |
168 break; |
212 break; |
169 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
213 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
|
214 // intentional fall through |
170 case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL: |
215 case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL: |
171 ToolbarChromeItem::paint(painter, opt, widget); |
216 ToolbarChromeItem::paint(painter, opt, widget); |
|
217 // intentional fall through |
172 case CONTENT_TOOLBAR_STATE_FULL: |
218 case CONTENT_TOOLBAR_STATE_FULL: |
|
219 #if defined(Q_WS_MAEMO_5) || defined(BROWSER_LAYOUT_TENONE) |
|
220 if(m_backgroundDirty) { |
|
221 updateBackgroundPixmap(geometry().size().toSize(), widget); |
|
222 m_backgroundPainter->unloadPixmaps(); |
|
223 } |
|
224 painter->drawPixmap(opt->exposedRect, *m_backgroundPixmap, opt->exposedRect); |
|
225 #else |
173 // fill path with color |
226 // fill path with color |
174 painter->fillPath(*m_background,QBrush(grad())); |
227 painter->fillPath(*m_background,QBrush(grad())); |
175 painter->drawPath(*m_background); |
228 painter->drawPath(*m_background); |
|
229 #endif |
176 if(m_state == CONTENT_TOOLBAR_STATE_FULL && !isEnabled()) { |
230 if(m_state == CONTENT_TOOLBAR_STATE_FULL && !isEnabled()) { |
177 // Disabled, apply whitewash. |
231 // Disabled, apply whitewash. |
178 ChromeEffect::paintDisabledRect(painter, opt->exposedRect); |
232 ChromeEffect::paintDisabledRect(painter, opt->exposedRect); |
179 } |
233 } |
180 break; |
234 break; |
198 |
252 |
199 } |
253 } |
200 |
254 |
201 void ContentToolbarChromeItem::onChromeComplete() { |
255 void ContentToolbarChromeItem::onChromeComplete() { |
202 |
256 |
203 GWebContentView* webView = static_cast<GWebContentView*> (m_snippet->chrome()->getView("WebView")); |
257 m_webView = static_cast<GWebContentView*> (m_snippet->chrome()->getView("WebView")); |
204 //qDebug() << __PRETTY_FUNCTION__ << webView; |
258 //qDebug() << __PRETTY_FUNCTION__ << webView; |
205 if (webView ) { |
259 if (m_webView ) { |
206 connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
260 connect(m_webView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
207 connect(webView, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
261 connect(m_webView, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
208 #ifdef BEDROCK_TILED_BACKING_STORE |
262 #ifdef BEDROCK_TILED_BACKING_STORE |
209 connect(webView, SIGNAL(contextEvent(::WebViewEventContext *)), this, SLOT(resetTimer())); |
263 connect(m_webView, SIGNAL(contextEvent(::WebViewEventContext *)), this, SLOT(resetTimer())); |
210 #else |
264 #else |
211 connect(webView->widget(), SIGNAL(contextEvent(::WebViewEventContext *)), this, SLOT(resetTimer())); |
265 connect(m_webView->widget(), SIGNAL(contextEvent(::WebViewEventContext *)), this, SLOT(resetTimer())); |
212 #endif |
266 #endif |
213 } |
267 } |
214 |
268 |
215 } |
269 } |
216 |
270 |
222 |
276 |
223 |
277 |
224 void ContentToolbarChromeItem::onLoadFinished(bool ok) { |
278 void ContentToolbarChromeItem::onLoadFinished(bool ok) { |
225 |
279 |
226 Q_UNUSED(ok); |
280 Q_UNUSED(ok); |
|
281 |
|
282 if(!ok) { |
|
283 // Don't hide the toolbar etc. on load error since the user is likely to start |
|
284 // typing in the UrlSearch bar, we don't want to trigger the flashing and re-layout |
|
285 // that happens when switching screen modes. |
|
286 return; |
|
287 } |
|
288 |
227 //qDebug() << __PRETTY_FUNCTION__ << m_state << "Timer Allowed" << m_timerState; |
289 //qDebug() << __PRETTY_FUNCTION__ << m_state << "Timer Allowed" << m_timerState; |
228 |
290 |
229 if (m_autoHideToolbar && m_timerState == CONTENT_TOOLBAR_TIMER_STATE_ALLOW) { |
291 if (m_autoHideToolbar && m_timerState == CONTENT_TOOLBAR_TIMER_STATE_ALLOW) { |
230 ControllableViewBase* curView = m_snippet->chrome()->viewController()->currentView(); |
292 ControllableViewBase* curView = m_snippet->chrome()->viewController()->currentView(); |
231 if (curView && curView->type() == "webView") { |
293 if (curView && curView->type() == "webView") { |
259 //qDebug() << __PRETTY_FUNCTION__ << m_state; |
321 //qDebug() << __PRETTY_FUNCTION__ << m_state; |
260 |
322 |
261 //We are here because inactivity timer timed out. So we have to be in full toolbar state with no |
323 //We are here because inactivity timer timed out. So we have to be in full toolbar state with no |
262 // popups. So change fade to Partial state after stopping inactivity timer |
324 // popups. So change fade to Partial state after stopping inactivity timer |
263 m_inactivityTimer->stop(); |
325 m_inactivityTimer->stop(); |
|
326 #if defined(Q_WS_MAEMO_5) || defined(BROWSER_LAYOUT_TENONE) |
|
327 emit inactivityTimer(); |
|
328 #else |
264 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true); |
329 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true); |
|
330 #endif |
265 } |
331 } |
266 |
332 |
267 void ContentToolbarChromeItem::onSnippetMouseEvent( QEvent::Type type) { |
333 void ContentToolbarChromeItem::onSnippetMouseEvent( QEvent::Type type) { |
268 |
334 |
269 //qDebug() << __PRETTY_FUNCTION__ << type ; |
335 //qDebug() << __PRETTY_FUNCTION__ << type ; |
291 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
357 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
292 // Do nothing here - will reset inactivity timer when |
358 // Do nothing here - will reset inactivity timer when |
293 // animation completes |
359 // animation completes |
294 break; |
360 break; |
295 case CONTENT_TOOLBAR_STATE_FULL: |
361 case CONTENT_TOOLBAR_STATE_FULL: |
296 // if MV is active then wait for it to hide before changing the toolbar state |
362 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true); |
297 if (mvSnippetVisible()) { |
|
298 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, false); |
|
299 } |
|
300 else { |
|
301 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true); |
|
302 } |
|
303 break; |
363 break; |
304 default: |
364 default: |
305 break; |
365 break; |
306 } |
366 } |
307 } |
367 } |
357 //qDebug() << __PRETTY_FUNCTION__ << m_state; |
417 //qDebug() << __PRETTY_FUNCTION__ << m_state; |
358 |
418 |
359 } |
419 } |
360 void ContentToolbarChromeItem::addFullBackground() { |
420 void ContentToolbarChromeItem::addFullBackground() { |
361 |
421 |
362 //qDebug() << __PRETTY_FUNCTION__ ; |
|
363 qreal roundness((boundingRect().height() -TOOLBAR_MARGIN)/2); |
422 qreal roundness((boundingRect().height() -TOOLBAR_MARGIN)/2); |
364 QRectF r(1, 1, boundingRect().width()-TOOLBAR_MARGIN, boundingRect().height()-TOOLBAR_MARGIN); |
423 QRectF r(1, 1, boundingRect().width()-TOOLBAR_MARGIN, boundingRect().height()-TOOLBAR_MARGIN); |
365 |
424 |
|
425 #if !defined(BROWSER_LAYOUT_TENONE) && !defined(Q_WS_MAEMO_5) |
366 if (m_background ) { |
426 if (m_background ) { |
367 delete m_background; |
427 delete m_background; |
368 m_background = NULL; |
428 m_background = NULL; |
369 } |
429 } |
370 m_background = new QPainterPath(); |
430 m_background = new QPainterPath(); |
371 m_background->addRoundedRect(r, roundness, roundness); |
431 m_background->addRoundedRect(r, roundness, roundness); |
372 } |
432 #endif |
|
433 } |
|
434 |
|
435 #if defined(Q_WS_MAEMO_5) || defined(BROWSER_LAYOUT_TENONE) |
|
436 void ContentToolbarChromeItem::updateBackgroundPixmap(const QSize &size, QWidget* widget) { |
|
437 delete m_backgroundPixmap; |
|
438 m_backgroundPixmap = new QPixmap(size); |
|
439 m_backgroundPixmap->fill(QColor(0xff, 0xff, 0xff, 0)); |
|
440 QPainter painter(m_backgroundPixmap); |
|
441 m_backgroundPainter->paint(&painter, QRect(0, 0, size.width(), size.height()), widget); |
|
442 m_backgroundDirty = false; |
|
443 } |
|
444 #endif |
373 |
445 |
374 void ContentToolbarChromeItem::stateEnterFull(bool animate) { |
446 void ContentToolbarChromeItem::stateEnterFull(bool animate) { |
375 |
447 |
376 //qDebug() <<__PRETTY_FUNCTION__ ; |
448 //qDebug() <<__PRETTY_FUNCTION__ ; |
377 ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet); |
449 ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet); |
378 |
450 |
379 // Show the middle snippet and reset the opacity if we are here directly with no aniamtion |
451 // Show the middle snippet and reset the opacity if we are here directly with no aniamtion |
380 if (!animate) { |
452 if (!animate) { |
|
453 #if !defined(BROWSER_LAYOUT_TENONE) || !defined(Q_WS_MAEMO_5) |
381 m_bgopacity = 0.75; |
454 m_bgopacity = 0.75; |
|
455 #else |
|
456 m_bgopacity = 1.0; |
|
457 #endif |
382 s->middleSnippet()->show(); |
458 s->middleSnippet()->show(); |
383 } |
459 } |
384 |
460 |
385 m_state = CONTENT_TOOLBAR_STATE_FULL; |
461 m_state = CONTENT_TOOLBAR_STATE_FULL; |
386 s->middleSnippet()->widget()->setOpacity(1.0); |
462 s->middleSnippet()->widget()->setOpacity(1.0); |
|
463 s->handleToolbarStateChange(m_state); |
387 // TODO: specify the rect to be updated to avoid full repaint |
464 // TODO: specify the rect to be updated to avoid full repaint |
388 update(); |
465 update(); |
389 } |
466 } |
390 |
467 |
391 void ContentToolbarChromeItem::stateEnterPartial(bool animate) { |
468 void ContentToolbarChromeItem::stateEnterPartial(bool animate) { |
398 // signals that it is expecting |
475 // signals that it is expecting |
399 hideLinkedChildren(); |
476 hideLinkedChildren(); |
400 |
477 |
401 s->middleSnippet()->hide(); |
478 s->middleSnippet()->hide(); |
402 m_state = CONTENT_TOOLBAR_STATE_PARTIAL; |
479 m_state = CONTENT_TOOLBAR_STATE_PARTIAL; |
403 |
480 #if defined(Q_WS_MAEMO_5) || defined(BROWSER_LAYOUT_TENONE) |
|
481 s->handleToolbarStateChange(m_state); |
|
482 #endif |
404 } |
483 } |
405 |
484 |
406 void ContentToolbarChromeItem::stateEnterAnimToFull(bool animate) { |
485 void ContentToolbarChromeItem::stateEnterAnimToFull(bool animate) { |
407 |
486 |
408 //qDebug() <<__PRETTY_FUNCTION__ ; |
487 //qDebug() <<__PRETTY_FUNCTION__ ; |
429 } |
508 } |
430 |
509 |
431 } |
510 } |
432 |
511 |
433 void ContentToolbarChromeItem::changeState( ContentToolbarState state, bool animate){ |
512 void ContentToolbarChromeItem::changeState( ContentToolbarState state, bool animate){ |
434 |
|
435 onStateEntry(state, animate); |
513 onStateEntry(state, animate); |
436 } |
514 } |
437 |
515 |
438 void ContentToolbarChromeItem::onStateEntry(ContentToolbarState state, bool animate){ |
516 void ContentToolbarChromeItem::onStateEntry(ContentToolbarState state, bool animate){ |
439 |
517 if(state != m_state) |
440 //qDebug() << __PRETTY_FUNCTION__ ; |
518 { |
441 switch (state) { |
519 //qDebug() << __PRETTY_FUNCTION__ ; |
442 case CONTENT_TOOLBAR_STATE_PARTIAL: |
520 switch (state) { |
443 stateEnterPartial(animate); |
521 case CONTENT_TOOLBAR_STATE_PARTIAL: |
444 break; |
522 stateEnterPartial(animate); |
445 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
523 break; |
446 stateEnterAnimToFull(animate); |
524 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
447 break; |
525 stateEnterAnimToFull(animate); |
448 case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL: |
526 break; |
449 stateEnterAnimToPartial(animate); |
527 case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL: |
450 break; |
528 stateEnterAnimToPartial(animate); |
451 case CONTENT_TOOLBAR_STATE_FULL: |
529 break; |
452 stateEnterFull(animate); |
530 case CONTENT_TOOLBAR_STATE_FULL: |
453 break; |
531 stateEnterFull(animate); |
454 default: |
532 break; |
455 qDebug() << "ContentToolbarChromeItem::onStateEntry - invalid state" ; |
533 default: |
456 break; |
534 qDebug() << "ContentToolbarChromeItem::onStateEntry - invalid state" ; |
|
535 break; |
|
536 } |
457 } |
537 } |
458 } |
538 } |
459 |
539 |
460 bool ContentToolbarChromeItem::mvSnippetVisible() { |
540 bool ContentToolbarChromeItem::mvSnippetVisible() { |
461 |
541 |