summaryrefslogtreecommitdiffstats
path: root/ash/wm/cursor_manager.cc
blob: 1ebc72bfc7196f67fa71b3bda4523b0aafae1960 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2012 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 "ash/wm/cursor_manager.h"

#include "ash/wm/cursor_delegate.h"
#include "base/logging.h"
#include "ui/aura/env.h"

namespace ash {

CursorManager::CursorManager()
    : delegate_(NULL),
      cursor_lock_count_(0),
      did_cursor_change_(false),
      cursor_to_set_on_unlock_(0),
      cursor_visible_(true) {
}

CursorManager::~CursorManager() {
}

void CursorManager::LockCursor() {
  cursor_lock_count_++;
}

void CursorManager::UnlockCursor() {
  cursor_lock_count_--;
  DCHECK_GE(cursor_lock_count_, 0);
  if (cursor_lock_count_ == 0) {
    if (did_cursor_change_) {
      did_cursor_change_ = false;
      if (delegate_)
        delegate_->SetCursor(cursor_to_set_on_unlock_);
    }
    did_cursor_change_ = false;
    cursor_to_set_on_unlock_ = gfx::kNullCursor;
  }
}

void CursorManager::SetCursor(gfx::NativeCursor cursor) {
  if (cursor_lock_count_ == 0) {
    if (delegate_)
      delegate_->SetCursor(cursor);
  } else {
    cursor_to_set_on_unlock_ = cursor;
    did_cursor_change_ = true;
  }
}

void CursorManager::ShowCursor(bool show) {
  cursor_visible_ = show;
  if (delegate_)
    delegate_->ShowCursor(show);
}

bool CursorManager::IsCursorVisible() const {
  return cursor_visible_;
}

}  // namespace ash