@@ -39,6 +39,14 @@ CGUIWebBrowser_Impl::CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent
3939
4040 AddEvents ();
4141
42+ // Apply browser events
43+ m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseButtonDown, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseButtonDown, this ) );
44+ m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseButtonUp, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseButtonUp, this ) );
45+ m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseMove, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseMove, this ) );
46+ m_pWindow->subscribeEvent ( CEGUI::Window::EventMouseWheel, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_MouseWheel, this ) );
47+ m_pWindow->subscribeEvent ( CEGUI::Window::EventActivated, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_Activated, this ) );
48+ m_pWindow->subscribeEvent ( CEGUI::Window::EventDeactivated, CEGUI::Event::Subscriber ( &CGUIWebBrowser_Impl::Event_Deactivated, this ) );
49+
4250 // If a parent is specified, add it to it's children list, if not, add it as a child to the pManager
4351 if ( pParent )
4452 {
@@ -51,14 +59,28 @@ CGUIWebBrowser_Impl::CGUIWebBrowser_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent
5159 }
5260}
5361
54- CGUIWebBrowser_Impl::~CGUIWebBrowser_Impl ( void )
62+ CGUIWebBrowser_Impl::~CGUIWebBrowser_Impl ()
5563{
56- // Clear the image
57- Clear ();
64+ Clear ();
5865
5966 DestroyElement ();
6067}
6168
69+ void CGUIWebBrowser_Impl::Clear ()
70+ {
71+ // Stop the control from using it
72+ reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow )->setImage ( nullptr );
73+
74+ // Kill the images
75+ if ( m_pImageset )
76+ {
77+ m_pImageset->undefineAllImages ();
78+ m_pImagesetManager->destroyImageset ( m_pImageset );
79+ m_pImage = nullptr ;
80+ m_pImageset = nullptr ;
81+ }
82+ }
83+
6284bool CGUIWebBrowser_Impl::LoadFromTexture ( IDirect3DTexture9* pTexture )
6385{
6486 if ( m_pImageset && m_pImage )
@@ -102,35 +124,6 @@ void CGUIWebBrowser_Impl::LoadFromWebView ( CWebViewInterface* pWebView )
102124 LoadFromTexture ( pWebView->GetTexture () );
103125}
104126
105- void CGUIWebBrowser_Impl::Clear ( void )
106- {
107- // Stop the control from using it
108- reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow )->setImage ( nullptr );
109-
110- // Kill the images
111- if ( m_pImageset )
112- {
113- m_pImageset->undefineAllImages ();
114- m_pImagesetManager->destroyImageset ( m_pImageset );
115- m_pImage = nullptr ;
116- m_pImageset = nullptr ;
117- }
118- }
119-
120- bool CGUIWebBrowser_Impl::GetNativeSize ( CVector2D& vecSize )
121- {
122- auto pTexture = m_pWebView->GetTexture ();
123- D3DSURFACE_DESC SurfaceDesc;
124- if ( pTexture->GetLevelDesc ( 0 , &SurfaceDesc ) == ERROR_SUCCESS )
125- {
126- vecSize.fX = (float )SurfaceDesc.Width ;
127- vecSize.fY = (float )SurfaceDesc.Height ;
128- return true ;
129- }
130-
131- return false ;
132- }
133-
134127void CGUIWebBrowser_Impl::SetFrameEnabled ( bool bFrameEnabled )
135128{
136129 reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> setFrameEnabled ( bFrameEnabled );
@@ -153,10 +146,64 @@ void CGUIWebBrowser_Impl::Render ( void )
153146 return reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow ) -> render ();
154147}
155148
149+ bool CGUIWebBrowser_Impl::Event_MouseButtonDown ( const CEGUI::EventArgs& e )
150+ {
151+ const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e );
152+
153+ if ( args.button == CEGUI::MouseButton::LeftButton )
154+ m_pWebView->InjectMouseDown ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_LEFT );
155+ else if ( args.button == CEGUI::MouseButton::MiddleButton )
156+ m_pWebView->InjectMouseDown ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_MIDDLE );
157+ else if ( args.button == CEGUI::MouseButton::RightButton )
158+ m_pWebView->InjectMouseDown ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_RIGHT );
159+
160+ return true ;
161+ }
162+
163+ bool CGUIWebBrowser_Impl::Event_MouseButtonUp ( const CEGUI::EventArgs& e )
164+ {
165+ const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e );
166+
167+ if ( args.button == CEGUI::MouseButton::LeftButton )
168+ m_pWebView->InjectMouseUp ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_LEFT );
169+ else if ( args.button == CEGUI::MouseButton::MiddleButton )
170+ m_pWebView->InjectMouseUp ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_MIDDLE );
171+ else if ( args.button == CEGUI::MouseButton::RightButton )
172+ m_pWebView->InjectMouseUp ( eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_RIGHT );
173+
174+ return true ;
175+ }
176+
177+ bool CGUIWebBrowser_Impl::Event_MouseMove ( const CEGUI::EventArgs& e )
178+ {
179+ const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e );
180+
181+ m_pWebView->InjectMouseMove ( (int )args.position .d_x - m_pWindow->windowToScreenX ( 0 .0f ), (int )args.position .d_y - m_pWindow->windowToScreenY ( 0 .0f ) );
182+ return true ;
183+ }
184+
185+ bool CGUIWebBrowser_Impl::Event_MouseWheel ( const CEGUI::EventArgs& e )
186+ {
187+ const CEGUI::MouseEventArgs& args = reinterpret_cast < const CEGUI::MouseEventArgs& > ( e );
188+
189+ m_pWebView->InjectMouseWheel ( args.wheelChange * 30 , 0 );
190+ return true ;
191+ }
192+
193+ bool CGUIWebBrowser_Impl::Event_Activated ( const CEGUI::EventArgs& e )
194+ {
195+ m_pWebView->Focus ( true );
196+ return true ;
197+ }
156198
199+ bool CGUIWebBrowser_Impl::Event_Deactivated ( const CEGUI::EventArgs& e )
200+ {
201+ m_pWebView->Focus ( false );
202+ return true ;
203+ }
157204
158205
159- CGUIWebBrowserTexture::CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture ) : CEGUI::DirectX9Texture( pOwner)
206+ CGUIWebBrowserTexture::CGUIWebBrowserTexture ( CEGUI::Renderer* pOwner, IDirect3DTexture9* pTexture ) : CEGUI::DirectX9Texture ( pOwner )
160207{
161208 m_pTexture = pTexture;
162209
0 commit comments