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 #include "ui/base/cursor/cursor.h"
6 
7 #include "base/logging.h"
8 #include "ui/gfx/skia_util.h"
9 
10 namespace ui {
11 
12 Cursor::Cursor() = default;
13 
Cursor(mojom::CursorType type)14 Cursor::Cursor(mojom::CursorType type) : type_(type) {}
15 
Cursor(const Cursor & cursor)16 Cursor::Cursor(const Cursor& cursor)
17     : type_(cursor.type_),
18       platform_cursor_(cursor.platform_cursor_),
19       image_scale_factor_(cursor.image_scale_factor_) {
20   if (type_ == mojom::CursorType::kCustom) {
21     custom_hotspot_ = cursor.custom_hotspot_;
22     custom_bitmap_ = cursor.custom_bitmap_;
23     RefCustomCursor();
24   }
25 }
26 
~Cursor()27 Cursor::~Cursor() {
28   if (type_ == mojom::CursorType::kCustom)
29     UnrefCustomCursor();
30 }
31 
SetPlatformCursor(const PlatformCursor & platform)32 void Cursor::SetPlatformCursor(const PlatformCursor& platform) {
33   if (type_ == mojom::CursorType::kCustom)
34     UnrefCustomCursor();
35   platform_cursor_ = platform;
36   if (type_ == mojom::CursorType::kCustom)
37     RefCustomCursor();
38 }
39 
40 #if !defined(USE_AURA)
RefCustomCursor()41 void Cursor::RefCustomCursor() {
42   NOTIMPLEMENTED();
43 }
UnrefCustomCursor()44 void Cursor::UnrefCustomCursor() {
45   NOTIMPLEMENTED();
46 }
47 #endif
48 
operator ==(const Cursor & cursor) const49 bool Cursor::operator==(const Cursor& cursor) const {
50   return type_ == cursor.type_ && platform_cursor_ == cursor.platform_cursor_ &&
51          image_scale_factor_ == cursor.image_scale_factor_ &&
52          (type_ != mojom::CursorType::kCustom ||
53           (custom_hotspot_ == cursor.custom_hotspot_ &&
54            gfx::BitmapsAreEqual(custom_bitmap_, cursor.custom_bitmap_)));
55 }
56 
operator =(const Cursor & cursor)57 void Cursor::operator=(const Cursor& cursor) {
58   if (*this == cursor)
59     return;
60   if (type_ == mojom::CursorType::kCustom)
61     UnrefCustomCursor();
62   type_ = cursor.type_;
63   platform_cursor_ = cursor.platform_cursor_;
64   if (type_ == mojom::CursorType::kCustom) {
65     RefCustomCursor();
66     custom_hotspot_ = cursor.custom_hotspot_;
67     custom_bitmap_ = cursor.custom_bitmap_;
68   }
69   image_scale_factor_ = cursor.image_scale_factor_;
70 }
71 
72 }  // namespace ui
73