Automated Commit: Committing new LKGM version 7479.0.0 for chromeos.
[chromium-blink-merge.git] / ui / views / test / test_views.h
blob28cc27600b799c14c47a4444286f74255f380589
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.
5 #ifndef UI_VIEWS_TEST_TEST_VIEWS_H_
6 #define UI_VIEWS_TEST_TEST_VIEWS_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "ui/events/event_constants.h"
10 #include "ui/views/view.h"
12 namespace views {
14 // A view that requests a set amount of space.
15 class StaticSizedView : public View {
16 public:
17 explicit StaticSizedView(const gfx::Size& size);
18 ~StaticSizedView() override;
20 void set_minimum_size(const gfx::Size& minimum_size) {
21 minimum_size_ = minimum_size;
24 void set_maximum_size(const gfx::Size& maximum_size) {
25 maximum_size_ = maximum_size;
28 // View overrides:
29 gfx::Size GetPreferredSize() const override;
30 gfx::Size GetMinimumSize() const override;
31 gfx::Size GetMaximumSize() const override;
33 private:
34 gfx::Size size_;
35 gfx::Size minimum_size_;
36 gfx::Size maximum_size_;
38 DISALLOW_COPY_AND_ASSIGN(StaticSizedView);
41 // A view that accomodates testing layouts that use GetHeightForWidth.
42 class ProportionallySizedView : public View {
43 public:
44 explicit ProportionallySizedView(int factor);
45 ~ProportionallySizedView() override;
47 void set_preferred_width(int width) { preferred_width_ = width; }
49 int GetHeightForWidth(int w) const override;
50 gfx::Size GetPreferredSize() const override;
52 private:
53 // The multiplicative factor between width and height, i.e.
54 // height = width * factor_.
55 int factor_;
57 // The width used as the preferred size. -1 if not used.
58 int preferred_width_;
60 DISALLOW_COPY_AND_ASSIGN(ProportionallySizedView);
63 // Class that closes the widget (which ends up deleting it immediately) when the
64 // appropriate event is received.
65 class CloseWidgetView : public View {
66 public:
67 explicit CloseWidgetView(ui::EventType event_type);
69 // ui::EventHandler override:
70 void OnEvent(ui::Event* event) override;
72 private:
73 const ui::EventType event_type_;
75 DISALLOW_COPY_AND_ASSIGN(CloseWidgetView);
78 // A view that keeps track of the events it receives, optionally consuming them.
79 class EventCountView : public View {
80 public:
81 // Whether to call SetHandled() on events as they are received. For some event
82 // types, this will allow EventCountView to receives future events in the
83 // event sequence, such as a drag.
84 enum HandleMode { PROPAGATE_EVENTS, CONSUME_EVENTS };
86 EventCountView();
87 ~EventCountView() override;
89 int GetEventCount(ui::EventType type);
90 void ResetCounts();
92 int last_flags() const { return last_flags_; }
94 void set_handle_mode(HandleMode handle_mode) { handle_mode_ = handle_mode; }
96 protected:
97 // Overridden from View:
98 void OnMouseMoved(const ui::MouseEvent& event) override;
100 // Overridden from ui::EventHandler:
101 void OnKeyEvent(ui::KeyEvent* event) override;
102 void OnMouseEvent(ui::MouseEvent* event) override;
103 void OnScrollEvent(ui::ScrollEvent* event) override;
104 void OnGestureEvent(ui::GestureEvent* event) override;
106 private:
107 void RecordEvent(ui::Event* event);
109 std::map<ui::EventType, int> event_count_;
110 int last_flags_;
111 HandleMode handle_mode_;
113 DISALLOW_COPY_AND_ASSIGN(EventCountView);
116 } // namespace views
118 #endif // UI_VIEWS_TEST_TEST_VIEWS_H_