Sirikata
libogre/include/sirikata/ogre/WebViewManager.hpp
Go to the documentation of this file.
00001 /*  Sirikata
00002  *  WebViewManager.hpp
00003  *
00004  *  Copyright (c) 2009, Adam Jean Simmons
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions are
00009  *  met:
00010  *  * Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  *  * Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in
00014  *    the documentation and/or other materials provided with the
00015  *    distribution.
00016  *  * Neither the name of Sirikata nor the names of its contributors may
00017  *    be used to endorse or promote products derived from this software
00018  *    without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00021  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00022  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00023  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00024  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00026  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  */
00032 
00033 #ifndef _SIRIKATA_GRAPHICS_WEBVIEWMANAGER_HPP_
00034 #define _SIRIKATA_GRAPHICS_WEBVIEWMANAGER_HPP_
00035 
00036 #include <sirikata/ogre/OgreHeaders.hpp>
00037 #include "Ogre.h"
00038 #include <sirikata/ogre/ViewportOverlay.hpp>
00039 #include <sirikata/ogre/input/InputEvents.hpp>
00040 #include <sirikata/ogre/input/InputManager.hpp>
00041 #include <sirikata/ogre/WebView.hpp>
00042 
00043 namespace Sirikata {
00044 
00045 
00046 typedef Sirikata::DataReference<const char*> JSArgument;
00047 typedef std::vector<JSArgument> JSArguments;
00048 typedef JSArguments::const_iterator JSIter;
00049 
00050 
00051 namespace Graphics {
00052 
00056 enum MouseButtonID
00057 {
00058     LeftMouseButton = 0,
00059     RightMouseButton = 1,
00060     MiddleMouseButton = 2,
00061         ScrollUpButton = 3,
00062         ScrollDownButton = 4,
00063         UnknownMouseButton = 0xFFFF
00064 };
00065 
00066 struct WebViewCoord {
00067     int x;
00068     int y;
00069 
00070     WebViewCoord(int _x, int _y)
00071      : x(_x), y(_y)
00072     {
00073     }
00074 };
00075 
00076 
00082 class SIRIKATA_OGRE_EXPORT WebViewManager : public Ogre::Singleton<WebViewManager>
00083 {
00084 public:
00099     WebViewManager(Ogre::Viewport* defaultViewport, Sirikata::Input::InputManager* inputMgr, const std::string& binDirectory, const std::string& baseDirectory);
00100 
00104     ~WebViewManager();
00105 
00113     static WebViewManager& getSingleton();
00114 
00121     static WebViewManager* getSingletonPtr();
00122 
00127     void Update();
00128 
00134     WebView* createWebView(
00135         Context* ctx,const std::string &webViewName,
00136         const std::string& webViewType,unsigned short width,
00137         unsigned short height,const OverlayPosition &webViewPosition,
00138         Network::IOStrandPtr postStrand,
00139         bool asyncRender = false, int maxAsyncRenderRate = 70,
00140         Tier tier = TIER_MIDDLE, Ogre::Viewport* viewport = 0,
00141         const WebView::WebViewBorderSize& border = WebView::mDefaultBorder);
00142 
00143 #ifdef HAVE_BERKELIUM
00144 
00147     WebView* createWebViewPopup(
00148             Context* ctx,const std::string &webViewName,
00149             unsigned short width, unsigned short height,
00150             const OverlayPosition &webViewPosition,
00151             Berkelium::Window *newwin, Network::IOStrandPtr postingStrand,
00152             Tier tier = TIER_MIDDLE, Ogre::Viewport* viewport = 0);
00153 #endif
00154 
00159     WebView* createWebViewMaterial(
00160             Context* ctx,const std::string &webViewName,
00161             unsigned short width, unsigned short height,
00162             Network::IOStrandPtr postingStrand,
00163             bool asyncRender = false, int maxAsyncRenderRate = 70,
00164             Ogre::FilterOptions texFiltering = Ogre::FO_ANISOTROPIC);
00165 
00173     WebView* getWebView(const std::string &webViewName);
00174 
00180     void destroyWebView(const std::string &webViewName);
00181 
00186     void destroyWebView(WebView* webViewToDestroy);
00187 
00191     void resetAllPositions();
00192 
00198     bool isAnyWebViewFocused();
00199 
00205     WebView* getFocusedWebView();
00206 
00216     bool injectMouseMove(const WebViewCoord& coord);
00217 
00229     bool injectMouseWheel(const WebViewCoord& relScroll);
00230 
00239     bool injectMouseDown(int buttonID);
00240 
00249     bool injectMouseUp(int buttonID);
00250 
00251     bool injectCut();
00252     bool injectCopy();
00253     bool injectPaste();
00254 
00255     bool injectKeyEvent(bool pressed, bool repeat, Sirikata::Input::Modifier mod, Sirikata::Input::KeyButton button);
00256 
00257     bool injectTextEvent(std::string utf8);
00258 
00262     void deFocusAllWebViews();
00263 
00264     bool focusWebView(WebView* selection);
00265 
00266     void setDefaultViewport(Ogre::Viewport* newViewport);
00267 
00268 
00269     const std::string &getBaseDir() const {
00270         return baseDirectory;
00271     }
00272 
00273 protected:
00274     friend class WebView; // Our very close friend <3
00275 
00276     typedef std::map<std::string,WebView*> WebViewMap;
00277     WebViewMap activeWebViews;
00278     WebView* focusedWebView;
00279     WebView* tooltipWebView;
00280     WebView* tooltipParent;
00281     WebView* chromeWebView;
00282     WebView* focusedNonChromeWebView;
00283 
00284     Ogre::Viewport* defaultViewport;
00285     int mouseXPos, mouseYPos;
00286     bool isDragging;
00287     bool isResizing;
00288     unsigned short zOrderCounter;
00289     Ogre::Timer tooltipTimer;
00290     double lastTooltip, tooltipShowTime;
00291     bool isDraggingFocusedWebView;
00292     std::string baseDirectory;
00293 
00294 #ifdef HAVE_BERKELIUM
00295     Berkelium::Context *bkContext;
00296 #endif
00297 
00298     WebView* getTopWebView(int x, int y);
00299     void onResizeTooltip(WebView* WebView, const JSArguments& args);
00300     void handleTooltip(WebView* tooltipParent, const std::wstring& tipText);
00301     void handleRequestDrag(WebView* caller);
00302 
00303     Sirikata::Input::InputManager* mInputManager;
00304 
00317     boost::any onRaiseWebViewEvent(WebView* webview, const JSArguments& args);
00318 public:
00319 
00320     Input::EventResponse onMouseHover(Input::MouseHoverEventPtr evt);
00321     Input::EventResponse onMousePressed(Input::MousePressedEventPtr evt);
00322     Input::EventResponse onMouseDrag(Input::MouseDragEventPtr evt);
00323     Input::EventResponse onMouseReleased(Input::MouseReleasedEventPtr evt);
00324     Input::EventResponse onMouseClick(Input::MouseClickEventPtr evt);
00325     Input::EventResponse onButton(Input::ButtonEventPtr evt);
00326     Input::EventResponse onKeyTextInput(Input::TextInputEventPtr evt);
00327 };
00328 
00329 }
00330 }
00331 
00332 #endif