cursor_loader_x11.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ 6#define UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ 7 8#include <X11/Xcursor/Xcursor.h> 9#include <map> 10 11#include "base/compiler_specific.h" 12#include "ui/base/cursor/cursor.h" 13#include "ui/base/cursor/cursor_loader.h" 14#include "ui/base/ui_export.h" 15#include "ui/base/x/x11_util.h" 16 17namespace ui { 18 19class UI_EXPORT CursorLoaderX11 : public CursorLoader { 20 public: 21 CursorLoaderX11(); 22 virtual ~CursorLoaderX11(); 23 24 // Overridden from CursorLoader: 25 virtual void LoadImageCursor(int id, 26 int resource_id, 27 const gfx::Point& hot) OVERRIDE; 28 virtual void LoadAnimatedCursor(int id, 29 int resource_id, 30 const gfx::Point& hot, 31 int frame_delay_ms) OVERRIDE; 32 virtual void UnloadAll() OVERRIDE; 33 virtual void SetPlatformCursor(gfx::NativeCursor* cursor) OVERRIDE; 34 virtual void SetCursorResourceModule(const string16& module_name) OVERRIDE { 35 } 36 37 private: 38 // Returns true if we have an image resource loaded for the |native_cursor|. 39 bool IsImageCursor(gfx::NativeCursor native_cursor); 40 41 // Gets the X Cursor corresponding to the |native_cursor|. 42 ::Cursor ImageCursorFromNative(gfx::NativeCursor native_cursor); 43 44 // A map to hold all image cursors. It maps the cursor ID to the X Cursor. 45 typedef std::map<int, ::Cursor> ImageCursorMap; 46 ImageCursorMap cursors_; 47 48 // A map to hold all animated cursors. It maps the cursor ID to the pair of 49 // the X Cursor and the corresponding XcursorImages. We need a pointer to the 50 // images so that we can free them on destruction. 51 typedef std::map<int, std::pair< ::Cursor, XcursorImages*> > 52 AnimatedCursorMap; 53 AnimatedCursorMap animated_cursors_; 54 55 const XScopedCursor invisible_cursor_; 56 57 DISALLOW_COPY_AND_ASSIGN(CursorLoaderX11); 58}; 59 60} // namespace ui 61 62#endif // UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ 63