Changeset 64526 in webkit


Ignore:
Timestamp:
Aug 2, 2010 7:44:57 PM (14 years ago)
Author:
Martin Robinson
Message:

2010-08-02 Martin Robinson <mrobinson@igalia.com>

Reviewed by Gustavo Noronha Silva.

[GTK] WebKit2 requires lazy cursor support
https://bugs.webkit.org/show_bug.cgi?id=43053

Add lazy cursor support for GTK+. Lazy cursor support is used on some
WebKit2 ports to support changing the cursor.

No new tests, as this should not change functionality.

  • platform/Cursor.h: Changed the m_platformCursor member to be a GRefPtr. This simplifies the logic a great deal.
  • platform/gtk/CursorGtk.cpp: (WebCore::createNamedCursor): Added, adapted from existing code. (WebCore::createCustomCursor): Added, adapted from existing code. (WebCore::Cursor::ensurePlatformCursor): Added. (WebCore::Cursor::Cursor): Added. (WebCore::Cursor::operator=): Added. (WebCore::Cursor::~Cursor): Added.
  • platform/gtk/WidgetGtk.cpp: (WebCore::Widget::setCursor): Call platformCusor now to get the actual GdkCursor.
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64525 r64526  
     12010-08-02  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Gustavo Noronha Silva.
     4
     5        [GTK] WebKit2 requires lazy cursor support
     6        https://bugs.webkit.org/show_bug.cgi?id=43053
     7
     8        Add lazy cursor support for GTK+. Lazy cursor support is used on some
     9        WebKit2 ports to support changing the cursor.
     10
     11        No new tests, as this should not change functionality.
     12
     13        * platform/Cursor.h: Changed the m_platformCursor member to be a GRefPtr.
     14        This simplifies the logic a great deal.
     15        * platform/gtk/CursorGtk.cpp:
     16        (WebCore::createNamedCursor): Added, adapted from existing code.
     17        (WebCore::createCustomCursor): Added, adapted from existing code.
     18        (WebCore::Cursor::ensurePlatformCursor): Added.
     19        (WebCore::Cursor::Cursor): Added.
     20        (WebCore::Cursor::operator=): Added.
     21        (WebCore::Cursor::~Cursor): Added.
     22        * platform/gtk/WidgetGtk.cpp:
     23        (WebCore::Widget::setCursor): Call platformCusor now to get the actual GdkCursor.
     24
    1252010-08-02  Rajiv Makhijani  <rajivmakhijani@chromium.org>
    226
  • trunk/WebCore/platform/Cursor.h

    r63339 r64526  
    3737#include <wtf/RefCounted.h>
    3838#elif PLATFORM(GTK)
    39 typedef struct _GdkCursor GdkCursor;
     39#include "GRefPtrGtk.h"
    4040#elif PLATFORM(QT)
    4141#include <QCursor>
     
    6363#endif
    6464
    65 #if PLATFORM(WIN) || PLATFORM(MAC)
     65#if PLATFORM(WIN) || PLATFORM(MAC) || PLATFORM(GTK)
    6666#define WTF_USE_LAZY_NATIVE_CURSOR 1
    6767#endif
     
    8585    typedef NSCursor* PlatformCursor;
    8686#elif PLATFORM(GTK)
    87     typedef GdkCursor* PlatformCursor;
     87    typedef GRefPtr<GdkCursor> PlatformCursor;
    8888#elif PLATFORM(EFL)
    8989    typedef const char* PlatformCursor;
  • trunk/WebCore/platform/gtk/CursorGtk.cpp

    r63339 r64526  
    22 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
    33 * Copyright (C) 2007 Christian Dywan <christian@twotoasts.de>
     4 * Copyright (C) 2010 Igalia S.L.
    45 * All rights reserved.
    56 *
     
    3132#include "Image.h"
    3233#include "IntPoint.h"
    33 
    34 #include <wtf/Assertions.h>
    35 
    3634#include <gdk/gdk.h>
    3735#include <gtk/gtk.h>
     36#include <wtf/Assertions.h>
    3837
    3938namespace WebCore {
    4039
    41 static GdkCursor* customCursorNew(CustomCursorType cursorType)
     40static GdkCursor* createNamedCursor(CustomCursorType cursorType)
    4241{
    4342    CustomCursor cursor = CustomCursors[cursorType];
    4443    GdkCursor* c = gdk_cursor_new_from_name(gdk_display_get_default(), cursor.name);
    45     if (!c) {
    46         const GdkColor fg = { 0, 0, 0, 0 };
    47         const GdkColor bg = { 65535, 65535, 65535, 65535 };
    48 
    49         GdkPixmap* source = gdk_bitmap_create_from_data(NULL, cursor.bits, 32, 32);
    50         GdkPixmap* mask = gdk_bitmap_create_from_data(NULL, cursor.mask_bits, 32, 32);
    51         c = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, cursor.hot_x, cursor.hot_y);
    52         g_object_unref(source);
    53         g_object_unref(mask);
     44    if (c)
     45        return c;
     46
     47    const GdkColor fg = { 0, 0, 0, 0 };
     48    const GdkColor bg = { 65535, 65535, 65535, 65535 };
     49    GRefPtr<GdkPixmap> source = adoptGRef(gdk_bitmap_create_from_data(0, cursor.bits, 32, 32));
     50    GRefPtr<GdkPixmap> mask = adoptGRef(gdk_bitmap_create_from_data(0, cursor.mask_bits, 32, 32));
     51    return gdk_cursor_new_from_pixmap(source.get(), mask.get(), &fg, &bg, cursor.hot_x, cursor.hot_y);
     52}
     53
     54static GdkCursor* createCustomCursor(Image* image, const IntPoint& hotSpot)
     55{
     56    IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot);
     57    GRefPtr<GdkPixbuf> pixbuf = adoptGRef(image->getGdkPixbuf());
     58    return gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf.get(), effectiveHotSpot.x(), effectiveHotSpot.y());
     59}
     60
     61void Cursor::ensurePlatformCursor() const
     62{
     63    if (m_platformCursor || m_type == Cursor::Pointer)
     64        return;
     65
     66    switch (m_type) {
     67    case Cursor::Pointer:
     68        // A null GdkCursor is the default cursor for the window.
     69        m_platformCursor = 0;
     70        break;
     71    case Cursor::Cross:
     72        m_platformCursor = gdk_cursor_new(GDK_CROSS);
     73        break;
     74    case Cursor::Hand:
     75        m_platformCursor = gdk_cursor_new(GDK_HAND2);
     76        break;
     77    case Cursor::IBeam:
     78        m_platformCursor = gdk_cursor_new(GDK_XTERM);
     79        break;
     80    case Cursor::Wait:
     81        m_platformCursor = gdk_cursor_new(GDK_WATCH);
     82        break;
     83    case Cursor::Help:
     84        m_platformCursor = gdk_cursor_new(GDK_QUESTION_ARROW);
     85        break;
     86    case Cursor::Move:
     87    case Cursor::MiddlePanning:
     88        m_platformCursor = gdk_cursor_new(GDK_FLEUR);
     89        break;
     90    case Cursor::EastResize:
     91    case Cursor::EastPanning:
     92        m_platformCursor = gdk_cursor_new(GDK_RIGHT_SIDE);
     93        break;
     94    case Cursor::NorthResize:
     95    case Cursor::NorthPanning:
     96        m_platformCursor = gdk_cursor_new(GDK_TOP_SIDE);
     97        break;
     98    case Cursor::NorthEastResize:
     99    case Cursor::NorthEastPanning:
     100        m_platformCursor = gdk_cursor_new(GDK_LEFT_SIDE);
     101        break;
     102    case Cursor::NorthWestResize:
     103    case Cursor::NorthWestPanning:
     104        m_platformCursor = gdk_cursor_new(GDK_TOP_LEFT_CORNER);
     105        break;
     106    case Cursor::SouthResize:
     107    case Cursor::SouthPanning:
     108        m_platformCursor = gdk_cursor_new(GDK_BOTTOM_SIDE);
     109        break;
     110    case Cursor::SouthEastResize:
     111    case Cursor::SouthEastPanning:
     112        m_platformCursor = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER);
     113        break;
     114    case Cursor::SouthWestResize:
     115    case Cursor::SouthWestPanning:
     116        m_platformCursor = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER);
     117        break;
     118    case Cursor::WestResize:
     119        m_platformCursor = gdk_cursor_new(GDK_LEFT_SIDE);
     120        break;
     121    case Cursor::NorthSouthResize:
     122        m_platformCursor = gdk_cursor_new(GDK_TOP_TEE);
     123        break;
     124    case Cursor::EastWestResize:
     125    case Cursor::WestPanning:
     126        m_platformCursor = gdk_cursor_new(GDK_LEFT_SIDE);
     127        break;
     128    case Cursor::NorthEastSouthWestResize:
     129    case Cursor::NorthWestSouthEastResize:
     130        m_platformCursor = gdk_cursor_new(GDK_SIZING);
     131        break;
     132    case Cursor::ColumnResize:
     133        m_platformCursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
     134        break;
     135    case Cursor::RowResize:
     136        m_platformCursor = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW);
     137        break;
     138    case Cursor::VerticalText:
     139        m_platformCursor = createNamedCursor(CustomCursorVerticalText);
     140        break;
     141    case Cursor::Cell:
     142        m_platformCursor = gdk_cursor_new(GDK_PLUS);
     143        break;
     144    case Cursor::ContextMenu:
     145        m_platformCursor = createNamedCursor(CustomCursorContextMenu);
     146        break;
     147    case Cursor::Alias:
     148        m_platformCursor = createNamedCursor(CustomCursorAlias);
     149        break;
     150    case Cursor::Progress:
     151        m_platformCursor = createNamedCursor(CustomCursorProgress);
     152        break;
     153    case Cursor::NoDrop:
     154    case Cursor::NotAllowed:
     155        m_platformCursor = createNamedCursor(CustomCursorNoDrop);
     156        break;
     157    case Cursor::Copy:
     158        m_platformCursor = createNamedCursor(CustomCursorCopy);
     159        break;
     160    case Cursor::None:
     161        m_platformCursor = createNamedCursor(CustomCursorNone);
     162        break;
     163    case Cursor::ZoomIn:
     164        m_platformCursor = createNamedCursor(CustomCursorZoomIn);
     165        break;
     166    case Cursor::ZoomOut:
     167        m_platformCursor = createNamedCursor(CustomCursorZoomOut);
     168        break;
     169    case Cursor::Grab:
     170        m_platformCursor = createNamedCursor(CustomCursorGrab);
     171        break;
     172    case Cursor::Grabbing:
     173        m_platformCursor = createNamedCursor(CustomCursorGrabbing);
     174        break;
     175    case Cursor::Custom:
     176        m_platformCursor = createCustomCursor(m_image.get(), m_hotSpot);
     177        break;
    54178    }
    55     return c;
    56 }
    57 
     179}
    58180
    59181Cursor::Cursor(const Cursor& other)
    60     : m_platformCursor(other.m_platformCursor)
    61 {
    62     if (m_platformCursor)
    63         gdk_cursor_ref(m_platformCursor);
    64 }
    65 
    66 Cursor::Cursor(Image* image, const IntPoint& hotSpot)
    67 {
    68     IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot);
    69     GdkPixbuf* pixbuf = image->getGdkPixbuf();
    70     m_platformCursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, effectiveHotSpot.x(), effectiveHotSpot.y());
    71     g_object_unref(pixbuf);
    72 }
    73 
    74 Cursor::~Cursor()
    75 {
    76     if (m_platformCursor)
    77         gdk_cursor_unref(m_platformCursor);
     182    : m_type(other.m_type)
     183    , m_image(other.m_image)
     184    , m_hotSpot(other.m_hotSpot)
     185    , m_platformCursor(other.m_platformCursor)
     186{
    78187}
    79188
    80189Cursor& Cursor::operator=(const Cursor& other)
    81190{
    82     gdk_cursor_ref(other.m_platformCursor);
    83     gdk_cursor_unref(m_platformCursor);
     191    m_type = other.m_type;
     192    m_image = other.m_image;
     193    m_hotSpot = other.m_hotSpot;
    84194    m_platformCursor = other.m_platformCursor;
    85195    return *this;
    86196}
    87197
    88 Cursor::Cursor(GdkCursor* c)
    89     : m_platformCursor(c)
    90 {
    91     m_platformCursor = c;
    92 
    93     // The GdkCursor may be NULL - the default cursor for the window.
    94     if (c)
    95         gdk_cursor_ref(c);
    96 }
    97 
    98 const Cursor& pointerCursor()
    99 {
    100     static Cursor c = 0;
    101     return c;
    102 }
    103 
    104 const Cursor& crossCursor()
    105 {
    106     static Cursor c = gdk_cursor_new(GDK_CROSS);
    107     return c;
    108 }
    109 
    110 const Cursor& handCursor()
    111 {
    112     static Cursor c = gdk_cursor_new(GDK_HAND2);
    113     return c;
    114 }
    115 
    116 const Cursor& moveCursor()
    117 {
    118     static Cursor c = gdk_cursor_new(GDK_FLEUR);
    119     return c;
    120 }
    121 
    122 const Cursor& iBeamCursor()
    123 {
    124     static Cursor c = gdk_cursor_new(GDK_XTERM);
    125     return c;
    126 }
    127 
    128 const Cursor& waitCursor()
    129 {
    130     static Cursor c = gdk_cursor_new(GDK_WATCH);
    131     return c;
    132 }
    133 
    134 const Cursor& helpCursor()
    135 {
    136     static Cursor c = gdk_cursor_new(GDK_QUESTION_ARROW);
    137     return c;
    138 }
    139 
    140 const Cursor& eastResizeCursor()
    141 {
    142     static Cursor c = gdk_cursor_new(GDK_RIGHT_SIDE);
    143     return c;
    144 }
    145 
    146 const Cursor& northResizeCursor()
    147 {
    148     static Cursor c = gdk_cursor_new(GDK_TOP_SIDE);
    149     return c;
    150 }
    151 
    152 const Cursor& northEastResizeCursor()
    153 {
    154     static Cursor c = gdk_cursor_new(GDK_TOP_RIGHT_CORNER);
    155     return c;
    156 }
    157 
    158 const Cursor& northWestResizeCursor()
    159 {
    160     static Cursor c = gdk_cursor_new(GDK_TOP_LEFT_CORNER);
    161     return c;
    162 }
    163 
    164 const Cursor& southResizeCursor()
    165 {
    166     static Cursor c = gdk_cursor_new(GDK_BOTTOM_SIDE);
    167     return c;
    168 }
    169 
    170 const Cursor& southEastResizeCursor()
    171 {
    172     static Cursor c = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER);
    173     return c;
    174 }
    175 
    176 const Cursor& southWestResizeCursor()
    177 {
    178     static Cursor c = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER);
    179     return c;
    180 }
    181 
    182 const Cursor& westResizeCursor()
    183 {
    184     static Cursor c = gdk_cursor_new(GDK_LEFT_SIDE);
    185     return c;
    186 }
    187 
    188 const Cursor& northSouthResizeCursor()
    189 {
    190     static Cursor c = gdk_cursor_new(GDK_TOP_TEE);
    191     return c;
    192 }
    193 
    194 const Cursor& eastWestResizeCursor()
    195 {
    196     static Cursor c = gdk_cursor_new(GDK_LEFT_SIDE);
    197     return c;
    198 }
    199 
    200 const Cursor& northEastSouthWestResizeCursor()
    201 {
    202     static Cursor c = gdk_cursor_new(GDK_SIZING);
    203     return c;
    204 }
    205 
    206 const Cursor& northWestSouthEastResizeCursor()
    207 {
    208     static Cursor c = gdk_cursor_new(GDK_SIZING);
    209     return c;
    210 }
    211 
    212 const Cursor& columnResizeCursor()
    213 {
    214     static Cursor c = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
    215     return c;
    216 }
    217 
    218 const Cursor& rowResizeCursor()
    219 {
    220     static Cursor c = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW);
    221     return c;
    222 }
    223    
    224 const Cursor& middlePanningCursor()
    225 {
    226     return moveCursor();
    227 }
    228 
    229 const Cursor& eastPanningCursor()
    230 {
    231     return eastResizeCursor();
    232 }
    233 
    234 const Cursor& northPanningCursor()
    235 {
    236     return northResizeCursor();
    237 }
    238 
    239 const Cursor& northEastPanningCursor()
    240 {
    241     return northEastResizeCursor();
    242 }
    243 
    244 const Cursor& northWestPanningCursor()
    245 {
    246     return northWestResizeCursor();
    247 }
    248 
    249 const Cursor& southPanningCursor()
    250 {
    251     return southResizeCursor();
    252 }
    253 
    254 const Cursor& southEastPanningCursor()
    255 {
    256     return southEastResizeCursor();
    257 }
    258 
    259 const Cursor& southWestPanningCursor()
    260 {
    261     return southWestResizeCursor();
    262 }
    263 
    264 const Cursor& westPanningCursor()
    265 {
    266     return westResizeCursor();
    267 }
    268    
    269 
    270 const Cursor& verticalTextCursor()
    271 {
    272     static Cursor c = customCursorNew(CustomCursorVerticalText);
    273     return c;
    274 }
    275 
    276 const Cursor& cellCursor()
    277 {
    278     static Cursor c = gdk_cursor_new(GDK_PLUS);
    279     return c;
    280 }
    281 
    282 const Cursor& contextMenuCursor()
    283 {
    284     static Cursor c = customCursorNew(CustomCursorContextMenu);
    285     return c;
    286 }
    287 
    288 const Cursor& noDropCursor()
    289 {
    290     static Cursor c = customCursorNew(CustomCursorNoDrop);
    291     return c;
    292 }
    293 
    294 const Cursor& copyCursor()
    295 {
    296     static Cursor c = customCursorNew(CustomCursorCopy);
    297     return c;
    298 }
    299 
    300 const Cursor& progressCursor()
    301 {
    302     static Cursor c = customCursorNew(CustomCursorProgress);
    303     return c;
    304 }
    305 
    306 const Cursor& aliasCursor()
    307 {
    308     static Cursor c = customCursorNew(CustomCursorAlias);
    309     return c;
    310 }
    311 
    312 const Cursor& noneCursor()
    313 {
    314     static Cursor c = customCursorNew(CustomCursorNone);
    315     return c;
    316 }
    317 
    318 const Cursor& notAllowedCursor()
    319 {
    320     return noDropCursor();
    321 }
    322 
    323 const Cursor& zoomInCursor()
    324 {
    325     static Cursor c = customCursorNew(CustomCursorZoomIn);
    326     return c;
    327 }
    328 
    329 const Cursor& zoomOutCursor()
    330 {
    331     static Cursor c = customCursorNew(CustomCursorZoomOut);
    332     return c;
    333 }
    334 
    335 const Cursor& grabCursor()
    336 {
    337     static Cursor c = customCursorNew(CustomCursorGrab);
    338     return c;
    339 }
    340 
    341 const Cursor& grabbingCursor()
    342 {
    343     static Cursor c = customCursorNew(CustomCursorGrabbing);
    344     return c;
    345 }
    346 
    347 }
     198Cursor::~Cursor()
     199{
     200}
     201
     202}
  • trunk/WebCore/platform/gtk/WidgetGtk.cpp

    r60846 r64526  
    6868void Widget::setCursor(const Cursor& cursor)
    6969{
    70     GdkCursor* platformCursor = cursor.impl();
     70    GdkCursor* platformCursor = cursor.platformCursor().get();
    7171
    7272    // http://bugs.webkit.org/show_bug.cgi?id=16388
Note: See TracChangeset for help on using the changeset viewer.