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 #include "ui/views/test/test_views.h"
7 #include "ui/events/event.h"
8 #include "ui/views/widget/native_widget_private.h"
9 #include "ui/views/widget/widget.h"
13 StaticSizedView::StaticSizedView(const gfx::Size
& size
)
14 // Default GetMinimumSize() is GetPreferredSize(). Default GetMaximumSize()
20 StaticSizedView::~StaticSizedView() {}
22 gfx::Size
StaticSizedView::GetPreferredSize() const {
26 gfx::Size
StaticSizedView::GetMinimumSize() const {
30 gfx::Size
StaticSizedView::GetMaximumSize() const {
34 ProportionallySizedView::ProportionallySizedView(int factor
)
35 : factor_(factor
), preferred_width_(-1) {}
37 ProportionallySizedView::~ProportionallySizedView() {}
39 int ProportionallySizedView::GetHeightForWidth(int w
) const {
43 gfx::Size
ProportionallySizedView::GetPreferredSize() const {
44 if (preferred_width_
>= 0)
45 return gfx::Size(preferred_width_
, GetHeightForWidth(preferred_width_
));
46 return View::GetPreferredSize();
49 CloseWidgetView::CloseWidgetView(ui::EventType event_type
)
50 : event_type_(event_type
) {
53 void CloseWidgetView::OnEvent(ui::Event
* event
) {
54 if (event
->type() == event_type_
) {
55 // Go through NativeWidgetPrivate to simulate what happens if the OS
56 // deletes the NativeWindow out from under us.
57 // TODO(tapted): Change this to WidgetTest::SimulateNativeDestroy for a more
58 // authentic test on Mac.
59 GetWidget()->native_widget_private()->CloseNow();
62 if (!event
->IsTouchEvent())
67 EventCountView::EventCountView()
68 : last_flags_(0), handle_mode_(PROPAGATE_EVENTS
) {}
70 EventCountView::~EventCountView() {}
72 int EventCountView::GetEventCount(ui::EventType type
) {
73 return event_count_
[type
];
76 void EventCountView::ResetCounts() {
80 void EventCountView::OnMouseMoved(const ui::MouseEvent
& event
) {
81 // MouseMove events are not re-dispatched from the RootView.
82 ++event_count_
[ui::ET_MOUSE_MOVED
];
86 void EventCountView::OnKeyEvent(ui::KeyEvent
* event
) {
90 void EventCountView::OnMouseEvent(ui::MouseEvent
* event
) {
94 void EventCountView::OnScrollEvent(ui::ScrollEvent
* event
) {
98 void EventCountView::OnGestureEvent(ui::GestureEvent
* event
) {
102 void EventCountView::RecordEvent(ui::Event
* event
) {
103 ++event_count_
[event
->type()];
104 last_flags_
= event
->flags();
105 if (handle_mode_
== CONSUME_EVENTS
)