gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11605: Various cleanups after Displ


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11605: Various cleanups after DisplayObject separation.
Date: Fri, 06 Nov 2009 11:06:10 +0100
User-agent: Bazaar (1.16.1)

------------------------------------------------------------
revno: 11605 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2009-11-06 11:06:10 +0100
message:
  Various cleanups after DisplayObject separation.
modified:
  libcore/DisplayList.cpp
  libcore/DisplayObject.cpp
  libcore/DisplayObject.h
  libcore/MovieClip.cpp
  libcore/MovieClip.h
  libcore/TextField.cpp
  libcore/as_environment.cpp
  libcore/as_object.h
  libcore/asobj/flash/display/DisplayObjectContainer_as.cpp
  libcore/asobj/flash/media/Sound_as.cpp
  libcore/event_id.h
  libcore/movie_root.cpp
  libcore/movie_root.h
  libcore/swf_function.cpp
  libcore/vm/action.cpp
=== modified file 'libcore/DisplayList.cpp'
--- a/libcore/DisplayList.cpp   2009-11-04 13:37:17 +0000
+++ b/libcore/DisplayList.cpp   2009-11-06 09:07:36 +0000
@@ -299,7 +299,7 @@
 
         if (use_old_matrix) {
             // Use the SWFMatrix from the old DisplayObject.
-            ch->copyMatrix(*oldch); // copy SWFMatrix and caches
+            ch->setMatrix(oldch->getMatrix(), true); 
         }
         
         // remember bounds of old char
@@ -961,7 +961,7 @@
                     // replace the transformation SWFMatrix if the old
                     // DisplayObject accepts static transformation.
                     if (chOld->get_accept_anim_moves()) {
-                        chOld->copyMatrix(*chNew); // copy SWFMatrix and 
caches 
+                        chOld->setMatrix(chNew->getMatrix(), true); 
                         chOld->set_cxform(chNew->get_cxform());
                     }
                     chNew->unload();

=== modified file 'libcore/DisplayObject.cpp'
--- a/libcore/DisplayObject.cpp 2009-11-04 15:03:15 +0000
+++ b/libcore/DisplayObject.cpp 2009-11-06 09:07:36 +0000
@@ -247,11 +247,6 @@
        m_old_invalidated_ranges.add(ranges);
 }
 
-void
-attachDisplayObjectProperties(as_object& /*o*/)
-{
-}
-
 as_value
 DisplayObject::blendMode(const fn_call& fn)
 {
@@ -394,15 +389,6 @@
 }
 
 void
-DisplayObject::copyMatrix(const DisplayObject& c)
-{
-       m_matrix = c.m_matrix;
-       _xscale = c._xscale;
-       _yscale = c._yscale;
-       _rotation = c._rotation;
-}
-
-void
 DisplayObject::setMatrix(const SWFMatrix& m, bool updateCache)
 {
 
@@ -760,6 +746,30 @@
        if (_maskee) _maskee->setReachable();
 }
 
+/// Whether to use a hand cursor when the mouse is over this DisplayObject
+//
+/// This depends on the useHandCursor AS property, but:
+/// 1. Only AS-referenceable objects may use a hand cursor (TODO: check
+///    Video).
+/// 2. Only objects with a release event may use a hand cursor.
+/// 3. The default value (if the property is not defined) is true.
+bool
+DisplayObject::allowHandCursor() const
+{
+    if (!getObject(this)) return false;
+
+    if (!hasEventHandler(event_id::RELEASE)) return false;
+
+    as_value val;
+    // const_cast needed due to get_member being non-const due to the 
+    // possibility that a getter-setter would actually modify us ...
+    if (!getObject(const_cast<DisplayObject*>(this))->get_member(
+                NSV::PROP_USEHANDCURSOR, &val)) {
+         return true;
+    }
+    return val.to_bool();
+}
+
 void
 DisplayObject::setMask(DisplayObject* mask)
 {

=== modified file 'libcore/DisplayObject.h'
--- a/libcore/DisplayObject.h   2009-11-04 15:03:15 +0000
+++ b/libcore/DisplayObject.h   2009-11-06 08:44:44 +0000
@@ -63,17 +63,16 @@
 /// Returns true if the DisplayObject is referenceable in ActionScript
 //
 /// A DisplayObject is referenceable if it has an associated object.
-bool isReferenceable(DisplayObject& d);
-
-/// Attaches common DisplayObject properties such as _height, _x, _visible
-//
-/// This should be called by DisplayObject subclasses to ensure that
-/// the correct properties are attached.
-void attachDisplayObjectProperties(as_object& o);
+bool isReferenceable(const DisplayObject& d);
 
 /// Set special properties
 //
 /// This sets the magic properties of DisplayObjects.
+//
+/// @param key      The string table key of the property to set.
+/// @param obj      The DisplayObject whose property should be set
+/// @param val      An as_value representing the new value of the property.
+///                 Some values may be rejected.
 bool setDisplayObjectProperty(DisplayObject& obj, string_table::key key,
         const as_value& val);
 
@@ -81,19 +80,38 @@
 //
 /// This gets the magic properties of DisplayObjects and handles special
 /// MovieClip properties such as DisplayList members.
+//
+/// @param key      The string table key of the property to get.
+/// @param obj      The DisplayObject whose property should be got
+/// @param val      An as_value to be set to the value of the property.
 bool getDisplayObjectProperty(DisplayObject& obj, string_table::key key,
         as_value& val);
 
 /// Get a property by its numeric index.
 //
-/// By ASHandlers to get the DisplayObject properties indexed by number
+/// Used by ASHandlers to get the DisplayObject properties indexed by number
+//
+/// @param index    The index of the property to get.
+/// @param o        The DisplayObject whose property should be got
+/// @param val      An as_value to be set to the value of the property.
 void getIndexedProperty(size_t index, DisplayObject& o, as_value& val);
 
 /// Set a property by its numeric index.
 //
-/// By ASHandlers to set the DisplayObject properties indexed by number
+/// Used by ASHandlers to set the DisplayObject properties indexed by number
+//
+/// @param index    The index of the property to set.
+/// @param o        The DisplayObject whose property should be set
+/// @param val      An as_value representing the new value of the property.
+///                 Some values may be rejected.
 void setIndexedProperty(size_t index, DisplayObject& o, const as_value& val);
 
+/// Copy SWFMatrix and caches from given DisplayObjecta
+//
+/// @param from     The DisplayObject to copy from
+/// @param to       The DisplayObject to copy to.
+void copyMatrix(const DisplayObject& from, DisplayObject& to);
+
 /// DisplayObject is the base class for all DisplayList objects.
 //
 /// It represents a single active element in a movie. This class does not
@@ -171,23 +189,11 @@
     /// So, to recap:
     ///   1:  -32769 to -16385 are removed
     ///   2:  -16384 to      0 are statics
-    ///   3:  Max depth for a PlaceoObject call is 16384 (which becomes 
+    ///   3:  Max depth for a PlaceObject call is 16384 (which becomes 
     ///       0 in the statics)
     /// (all of the above correct?)
     static const int removedDepthOffset = -32769; 
 
-    /// Return true if the given depth is in the removed zone
-    static bool depthInRemovedZone(int depth)
-    {
-        return depth < staticDepthOffset;
-    }
-
-    /// Return true if this DisplayObject's depth is in the removed zone
-    bool depthInRemovedZone()
-    {
-        return depthInRemovedZone(get_depth());
-    }
-    
     /// This value is used for m_clip_depth when 
     /// the DisplayObject is not a layer mask.
     //
@@ -282,9 +288,6 @@
     ///
     void set_x_scale(double factor);
 
-    /// Copy SWFMatrix and caches from given DisplayObject
-    void copyMatrix(const DisplayObject& ch);
-
     /// Set the yscale value of current SWFMatrix
     //
     /// This is used when setting _yscale 
@@ -388,18 +391,12 @@
         return (_maskee);
     }
 
-    DisplayObject* toDisplayObject() { return this; }
-
     /// Return the DisplayObject masking this instance (if any)
     DisplayObject* getMask() const
     {
-        if ( ! _mask ) return NULL;
-        if ( _mask->_maskee != this )
-        {
-            // TODO: fix this !
-            log_error("Our mask maskee is not us");
-            return NULL; 
-        }
+#if GNASH_PARANOIA_LEVEL > 1
+        if (_mask) assert(_mask->_maskee == this);
+#endif
         return _mask;
     }
 
@@ -698,20 +695,6 @@
         return 0;
     }
 
-    /// Returns the closest as-referenceable ancestor
-    DisplayObject* getClosestASReferenceableAncestor() 
-    {
-        if (isReferenceable(*this)) return this;
-        assert(_parent);
-        return _parent->getClosestASReferenceableAncestor();
-    }
-
-    const DisplayObject* getClosestASReferenceableAncestor() const
-    {
-        DisplayObject* nonconst_this = const_cast<DisplayObject*>(this);
-        return nonconst_this->getClosestASReferenceableAncestor();
-    }
-
     /// @}
 
     /// \brief
@@ -890,7 +873,7 @@
     /// Return true if this DisplayObject allows turning the cursor
     /// into an hand shape when it happens to be the one receiving
     /// mouse events.
-    virtual bool allowHandCursor() const { return true; }
+    bool allowHandCursor() const;
 
 #ifdef USE_SWFTREE
     typedef std::pair<std::string, std::string> StringPair; 
@@ -1153,7 +1136,7 @@
 };
 
 inline bool
-isReferenceable(DisplayObject& d)
+isReferenceable(const DisplayObject& d)
 {
     return d.object();
 }
@@ -1164,7 +1147,7 @@
 /// @return     null if either the DisplayObject or the associated object is
 ///             null. Otherwise the associated object.
 inline as_object*
-getObject(DisplayObject* d)
+getObject(const DisplayObject* d)
 {
     return d ? d->object() : 0;
 }

=== modified file 'libcore/MovieClip.cpp'
--- a/libcore/MovieClip.cpp     2009-11-04 20:39:35 +0000
+++ b/libcore/MovieClip.cpp     2009-11-06 09:07:36 +0000
@@ -374,41 +374,6 @@
     SWFRect& _bounds;
 };
 
-/// A DisplayList visitor used to extract script DisplayObjects
-//
-/// Script DisplayObjects are DisplayObjects created or transformed
-/// by ActionScript. 
-///
-class ScriptObjectsFinder
-{
-public:
-    ScriptObjectsFinder(std::vector<DisplayObject*>& dynamicChars,
-            std::vector<DisplayObject*>& staticChars)
-        :
-        _dynamicChars(dynamicChars),
-        _staticChars(staticChars)
-    {}
-
-    void operator() (DisplayObject* ch) {
-        // don't include bounds of unloaded DisplayObjects
-        if ( ch->unloaded() ) return;
-
-        // TODO: Are script-transformed object to be kept ?
-        //             Need a testcase for this
-        //if ( ! ch->get_accept_anim_moves() )
-        //if ( ch->isDynamic() )
-        int depth = ch->get_depth();
-        if (depth < DisplayObject::lowerAccessibleBound || depth >= 0) {
-            _dynamicChars.push_back(ch);
-        }
-        else _staticChars.push_back(ch);
-    }
-
-private:
-    std::vector<DisplayObject*>& _dynamicChars;
-    std::vector<DisplayObject*>& _staticChars;
-};
-
 } // anonymous namespace
 
 
@@ -635,7 +600,7 @@
     newmovieclip->_drawable = _drawable;
     
     newmovieclip->set_cxform(get_cxform());    
-    newmovieclip->copyMatrix(*this); // copy SWFMatrix and caches
+    newmovieclip->setMatrix(getMatrix(), true); 
     newmovieclip->set_ratio(get_ratio());    
     newmovieclip->set_clip_depth(get_clip_depth());    
     
@@ -2291,21 +2256,6 @@
     return enabled.to_bool();
 }
 
-bool
-MovieClip::allowHandCursor() const
-{
-    as_value val;
-    // const_cast needed due to get_member being non-const due to the 
-    // possibility that a getter-setter would actually modify us ...
-    if (!getObject(const_cast<MovieClip*>(this))->get_member(
-                NSV::PROP_USEHANDCURSOR, &val))
-    {
-         // true if not found..
-         return true;
-    }
-    return val.to_bool();
-}
-
 class EnumerateVisitor {
 
     as_environment& _env;

=== modified file 'libcore/MovieClip.h'
--- a/libcore/MovieClip.h       2009-11-04 17:27:42 +0000
+++ b/libcore/MovieClip.h       2009-11-06 08:44:44 +0000
@@ -797,9 +797,6 @@
     /// are disabled, and automatic tab ordering won't include it.
     bool isEnabled() const;
 
-    // See dox in DisplayObject.h
-    bool allowHandCursor() const;
-
     /// Check whether a point hits our drawable shape.
     //
     /// This is possible because the drawable does not have its own

=== modified file 'libcore/TextField.cpp'
--- a/libcore/TextField.cpp     2009-11-04 20:07:58 +0000
+++ b/libcore/TextField.cpp     2009-11-06 07:09:05 +0000
@@ -606,9 +606,9 @@
                case event_id::PRESS:
                {
                        movie_root& root = stage();
-                       
-                       int x_mouse = pixelsToTwips(root.getXMouseLoc());
-                       int y_mouse = pixelsToTwips(root.getYMouseLoc());
+            int x_mouse, y_mouse;
+            boost::int32_t buttons;
+            root.get_mouse_state(x_mouse, y_mouse, buttons);
                        
                        SWFMatrix m = getMatrix();
                        

=== modified file 'libcore/as_environment.cpp'
--- a/libcore/as_environment.cpp        2009-10-28 11:29:28 +0000
+++ b/libcore/as_environment.cpp        2009-11-06 07:54:33 +0000
@@ -565,8 +565,7 @@
 as_environment::find_target(const std::string& path_in) const
 {
     as_object* o = find_object(path_in);
-    if (o) return o->toDisplayObject(); 
-    return 0;
+    return get<DisplayObject>(o); 
 }
 
 

=== modified file 'libcore/as_object.h'
--- a/libcore/as_object.h       2009-11-04 12:23:50 +0000
+++ b/libcore/as_object.h       2009-11-06 07:54:33 +0000
@@ -810,13 +810,6 @@
     /// Cast to a as_function, or return NULL
     virtual as_function* to_function() { return NULL; }
 
-    /// Cast to a DisplayObject, or return NULL
-    DisplayObject* toDisplayObject() { return displayObject(); }
-
-    const DisplayObject* toDisplayObject() const {
-        return const_cast<as_object*>(this)->displayObject();
-    }
-
     /// Return true if this is a 'super' object
     virtual bool isSuper() const { return false; }
 

=== modified file 'libcore/asobj/flash/display/DisplayObjectContainer_as.cpp'
--- a/libcore/asobj/flash/display/DisplayObjectContainer_as.cpp 2009-10-27 
09:44:54 +0000
+++ b/libcore/asobj/flash/display/DisplayObjectContainer_as.cpp 2009-11-06 
07:54:33 +0000
@@ -145,20 +145,12 @@
     }
 
     as_object* objArg = fn.arg(0).to_object(getGlobal(fn));
-    if (!objArg) {
-        IF_VERBOSE_ASCODING_ERRORS(
-        std::stringstream ss; fn.dump_args(ss);
-        log_aserror("addChild(%s): first arg doesn't cast to an object",
-            ss.str());
-        );
-        return ret;
-    }
+    DisplayObject* ch = get<DisplayObject>(objArg);
 
-    DisplayObject* ch = objArg->toDisplayObject();
     if (!ch) {
         IF_VERBOSE_ASCODING_ERRORS(
         std::stringstream ss; fn.dump_args(ss);
-        log_aserror("addChild(%s): first arg doesn't cast to a "
+        log_aserror("addChild(%s): first arg is not a "
             "DisplayObject", ss.str());
         );
         return ret;
@@ -190,20 +182,11 @@
     }
 
     as_object* objArg = fn.arg(0).to_object(getGlobal(fn));
-    if (!objArg) {
-        IF_VERBOSE_ASCODING_ERRORS(
-        std::stringstream ss; fn.dump_args(ss);
-        log_aserror("addChildAt(%s): first arg doesn't cast to an object",
-            ss.str());
-        );
-        return ret;
-    }
-
-    DisplayObject* ch = objArg->toDisplayObject();
+    DisplayObject* ch = get<DisplayObject>(objArg);
     if (!ch) {
         IF_VERBOSE_ASCODING_ERRORS(
         std::stringstream ss; fn.dump_args(ss);
-        log_aserror("addChildAt(%s): first arg doesn't cast to a "
+        log_aserror("addChildAt(%s): first arg is not a "
             "DisplayObject", ss.str());
         );
         return ret;

=== modified file 'libcore/asobj/flash/media/Sound_as.cpp'
--- a/libcore/asobj/flash/media/Sound_as.cpp    2009-10-23 06:25:25 +0000
+++ b/libcore/asobj/flash/media/Sound_as.cpp    2009-11-06 07:54:33 +0000
@@ -811,12 +811,12 @@
         if ( ! arg0.is_null() && ! arg0.is_undefined() )
         {
             as_object* obj = arg0.to_object(getGlobal(fn));
-            DisplayObject* ch = obj ? obj->toDisplayObject() : 0;
+            DisplayObject* ch = get<DisplayObject>(obj);
             IF_VERBOSE_ASCODING_ERRORS(
             if (!ch) {
                 std::stringstream ss; fn.dump_args(ss);
                 log_aserror("new Sound(%s) : first argument isn't null "
-                    "nor undefined, and doesn't cast to a DisplayObject. "
+                    "or undefined, and isn't a DisplayObject. "
                     "We'll take as an invalid DisplayObject ref.",
                     ss.str());
             }

=== modified file 'libcore/event_id.h'
--- a/libcore/event_id.h        2009-04-03 09:48:13 +0000
+++ b/libcore/event_id.h        2009-11-06 07:15:47 +0000
@@ -60,23 +60,7 @@
         KEY_UP,
         DATA,
         
-        // These are for the MoveClipLoader ActionScript only
-        LOAD_START,
-        LOAD_ERROR,
-        LOAD_PROGRESS,
-        LOAD_INIT,
-        
-        // These are for the XMLSocket ActionScript only
-        CLOSE,
-        CONNECT,
-        XML,
-        
-        // This is for setInterval
-        TIMER,
-
         CONSTRUCT,
-        SETFOCUS,
-        KILLFOCUS,
 
         EVENT_COUNT
     };

=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp    2009-11-05 20:46:48 +0000
+++ b/libcore/movie_root.cpp    2009-11-06 07:54:33 +0000
@@ -77,9 +77,16 @@
 //
 //#define GNASH_DEBUG_DLIST_CLEANUP 1
 
-namespace gnash
-{
-
+namespace gnash {
+
+namespace {
+    bool generate_mouse_button_events(movie_root& mr, MouseButtonState& ms);
+    const DisplayObject* getNearestObject(const DisplayObject* o);
+}
+
+}
+
+namespace gnash {
 
 inline bool
 movie_root::testInvariant() const
@@ -700,120 +707,6 @@
        return fire_mouse_event();
 }
 
-// Return whether any action triggered by this event requires display redraw.
-// See page about events_handling (in movie_interface.h)
-//
-/// TODO: make this code more readable !
-bool
-movie_root::generate_mouse_button_events()
-{
-
-    MouseButtonState& ms = m_mouse_button_state;
-
-       // Did this event trigger any action that needs redisplay ?
-       bool need_redisplay = false;
-
-    // TODO: have mouseEvent return
-    // whether the action must trigger
-    // a redraw.
-
-    switch (ms.previousButtonState)
-    {
-        case MouseButtonState::DOWN:
-           {
-                   // TODO: Handle trackAsMenu dragOver
-                   // Handle onDragOut, onDragOver
-                   if (!ms.wasInsideActiveEntity) {
-
-                           if (ms.topmostEntity == ms.activeEntity) {
-
-                                   // onDragOver
-                                   if (ms.activeEntity) {
-                                           
ms.activeEntity->mouseEvent(event_id::DRAG_OVER);
-                                           need_redisplay=true;
-                                   }
-                                   ms.wasInsideActiveEntity = true;
-                           }
-                   }
-                   else if (ms.topmostEntity != ms.activeEntity) {
-                           // onDragOut
-                           if (ms.activeEntity) {
-                                   
ms.activeEntity->mouseEvent(event_id::DRAG_OUT);
-                                   need_redisplay=true;
-                           }
-                           ms.wasInsideActiveEntity = false;
-                   }
-
-                   // Handle onRelease, onReleaseOutside
-                   if (ms.currentButtonState == MouseButtonState::UP) {
-                           // Mouse button just went up.
-                           ms.previousButtonState = MouseButtonState::UP;
-
-                           if (ms.activeEntity) {
-                                   if (ms.wasInsideActiveEntity) {
-                                           // onRelease
-                                           
ms.activeEntity->mouseEvent(event_id::RELEASE);
-                                           need_redisplay = true;
-                                   }
-                                   else {
-                                           // TODO: Handle trackAsMenu 
-                                           // onReleaseOutside
-                                           
ms.activeEntity->mouseEvent(event_id::RELEASE_OUTSIDE);
-                                           // We got out of active entity
-                                           ms.activeEntity = 0; // so we don't 
get RollOut next...
-                                           need_redisplay = true;
-                                   }
-                           }
-                   }
-               return need_redisplay;
-           }
-
-           case MouseButtonState::UP:
-        {
-               // New active entity is whatever is below the mouse right now.
-               if (ms.topmostEntity != ms.activeEntity)
-               {
-                       // onRollOut
-                       if (ms.activeEntity) {
-                               ms.activeEntity->mouseEvent(event_id::ROLL_OUT);
-                               need_redisplay=true;
-                       }
-
-                       ms.activeEntity = ms.topmostEntity;
-
-                       // onRollOver
-                       if (ms.activeEntity) {
-                               
ms.activeEntity->mouseEvent(event_id::ROLL_OVER);
-                               need_redisplay=true;
-                       }
-
-                       ms.wasInsideActiveEntity = true;
-               }
-
-               // mouse button press
-               if (ms.currentButtonState == MouseButtonState::DOWN) {
-                       // onPress
-
-                // Try setting focus on the new DisplayObject. This will handle
-                // all necessary events and removal of current focus.
-                // Do not set focus to NULL.
-                if (ms.activeEntity) {
-                    setFocus(ms.activeEntity);
-
-                               ms.activeEntity->mouseEvent(event_id::PRESS);
-                               need_redisplay=true;
-                       }
-
-                       ms.wasInsideActiveEntity = true;
-                       ms.previousButtonState = MouseButtonState::DOWN;
-               }
-        }
-        default:
-           return need_redisplay;
-    }
-
-}
-
 
 bool
 movie_root::fire_mouse_event()
@@ -826,8 +719,8 @@
     boost::int32_t y = pixelsToTwips(m_mouse_y);
 
     // Generate a mouse event
-    m_mouse_button_state.topmostEntity = getTopmostMouseEntity(x, y);
-    m_mouse_button_state.currentButtonState = (m_mouse_buttons & 1);
+    _mouseButtonState.topmostEntity = getTopmostMouseEntity(x, y);
+    _mouseButtonState.currentButtonState = (m_mouse_buttons & 1);
 
     // Set _droptarget if dragging a sprite
     MovieClip* dragging = 0;
@@ -841,7 +734,7 @@
         if (dropChar)
         {
             // Use target of closest script DisplayObject containing this
-            dropChar = dropChar->getClosestASReferenceableAncestor();
+            dropChar = getNearestObject(dropChar);
             dragging->setDropTarget(dropChar->getTargetPath());
         }
         else dragging->setDropTarget("");
@@ -855,7 +748,7 @@
 
     try
     {
-        need_redraw = generate_mouse_button_events();
+        need_redraw = generate_mouse_button_events(*this, _mouseButtonState);
         processActionQueue();
     }
     catch (ActionLimitException& al)
@@ -872,10 +765,6 @@
 movie_root::get_mouse_state(boost::int32_t& x, boost::int32_t& y,
         boost::int32_t& buttons)
 {
-//         GNASH_REPORT_FUNCTION;
-
-//             log_debug ("X is %d, Y is %d, Button is %d", m_mouse_x,
-//                      m_mouse_y, m_mouse_buttons);
 
        assert(testInvariant());
 
@@ -1265,22 +1154,17 @@
                }
        }
 
-       // Now broadcast message for Mouse listeners
-       typedef as_object* ObjPtr;
-       ObjPtr mouseObj = getMouseObject();
-       if ( mouseObj )
-       {
+       as_object* mouseObj = getMouseObject();
+       if (mouseObj) {
 
-        try
-        {
+        try {
             // Can throw an action limit exception if the stack limit is 0 or 
1.
             // A stack limit like that is hardly of any use, but could be used
             // maliciously to crash Gnash.
                    mouseObj->callMethod(NSV::PROP_BROADCAST_MESSAGE, 
                     event.functionName());
                }
-           catch (ActionLimitException &e)
-           {
+           catch (ActionLimitException &e) {
             log_error(_("ActionLimits hit notifying mouse events: %s."),
                     e.what());
             clearActionQueue();
@@ -1361,7 +1245,7 @@
 DisplayObject*
 movie_root::getActiveEntityUnderPointer() const
 {
-       return m_mouse_button_state.activeEntity;
+       return _mouseButtonState.activeEntity;
 }
 
 DisplayObject*
@@ -1384,7 +1268,7 @@
 movie_root::isMouseOverActiveEntity() const
 {
        assert(testInvariant());
-    return (m_mouse_button_state.activeEntity);
+    return (_mouseButtonState.activeEntity);
 }
 
 void
@@ -1853,7 +1737,7 @@
     if ( _rootMovie ) _rootMovie->setReachable();
 
     // Mark mouse entities 
-    m_mouse_button_state.markReachableResources();
+    _mouseButtonState.markReachableResources();
     
     // Mark timer targets
     for (TimerMap::const_iterator i=_intervalTimers.begin(),
@@ -2140,7 +2024,7 @@
                if (to == std::string::npos) break;
                from = to + 1;
        }
-       return o->toDisplayObject();
+       return get<DisplayObject>(o);
 }
 
 void
@@ -2411,11 +2295,6 @@
     localIter = tr.append_child(it, StringPair("Rendered dimensions", 
os.str()));
 
 #if 0
-    /// Stage: pixel scale
-    os.str("");
-    os << m_pixel_scale;
-    localIter = tr.append_child(it, StringPair("Pixel scale", os.str()));
-
     /// Stage: scaling allowed.
     localIter = tr.append_child(it, StringPair("Scaling allowed",
                 _allowRescale ? yes : no));
@@ -2498,23 +2377,19 @@
 
     // Easy enough to do bitwise - std::bitset is not
     // really necessary!
-    if (str.find_first_of("lL") != std::string::npos)
-    {
+    if (str.find_first_of("lL") != std::string::npos) {
         am |= 1 << movie_root::STAGE_ALIGN_L;
     } 
 
-    if (str.find_first_of("tT") != std::string::npos)
-    {
+    if (str.find_first_of("tT") != std::string::npos) {
         am |= 1 << movie_root::STAGE_ALIGN_T;
     } 
 
-    if (str.find_first_of("rR") != std::string::npos)
-    {
+    if (str.find_first_of("rR") != std::string::npos) {
         am |= 1 << movie_root::STAGE_ALIGN_R;
     } 
 
-    if (str.find_first_of("bB") != std::string::npos)
-    {
+    if (str.find_first_of("bB") != std::string::npos) {
         am |= 1 << movie_root::STAGE_ALIGN_B;
     }
 
@@ -2522,5 +2397,133 @@
 
 }
 
+
+namespace {
+
+// Return whether any action triggered by this event requires display redraw.
+// See page about events_handling (in movie_interface.h)
+//
+/// TODO: make this code more readable !
+bool
+generate_mouse_button_events(movie_root& mr, MouseButtonState& ms)
+{
+
+       // Did this event trigger any action that needs redisplay ?
+       bool need_redisplay = false;
+
+    // TODO: have mouseEvent return
+    // whether the action must trigger
+    // a redraw.
+
+    switch (ms.previousButtonState)
+    {
+        case MouseButtonState::DOWN:
+           {
+                   // TODO: Handle trackAsMenu dragOver
+                   // Handle onDragOut, onDragOver
+                   if (!ms.wasInsideActiveEntity) {
+
+                           if (ms.topmostEntity == ms.activeEntity) {
+
+                                   // onDragOver
+                                   if (ms.activeEntity) {
+                                           
ms.activeEntity->mouseEvent(event_id::DRAG_OVER);
+                                           need_redisplay=true;
+                                   }
+                                   ms.wasInsideActiveEntity = true;
+                           }
+                   }
+                   else if (ms.topmostEntity != ms.activeEntity) {
+                           // onDragOut
+                           if (ms.activeEntity) {
+                                   
ms.activeEntity->mouseEvent(event_id::DRAG_OUT);
+                                   need_redisplay=true;
+                           }
+                           ms.wasInsideActiveEntity = false;
+                   }
+
+                   // Handle onRelease, onReleaseOutside
+                   if (ms.currentButtonState == MouseButtonState::UP) {
+                           // Mouse button just went up.
+                           ms.previousButtonState = MouseButtonState::UP;
+
+                           if (ms.activeEntity) {
+                                   if (ms.wasInsideActiveEntity) {
+                                           // onRelease
+                                           
ms.activeEntity->mouseEvent(event_id::RELEASE);
+                                           need_redisplay = true;
+                                   }
+                                   else {
+                                           // TODO: Handle trackAsMenu 
+                                           // onReleaseOutside
+                                           
ms.activeEntity->mouseEvent(event_id::RELEASE_OUTSIDE);
+                                           // We got out of active entity
+                                           ms.activeEntity = 0; // so we don't 
get RollOut next...
+                                           need_redisplay = true;
+                                   }
+                           }
+                   }
+               return need_redisplay;
+           }
+
+           case MouseButtonState::UP:
+        {
+               // New active entity is whatever is below the mouse right now.
+               if (ms.topmostEntity != ms.activeEntity)
+               {
+                       // onRollOut
+                       if (ms.activeEntity) {
+                               ms.activeEntity->mouseEvent(event_id::ROLL_OUT);
+                               need_redisplay=true;
+                       }
+
+                       ms.activeEntity = ms.topmostEntity;
+
+                       // onRollOver
+                       if (ms.activeEntity) {
+                               
ms.activeEntity->mouseEvent(event_id::ROLL_OVER);
+                               need_redisplay=true;
+                       }
+
+                       ms.wasInsideActiveEntity = true;
+               }
+
+               // mouse button press
+               if (ms.currentButtonState == MouseButtonState::DOWN) {
+                       // onPress
+
+                // Try setting focus on the new DisplayObject. This will handle
+                // all necessary events and removal of current focus.
+                // Do not set focus to NULL.
+                if (ms.activeEntity) {
+                    mr.setFocus(ms.activeEntity);
+
+                               ms.activeEntity->mouseEvent(event_id::PRESS);
+                               need_redisplay=true;
+                       }
+
+                       ms.wasInsideActiveEntity = true;
+                       ms.previousButtonState = MouseButtonState::DOWN;
+               }
+        }
+        default:
+           return need_redisplay;
+    }
+
+}
+
+const DisplayObject*
+getNearestObject(const DisplayObject* o)
+{
+    while (1) {
+        assert(o);
+        if (isReferenceable(*o)) return o;
+        o = o->get_parent();
+    }
+}
+
+}
+
+
 } // namespace gnash
 

=== modified file 'libcore/movie_root.h'
--- a/libcore/movie_root.h      2009-11-05 20:46:48 +0000
+++ b/libcore/movie_root.h      2009-11-06 07:39:15 +0000
@@ -154,8 +154,6 @@
             : stream(s), obj(o) {}
     };
         
-    //typedef std::pair<boost::shared_ptr<IOChannel>, as_object*> LoadCallback;
-        
     typedef std::list<LoadCallback> LoadCallbacks;
 
     /// Default constructor
@@ -892,17 +890,6 @@
     ///
     void addChildAt(DisplayObject* ch, int depth);
        
-       int getXMouseLoc()
-       {
-               return m_mouse_x;
-       }
-       
-       int getYMouseLoc()
-       {
-               return m_mouse_y;
-       }
-       
-
 private:
 
     /// Set the root movie, replacing the current one if any.
@@ -1051,8 +1038,6 @@
     /// more info.
     bool fire_mouse_event();
 
-    bool generate_mouse_button_events();
-
     /// \brief
     /// Return the topmost entity covering the given point
     /// and enabled to receive mouse events.
@@ -1169,7 +1154,7 @@
     float m_timer;
     int m_mouse_x, m_mouse_y, m_mouse_buttons;
 
-    MouseButtonState  m_mouse_button_state;
+    MouseButtonState  _mouseButtonState;
 
     /// Objects requesting a callback on every movie_root::advance()
     typedef std::set<ActiveRelay*> ObjectCallbacks;

=== modified file 'libcore/swf_function.cpp'
--- a/libcore/swf_function.cpp  2009-10-27 09:44:54 +0000
+++ b/libcore/swf_function.cpp  2009-11-06 07:54:33 +0000
@@ -140,7 +140,7 @@
                // See actionscript.all/setProperty.as
                // 
                if (fn.this_ptr) {
-                       DisplayObject* ch = fn.this_ptr->toDisplayObject();
+                       DisplayObject* ch = get<DisplayObject>(fn.this_ptr);
                        if (ch) {
                                target = ch;
                                orig_target = ch;

=== modified file 'libcore/vm/action.cpp'
--- a/libcore/vm/action.cpp     2009-08-20 06:55:15 +0000
+++ b/libcore/vm/action.cpp     2009-11-06 07:38:41 +0000
@@ -121,17 +121,7 @@
                (KEY_DOWN, "onKeyDown")
                (KEY_UP, "onKeyUp")     
                (DATA, "onData")
-               (LOAD_START, "onLoadStart")     
-               (LOAD_ERROR, "onLoadError")
-               (LOAD_PROGRESS, "onLoadProgress")       
-               (LOAD_INIT, "onLoadInit")
-               (CLOSE, "onClose")
-               (CONNECT, "onConnect")
-               (XML, "onXML")
-               (TIMER, "onTimer")
-               (CONSTRUCT, "onConstruct")
-               (SETFOCUS, "onSetFocus")
-               (KILLFOCUS, "onKillFocus");
+               (CONSTRUCT, "onConstruct");
 
     EventFunctionNameMap::const_iterator it = e.find(_id);
     assert(it != e.end());
@@ -161,17 +151,7 @@
                (KEY_DOWN, NSV::PROP_ON_KEY_DOWN)
                (KEY_UP, NSV::PROP_ON_KEY_UP)
                (DATA, NSV::PROP_ON_DATA)
-               (LOAD_START, NSV::PROP_ON_LOAD_START)
-               (LOAD_ERROR, NSV::PROP_ON_LOAD_ERROR)
-               (LOAD_PROGRESS, NSV::PROP_ON_LOAD_PROGRESS)
-               (LOAD_INIT, NSV::PROP_ON_LOAD_INIT)
-               (CLOSE, NSV::PROP_ON_CLOSE)
-               (CONNECT, NSV::PROP_ON_CONNECT)
-               (XML, NSV::PROP_ON_XML)
-               (TIMER, NSV::PROP_ON_TIMER)
-               (CONSTRUCT, NSV::PROP_ON_CONSTRUCT)
-               (SETFOCUS, NSV::PROP_ON_SET_FOCUS)
-               (KILLFOCUS, NSV::PROP_ON_KILL_FOCUS);
+               (CONSTRUCT, NSV::PROP_ON_CONSTRUCT);
 
     EventFunctionMap::const_iterator it = e.find(_id);
     assert(it != e.end());
@@ -204,7 +184,7 @@
        switch (_id)
        {
                case event_id::KEY_DOWN:
-               case event_id::KEY_PRESS :
+               case event_id::KEY_PRESS:
                case event_id::KEY_UP:
                        return true;
                default:
@@ -218,7 +198,7 @@
        switch (_id)
        {
                case event_id::PRESS:
-               case event_id::RELEASE :
+               case event_id::RELEASE:
                case event_id::RELEASE_OUTSIDE:
                case event_id::ROLL_OVER:
                case event_id::ROLL_OUT:


reply via email to

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