/*
-----------------------------------------------------------------------------
This source file is part of OpenSpace3D
For the latest info, see http://www.openspace3d.com

Copyright (c) 2011 I-maginer

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt
-----------------------------------------------------------------------------
*/

#ifndef _SCOL_EMBEDDED_WEB_NAVIGATOR_CLIENT_
#define _SCOL_EMBEDDED_WEB_NAVIGATOR_CLIENT_

#include "embeddedWebNavigatorPrerequisites.h"
#include "embeddedWebNavigatorCriticalSection.h"

namespace Scol
{
  namespace EmbeddedWebNavigator
  {

class WebNavigatorClient : public CefClient
{
public:
protected:
private:
  const ScolWindowHandle scolMainWindowHandle;
  WebNavigator* parentWebNavigator;
  CefRefPtr<WebNavigatorCriticalSection> offscreenBufferCriticalSection;
  CefRefPtr<WebNavigatorDisplayHandler> displayHandler;
  CefRefPtr<WebNavigatorDragHandler> dragHandler;
  CefRefPtr<WebNavigatorFindHandler> findHandler;
  CefRefPtr<WebNavigatorFocusHandler> focusHandler;
  CefRefPtr<WebNavigatorJSDialogHandler> jsDialogHandler;
  CefRefPtr<WebNavigatorKeyboardHandler> keyboardHandler;
  CefRefPtr<WebNavigatorLifeSpanHandler> lifeSpanHandler;
  CefRefPtr<WebNavigatorLoadHandler> loadHandler;
  CefRefPtr<WebNavigatorMenuHandler> menuHandler;
  CefRefPtr<WebNavigatorPrintHandler> printHandler;
  CefRefPtr<WebNavigatorRenderHandler> renderHandler;
  CefRefPtr<WebNavigatorRequestHandler> requestHandler;
  CefRefPtr<WebNavigatorV8ContextHandler> v8ContextHandler;
  CefRefPtr<CefBrowser> cefBrowser;

public:
  /*!
  Constructor.
  */
  WebNavigatorClient(WebNavigator* parentWebNavigatorInstance, const ScolWindowHandle& scolMainWindow, bool offscreen, CefRefPtr<WebNavigatorCriticalSection>& offscreenBufferCriticalSectionInstance);

  /*!
  Destructor.
  */
  ~WebNavigatorClient();

  /*!
  return true if success, false if size of the destination buffer is inconsistent
  */
  bool BlitOffscreenBitmap(unsigned char* dest, int destWidth, int destHeight, int destBytesPerPixel, int destBitsPerLine);

  /*!
  return true if success, false if size of the destination buffer is inconsistent
  */
  bool BlitOffscreenAlphaBitmap(unsigned char* destColor, unsigned char* destAlpha, int destWidth, int destHeight, int destColorBytesPerPixel, int destColorBitsPerLine);

  /*!
  @copydoc CefLifeSpanHandler::GetLifeSpanHandler
  */
  virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetLoadHandler
  */
  virtual CefRefPtr<CefLoadHandler> GetLoadHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetRequestHandler
  */
  virtual CefRefPtr<CefRequestHandler> GetRequestHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetDisplayHandler
  */
  virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetFocusHandler
  */
  virtual CefRefPtr<CefFocusHandler> GetFocusHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetKeyboardHandler
  */
  virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetMenuHandler
  */
  virtual CefRefPtr<CefMenuHandler> GetMenuHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetPrintHandler
  */
  virtual CefRefPtr<CefPrintHandler> GetPrintHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetFindHandler
  */
  virtual CefRefPtr<CefFindHandler> GetFindHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetJSDialogHandler
  */
  virtual CefRefPtr<CefJSDialogHandler> GetJSDialogHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetV8ContextHandler
  */
  virtual CefRefPtr<CefV8ContextHandler> GetV8ContextHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetRenderHandler
  */
  virtual CefRefPtr<CefRenderHandler> GetRenderHandler();

  /*!
  @copydoc CefLifeSpanHandler::GetDragHandler
  */
  virtual CefRefPtr<CefDragHandler> GetDragHandler();

  /*!
  */
  CefRefPtr<CefBrowser> GetBrowser();

  /*!
  */
  WebNavigator* GetParentWebNavigator();

  /*!
  Initialise the browser ptr once it's created.
  @remarks Internal use only!!!
  */
  void _NotifyBrowserCreated(CefRefPtr<CefBrowser> browser);

  /*!
  Release the browser ptr on deletion.
  @remarks Internal use only!!!
  */
  void _NotifyBrowserDestroyed(CefRefPtr<CefBrowser> browser);

  /*!
  Release internal references to WebNavigatorClient
  @remarks Internal use only!!!
  */
  void _Cleanup();
protected:
  //Include the default reference counting implementation.
  IMPLEMENT_REFCOUNTING(WebNavigatorClient);

  // Include the default locking implementation.
  IMPLEMENT_LOCKING(WebNavigatorClient);
private:
  /*!
  Forbiden ctor.
  */
  WebNavigatorClient();
};

  }
}

#endif
