@@ -64,7 +64,7 @@ class CefBrowser(Widget):
6464 # Keyboard mode: "global" or "local".
6565 # 1. Global mode forwards keys to CEF all the time.
6666 # 2. Local mode forwards keys to CEF only when an editable
67- # control is focused (input type=text or textarea).
67+ # control is focused (input type=text|password or textarea).
6868 keyboard_mode = "global"
6969
7070 '''Represent a browser widget for kivy, which can be used like a normal widget.
@@ -208,9 +208,25 @@ def set_js_bindings(self):
208208
209209
210210 def change_url (self , * kwargs ):
211- self .browser .Navigate ("http://www.google.com/" )
212- self ._client_handler ._reset_js_bindings = True
211+ # Doing a javascript redirect instead of Navigate()
212+ # solves the js bindings error. The url here need to
213+ # be preceded with "http://". Calling StopLoad()
214+ # might be a good idea before making the js navigation.
215+
216+ self .browser .StopLoad ()
217+ self .browser .GetMainFrame ().ExecuteJavascript (
218+ "window.location='http://www.youtube.com/'" )
219+
220+ # Do not use Navigate() or GetMainFrame()->LoadURL(),
221+ # as it causes the js bindings to be removed. There is
222+ # a bug in CEF, that happens after a call to Navigate().
223+ # The OnBrowserDestroyed() callback is fired and causes
224+ # the js bindings to be removed. See this topic for more
225+ # details:
226+ # http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=11009
213227
228+ # OFF:
229+ # | self.browser.Navigate("http://www.youtube.com/")
214230
215231 _keyboard = None
216232
@@ -226,13 +242,15 @@ def request_keyboard(self):
226242 self .is_ctrl2 = False
227243 self .is_alt1 = False
228244 self .is_alt2 = False
229- # Browser lost its focus after the LoadURL() and the
230- # OnBrowserDestroyed() callback bug. This will only work
231- # when keyboard mode is local.
245+ # Not sure if it is still required to send the focus
246+ # (some earlier bug), but it shouldn't hurt to call it.
232247 self .browser .SendFocusEvent (True )
233248
234249
235250 def release_keyboard (self ):
251+ # When using local keyboard mode, do all the request
252+ # and releases of the keyboard through js bindings,
253+ # otherwise some focus problems arise.
236254 self .is_shift1 = False
237255 self .is_shift2 = False
238256 self .is_ctrl1 = False
@@ -594,15 +612,6 @@ def OnLoadingStateChange(self, browser, isLoading, canGoBack,
594612 canGoForward ):
595613 print ("OnLoadingStateChange(): isLoading = %s" % isLoading )
596614 browserWidget = browser .GetUserData ("browserWidget" )
597- if self ._reset_js_bindings and not isLoading :
598- if browserWidget :
599- browserWidget .set_js_bindings ()
600- self ._reset_js_bindings = False
601- if isLoading and browserWidget \
602- and browserWidget .keyboard_mode == "local" :
603- # Release keyboard when navigating to a new page.
604- browserWidget .release_keyboard ()
605- pass
606615
607616
608617 def OnPaint (self , browser , paintElementType , dirtyRects , buffer , width ,
0 commit comments