summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/aura.gyp1
-rw-r--r--ui/aura/client/cursor_client.h5
-rw-r--r--ui/aura/client/cursor_client_observer.h24
-rw-r--r--ui/views/corewm/compound_event_filter_unittest.cc8
-rw-r--r--ui/views/corewm/cursor_manager.cc17
-rw-r--r--ui/views/corewm/cursor_manager.h7
-rw-r--r--ui/views/corewm/cursor_manager_unittest.cc76
7 files changed, 138 insertions, 0 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index f6ec2ce..3fd58f4 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -38,6 +38,7 @@
'client/capture_delegate.h',
'client/cursor_client.cc',
'client/cursor_client.h',
+ 'client/cursor_client_observer.h',
'client/default_capture_client.cc',
'client/default_capture_client.h',
'client/dispatcher_client.cc',
diff --git a/ui/aura/client/cursor_client.h b/ui/aura/client/cursor_client.h
index fb2dde2..d79bed5 100644
--- a/ui/aura/client/cursor_client.h
+++ b/ui/aura/client/cursor_client.h
@@ -16,6 +16,7 @@ class Display;
namespace aura {
class Window;
namespace client {
+class CursorClientObserver;
// An interface that receives cursor change events.
class AURA_EXPORT CursorClient {
@@ -60,6 +61,10 @@ class AURA_EXPORT CursorClient {
// typically used to load non system cursors.
virtual void SetCursorResourceModule(const string16& module_name) = 0;
+ // Used to add or remove a CursorClientObserver.
+ virtual void AddObserver(CursorClientObserver* observer) = 0;
+ virtual void RemoveObserver(CursorClientObserver* observer) = 0;
+
protected:
virtual ~CursorClient() {}
};
diff --git a/ui/aura/client/cursor_client_observer.h b/ui/aura/client/cursor_client_observer.h
new file mode 100644
index 0000000..1a6d1a8
--- /dev/null
+++ b/ui/aura/client/cursor_client_observer.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2013 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.
+
+#ifndef UI_AURA_CLIENT_CURSOR_CLIENT_OBSERVER_H_
+#define UI_AURA_CLIENT_CURSOR_CLIENT_OBSERVER_H_
+
+#include "ui/aura/aura_export.h"
+
+namespace aura {
+namespace client {
+
+class AURA_EXPORT CursorClientObserver {
+ public:
+ virtual void OnCursorVisibilityChanged(bool is_visible) = 0;
+
+ protected:
+ virtual ~CursorClientObserver() {}
+};
+
+} // namespace client
+} // namespace aura
+
+#endif // UI_AURA_CLIENT_CURSOR_CLIENT_OBSERVER_H_
diff --git a/ui/views/corewm/compound_event_filter_unittest.cc b/ui/views/corewm/compound_event_filter_unittest.cc
index d3c32ee..412852c 100644
--- a/ui/views/corewm/compound_event_filter_unittest.cc
+++ b/ui/views/corewm/compound_event_filter_unittest.cc
@@ -65,6 +65,14 @@ class TestCursorClient : public aura::client::CursorClient {
virtual void SetCursorResourceModule(const string16& module_name) OVERRIDE {
}
+ virtual void AddObserver(
+ aura::client::CursorClientObserver* observer) OVERRIDE {
+ }
+
+ virtual void RemoveObserver(
+ aura::client::CursorClientObserver* observer) OVERRIDE {
+ }
+
private:
bool visible_;
bool mouse_events_enabled_;
diff --git a/ui/views/corewm/cursor_manager.cc b/ui/views/corewm/cursor_manager.cc
index 24abfe2..9e7a3bd 100644
--- a/ui/views/corewm/cursor_manager.cc
+++ b/ui/views/corewm/cursor_manager.cc
@@ -5,6 +5,7 @@
#include "ui/views/corewm/cursor_manager.h"
#include "base/logging.h"
+#include "ui/aura/client/cursor_client_observer.h"
#include "ui/views/corewm/native_cursor_manager.h"
#include "ui/views/corewm/native_cursor_manager_delegate.h"
@@ -86,6 +87,8 @@ void CursorManager::ShowCursor() {
if (cursor_lock_count_ == 0 &&
IsCursorVisible() != state_on_unlock_->visible()) {
delegate_->SetVisibility(state_on_unlock_->visible(), this);
+ FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
+ OnCursorVisibilityChanged(true));
}
}
@@ -94,6 +97,8 @@ void CursorManager::HideCursor() {
if (cursor_lock_count_ == 0 &&
IsCursorVisible() != state_on_unlock_->visible()) {
delegate_->SetVisibility(state_on_unlock_->visible(), this);
+ FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
+ OnCursorVisibilityChanged(false));
}
}
@@ -154,6 +159,16 @@ void CursorManager::SetCursorResourceModule(const string16& module_name) {
delegate_->SetCursorResourceModule(module_name);
}
+void CursorManager::AddObserver(
+ aura::client::CursorClientObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void CursorManager::RemoveObserver(
+ aura::client::CursorClientObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
gfx::NativeCursor CursorManager::GetCurrentCursor() const {
return current_state_->cursor();
}
@@ -171,6 +186,8 @@ void CursorManager::CommitCursor(gfx::NativeCursor cursor) {
}
void CursorManager::CommitVisibility(bool visible) {
+ FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
+ OnCursorVisibilityChanged(visible));
current_state_->SetVisible(visible);
}
diff --git a/ui/views/corewm/cursor_manager.h b/ui/views/corewm/cursor_manager.h
index 7197995..136e4bd 100644
--- a/ui/views/corewm/cursor_manager.h
+++ b/ui/views/corewm/cursor_manager.h
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
+#include "base/observer_list.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/point.h"
@@ -51,6 +52,10 @@ class VIEWS_EXPORT CursorManager : public aura::client::CursorClient,
virtual void LockCursor() OVERRIDE;
virtual void UnlockCursor() OVERRIDE;
virtual void SetCursorResourceModule(const string16& module_name) OVERRIDE;
+ virtual void AddObserver(
+ aura::client::CursorClientObserver* observer) OVERRIDE;
+ virtual void RemoveObserver(
+ aura::client::CursorClientObserver* observer) OVERRIDE;
private:
// Overridden from NativeCursorManagerDelegate:
@@ -73,6 +78,8 @@ class VIEWS_EXPORT CursorManager : public aura::client::CursorClient,
// The cursor state to restore when the cursor is unlocked.
scoped_ptr<internal::CursorState> state_on_unlock_;
+ ObserverList<aura::client::CursorClientObserver> observers_;
+
DISALLOW_COPY_AND_ASSIGN(CursorManager);
};
diff --git a/ui/views/corewm/cursor_manager_unittest.cc b/ui/views/corewm/cursor_manager_unittest.cc
index 3f53370..d05990f 100644
--- a/ui/views/corewm/cursor_manager_unittest.cc
+++ b/ui/views/corewm/cursor_manager_unittest.cc
@@ -4,6 +4,7 @@
#include "ui/views/corewm/cursor_manager.h"
+#include "ui/aura/client/cursor_client_observer.h"
#include "ui/views/corewm/native_cursor_manager.h"
#include "ui/views/test/views_test_base.h"
@@ -60,6 +61,28 @@ class CursorManagerTest : public views::ViewsTestBase {
views::corewm::CursorManager cursor_manager_;
};
+class TestingCursorClientObserver : public aura::client::CursorClientObserver {
+ public:
+ TestingCursorClientObserver()
+ : cursor_visibility_(false),
+ did_visibility_change_(false) {}
+ void reset() { cursor_visibility_ = did_visibility_change_ = false; }
+ bool is_cursor_visible() const { return cursor_visibility_; }
+ bool did_visibility_change() const { return did_visibility_change_; }
+
+ // Overridden from aura::client::CursorClientObserver:
+ virtual void OnCursorVisibilityChanged(bool is_visible) OVERRIDE {
+ cursor_visibility_ = is_visible;
+ did_visibility_change_ = true;
+ }
+
+ private:
+ bool cursor_visibility_;
+ bool did_visibility_change_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver);
+};
+
TEST_F(CursorManagerTest, ShowHideCursor) {
cursor_manager_.SetCursor(ui::kCursorCopy);
EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type());
@@ -244,3 +267,56 @@ TEST_F(CursorManagerTest, MultipleEnableMouseEvents) {
cursor_manager_.UnlockCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
}
+
+TEST_F(CursorManagerTest, TestCursorClientObserver) {
+ // Add two observers. Both should have OnCursorVisibilityChanged()
+ // invoked when the visibility of the cursor changes.
+ TestingCursorClientObserver observer_a;
+ TestingCursorClientObserver observer_b;
+ cursor_manager_.AddObserver(&observer_a);
+ cursor_manager_.AddObserver(&observer_b);
+
+ // Initial state before any events have been sent.
+ observer_a.reset();
+ observer_b.reset();
+ EXPECT_FALSE(observer_a.did_visibility_change());
+ EXPECT_FALSE(observer_b.did_visibility_change());
+ EXPECT_FALSE(observer_a.is_cursor_visible());
+ EXPECT_FALSE(observer_b.is_cursor_visible());
+
+ // Hide the cursor using HideCursor().
+ cursor_manager_.HideCursor();
+ EXPECT_TRUE(observer_a.did_visibility_change());
+ EXPECT_TRUE(observer_b.did_visibility_change());
+ EXPECT_FALSE(observer_a.is_cursor_visible());
+ EXPECT_FALSE(observer_b.is_cursor_visible());
+
+ // Show the cursor using ShowCursor().
+ observer_a.reset();
+ observer_b.reset();
+ cursor_manager_.ShowCursor();
+ EXPECT_TRUE(observer_a.did_visibility_change());
+ EXPECT_TRUE(observer_b.did_visibility_change());
+ EXPECT_TRUE(observer_a.is_cursor_visible());
+ EXPECT_TRUE(observer_b.is_cursor_visible());
+
+ // Remove observer_b. Its OnCursorVisibilityChanged() should
+ // not be invoked past this point.
+ cursor_manager_.RemoveObserver(&observer_b);
+
+ // Hide the cursor using HideCursor().
+ observer_a.reset();
+ observer_b.reset();
+ cursor_manager_.HideCursor();
+ EXPECT_TRUE(observer_a.did_visibility_change());
+ EXPECT_FALSE(observer_b.did_visibility_change());
+ EXPECT_FALSE(observer_a.is_cursor_visible());
+
+ // Show the cursor using ShowCursor().
+ observer_a.reset();
+ observer_b.reset();
+ cursor_manager_.ShowCursor();
+ EXPECT_TRUE(observer_a.did_visibility_change());
+ EXPECT_FALSE(observer_b.did_visibility_change());
+ EXPECT_TRUE(observer_a.is_cursor_visible());
+}