{-# LINE 2 "./Graphics/UI/Gtk/WebKit/WebInspector.chs" #-}
-- -*-haskell-*-
-----------------------------------------------------------------------------
-- Module : Graphics.UI.Gtk.WebKit.WebInspector
-- Author : Cjacker Huang
-- Copyright : (c) 2009 Cjacker Huang <jzhuang@redflag-1 .com>
--
-- This library 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.1 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
-- Lesser General Public License for more details.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- Access to the WebKit Inspector
-----------------------------------------------------------------------------

module Graphics.UI.Gtk.WebKit.WebInspector (
-- * Description
-- | The WebKit Inspector is a graphical tool to inspect and change the content of a WebKitWebView. It
-- also includes an interactive JavaScriptDebugger. Using this class one can get a 'Widget' which can
-- be embedded into an application to show the inspector.
--
-- The inspector is available when the WebKitWebSettings of the WebKitWebView has set the
-- 'enableDeveloperExtras' to true otherwise no inspector is available.

-- * Types
  WebInspector,
  WebInspectorClass,

-- * Methods
  webInspectorGetInspectedUri,
  webInspectorGetWebView,

  webInspectorInspectCoordinates,
  webInspectorShow,
  webInspectorClose,


-- * Attribute
  webInspectorInspectedUri,
  webInspectorJSProfilingEnable,

  webInspectorTimelineProfilingEnabled,

  webInspectorWebView,

-- * Signals
  attachWindow,
  detachWindow,
  closeWindow,
  showWindow,
  finished,
  inspectWebView,
) where

import Control.Monad (liftM)

import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.GList
import System.Glib.GError
import System.Glib.Attributes
import System.Glib.Properties
import Graphics.UI.Gtk.Gdk.Events

import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
import Graphics.UI.Gtk.WebKit.Types
{-# LINE 77 "./Graphics/UI/Gtk/WebKit/WebInspector.chs" #-}
import Graphics.UI.Gtk.WebKit.Internal
{-# LINE 78 "./Graphics/UI/Gtk/WebKit/WebInspector.chs" #-}
import Graphics.UI.Gtk.WebKit.Signals
{-# LINE 79 "./Graphics/UI/Gtk/WebKit/WebInspector.chs" #-}
import System.Glib.GObject
{-# LINE 80 "./Graphics/UI/Gtk/WebKit/WebInspector.chs" #-}


{-# LINE 82 "./Graphics/UI/Gtk/WebKit/WebInspector.chs" #-}


------------------
-- | Obtains the URI that is currently being inspected
webInspectorGetInspectedUri ::
    (WebInspectorClass self, GlibString string) => self
 -> IO string
webInspectorGetInspectedUri inspector =
    (\(WebInspector arg1) -> withForeignPtr arg1 $ \argPtr1 ->webkit_web_inspector_get_inspected_uri argPtr1) (toWebInspector inspector) >>= peekUTFString

-- | Obtains the 'WebView' that is used to render the 'WebInspector'.
--
-- The 'WebView' instance is created by the application,
-- by handling the "inspect-web-view" signal.
-- This means that it may return @Nothing@ if the user hasn't inspected anything
webInspectorGetWebView ::
    WebInspectorClass self => self
 -> IO (Maybe WebView)
webInspectorGetWebView inspector =
    maybeNull (makeNewObject mkWebView) $ liftM castPtr $
      (\(WebInspector arg1) -> withForeignPtr arg1 $ \argPtr1 ->webkit_web_inspector_get_web_view argPtr1)
{-# LINE 103 "./Graphics/UI/Gtk/WebKit/WebInspector.chs" #-}
        (toWebInspector inspector)


-- | Causes the Web Inspector to inspect the node that is located at the given coordinates of the
-- widget. The coordinates should be relative to the WebKitWebView widget, not to the scrollable
-- content, and may be obtained from a 'Event' directly.
--
-- This means x, and y being zero doesn't guarantee you will hit the left-most top corner of the
-- content, since the contents may have been scrolled.
--
-- * Since 1.1.17
webInspectorInspectCoordinates :: WebInspectorClass self
  => self -- ^ @webInspector@ the WebKitWebInspector that will do the inspection
  -> Int -- ^ @x@ the X coordinate of the node to be inspected
  -> Int -- ^ @y@ the Y coordinate of the node to be inspected
  -> IO ()
webInspectorInspectCoordinates inspect x y =
  (\(WebInspector arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->webkit_web_inspector_inspect_coordinates argPtr1 arg2 arg3)
{-# LINE 121 "./Graphics/UI/Gtk/WebKit/WebInspector.chs" #-}
    (toWebInspector inspect)
    (fromIntegral x)
    (fromIntegral y)

-- | Causes the Web Inspector to be shown.
--
-- * Since 1.1.17
webInspectorShow :: WebInspectorClass self => self -> IO ()
webInspectorShow inspect =
  (\(WebInspector arg1) -> withForeignPtr arg1 $ \argPtr1 ->webkit_web_inspector_show argPtr1) (toWebInspector inspect)

-- | Causes the Web Inspector to be closed.
--
-- * Since 1.1.17
webInspectorClose :: WebInspectorClass self => self -> IO ()
webInspectorClose inspect =
  (\(WebInspector arg1) -> withForeignPtr arg1 $ \argPtr1 ->webkit_web_inspector_close argPtr1) (toWebInspector inspect)


-- * Attribute

-- | The URI that is currently being inspected.
webInspectorInspectedUri :: (WebInspectorClass self, GlibString string) => ReadAttr self string
webInspectorInspectedUri = readAttr webInspectorGetInspectedUri

-- | This is enabling JavaScript profiling in the Inspector. This means that Console.profiles will return the profiles.
webInspectorJSProfilingEnable :: (WebInspectorClass self) => Attr self Bool
webInspectorJSProfilingEnable = newAttrFromBoolProperty "javascript-profiling-enabled"


-- | This is enabling Timeline profiling in the Inspector.
--
-- Default value: 'False'
--
-- * Since 1.1.17
webInspectorTimelineProfilingEnabled :: (WebInspectorClass self) => Attr self Bool
webInspectorTimelineProfilingEnabled = newAttrFromBoolProperty "timeline-profiling-enabled"


-- | The Web View that renders the Web Inspector itself.
webInspectorWebView :: (WebInspectorClass self) => ReadAttr self WebView
webInspectorWebView =
  readAttrFromObjectProperty "web-view"
  webkit_web_view_get_type
{-# LINE 165 "./Graphics/UI/Gtk/WebKit/WebInspector.chs" #-}

-- * Signals

-- | Emitted when the inspector should appear in a separate window
--
-- return True if the signal is handled
attachWindow :: WebInspectorClass self => Signal self (IO Bool)
attachWindow = Signal (connect_NONE__BOOL "attach_window")

-- | Emitted when the inspector should appear in a separate window.
--
-- return True if the signal has been handled
detachWindow :: WebInspectorClass self => Signal self (IO Bool)
detachWindow = Signal (connect_NONE__BOOL "detach_window")

-- | Emitted when the inspector window should be closed.
--
-- return True if the signal is handled.
closeWindow :: WebInspectorClass self => Signal self (IO Bool)
closeWindow = Signal (connect_NONE__BOOL "close_window")

-- | Emitted when the inspector window should be displayed.
-- Notice that the window must have been created already by handling 'inspectWebView'.
--
-- return True if the signal has been handled
showWindow :: WebInspectorClass self => Signal self (IO Bool)
showWindow = Signal (connect_NONE__BOOL "show_window")

-- | Emitted when the inspection is done. You should release your references on the inspector at this time.
-- The inspected 'WebView' may no longer exist when this signal is emitted.
finished :: WebInspectorClass self => Signal self (IO ())
finished = Signal (connect_NONE__NONE "finished")

-- | Emitted when the user activates the 'inspect' context menu item to inspect a web view.
-- The application which is interested in the inspector should create a window,
-- or otherwise add the 'WebView' it creates to an existing window.
--
-- You don't need to handle the reference count of the 'WebView' instance you create;
-- the widget to which you add it will do that.
inspectWebView :: WebInspectorClass self => Signal self (WebView -> IO WebView)
inspectWebView = Signal (connect_OBJECT__OBJECTPTR "inspect_web_view")

foreign import ccall safe "webkit_web_inspector_get_inspected_uri"
  webkit_web_inspector_get_inspected_uri :: ((Ptr WebInspector) -> (IO (Ptr CChar)))

foreign import ccall safe "webkit_web_inspector_get_web_view"
  webkit_web_inspector_get_web_view :: ((Ptr WebInspector) -> (IO (Ptr WebView)))

foreign import ccall safe "webkit_web_inspector_inspect_coordinates"
  webkit_web_inspector_inspect_coordinates :: ((Ptr WebInspector) -> (CDouble -> (CDouble -> (IO ()))))

foreign import ccall safe "webkit_web_inspector_show"
  webkit_web_inspector_show :: ((Ptr WebInspector) -> (IO ()))

foreign import ccall safe "webkit_web_inspector_close"
  webkit_web_inspector_close :: ((Ptr WebInspector) -> (IO ()))

foreign import ccall safe "webkit_web_view_get_type"
  webkit_web_view_get_type :: CULong