Automated Commit: Committing new LKGM version 7479.0.0 for chromeos.
[chromium-blink-merge.git] / ui / views / test / test_views.cc
blobd0ad7d53186134e23fd4e6e6f76a2b7f9ded69d7
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"
11 namespace views {
13 StaticSizedView::StaticSizedView(const gfx::Size& size)
14 // Default GetMinimumSize() is GetPreferredSize(). Default GetMaximumSize()
15 // is 0x0.
16 : size_(size),
17 minimum_size_(size) {
20 StaticSizedView::~StaticSizedView() {}
22 gfx::Size StaticSizedView::GetPreferredSize() const {
23 return size_;
26 gfx::Size StaticSizedView::GetMinimumSize() const {
27 return minimum_size_;
30 gfx::Size StaticSizedView::GetMaximumSize() const {
31 return maximum_size_;
34 ProportionallySizedView::ProportionallySizedView(int factor)
35 : factor_(factor), preferred_width_(-1) {}
37 ProportionallySizedView::~ProportionallySizedView() {}
39 int ProportionallySizedView::GetHeightForWidth(int w) const {
40 return w * factor_;
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();
60 } else {
61 View::OnEvent(event);
62 if (!event->IsTouchEvent())
63 event->SetHandled();
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() {
77 event_count_.clear();
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];
83 last_flags_ = 0;
86 void EventCountView::OnKeyEvent(ui::KeyEvent* event) {
87 RecordEvent(event);
90 void EventCountView::OnMouseEvent(ui::MouseEvent* event) {
91 RecordEvent(event);
94 void EventCountView::OnScrollEvent(ui::ScrollEvent* event) {
95 RecordEvent(event);
98 void EventCountView::OnGestureEvent(ui::GestureEvent* event) {
99 RecordEvent(event);
102 void EventCountView::RecordEvent(ui::Event* event) {
103 ++event_count_[event->type()];
104 last_flags_ = event->flags();
105 if (handle_mode_ == CONSUME_EVENTS)
106 event->SetHandled();
109 } // namespace views