Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Unified Diff: ui/base/cursor/cursor_loader_ozone.cc

Issue 158023006: Adding Ozone CursorLoader and necessary API functions to allow setting the cursor in SoftwareFactor… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..290f996057e946df12a56c10b93d4b2306040664
--- /dev/null
+++ b/ui/base/cursor/cursor_loader_ozone.cc
@@ -0,0 +1,81 @@
+// 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()
+ .GetImageSkiaNamed(resource_id);
+
+ cursors_[id] = image;
sky 2014/02/12 21:47:22 nit: do away with temporary (eg assign directly).
dnicoara 2014/02/12 21:57:40 Done.
+}
+
+void CursorLoaderOzone::LoadAnimatedCursor(int id,
+ int resource_id,
+ const gfx::Point& hot,
+ int frame_delay_ms) {
+ // TODO(dnicoara) Add support: crbug.com/343245
+ 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) {
+ // TODO(dnicoara) Add support for custom cursors: crbug.com/343155
+ cursor->SetPlatformCursor(cursor->platform());
+ } 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

Powered by Google App Engine
This is Rietveld 408576698