## WebKitViewportAttributes WebKitViewportAttributes — Represents the viewport properties of a web page |

## Synopsis

                        WebKitViewportAttributes;
    void                webkit_viewport_attributes_recompute
                                                            (WebKitViewportAttributes *viewportAttributes);

## Object Hierarchy

      GObject
       +----WebKitViewportAttributes

## Properties

      "available-height"         gint                  : Read / Write
      "available-width"          gint                  : Read / Write
      "desktop-width"            gint                  : Read / Write
      "device-dpi"               gint                  : Read / Write
      "device-height"            gint                  : Read / Write
      "device-pixel-ratio"       gfloat                : Read
      "device-width"             gint                  : Read / Write
      "height"                   gint                  : Read
      "initial-scale-factor"     gfloat                : Read
      "maximum-scale-factor"     gfloat                : Read
      "minimum-scale-factor"     gfloat                : Read
      "user-scalable"            gboolean              : Read
      "valid"                    gboolean              : Read
      "width"                    gint                  : Read

## Description

WebKitViewportAttributes offers the viewport properties to user agents to control the viewport layout. It contains the viewport size, initial scale with limits, and information about whether a user is able to scale the contents in the viewport. This makes a web page fit the device screen.

The "viewport-attributes-changed" signal will be emitted with WebKitViewportAttributes when the viewport attributes are updated in the case of loading web pages contain the viewport properties and calling webkit_viewport_attributes_recompute.

If the device size, available size, desktop width, or device DPI needs to be changed due to a consequence of an explicit browser request (caused by screen rotation, resizing, or similar reasons), You should call webkit_viewport_attributes_recompute to recompute the viewport properties and override those values in the handler of "viewport-attributes-recompute-requested" signal.

For more information on the viewport properties, refer to the Safari reference library at http://developer.apple.com/safari/library/documentation/appleapplications/reference/safarihtmlref/articles/metatags.html

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    /* Connect to the viewport-attributes-changes signal */
    WebKitViewportAttributes* attributes = webkit_web_view_get_viewport_attributes (web_view);
    g_signal_connect (web_view, "viewport-attributes-recompute-requested", G_CALLBACK (viewport_recompute_cb), window);
    g_signal_connect (web_view, "viewport-attributes-changed", G_CALLBACK (viewport_changed_cb), window);
    g_signal_connect (attributes, "notify::valid", G_CALLBACK (viewport_valid_changed_cb), web_view);

    /* Handle the viewport-attributes-recompute-requested signal to override the device width */
    static void
    viewport_recompute_cb (WebKitWebView* web_view, WebKitViewportAttributes* attributes, GtkWidget* window)
    {
        int override_available_width = 480;
        g_object_set (G_OBJECT(attributes), "available-width", override_available_width, NULL);
    }

    /* Handle the viewport-attributes-changed signal to recompute the initial scale factor */
    static void
    viewport_changed_cb (WebKitWebView* web_view, WebKitViewportAttributes* attributes, gpointer data)
    {
        gfloat initialScale;
        g_object_get (G_OBJECT (atributes), "initial-scale-factor", &initialScale, NULL);
        webkit_web_view_set_zoom_level (web_view, initialScale);
    }

    /* Handle the notify::valid signal to initialize the zoom level */
    static void
    viewport_valid_changed_cb (WebKitViewportAttributes* attributes, GParamSpec* pspec, WebKitWebView* web_view)
    {
        gboolean is_valid;
        g_object_get (attributes, "valid", &is_valid, NULL);
        if (!is_valid)
            webkit_web_view_set_zoom_level (web_view, 1.0);
    }

## Details

### WebKitViewportAttributes

    typedef struct _WebKitViewportAttributes WebKitViewportAttributes;

### webkit_viewport_attributes_recompute ()

    void                webkit_viewport_attributes_recompute
                                                            (WebKitViewportAttributes *viewportAttributes);

Recompute the optimal viewport attributes and emit the viewport-attribute-changed signal. The viewport-attributes-recompute-requested signal also will be handled to override the device size, available size, desktop width, or device DPI.

`viewportAttributes` : | a WebKitViewportAttributes

Since 1.3.8

## Property Details

### The `"available-height"` property

      "available-height"         gint                  : Read / Write

The height of the visible area.

Allowed values: >= 0

Default value: 0

### The `"available-width"` property

      "available-width"          gint                  : Read / Write

The width of the visible area.

Allowed values: >= 0

Default value: 0

### The `"desktop-width"` property

      "desktop-width"            gint                  : Read / Write

The width of viewport that works well for most web pages designed for desktop.

Allowed values: >= 0

Default value: 980

### The `"device-dpi"` property

      "device-dpi"               gint                  : Read / Write

The number of dots per inch of the screen.

Allowed values: >= 0

Default value: 160

### The `"device-height"` property

      "device-height"            gint                  : Read / Write

The height of the screen.

Allowed values: >= 0

Default value: 0

### The `"device-pixel-ratio"` property

      "device-pixel-ratio"       gfloat                : Read

The device pixel ratio of the viewport.

Allowed values: >= -1

Default value: -1

### The `"device-width"` property

      "device-width"             gint                  : Read / Write

The width of the screen.

Allowed values: >= 0

Default value: 0

### The `"height"` property

      "height"                   gint                  : Read

The height of the viewport.

Allowed values: >= 0

Default value: 0

### The `"initial-scale-factor"` property

      "initial-scale-factor"     gfloat                : Read

The initial scale of the viewport.

Allowed values: >= -1

Default value: -1

### The `"maximum-scale-factor"` property

      "maximum-scale-factor"     gfloat                : Read

The maximum scale of the viewport.

Allowed values: >= -1

Default value: -1

### The `"minimum-scale-factor"` property

      "minimum-scale-factor"     gfloat                : Read

The minimum scale of the viewport.

Allowed values: >= -1

Default value: -1

### The `"user-scalable"` property

      "user-scalable"            gboolean              : Read

Determines whether or not the user can zoom in and out.

Default value: TRUE

### The `"valid"` property

      "valid"                    gboolean              : Read

Determines whether or not the attributes are valid, and can be used.

Default value: FALSE

### The `"width"` property

      "width"                    gint                  : Read

The width of the viewport.

Allowed values: >= 0

Default value: 0

## See Also

"viewport-attributes-recompute-requested", "viewport-attributes-changed"