author | hgs |
Wed, 01 Sep 2010 13:56:21 -0400 | |
changeset 11 | 786160610b4d |
parent 9 | b39122337a00 |
child 12 | afcd8e6d025b |
permissions | -rw-r--r-- |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
3 | 4 |
* |
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU Lesser General Public License as published by |
|
7 |
* the Free Software Foundation, version 2.1 of the License. |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
* |
3 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU Lesser General Public License for more details. |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
* |
3 | 14 |
* You should have received a copy of the GNU Lesser General Public License |
15 |
* along with this program. If not, |
|
16 |
* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
* |
3 | 18 |
* Description: |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
* |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
*/ |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
22 |
#include "UrlSearchSnippet.h" |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
23 |
#include "Utilities.h" |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
25 |
#include "ChromeRenderer.h" |
3 | 26 |
#include "ChromeLayout.h" |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
27 |
#include "ChromeWidget.h" |
3 | 28 |
#include "PageSnippet.h" |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
29 |
#include "ViewController.h" |
3 | 30 |
#include "ViewStack.h" |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
31 |
#include "WebChromeSnippet.h" |
3 | 32 |
#include "LoadController.h" |
33 |
#include "webpagecontroller.h" |
|
34 |
#include "GWebContentView.h" |
|
35 |
#include "WindowFlowView.h" |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
36 |
|
3 | 37 |
#include <QWebHistoryItem> |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
38 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
39 |
namespace GVA { |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
40 |
|
3 | 41 |
#define GO_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/go_btn.png" |
42 |
#define STOP_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/stop_btn.png" |
|
43 |
#define REFRESH_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/refresh_btn.png" |
|
9 | 44 |
#define SPECIFIC_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/com.svg" |
45 |
#define SPECIFIC_BUTTON_STRING ".com" |
|
3 | 46 |
#define BETWEEN_ENTRY_AND_BUTTON_SPACE 4 |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
47 |
|
3 | 48 |
GUrlSearchItem::GUrlSearchItem(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent) |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
49 |
: NativeChromeItem(snippet, parent) |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
50 |
, m_chrome(chrome) |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
51 |
, m_viewPortWidth(0.0) |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
52 |
, m_viewPortHeight(0.0) |
3 | 53 |
, m_pendingClearCalls(0) |
54 |
, m_backFromNewWinTrans(false) |
|
55 |
, m_justFocusIn(false) |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
56 |
{ |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
57 |
// Extract style information from element CSS. |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
58 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
59 |
// For border-related properties, we constrain all values (top, left, etc.) |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
60 |
// to be the same. These can be set using the css shorthand (e.g. padding:10px), |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
61 |
// but the computed css style will be for the four primitive values (padding-top, |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
62 |
// padding-left) etc, which will all be equal. Hence we just use one of the |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
63 |
// computed primitive values (top) to represent the common value. |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
64 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
65 |
QWebElement we = m_snippet->element(); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
66 |
|
3 | 67 |
QColor textColor; |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
NativeChromeItem::CSSToQColor( |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
69 |
we.styleProperty("color", QWebElement::ComputedStyle), |
3 | 70 |
textColor); |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
71 |
|
3 | 72 |
QColor backgroundColor; |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
73 |
NativeChromeItem::CSSToQColor( |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
74 |
we.styleProperty("background-color", QWebElement::ComputedStyle), |
3 | 75 |
backgroundColor); // FIXME text edit background color doesn't work |
76 |
||
77 |
QColor progressColor; |
|
78 |
NativeChromeItem::CSSToQColor( |
|
79 |
we.styleProperty("border-bottom-color", QWebElement::ComputedStyle), |
|
80 |
progressColor); //FIXME text-underline-color causes the crash |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
81 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
82 |
NativeChromeItem::CSSToQColor( |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
83 |
we.styleProperty("border-top-color", QWebElement::ComputedStyle), |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
84 |
m_borderColor); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
85 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
86 |
QString cssPadding = we.styleProperty("padding-top", QWebElement::ComputedStyle); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
87 |
m_padding = cssPadding.remove("px").toInt(); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
88 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
89 |
QString cssBorder = we.styleProperty("border-top-width", QWebElement::ComputedStyle); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
90 |
m_border = cssBorder.remove("px").toInt(); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
91 |
|
3 | 92 |
// Create the view port widget |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
93 |
m_viewPort = new QGraphicsWidget(this); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
94 |
m_viewPort->setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
95 |
|
3 | 96 |
// Create the url search editor |
97 |
m_urlSearchEditor = new GProgressEditor(snippet, chrome, m_viewPort); |
|
98 |
m_urlSearchEditor->setTextColor(textColor); |
|
99 |
m_urlSearchEditor->setBackgroundColor(backgroundColor); |
|
100 |
m_urlSearchEditor->setProgressColor(progressColor); |
|
101 |
m_urlSearchEditor->setBorderColor(m_borderColor); |
|
102 |
m_urlSearchEditor->setPadding(0.1); // draw the Rounded Rect |
|
103 |
m_urlSearchEditor->setInputMethodHints(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); |
|
9 | 104 |
m_urlSearchEditor->setSpecificButton(SPECIFIC_BUTTON_STRING, SPECIFIC_BUTTON_ICON); |
3 | 105 |
safe_connect(m_urlSearchEditor, SIGNAL(textMayChanged()), this, SLOT(updateLoadStateAndSuggest())); |
106 |
safe_connect(m_urlSearchEditor, SIGNAL(activated()),this, SLOT(urlSearchActivatedByEnterKey())); |
|
107 |
safe_connect(m_urlSearchEditor, SIGNAL(focusChanged(bool)),this, SLOT(focusChanged(bool))); |
|
108 |
safe_connect(m_urlSearchEditor, SIGNAL(tapped(QPointF&)),this, SLOT(tapped(QPointF&))); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
109 |
|
3 | 110 |
// Create the url search button |
111 |
m_urlSearchBtn = new ActionButton(snippet, m_viewPort); |
|
112 |
QAction* urlSearchBtnAction = new QAction(this); |
|
113 |
m_urlSearchBtn->setAction(urlSearchBtnAction); // FIXME: should use diff QActions |
|
114 |
||
115 |
m_urlSearchBtn->setActiveOnPress(false); |
|
116 |
safe_connect(urlSearchBtnAction, SIGNAL(triggered()), this, SLOT(urlSearchActivated())); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
117 |
|
3 | 118 |
// Get the icon size |
119 |
QIcon btnIcon(GO_BUTTON_ICON); |
|
120 |
QSize defaultSize(50, 50); |
|
121 |
QSize actualSize = btnIcon.actualSize(defaultSize); |
|
122 |
m_iconWidth = actualSize.width(); |
|
123 |
m_iconHeight = actualSize.height(); |
|
124 |
// Set the right text margin to accomodate the icon inside the editor |
|
125 |
m_urlSearchEditor->setRightTextMargin(m_iconWidth + BETWEEN_ENTRY_AND_BUTTON_SPACE); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
126 |
|
3 | 127 |
// Update state as soon as chrome completes loading. |
128 |
safe_connect(m_chrome, SIGNAL(chromeComplete()), |
|
129 |
this, SLOT(onChromeComplete())); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
130 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
131 |
// Monitor resize events. |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
132 |
safe_connect(m_chrome->renderer(), SIGNAL(chromeResized()), |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
133 |
this, SLOT(resize())); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
134 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
135 |
WebPageController * pageController = WebPageController::getSingleton(); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
136 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
137 |
safe_connect(pageController, SIGNAL(pageUrlChanged(const QString)), |
3 | 138 |
m_urlSearchEditor, SLOT(setText(const QString &))) |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
139 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
140 |
safe_connect(pageController, SIGNAL(pageLoadStarted()), |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
141 |
this, SLOT(setStarted())); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
142 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
143 |
safe_connect(pageController, SIGNAL(pageLoadProgress(const int)), |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
144 |
this, SLOT(setProgress(int))); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
145 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
146 |
safe_connect(pageController, SIGNAL(pageLoadFinished(bool)), |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
147 |
this, SLOT(setFinished(bool))); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
148 |
|
3 | 149 |
safe_connect(pageController, SIGNAL(pageCreated(WRT::WrtBrowserContainer*)), |
150 |
this, SLOT(setPageCreated())); |
|
151 |
||
152 |
safe_connect(pageController, SIGNAL(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)), |
|
153 |
this, SLOT(setPageChanged())); |
|
154 |
||
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
155 |
// Monitor view changes. |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
156 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
157 |
ViewController * viewController = chrome->viewController(); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
158 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
159 |
safe_connect(viewController, SIGNAL(currentViewChanged()), |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
160 |
this, SLOT(viewChanged())); |
3 | 161 |
|
162 |
/* safe_connect(ViewStack::getSingleton(), SIGNAL(currentViewChanged()), |
|
163 |
this, SLOT(viewChanged()));*/ |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
164 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
165 |
|
3 | 166 |
GUrlSearchItem::~GUrlSearchItem() |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
167 |
{ |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
168 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
169 |
|
3 | 170 |
//TODO: Shouldn't have to explicitly set the viewport sizes here |
171 |
||
172 |
void GUrlSearchItem::resizeEvent(QGraphicsSceneResizeEvent * event) |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
173 |
{ |
3 | 174 |
QSizeF size = event->newSize(); |
175 |
||
176 |
m_viewPortWidth = size.width() - m_padding * 2; |
|
177 |
m_viewPortHeight = size.height() - m_padding * 2; |
|
178 |
||
179 |
m_viewPort->setGeometry( |
|
180 |
m_padding, |
|
181 |
m_padding, |
|
182 |
m_viewPortWidth, |
|
183 |
m_viewPortHeight); |
|
184 |
||
185 |
qreal w = m_iconWidth; |
|
186 |
qreal h = m_iconHeight; |
|
187 |
||
188 |
m_urlSearchBtn->setGeometry( |
|
189 |
m_viewPortWidth - w - m_padding/2, |
|
190 |
(m_viewPortHeight - h)/2, |
|
191 |
w, |
|
192 |
h); |
|
193 |
||
194 |
m_urlSearchEditor->setGeometry(0, |
|
195 |
0, |
|
196 |
m_viewPortWidth, |
|
197 |
m_viewPortHeight); |
|
198 |
||
199 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
200 |
|
3 | 201 |
void GUrlSearchItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) |
202 |
{ |
|
203 |
Q_UNUSED(option); |
|
204 |
Q_UNUSED(widget); |
|
205 |
||
206 |
painter->save(); |
|
207 |
painter->setRenderHint(QPainter::Antialiasing); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
208 |
|
3 | 209 |
if (m_padding > 0 || m_border > 0) { |
210 |
QPainterPath border; |
|
211 |
border.addRect(boundingRect()); |
|
212 |
border.addRoundedRect( |
|
213 |
m_padding, |
|
214 |
m_padding, |
|
215 |
m_viewPortWidth, |
|
216 |
m_viewPortHeight, |
|
217 |
4, |
|
218 |
4); |
|
219 |
||
220 |
if (m_padding > 0) { |
|
221 |
painter->fillPath(border, m_borderColor); |
|
222 |
} |
|
223 |
||
224 |
if (m_border > 0) { |
|
225 |
QPen pen; |
|
226 |
pen.setWidth(m_border); |
|
227 |
pen.setBrush(m_borderColor); |
|
228 |
painter->setPen(pen); |
|
229 |
painter->drawPath(border); |
|
230 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
231 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
232 |
|
3 | 233 |
painter->restore(); |
234 |
NativeChromeItem::paint(painter, option, widget); |
|
235 |
} |
|
236 |
||
237 |
void GUrlSearchItem::onChromeComplete() |
|
238 |
{ |
|
239 |
setStarted(); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
240 |
|
3 | 241 |
WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_chrome->viewController()->view("WindowView")); |
242 |
safe_connect(windowView, SIGNAL(newWindowTransitionComplete()), this, SLOT(onNewWindowTransitionComplete())); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
243 |
|
3 | 244 |
PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId")); |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
245 |
|
3 | 246 |
// instantiate items needed to display suggest page snippet |
247 |
if (suggestSnippet) { |
|
248 |
suggestSnippet->instantiate(); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
249 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
250 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
251 |
|
3 | 252 |
void GUrlSearchItem::setStarted() |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
253 |
{ |
3 | 254 |
WebPageController * pageController = WebPageController::getSingleton(); |
255 |
ViewController * viewController = m_chrome->viewController(); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
256 |
|
3 | 257 |
m_urlSearchEditor->setText(pageController->currentRequestedUrl()); |
258 |
ControllableViewBase* curView = viewController->currentView(); |
|
259 |
if (curView && curView->type() == "webView") { |
|
260 |
GWebContentView * gView = qobject_cast<GWebContentView*> (curView); |
|
261 |
bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false; |
|
262 |
if(!isSuperPage) |
|
263 |
m_chrome->layout()->slideView(100); |
|
264 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
265 |
// Strictly speaking we should set progress to 0. |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
266 |
// But set it higher to give immediate visual feedback |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
267 |
// that something is happening. |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
268 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
269 |
int progress = 0; |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
270 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
271 |
if (pageController->isPageLoading()) { |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
272 |
progress = 5; |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
273 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
274 |
|
3 | 275 |
m_urlSearchEditor->setProgress(progress); |
276 |
updateUrlSearchBtn(); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
277 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
278 |
|
3 | 279 |
void GUrlSearchItem::setProgress(int percent) |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
280 |
{ |
3 | 281 |
m_urlSearchEditor->setProgress(percent); |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
282 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
283 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
284 |
// Wait a half-second before actually clearing the progress bar. |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
285 |
// |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
286 |
// We have to be careful of the following two use cases: |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
287 |
// |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
288 |
// 1. Another page starts loading between the call to setFinished() |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
289 |
// and the scheduled call to clearProgress(). |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
290 |
// |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
291 |
// We don't want to clear the progress bar if another page is |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
292 |
// loading. WebPageController::isPageLoading() can tell us |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
293 |
// if that is the case. |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
294 |
// |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
295 |
// 2. Another page finishes loading between the call to setFinished() |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
296 |
// and the scheduled call to clearProgress(). The sequence here is: |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
297 |
// |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
298 |
// setFinished(ok) // for URL #1 |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
299 |
// setFinished(ok) // for URL #2 |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
300 |
// clearProgress() // for URL #1 |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
301 |
// clearProgress() // for URL #2 |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
302 |
// |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
303 |
// We don't want to clear the progress bar in the first call to |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
304 |
// clearProgress() because we want the progress bar to retain its |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
305 |
// appearance for the full timeout period. We manage this by |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
306 |
// tracking the number of pending calls to clearProgress() and |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
307 |
// only clearing the progress bar when that number becomes 0. |
3 | 308 |
void GUrlSearchItem::setFinished(bool ok) |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
309 |
{ |
3 | 310 |
WebPageController * pageController = WebPageController::getSingleton(); |
311 |
// If the load was finished normally and not due to user stopping it, |
|
312 |
// simulate progress completion |
|
313 |
if (!pageController->loadCanceled()) |
|
314 |
m_urlSearchEditor->setProgress(100); |
|
315 |
||
316 |
if (ok) |
|
317 |
m_urlSearchEditor->setText(formattedUrl()); |
|
318 |
||
319 |
m_urlSearchEditor->removeFocus(); |
|
320 |
||
321 |
ViewController * viewController = m_chrome->viewController(); |
|
322 |
ControllableViewBase* curView = viewController->currentView(); |
|
323 |
if (curView && curView->type() == "webView" && pageController->contentsYPos() > 0) |
|
324 |
m_chrome->layout()->slideView(-100); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
325 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
326 |
++m_pendingClearCalls; |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
327 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
328 |
QTimer::singleShot(500, this, SLOT(clearProgress())); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
329 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
330 |
|
3 | 331 |
void GUrlSearchItem::setPageCreated() |
332 |
{ |
|
333 |
// remove slideview(100) since the new transition for the code-driven window |
|
334 |
//m_chrome->layout()->slideView(100); |
|
335 |
} |
|
336 |
||
337 |
void GUrlSearchItem::setPageChanged() |
|
338 |
{ |
|
339 |
m_urlSearchEditor->setText(formattedUrl()); |
|
340 |
updateUrlSearchBtn(); |
|
341 |
||
342 |
WebPageController * pageController = WebPageController::getSingleton(); |
|
343 |
int progress = pageController->loadProgressValue(); |
|
344 |
if (progress == 100) |
|
345 |
m_urlSearchEditor->removeFocus(); |
|
346 |
} |
|
347 |
||
348 |
void GUrlSearchItem::clearProgress() |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
349 |
{ |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
350 |
--m_pendingClearCalls; |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
351 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
352 |
if (m_pendingClearCalls > 0) { |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
353 |
return; |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
354 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
355 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
356 |
WebPageController * pageController = WebPageController::getSingleton(); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
357 |
if (pageController->isPageLoading()) { |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
358 |
return; |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
359 |
} |
3 | 360 |
m_urlSearchEditor->setProgress(0); |
361 |
updateUrlSearchBtn(); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
362 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
363 |
|
3 | 364 |
void GUrlSearchItem::viewChanged() |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
365 |
{ |
3 | 366 |
ViewController * viewController = m_chrome->viewController(); |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
367 |
WebPageController * pageController = WebPageController::getSingleton(); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
368 |
|
3 | 369 |
ControllableViewBase* curView = viewController->currentView(); |
370 |
GWebContentView * gView = qobject_cast<GWebContentView*> (curView); |
|
371 |
bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false; |
|
372 |
||
373 |
// view changes to web content view |
|
374 |
if (curView && curView->type() == "webView" && !isSuperPage) { |
|
375 |
int progress = pageController->loadProgressValue(); |
|
376 |
if (progress >= 100) |
|
377 |
progress = 0; |
|
378 |
m_urlSearchEditor->setProgress(progress); |
|
379 |
updateUrlSearchBtn(); |
|
380 |
||
381 |
// place focus in urlsearch bar when returning from adding a new window in windows view |
|
382 |
if (pageController->loadText() == "") { |
|
383 |
if (m_backFromNewWinTrans ) { |
|
384 |
m_backFromNewWinTrans = false; |
|
385 |
WebPageController * pageController = WebPageController::getSingleton(); |
|
386 |
m_urlSearchEditor->setText(pageController->currentRequestedUrl()); |
|
387 |
} |
|
388 |
else { |
|
389 |
m_urlSearchEditor->grabFocus(); |
|
390 |
} |
|
391 |
} |
|
392 |
if (!isSuperPage && (pageController->contentsYPos() <= 0 || pageController->isPageLoading())){ |
|
393 |
m_chrome->layout()->slideView(100); |
|
394 |
} else { |
|
395 |
m_chrome->layout()->slideView(-100); |
|
396 |
} |
|
397 |
m_backFromNewWinTrans = false; |
|
398 |
} else { |
|
399 |
pageController->urlTextChanged(m_urlSearchEditor->text()); |
|
400 |
// Remove progress bar |
|
401 |
// incorrect values are not seen before we can update when we come back |
|
402 |
m_urlSearchEditor->setProgress(0); |
|
403 |
m_chrome->layout()->slideView(-100); |
|
404 |
} |
|
405 |
} |
|
406 |
||
407 |
void GUrlSearchItem::urlSearchActivatedByEnterKey() |
|
408 |
{ |
|
409 |
m_urlSearchEditor->removeFocus(); |
|
410 |
urlSearchActivated(); |
|
411 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
412 |
|
3 | 413 |
void GUrlSearchItem::urlSearchActivated() |
414 |
{ |
|
415 |
WebPageController * pageController = WebPageController::getSingleton(); |
|
416 |
switch (pageController->loadState()) { |
|
417 |
case WRT::LoadController::GotoModeLoading: |
|
418 |
pageController->currentStop(); |
|
419 |
++m_pendingClearCalls; |
|
420 |
QTimer::singleShot(500, this, SLOT(clearProgress())); |
|
421 |
break; |
|
422 |
case WRT::LoadController::GotoModeEditing: |
|
423 |
loadToMainWindow(); |
|
424 |
break; |
|
425 |
case WRT::LoadController::GotoModeReloadable: |
|
426 |
if (pageController->currentDocUrl() == m_urlSearchEditor->text()) |
|
427 |
pageController->currentReload(); |
|
428 |
else |
|
429 |
loadToMainWindow(); |
|
430 |
break; |
|
431 |
default: |
|
432 |
qDebug() << "Incorrect state"; |
|
433 |
break; |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
434 |
} |
3 | 435 |
updateUrlSearchBtn(); |
436 |
} |
|
437 |
||
438 |
void GUrlSearchItem::updateUrlSearchBtn() |
|
439 |
{ |
|
440 |
WebPageController * pageController = WebPageController::getSingleton(); |
|
441 |
switch (pageController->loadState()) { |
|
442 |
case WRT::LoadController::GotoModeLoading: |
|
443 |
m_urlSearchBtn->addIcon(STOP_BUTTON_ICON); |
|
444 |
break; |
|
445 |
case WRT::LoadController::GotoModeEditing: |
|
446 |
m_urlSearchBtn->addIcon(GO_BUTTON_ICON); |
|
447 |
break; |
|
448 |
case WRT::LoadController::GotoModeReloadable: |
|
449 |
m_urlSearchBtn->addIcon(REFRESH_BUTTON_ICON); |
|
450 |
break; |
|
451 |
default: |
|
452 |
qDebug() << "Incorrect state"; |
|
453 |
break; |
|
454 |
} |
|
455 |
m_urlSearchBtn->update(); |
|
456 |
||
457 |
// notify suggest object of changes in load state |
|
458 |
PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId")); |
|
459 |
if (suggestSnippet) { |
|
460 |
QString cmd = "searchSuggests.updateLoadState();"; |
|
461 |
suggestSnippet->evaluateJavaScript(cmd); |
|
462 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
463 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
464 |
|
3 | 465 |
void GUrlSearchItem::loadToMainWindow() |
466 |
{ |
|
467 |
QString url = m_urlSearchEditor->text(); |
|
468 |
WebPageController * pageController = WebPageController::getSingleton(); |
|
469 |
QString gotourl = pageController->guessUrlFromString(url); |
|
470 |
m_urlSearchEditor->setText(gotourl); |
|
471 |
pageController->currentLoad(gotourl); |
|
472 |
pageController->urlTextChanged(gotourl); |
|
473 |
} |
|
474 |
||
475 |
void GUrlSearchItem::updateLoadState() |
|
476 |
{ |
|
477 |
WebPageController * pageController = WebPageController::getSingleton(); |
|
478 |
if (pageController->loadState() == WRT::LoadController::GotoModeReloadable) { |
|
479 |
pageController->setLoadState(WRT::LoadController::GotoModeEditing); |
|
480 |
updateUrlSearchBtn(); |
|
481 |
} |
|
482 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
483 |
|
3 | 484 |
void GUrlSearchItem::updateLoadStateAndSuggest() |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
485 |
{ |
3 | 486 |
updateLoadState(); |
487 |
PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId")); |
|
488 |
if (suggestSnippet) { |
|
489 |
QString cmd = "searchSuggests.updateUserInput();"; |
|
490 |
suggestSnippet->evaluateJavaScript(cmd); |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
void GUrlSearchItem::tapped(QPointF& pos) |
|
495 |
{ |
|
496 |
bool hitText = m_urlSearchEditor->tappedOnText(pos.x()); |
|
497 |
if (!m_justFocusIn && !hitText) |
|
498 |
m_urlSearchEditor->unselect(); |
|
499 |
||
500 |
if (m_justFocusIn) { |
|
501 |
m_justFocusIn = false; |
|
502 |
if (hitText && !m_urlSearchEditor->hasSelection()) |
|
503 |
m_urlSearchEditor->selectAll(); |
|
504 |
} |
|
505 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
506 |
|
3 | 507 |
void GUrlSearchItem::focusChanged(bool focusIn) |
508 |
{ |
|
509 |
if (focusIn) |
|
510 |
m_justFocusIn = true; |
|
511 |
else { |
|
512 |
m_justFocusIn = false; |
|
513 |
m_urlSearchEditor->unselect(); |
|
514 |
m_urlSearchEditor->shiftToLeftEnd(); |
|
515 |
||
516 |
// Suggestion snippet needs to know about this event. |
|
517 |
PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId")); |
|
518 |
if (suggestSnippet) { |
|
519 |
QString cmd = "searchSuggests.urlSearchLostFocus();"; |
|
520 |
suggestSnippet->evaluateJavaScript(cmd); |
|
521 |
} |
|
522 |
} |
|
523 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
524 |
|
3 | 525 |
void GUrlSearchItem::resize() |
526 |
{ |
|
527 |
QWebElement we = m_snippet->element(); |
|
528 |
QRectF g = we.geometry(); |
|
529 |
qreal newWidth = g.width(); |
|
530 |
qreal newHeight = g.height(); |
|
531 |
QGraphicsWidget::resize(newWidth, newHeight); |
|
532 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
533 |
|
3 | 534 |
void GUrlSearchItem::onNewWindowTransitionComplete() |
535 |
{ |
|
536 |
m_backFromNewWinTrans = true; |
|
537 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
538 |
|
3 | 539 |
QString GUrlSearchItem::formattedUrl() const |
540 |
{ |
|
541 |
WebPageController * pageController = WebPageController::getSingleton(); |
|
542 |
QString url = pageController->loadText(); |
|
543 |
// for first load of the windows restored from last session |
|
544 |
if (url.isEmpty()&& pageController->currentDocUrl().isEmpty()) { |
|
545 |
QWebHistoryItem item = pageController->currentPage()->history()->currentItem(); |
|
546 |
url = item.url().toString(); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
547 |
} |
3 | 548 |
return url.replace(" ","+"); |
549 |
} |
|
550 |
||
551 |
GUrlSearchSnippet::GUrlSearchSnippet(const QString & elementId, ChromeWidget * chrome, |
|
552 |
QGraphicsWidget * widget, const QWebElement & element) |
|
553 |
: ChromeSnippet(elementId, chrome, widget, element) |
|
554 |
{ |
|
555 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
556 |
|
3 | 557 |
GUrlSearchSnippet * GUrlSearchSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element) |
558 |
{ |
|
559 |
GUrlSearchSnippet* that = new GUrlSearchSnippet(elementId, chrome, 0, element); |
|
560 |
that->setChromeWidget( new GUrlSearchItem( that, chrome ) ); |
|
561 |
return that; |
|
562 |
} |
|
563 |
||
564 |
inline GUrlSearchItem* GUrlSearchSnippet::urlSearchItem() |
|
565 |
{ |
|
566 |
return static_cast<GUrlSearchItem *>(widget()); |
|
567 |
} |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
568 |
|
3 | 569 |
inline GUrlSearchItem const * GUrlSearchSnippet::constUrlSearchItem() const |
570 |
{ |
|
571 |
return static_cast<GUrlSearchItem const *>(constWidget()); |
|
572 |
} |
|
573 |
||
574 |
QString GUrlSearchSnippet::url() const |
|
575 |
{ |
|
576 |
return constUrlSearchItem()->url(); |
|
577 |
} |
|
578 |
||
579 |
void GUrlSearchSnippet::setUrl(const QString &url) |
|
580 |
{ |
|
581 |
urlSearchItem()->setUrl(url); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
582 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
583 |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
584 |
} // namespace GVA |