gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r12297: Test key events more careful


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12297: Test key events more carefully. Minor fix to event order.
Date: Mon, 12 Jul 2010 11:57:55 +0200
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12297 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2010-07-12 11:57:55 +0200
message:
  Test key events more carefully. Minor fix to event order.
  
  More cleanups of event handling.
modified:
  gui/gui.cpp
  gui/pythonmod/gnash-view.cpp
  libcore/TextField.cpp
  libcore/movie_root.cpp
  libcore/movie_root.h
  testsuite/MovieTester.cpp
  testsuite/misc-ming.all/key_event_test.c
  testsuite/misc-ming.all/key_event_testrunner.cpp
=== modified file 'gui/gui.cpp'
--- a/gui/gui.cpp       2010-07-10 09:22:49 +0000
+++ b/gui/gui.cpp       2010-07-12 07:48:07 +0000
@@ -678,7 +678,7 @@
     
     if (_stopped) return;
     
-    if (_stage->notify_key_event(k, pressed)) {
+    if (_stage->keyEvent(k, pressed)) {
         // any action triggered by the
         // event required screen refresh
         display(_stage);

=== modified file 'gui/pythonmod/gnash-view.cpp'
--- a/gui/pythonmod/gnash-view.cpp      2010-07-10 10:57:31 +0000
+++ b/gui/pythonmod/gnash-view.cpp      2010-07-12 09:57:55 +0000
@@ -320,7 +320,7 @@
     gnash::key::code c = gdk_to_gnash_key(event->keyval);
     
     if (c != gnash::key::INVALID) {
-        if( view->stage->notify_key_event(c, true) )
+        if( view->stage->keyEvent(c, true) )
             gnash_view_display(view);
         return TRUE;
     }
@@ -339,7 +339,7 @@
     gnash::key::code c = gdk_to_gnash_key(event->keyval);
     
     if (c != gnash::key::INVALID) {
-        if( view->stage->notify_key_event(c, false) )
+        if( view->stage->keyEvent(c, false) )
             gnash_view_display(view);
         return TRUE;
     }

=== modified file 'libcore/TextField.cpp'
--- a/libcore/TextField.cpp     2010-07-10 11:20:23 +0000
+++ b/libcore/TextField.cpp     2010-07-12 07:06:03 +0000
@@ -2610,10 +2610,6 @@
 
     m_has_focus = true;
 
-    // why should we add to the key listener list every time
-    // we call setFocus()???
-    stage().add_key_listener(this);
-
     m_cursor = _text.size();
     format_text();
     return true;
@@ -2629,7 +2625,6 @@
     set_invalidated();
     m_has_focus = false;
 
-    stage().remove_key_listener(this);
     format_text(); // is this needed ?
 
 }

=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp    2010-07-11 07:21:31 +0000
+++ b/libcore/movie_root.cpp    2010-07-12 07:59:56 +0000
@@ -41,6 +41,7 @@
 #include "RunResources.h"
 #include "Renderer.h"
 #include "ExternalInterface.h"
+#include "TextField.h"
 
 #include <sys/ioctl.h>
 #include <sys/types.h>
@@ -564,10 +565,8 @@
     m_viewport_height = h;
 
     if (_scaleMode == SCALEMODE_NOSCALE) {
-        //log_debug("Rescaling disabled");
         as_object* stage = getBuiltinObject(*this, NSV::CLASS_STAGE);
         if (stage) {
-            log_debug("notifying Stage listeners about a resize");
             callMethod(stage, NSV::PROP_BROADCAST_MESSAGE, "onResize");
         }
 
@@ -583,14 +582,12 @@
 
     _mouseX = x;
     _mouseY = y;
-    notify_mouse_listeners(event_id::MOUSE_MOVE);
-    return fire_mouse_event();
-
+    return notify_mouse_listeners(event_id::MOUSE_MOVE);
 }
 
 
 bool
-movie_root::notify_key_event(key::code k, bool down)
+movie_root::keyEvent(key::code k, bool down)
 {
     _lastKeyEvent = k;
     const size_t keycode = key::codeMap[k][key::KEY];
@@ -598,11 +595,27 @@
         _unreleasedKeys.set(keycode, down);
     }
 
-    // Notify DisplayObject key listeners for clip key events
-    notify_key_listeners(k, down);
-
-    // Notify both DisplayObject and non-DisplayObject Key listeners
-    //    for user defined handers.
+    Listeners copy = _keyListeners;
+
+    for (Listeners::iterator iter = copy.begin(), itEnd=copy.end();
+            iter != itEnd; ++iter) {
+
+        // sprite, button & input_edit_text DisplayObjects
+        InteractiveObject* const ch = *iter;
+        if (!ch->unloaded()) {
+            if (down) {
+                // KEY_UP and KEY_DOWN events are unrelated to any key!
+                ch->notifyEvent(event_id(event_id::KEY_DOWN, key::INVALID)); 
+                // Pass the unique Gnash key code!
+                ch->notifyEvent(event_id(event_id::KEY_PRESS, k));
+            }
+            else {
+                ch->notifyEvent(event_id(event_id::KEY_UP, key::INVALID));   
+            }
+        }
+    }
+
+    // Broadcast event to Key._listeners.
     as_object* key = getBuiltinObject(*this, NSV::CLASS_KEY);
     if (key) {
 
@@ -626,9 +639,15 @@
         }
     }
 
+    // If we're focused on an editable text field, finally the text is updated
+    if (down) {
+        TextField* tf = dynamic_cast<TextField*>(_currentFocus);
+        if (tf) tf->notifyEvent(event_id(event_id::KEY_PRESS, k));
+    }
+
     processActionQueue();
 
-    return false; // should return true if needs updatee ...
+    return false; 
 }
 
 bool
@@ -657,20 +676,15 @@
     _mouseButtonState.isDown = mouse_pressed;
 
     if (mouse_pressed) {
-        notify_mouse_listeners(event_id(event_id::MOUSE_DOWN));
-    }
-    else {
-        notify_mouse_listeners(event_id(event_id::MOUSE_UP));
-    }
-
-    return fire_mouse_event();
+        return notify_mouse_listeners(event_id(event_id::MOUSE_DOWN));
+    }
+    return notify_mouse_listeners(event_id(event_id::MOUSE_UP));
 }
 
 
 bool
 movie_root::fire_mouse_event()
 {
-//    GNASH_REPORT_FUNCTION;
 
     assert(testInvariant());
 
@@ -984,40 +998,7 @@
     renderer->end_display();
 }
 
-
-
-void
-movie_root::notify_key_listeners(key::code k, bool down)
-{
-
-    Listeners copy = _keyListeners;
-    for (Listeners::iterator iter = copy.begin(), itEnd=copy.end();
-            iter != itEnd; ++iter)
-    {
-        // sprite, button & input_edit_text DisplayObjects
-        InteractiveObject* const ch = *iter;
-        if (!ch->unloaded()) {
-            if (down) {
-                // KEY_UP and KEY_DOWN events are unrelated to any key!
-                ch->notifyEvent(event_id(event_id::KEY_DOWN, key::INVALID)); 
-                // Pass the unique Gnash key code!
-                ch->notifyEvent(event_id(event_id::KEY_PRESS, k));
-            }
-            else {
-                ch->notifyEvent(event_id(event_id::KEY_UP, key::INVALID));   
-            }
-        }
-    }
-
-    assert(testInvariant());
-
-    if (!copy.empty()) {
-        // process actions queued in the above step
-        processActionQueue();
-    }
-}
-
-void
+bool
 movie_root::notify_mouse_listeners(const event_id& event)
 {
 
@@ -1055,6 +1036,7 @@
         // process actions queued in the above step
         processActionQueue();
     }
+    return fire_mouse_event();
 }
 
 DisplayObject*
@@ -1306,7 +1288,6 @@
     if (notifyResize) {
         as_object* stage = getBuiltinObject(*this, NSV::CLASS_STAGE);
         if (stage) {
-            log_debug("notifying Stage listeners about a resize");
             callMethod(stage, NSV::PROP_BROADCAST_MESSAGE, "onResize");
         }
     }
@@ -1319,7 +1300,6 @@
 
     as_object* stage = getBuiltinObject(*this, NSV::CLASS_STAGE);
     if (stage) {
-        log_debug("notifying Stage listeners about fullscreen state");
         const bool fs = _displayState == DISPLAYSTATE_FULLSCREEN;
         callMethod(stage, NSV::PROP_BROADCAST_MESSAGE, "onFullScreen", fs);
     }

=== modified file 'libcore/movie_root.h'
--- a/libcore/movie_root.h      2010-07-11 06:43:23 +0000
+++ b/libcore/movie_root.h      2010-07-12 07:48:07 +0000
@@ -269,17 +269,12 @@
     /// This currently also change the display scale
     /// but we should instead only do it if rescaling
     /// is allowed.
-    ///
     void set_display_viewport(int x0, int y0, int w, int h);
 
-    /// \brief
-    /// Return the notional width of the stage, value depending
-    /// on scaleMode
+    /// Notional width of the stage, actual value depending on scaleMode
     unsigned getStageWidth() const;
 
-    /// \brief
-    /// Return the notional height of the stage, actual value depending
-    /// on scaleMode
+    /// Notional height of the stage, actual value depending on scaleMode
     unsigned getStageHeight() const;
 
     /// Inform the Stage that the mouse has moved.
@@ -292,13 +287,13 @@
     ///
     /// TODO: take twips (or float pixels), or we won't be able to
     ///       support sub-pixel accuracy in collision detection.
-    bool mouseMoved(boost::int32_t x, boost::int32_t y);
+    DSOEXPORT bool mouseMoved(boost::int32_t x, boost::int32_t y);
 
     /// Inform the Stage that a mouse click has occurred.
     //
     /// @param press    true for a mouse click, false for a release
     /// @return         true if any action triggered requires a redraw.
-    bool mouseClick(bool press);
+    DSOEXPORT bool mouseClick(bool press);
 
     /// Inform the Stage that a mouse wheel has moved.
     //
@@ -306,17 +301,14 @@
     ///                 for down. Although values from about -3 to 3 are
     ///                 documented, only -1 and 1 have been observed.
     /// @return         true if any action triggered requires a redraw.
-    bool mouseWheel(int delta);
+    DSOEXPORT bool mouseWheel(int delta);
 
-    /// \brief
-    /// The host app can use this to tell the movie when
-    /// user pressed or released a key.
+    /// Tell the movie when the user pressed or released a key.
     //
-    /// This function should return TRUE iff any action triggered
+    /// This function should return TRUE if any action triggered
     /// by the event requires redraw, see \ref events_handling for
     /// more info.
-    ///
-    bool notify_key_event(key::code k, bool down);
+    DSOEXPORT bool keyEvent(key::code k, bool down);
 
     /// Use this to retrieve the last state of the mouse.
     //
@@ -464,18 +456,12 @@
     /// Get a unique number for unnamed instances.
     size_t nextUnnamedInstance();
 
-    /// Notify still loaded DisplayObject listeners for key events
-    DSOEXPORT void notify_key_listeners(key::code k, bool down);
-
     /// Push a new DisplayObject listener for key events
     void add_key_listener(InteractiveObject* listener);
 
     /// Remove a DisplayObject listener for key events
     void remove_key_listener(InteractiveObject* listener);
 
-    /// Notify still loaded DisplayObject listeners for mouse events
-    DSOEXPORT void notify_mouse_listeners(const event_id& event);
-
     /// Get the DisplayObject having focus
     //
     /// The DisplayObject having focus will receive mouse button
@@ -956,6 +942,14 @@
     ///
     void setRootMovie(Movie* movie);
 
+    /// Handle mouse events.
+    bool notify_mouse_listeners(const event_id& event);
+    
+    /// This function should return TRUE iff any action triggered
+    /// by the event requires redraw, see \ref events_handling for
+    /// more info.
+    bool fire_mouse_event();
+
     const RunResources& _runResources; 
 
     /// The URL of the original root movie.
@@ -994,11 +988,6 @@
 
     /// Cleanup references to unloaded DisplayObjects and run the GC.
     void cleanupAndCollect();
-    
-    /// This function should return TRUE iff any action triggered
-    /// by the event requires redraw, see \ref events_handling for
-    /// more info.
-    bool fire_mouse_event();
 
     /// \brief
     /// Return the topmost entity covering the given point

=== modified file 'testsuite/MovieTester.cpp'
--- a/testsuite/MovieTester.cpp 2010-07-11 06:16:06 +0000
+++ b/testsuite/MovieTester.cpp 2010-07-12 07:48:07 +0000
@@ -431,7 +431,7 @@
 void
 MovieTester::pressKey(key::code code)
 {
-    if ( _movie_root->notify_key_event(code, true) ) {
+    if ( _movie_root->keyEvent(code, true) ) {
        render();
     }
 }
@@ -439,7 +439,7 @@
 void
 MovieTester::releaseKey(key::code code)
 {
-    if ( _movie_root->notify_key_event(code, false) ) {
+    if ( _movie_root->keyEvent(code, false) ) {
        render();
     }
 }

=== modified file 'testsuite/misc-ming.all/key_event_test.c'
--- a/testsuite/misc-ming.all/key_event_test.c  2010-01-01 17:48:26 +0000
+++ b/testsuite/misc-ming.all/key_event_test.c  2010-07-12 07:05:17 +0000
@@ -322,8 +322,29 @@
   SWFMovie_nextFrame(mo);  // _root frame22
  
   check_equals(mo, "test5", 
"'0+ls3+ls2+ls1+obj1+ls1+obj2+ls2+obj3+obj1+obj2+obj3'");
+
+  add_actions(mo,
+     "o = new Object();"
+     "_root.t = '';"
+     "o.onKeyDown = function() { t = _root.ff.text; play(); };"
+     "Key.addListener(o);"
+     "_root.createTextField('ff', 987, 300, 20, 200, 40);"
+     "_root.ff.type = 'input';"
+     "_root.ff.text = 'Input here';"
+     "_root.ff.border = true;"
+    "_root.note('10. Click on the TextField and type \"i\"');"
+    "stop();"
+  );
+  
+  SWFMovie_nextFrame(mo);  // _root frame23
+
+  // The listener is called before text is updated!
+  check_equals(mo, "_root.t", "'Input here'");
+  check_equals(mo, "_root.ff.text", "'Input herei'");
+
+
   add_actions(mo, "totals(); stop();");
-  SWFMovie_nextFrame(mo);  // _root frame23
+  SWFMovie_nextFrame(mo);  // _root frame24
   //Output movie
   puts("Saving " OUTPUT_FILENAME );
   SWFMovie_save(mo, OUTPUT_FILENAME);

=== modified file 'testsuite/misc-ming.all/key_event_testrunner.cpp'
--- a/testsuite/misc-ming.all/key_event_testrunner.cpp  2010-01-01 17:48:26 
+0000
+++ b/testsuite/misc-ming.all/key_event_testrunner.cpp  2010-07-12 07:05:17 
+0000
@@ -46,7 +46,7 @@
   MovieClip* root = tester.getRootMovie();
   assert(root);
 
-  check_equals(root->get_frame_count(), 23);
+  check_equals(root->get_frame_count(), 24);
   check_equals(root->get_current_frame(), 0);
 
   tester.advance();
@@ -180,6 +180,14 @@
   tester.releaseKey(key::K);
   tester.advance();
 
+  // Select the text field
+  tester.movePointerTo(310, 25);
+  tester.click();
+
+  // Enter 'i'
+  tester.pressKey(key::i);
+  tester.advance();
+
   // reached frame23, test finished
-  check_equals(root->get_current_frame(), 22);
+  check_equals(root->get_current_frame(), 23);
 }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]