• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 #ifndef UI_EVENTS_TEST_TEST_EVENT_TARGET_H_
6 #define UI_EVENTS_TEST_TEST_EVENT_TARGET_H_
7 
8 #include <set>
9 #include <string>
10 #include <vector>
11 
12 #include "base/memory/scoped_vector.h"
13 #include "ui/events/event_target.h"
14 
15 typedef std::vector<std::string> HandlerSequenceRecorder;
16 
17 namespace gfx {
18 class Point;
19 }
20 
21 namespace ui {
22 namespace test {
23 
24 class TestEventTarget : public EventTarget {
25  public:
26   TestEventTarget();
27   virtual ~TestEventTarget();
28 
29   void AddChild(scoped_ptr<TestEventTarget> child);
30   scoped_ptr<TestEventTarget> RemoveChild(TestEventTarget* child);
31 
parent()32   TestEventTarget* parent() { return parent_; }
33 
set_mark_events_as_handled(bool handle)34   void set_mark_events_as_handled(bool handle) {
35     mark_events_as_handled_ = handle;
36   }
37 
child_at(int index)38   TestEventTarget* child_at(int index) { return children_[index]; }
child_count()39   size_t child_count() const { return children_.size(); }
40 
41   void SetEventTargeter(scoped_ptr<EventTargeter> targeter);
42 
43   bool DidReceiveEvent(ui::EventType type) const;
44   void ResetReceivedEvents();
45 
set_recorder(HandlerSequenceRecorder * recorder)46   void set_recorder(HandlerSequenceRecorder* recorder) {
47     recorder_ = recorder;
48   }
set_target_name(const std::string & target_name)49   void set_target_name(const std::string& target_name) {
50     target_name_ = target_name;
51   }
52 
53  protected:
54   bool Contains(TestEventTarget* target) const;
55 
56   // EventTarget:
57   virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
58   virtual EventTarget* GetParentTarget() OVERRIDE;
59   virtual scoped_ptr<EventTargetIterator> GetChildIterator() const OVERRIDE;
60   virtual EventTargeter* GetEventTargeter() OVERRIDE;
61 
62   // EventHandler:
63   virtual void OnEvent(Event* event) OVERRIDE;
64 
65  private:
set_parent(TestEventTarget * parent)66   void set_parent(TestEventTarget* parent) { parent_ = parent; }
67 
68   TestEventTarget* parent_;
69   ScopedVector<TestEventTarget> children_;
70   scoped_ptr<EventTargeter> targeter_;
71   bool mark_events_as_handled_;
72 
73   std::set<ui::EventType> received_;
74 
75   HandlerSequenceRecorder* recorder_;
76   std::string target_name_;
77 
78   DISALLOW_COPY_AND_ASSIGN(TestEventTarget);
79 };
80 
81 }  // namespace test
82 }  // namespace ui
83 
84 #endif  // UI_EVENTS_TEST_TEST_EVENT_TARGET_H_
85