200 @return reference to the main window |
198 @return reference to the main window |
201 @rtype WebBrowserWindow |
199 @rtype WebBrowserWindow |
202 """ |
200 """ |
203 return self.__mw |
201 return self.__mw |
204 |
202 |
205 def load(self, urlOrRequest): |
203 def load(self, url): |
206 """ |
204 """ |
207 Public method to load a web site. |
205 Public method to load a web site. |
208 |
206 |
209 @param urlOrRequest URL or request object |
207 @param url URL to be loaded |
210 @type QUrl or LoadRequest |
208 @type QUrl or LoadRequest |
211 """ |
209 """ |
212 if isinstance(urlOrRequest, QUrl): |
210 ## if isinstance(urlOrRequest, QUrl): |
213 super(WebBrowserView, self).load(urlOrRequest) |
211 super(WebBrowserView, self).load(url) |
214 |
212 |
215 if not self.__firstLoad: |
213 if not self.__firstLoad: |
216 self.__firstLoad = True |
214 self.__firstLoad = True |
217 WebInspector.pushView(self) |
215 WebInspector.pushView(self) |
218 elif isinstance(urlOrRequest, LoadRequest): |
216 ## elif isinstance(urlOrRequest, LoadRequest): |
219 reqUrl = urlOrRequest.url() |
217 ## reqUrl = urlOrRequest.url() |
220 if reqUrl.isEmpty(): |
218 ## if reqUrl.isEmpty(): |
221 return |
219 ## return |
222 |
220 ## |
223 if reqUrl.scheme() == "javascript": |
221 ## if reqUrl.scheme() == "javascript": |
224 script = reqUrl.toString()[11:] |
222 ## script = reqUrl.toString()[11:] |
225 # check if the javascript script is percent encode |
223 ## # check if the javascript script is percent encode |
226 # i.e. it contains '%' characters |
224 ## # i.e. it contains '%' characters |
227 if '%' in script: |
225 ## if '%' in script: |
228 script = QUrl.fromPercentEncoding( |
226 ## script = QUrl.fromPercentEncoding( |
229 QByteArray(script.encode("utf-8"))) |
227 ## QByteArray(script.encode("utf-8"))) |
230 self.page().runJavaScript(script) |
228 ## self.page().runJavaScript(script) |
231 return |
229 ## return |
232 |
230 ## |
233 if self.__isUrlValid(reqUrl): |
231 ## if self.__isUrlValid(reqUrl): |
234 self.loadRequest(urlOrRequest) |
232 ## self.loadRequest(urlOrRequest) |
235 return |
233 ## return |
236 |
234 ## |
237 # ensure proper loading of hosts without a '.' |
235 ## # ensure proper loading of hosts without a '.' |
238 if not reqUrl.isEmpty() and \ |
236 ## if not reqUrl.isEmpty() and \ |
239 reqUrl.scheme() and \ |
237 ## reqUrl.scheme() and \ |
240 not WebBrowserTools.containsSpace(reqUrl.path()) and \ |
238 ## not WebBrowserTools.containsSpace(reqUrl.path()) and \ |
241 '.' not in reqUrl.path(): |
239 ## '.' not in reqUrl.path(): |
242 u = QUrl("http://" + reqUrl.path()) |
240 ## u = QUrl("http://" + reqUrl.path()) |
243 if u.isValid(): |
241 ## if u.isValid(): |
244 info = QHostInfo.fromName(u.path()) |
242 ## info = QHostInfo.fromName(u.path()) |
245 if info.error() == QHostInfo.NoError: |
243 ## if info.error() == QHostInfo.NoError: |
246 req = LoadRequest(urlOrRequest) |
244 ## req = LoadRequest(urlOrRequest) |
247 req.setUrl(u) |
245 ## req.setUrl(u) |
248 self.loadRequest(req) |
246 ## self.loadRequest(req) |
249 return |
247 ## return |
250 |
248 ## |
251 def loadRequest(self, req): |
249 ## def loadRequest(self, req): |
252 """ |
250 ## """ |
253 Public method to load a page via a load request object. |
251 ## Public method to load a page via a load request object. |
254 |
252 ## |
255 @param req loaf request object |
253 ## @param req loaf request object |
256 @type LoadRequest |
254 ## @type LoadRequest |
257 """ |
255 ## """ |
258 if req.Operation == LoadRequestOperations.GetOperation: |
256 ## if req.Operation == LoadRequestOperations.GetOperation: |
259 self.load(req.url()) |
257 ## self.load(req.url()) |
260 else: |
258 ## else: |
261 self.page().runJavaScript( |
259 ## self.page().runJavaScript( |
262 Scripts.sendPostData(req.url(), req.data())) |
260 ## Scripts.sendPostData(req.url(), req.data())) |
263 |
261 |
264 # TODO: eliminate requestData, add param to get rid of __ctrlPressed |
262 # TODO: eliminate requestData, add param to get rid of __ctrlPressed |
265 def setSource(self, name, requestData=None): |
263 def setSource(self, name, requestData=None): |
266 """ |
264 """ |
267 Public method used to set the source to be displayed. |
265 Public method used to set the source to be displayed. |
502 """ |
494 """ |
503 Public slot to zoom into the page. |
495 Public slot to zoom into the page. |
504 """ |
496 """ |
505 index = self.__levelForZoom(self.__currentZoom) |
497 index = self.__levelForZoom(self.__currentZoom) |
506 if index < len(self.__zoomLevels) - 1: |
498 if index < len(self.__zoomLevels) - 1: |
507 self.__currentZoom = self.__zoomLevels[index + 1] |
499 self.setZoomValue(self.__zoomLevels[index + 1]) |
508 self.__applyZoom() |
|
509 |
500 |
510 def zoomOut(self): |
501 def zoomOut(self): |
511 """ |
502 """ |
512 Public slot to zoom out of the page. |
503 Public slot to zoom out of the page. |
513 """ |
504 """ |
514 index = self.__levelForZoom(self.__currentZoom) |
505 index = self.__levelForZoom(self.__currentZoom) |
515 if index > 0: |
506 if index > 0: |
516 self.__currentZoom = self.__zoomLevels[index - 1] |
507 self.setZoomValue(self.__zoomLevels[index - 1]) |
517 self.__applyZoom() |
|
518 |
508 |
519 def zoomReset(self): |
509 def zoomReset(self): |
520 """ |
510 """ |
521 Public method to reset the zoom factor. |
511 Public method to reset the zoom factor. |
522 """ |
512 """ |
523 index = self.__levelForZoom(WebBrowserView.ZoomLevelDefault) |
513 index = self.__levelForZoom(WebBrowserView.ZoomLevelDefault) |
524 self.__currentZoom = self.__zoomLevels[index] |
514 self.setZoomValue(self.__zoomLevels[index]) |
525 self.__applyZoom() |
|
526 |
515 |
527 def hasSelection(self): |
516 def hasSelection(self): |
528 """ |
517 """ |
529 Public method to determine, if there is some text selected. |
518 Public method to determine, if there is some text selected. |
530 |
519 |