/*
 * Copyright (C) 2007 Holger Hans Peter Freyther
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef ChromeClientGtk_h
#define ChromeClientGtk_h

#include "ChromeClient.h"
#include "KURL.h"
#include "PopupMenu.h"
#include "SearchPopupMenu.h"
#include "webkitwebwindowfeatures.h"

using namespace WebCore;
#if PLATFORM(GTK)
typedef struct _WebKitWebView WebKitWebView;
#endif

#if PLATFORM(CLUTTER)
typedef struct _WebKitWebActor WebKitWebActor;
#endif

namespace WebCore {
class PopupMenuClient;
class Tile;
}

namespace WebKit {

    class ChromeClient : public WebCore::ChromeClient {
    public:
#if PLATFORM(GTK)
        ChromeClient(WebKitWebView*);
        WebKitWebView* webView() const { return m_webView; }
#endif

#if PLATFORM(CLUTTER)
        ChromeClient(WebKitWebPage*);
        WebKitWebPage* webPage() const { return m_webPage; }
        virtual void* webView() const { return webPage(); }
#endif

        virtual void chromeDestroyed();

        virtual void setWindowRect(const WebCore::FloatRect&);
        virtual WebCore::FloatRect windowRect();
        virtual void toolkitSetWindowRect(const WebCore::FloatRect&);

        virtual WebCore::FloatRect pageRect();

        virtual float scaleFactor();

        virtual void focus();
        virtual void unfocus();

        virtual WebCore::Page* toolkitCreateWindow(WebCore::Frame*, const WebCore::FrameLoadRequest&, const WebCore::WindowFeatures&);
        virtual void toolkitLoadURL(WebCore::Page*, const WebCore::FrameLoadRequest&);
        virtual WebKitWebWindowFeatures* toolkitWindowFeatures();
        virtual void toolkitSetWindowFeatures(WebKitWebWindowFeatures*);
        virtual WebKitWebSettings* toolkitSettings();

        virtual bool canTakeFocus(WebCore::FocusDirection);
        virtual void takeFocus(WebCore::FocusDirection);

        virtual void focusedNodeChanged(WebCore::Node*);
        virtual void focusedFrameChanged(WebCore::Frame*);

        virtual WebCore::Page* createWindow(WebCore::Frame*, const WebCore::FrameLoadRequest&, const WebCore::WindowFeatures&, const WebCore::NavigationAction&);
        virtual void show();

        virtual bool canRunModal();
        virtual void runModal();

        virtual void setToolbarsVisible(bool);
        virtual bool toolbarsVisible();

        virtual void setStatusbarVisible(bool);
        virtual bool statusbarVisible();

        virtual void setScrollbarsVisible(bool);
        virtual bool scrollbarsVisible();

        virtual void setMenubarVisible(bool);
        virtual bool menubarVisible();

        virtual void setResizable(bool);

        virtual void addMessageToConsole(MessageSource, MessageLevel, const WTF::String& message, unsigned lineNumber, const WTF::String& sourceID);

        virtual bool canRunBeforeUnloadConfirmPanel();
        virtual bool runBeforeUnloadConfirmPanel(const WTF::String& message, WebCore::Frame* frame);

        virtual void closeWindowSoon();

        virtual void runJavaScriptAlert(WebCore::Frame*, const WTF::String&);
        virtual bool runJavaScriptConfirm(WebCore::Frame*, const WTF::String&);
        virtual bool runJavaScriptPrompt(WebCore::Frame*, const WTF::String& message, const WTF::String& defaultValue, WTF::String& result);
        virtual void setStatusbarText(const WTF::String&);
        virtual bool shouldInterruptJavaScript();
        virtual WebCore::KeyboardUIMode keyboardUIMode();

        virtual WebCore::IntRect windowResizerRect() const;

        virtual void invalidateRootView(const WebCore::IntRect&, bool);
        virtual void invalidateContentsAndRootView(const WebCore::IntRect&, bool);
        virtual void invalidateContentsForSlowScroll(const WebCore::IntRect&, bool);
        virtual void scroll(const WebCore::IntSize& scrollDelta, const WebCore::IntRect& rectToScroll, const WebCore::IntRect& clipRect);

        virtual WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) const;
        virtual WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) const;
        virtual PlatformPageClient platformPageClient() const;
        virtual void contentsSizeChanged(WebCore::Frame*, const WebCore::IntSize&) const;

        virtual void scrollbarsModeDidChange() const;
        virtual void mouseDidMoveOverElement(const WebCore::HitTestResult&, unsigned modifierFlags);

        virtual void setToolTip(const WTF::String&, WebCore::TextDirection);

        virtual void print(WebCore::Frame*);
#if ENABLE(SQL_DATABASE)
        virtual void exceededDatabaseQuota(Frame*, const WTF::String&, DatabaseDetails);
        virtual void toolkitExceededDatabaseQuota(WebKitWebFrame*, WebKitWebDatabase*);
#endif

        virtual void reachedMaxAppCacheSize(int64_t spaceNeeded);
        virtual void reachedApplicationCacheOriginQuota(WebCore::SecurityOrigin*, int64_t totalSpaceNeeded);

        virtual void runOpenPanel(WebCore::Frame*, PassRefPtr<WebCore::FileChooser>);
        virtual void loadIconForFiles(const Vector<WTF::String>&, WebCore::FileIconLoader*);

        virtual void formStateDidChange(const WebCore::Node*) { }

        virtual void setCursor(const WebCore::Cursor&);
        virtual void setCursorHiddenUntilMouseMoves(bool);

        virtual void scrollRectIntoView(const WebCore::IntRect&, const WebCore::ScrollView*) const {}

        virtual bool selectItemWritingDirectionIsNatural();
        virtual bool selectItemAlignmentFollowsMenuWritingDirection();
        virtual bool hasOpenedPopup() const;
        virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const;
        virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const;
#if ENABLE(VIDEO)
        virtual bool supportsFullscreenForNode(const WebCore::Node*);
        virtual void enterFullscreenForNode(WebCore::Node*);
        virtual void exitFullscreenForNode(WebCore::Node*);
#endif

#if ENABLE(FULLSCREEN_API)
        virtual bool supportsFullScreenForElement(const WebCore::Element*, bool withKeyboard);
        virtual void enterFullScreenForElement(WebCore::Element*);
        virtual void exitFullScreenForElement(WebCore::Element*);
#endif

        virtual bool shouldRubberBandInDirection(WebCore::ScrollDirection) const { return true; }
        virtual void numWheelEventHandlersChanged(unsigned) { }
        virtual void numTouchEventHandlersChanged(unsigned) { }

#if USE(ACCELERATED_COMPOSITING)
        // see ChromeClient.h
        // this is a hook for WebCore to tell us what we need to do with the GraphicsLayers
        virtual void attachRootGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*);
        virtual void setNeedsOneShotDrawingSynchronization();
        virtual void scheduleCompositingLayerFlush();
        virtual CompositingTriggerFlags allowedCompositingTriggers() const;
#endif

#if USE(TILED_BACKING_STORE)
        virtual WebCore::IntRect visibleRectForTiledBackingStore() const;
        virtual void delegatedScrollRequested(const WebCore::IntPoint&);
        virtual void tiledBackingStoreDidCreateTile(WebCore::Tile*);
#endif

#if ENABLE(TOUCH_EVENTS)
    virtual void needTouchEvents(bool);
#endif

    private:
#if PLATFORM(GTK)
        WebKitWebView* m_webView;
#endif
#if PLATFORM(CLUTTER)
        WebKitWebPage* m_webPage;
#endif
        WebCore::KURL m_hoveredLinkURL;
    };
}

#endif // ChromeClient_h
