1 /* |
|
2 * Copyright (c) 2009 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 |
|
19 #include "webnavigation.h" |
|
20 #include "qwebpage.h" |
|
21 #include "qwebframe.h" |
|
22 #include "webtouchnavigation.h" |
|
23 #include "webcursornavigation.h" |
|
24 #include "webhtmltabbednavigation.h" |
|
25 #include "webdirectionalnavigation.h" |
|
26 |
|
27 namespace WRT { |
|
28 |
|
29 /*! |
|
30 \class WebNavigation |
|
31 \since cwrt 1.0 |
|
32 \brief cwrt navigation. |
|
33 |
|
34 \sa WebTouchNavigation, WebCursorNavigation, WebDirectionalNavigation, WebHtmlTabIndexedNavigation |
|
35 */ |
|
36 WebNavigation::WebNavigation(QWebPage* webPage,QObject* view) : m_webPage(webPage) |
|
37 , m_view(view) |
|
38 , m_webTouchNavigation(0) |
|
39 , m_webCursorNavigation(0) |
|
40 , m_webDirectionalNavigation(0) |
|
41 , m_webHtmlTabIndexNavigation(0) |
|
42 { |
|
43 m_webPage->settings()->setUserStyleSheetUrl(QUrl("data:text/css;charset=utf-8;base64," \ |
|
44 + QByteArray("textarea:hover, textarea:focus { " \ |
|
45 " outline: auto; " \ |
|
46 " outline-style: solid; " \ |
|
47 " outline-color: rgb(140,140,255); " \ |
|
48 " outline-width: 2px; " \ |
|
49 "} " \ |
|
50 "select:hover, " \ |
|
51 "select[multiple]:hover, " \ |
|
52 "select:focus, " \ |
|
53 "select[multiple]:focus { " \ |
|
54 " outline: auto; " \ |
|
55 " outline-style: solid; " \ |
|
56 " outline-color: rgb(140,140,255); " \ |
|
57 " outline-width: 2px; " \ |
|
58 "} " \ |
|
59 "input:hover, input:focus { " \ |
|
60 " outline: auto; " \ |
|
61 " outline-style: solid; " \ |
|
62 " outline-color: rgb(140,140,255); " \ |
|
63 " outline-width: 2px; " \ |
|
64 "} " \ |
|
65 "object:hover, object:focus { " \ |
|
66 " outline: auto; " \ |
|
67 " outline-style: solid; " \ |
|
68 " outline-color: rgb(140,140,255); " \ |
|
69 " outline-width: 2px; " \ |
|
70 "} " \ |
|
71 "input:disabled, select:disabled, textarea:disabled { " \ |
|
72 " outline: none; " \ |
|
73 "} " \ |
|
74 "a:-webkit-any-link { " \ |
|
75 " padding: 1px 2px; " \ |
|
76 "} " \ |
|
77 "a:-webkit-any-link:visited { " \ |
|
78 " color: red; " \ |
|
79 "} " \ |
|
80 "a:-webkit-any-link:active { " \ |
|
81 " background-color: lightgray; " \ |
|
82 " -webkit-border-radius: 3px; " \ |
|
83 " text-decoration: none; " \ |
|
84 "} " \ |
|
85 "a:-webkit-any-link:focus { " \ |
|
86 " background-color: lightgray; " \ |
|
87 " -webkit-border-radius: 3px; " \ |
|
88 " text-decoration: none; " \ |
|
89 "} ").toBase64())); |
|
90 |
|
91 |
|
92 setNavigationMode(); |
|
93 connect(m_webPage->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(setNavigationMode())); |
|
94 connect(this, SIGNAL(longPressEvent()), m_webPage,SIGNAL(longPressEvent())); |
|
95 connect(this,SIGNAL(focusElementChanged(wrtBrowserDefs::BrowserElementType &)), |
|
96 m_webPage,SLOT(setElementType(wrtBrowserDefs::BrowserElementType &))); |
|
97 connect(this, SIGNAL(pageScrollPositionZero()), m_webPage, SIGNAL(pageScrollPositionZero())); |
|
98 |
|
99 } |
|
100 |
|
101 /*! |
|
102 */ |
|
103 WebNavigation::~WebNavigation() |
|
104 { |
|
105 delete m_webTouchNavigation; |
|
106 delete m_webCursorNavigation; |
|
107 delete m_webDirectionalNavigation; |
|
108 delete m_webHtmlTabIndexNavigation; |
|
109 } |
|
110 |
|
111 void WebNavigation::setPage(QWebPage * page) { |
|
112 |
|
113 m_webPage = page; |
|
114 if (m_webTouchNavigation) |
|
115 m_webTouchNavigation->setPage(page); |
|
116 if (m_webCursorNavigation) |
|
117 m_webCursorNavigation->setPage(page); |
|
118 if (m_webDirectionalNavigation) |
|
119 m_webDirectionalNavigation->setPage(page); |
|
120 if (m_webHtmlTabIndexNavigation) |
|
121 m_webHtmlTabIndexNavigation->setPage(page); |
|
122 } |
|
123 |
|
124 /*! |
|
125 Sets the navigation mode |
|
126 */ |
|
127 void WebNavigation::setNavigationMode() |
|
128 { |
|
129 if (!m_webPage) |
|
130 return; |
|
131 |
|
132 if (!m_view) |
|
133 return; |
|
134 |
|
135 if (m_webTouchNavigation) |
|
136 m_webTouchNavigation->uninstall(); |
|
137 if (m_webCursorNavigation) |
|
138 m_webCursorNavigation->uninstall(); |
|
139 if (m_webDirectionalNavigation) |
|
140 m_webDirectionalNavigation->uninstall(); |
|
141 if (m_webHtmlTabIndexNavigation) |
|
142 m_webHtmlTabIndexNavigation->uninstall(); |
|
143 |
|
144 QWebFrame* webFrame = m_webPage->currentFrame(); |
|
145 if (webFrame) { |
|
146 QMultiMap<QString, QString> map = webFrame->metaData(); |
|
147 if (map.value("touchnavigation") != "off" && map.value("navigation") != "none") { |
|
148 if (!m_webTouchNavigation) { |
|
149 m_webTouchNavigation = new WebTouchNavigation(m_webPage,m_view); |
|
150 connect( (const QObject*)(m_webTouchNavigation),SIGNAL(longPressEvent()),this,SIGNAL(longPressEvent())); |
|
151 connect((const QObject*)(m_webTouchNavigation), SIGNAL(focusElementChanged(wrtBrowserDefs::BrowserElementType &)), |
|
152 this, SIGNAL(focusElementChanged(wrtBrowserDefs::BrowserElementType &))); |
|
153 connect( (const QObject*)(m_webTouchNavigation),SIGNAL(pageScrollPositionZero()),this,SIGNAL(pageScrollPositionZero())); |
|
154 |
|
155 } |
|
156 else |
|
157 m_webTouchNavigation->install(); |
|
158 } |
|
159 |
|
160 // Enable key navigation, browser does not depend on meta data for navigation |
|
161 if (!m_webDirectionalNavigation) { |
|
162 m_webDirectionalNavigation = new WebDirectionalNavigation(m_webPage,m_view); |
|
163 connect( (const QObject*)(m_webDirectionalNavigation),SIGNAL(pageScrollPositionZero()),this,SIGNAL(pageScrollPositionZero())); |
|
164 } |
|
165 else { |
|
166 m_webDirectionalNavigation->install(); |
|
167 } |
|
168 } |
|
169 } |
|
170 |
|
171 } |
|