Chromium Code Reviews| Index: ui/base/cursor/cursor_loader_ozone.cc |
| diff --git a/ui/base/cursor/cursor_loader_ozone.cc b/ui/base/cursor/cursor_loader_ozone.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a9bf887b0d2f04d8eae01c2560212ee0c8de51fd |
| --- /dev/null |
| +++ b/ui/base/cursor/cursor_loader_ozone.cc |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/base/cursor/cursor_loader_ozone.h" |
| + |
| +#include "ui/base/cursor/cursor.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#include "ui/gfx/image/image_skia.h" |
| + |
| +namespace ui { |
| + |
| +namespace { |
| + |
| +// Creates a 1x1 cursor which will be fully transparent. |
| +SkBitmap CreateInvisibleCursor() { |
| + SkBitmap cursor; |
| + cursor.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
| + cursor.allocPixels(); |
| + |
| + cursor.lockPixels(); |
| + cursor.eraseARGB(0, 0, 0, 0); |
| + cursor.unlockPixels(); |
| + |
| + return cursor; |
| +} |
| + |
| +} // namespace |
| + |
| +CursorLoaderOzone::CursorLoaderOzone() |
| + : invisible_cursor_(CreateInvisibleCursor()) {} |
| + |
| +CursorLoaderOzone::~CursorLoaderOzone() {} |
| + |
| +void CursorLoaderOzone::LoadImageCursor(int id, |
| + int resource_id, |
| + const gfx::Point& hot) { |
| + const gfx::ImageSkia* image = ResourceBundle::GetSharedInstance() |
|
rjkroege
2014/02/12 18:03:17
Perhaps the point of maintaining the cursors_ cach
dnicoara
2014/02/12 20:44:57
GetImageSkiaName may not be as cheap since it need
|
| + .GetImageSkiaNamed(resource_id); |
| + |
| + cursors_[id] = image; |
| +} |
| + |
| +void CursorLoaderOzone::LoadAnimatedCursor(int id, |
| + int resource_id, |
| + const gfx::Point& hot, |
| + int frame_delay_ms) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void CursorLoaderOzone::UnloadAll() { |
| + cursors_.clear(); |
| +} |
| + |
| +void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) { |
| + if (cursors_.find(cursor->native_type()) != cursors_.end()) { |
| + const gfx::ImageSkiaRep& image_rep = |
| + cursors_[cursor->native_type()]->GetRepresentation( |
| + display().device_scale_factor()); |
| + |
| + cursor->SetPlatformCursor(&image_rep.sk_bitmap()); |
| + } else if (*cursor == kCursorNone) { |
| + cursor->SetPlatformCursor(&invisible_cursor_); |
| + } else if (*cursor == kCursorCustom) { |
| + cursor->SetPlatformCursor(cursor->platform()); |
|
dnicoara
2014/02/12 16:18:20
This is where the custom webkit cursors are being
rjkroege
2014/02/12 18:03:17
nit: can you add a TODO listing the bug. And add a
dnicoara
2014/02/12 20:44:57
Done.
|
| + } else { |
| + const gfx::ImageSkiaRep& image_rep = |
| + cursors_[kCursorPointer]->GetRepresentation( |
| + display().device_scale_factor()); |
| + |
| + cursor->SetPlatformCursor(&image_rep.sk_bitmap()); |
| + } |
| +} |
| + |
| +CursorLoader* CursorLoader::Create() { |
| + return new CursorLoaderOzone(); |
| +} |
| + |
| +} // namespace ui |