diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-14 20:22:31 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-14 20:22:31 +0000 |
commit | cf562b77683aeb8458aa3040a45f35475b59b763 (patch) | |
tree | ab7cacd23c436d5594d049449a1cf0546f0f58b8 /ui/base | |
parent | dc9df8abc079c3040d47d6b9bdd284d82766ab27 (diff) | |
download | chromium_src-cf562b77683aeb8458aa3040a45f35475b59b763.zip chromium_src-cf562b77683aeb8458aa3040a45f35475b59b763.tar.gz chromium_src-cf562b77683aeb8458aa3040a45f35475b59b763.tar.bz2 |
Rotate Cursor when the display is rotated
- moved Rotation enum from ash to gfx::Display so that
views/ui can use it.
- rotate image and hot point.
BUG=119268
TEST=covered by unit tests, and also test on device.
Review URL: https://chromiumcodereview.appspot.com/12666006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188174 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base')
-rw-r--r-- | ui/base/cursor/cursor_loader.h | 19 | ||||
-rw-r--r-- | ui/base/cursor/cursor_loader_x11.cc | 35 |
2 files changed, 39 insertions, 15 deletions
diff --git a/ui/base/cursor/cursor_loader.h b/ui/base/cursor/cursor_loader.h index 1a87a42..661ab08 100644 --- a/ui/base/cursor/cursor_loader.h +++ b/ui/base/cursor/cursor_loader.h @@ -7,6 +7,7 @@ #include "base/logging.h" #include "ui/base/ui_export.h" +#include "ui/gfx/display.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/point.h" @@ -14,17 +15,17 @@ namespace ui { class UI_EXPORT CursorLoader { public: - CursorLoader() : device_scale_factor_(1.0f) {} + CursorLoader() {} virtual ~CursorLoader() {} - // Returns the device scale factor used by the loader. - float device_scale_factor() const { - return device_scale_factor_; + // Returns the display the loader loads images for. + const gfx::Display& display() const { + return display_; } - // Sets the device scale factor used by the loader. - void set_device_scale_factor(float device_scale_factor) { - device_scale_factor_ = device_scale_factor; + // Sets the display the loader loads images for. + void set_display(const gfx::Display& display) { + display_ = display; } // Creates a cursor from an image resource and puts it in the cursor map. @@ -52,8 +53,8 @@ class UI_EXPORT CursorLoader { static CursorLoader* Create(); private: - // The device scale factor used by the loader. - float device_scale_factor_; + // The display the loader loads images for. + gfx::Display display_; }; } // namespace ui diff --git a/ui/base/cursor/cursor_loader_x11.cc b/ui/base/cursor/cursor_loader_x11.cc index 006f8ec..c4d3fd3 100644 --- a/ui/base/cursor/cursor_loader_x11.cc +++ b/ui/base/cursor/cursor_loader_x11.cc @@ -14,6 +14,7 @@ #include "ui/base/x/x11_util.h" #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_skia.h" +#include "ui/gfx/skbitmap_operations.h" namespace { @@ -156,9 +157,29 @@ void CursorLoaderX11::LoadImageCursor(int id, const gfx::ImageSkia* image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); const gfx::ImageSkiaRep& image_rep = image->GetRepresentation( - GetScaleFactorFromScale(device_scale_factor())); - XcursorImage* x_image = - SkBitmapToXcursorImage(&image_rep.sk_bitmap(), hot); + GetScaleFactorFromScale(display().device_scale_factor())); + SkBitmap bitmap = image_rep.sk_bitmap(); + gfx::Point hotpoint = hot; + switch (display().rotation()) { + case gfx::Display::ROTATE_0: + break; + case gfx::Display::ROTATE_90: + hotpoint.SetPoint(bitmap.height() - hot.y(), hot.x()); + bitmap = SkBitmapOperations::Rotate( + bitmap, SkBitmapOperations::ROTATION_90_CW); + break; + case gfx::Display::ROTATE_180: + hotpoint.SetPoint(bitmap.width() - hot.x(), bitmap.height() - hot.y()); + bitmap = SkBitmapOperations::Rotate( + bitmap, SkBitmapOperations::ROTATION_180_CW); + break; + case gfx::Display::ROTATE_270: + hotpoint.SetPoint(hot.y(), bitmap.width() - hot.x()); + bitmap = SkBitmapOperations::Rotate( + bitmap, SkBitmapOperations::ROTATION_270_CW); + break; + } + XcursorImage* x_image = SkBitmapToXcursorImage(&bitmap, hotpoint); cursors_[id] = CreateReffedCustomXCursor(x_image); // |image_rep| is owned by the resource bundle. So we do not need to free it. } @@ -170,7 +191,7 @@ void CursorLoaderX11::LoadAnimatedCursor(int id, const gfx::ImageSkia* image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); const gfx::ImageSkiaRep& image_rep = image->GetRepresentation( - GetScaleFactorFromScale(device_scale_factor())); + GetScaleFactorFromScale(display().device_scale_factor())); const SkBitmap bitmap = image_rep.sk_bitmap(); DCHECK_EQ(bitmap.config(), SkBitmap::kARGB_8888_Config); int frame_width = bitmap.height(); @@ -227,10 +248,12 @@ void CursorLoaderX11::SetPlatformCursor(gfx::NativeCursor* cursor) { xcursor = invisible_cursor_.get(); else if (*cursor == kCursorCustom) xcursor = cursor->platform(); - else if (device_scale_factor() == 1.0f) + else if (display().device_scale_factor() == 1.0f && + display().rotation() == gfx::Display::ROTATE_0) { xcursor = GetXCursor(CursorShapeFromNative(*cursor)); - else + } else { xcursor = ImageCursorFromNative(kCursorPointer); + } cursor->SetPlatformCursor(xcursor); } |