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
) : size_(size
) {}
15 StaticSizedView::~StaticSizedView() {}
17 gfx::Size
StaticSizedView::GetPreferredSize() const {
21 ProportionallySizedView::ProportionallySizedView(int factor
)
22 : factor_(factor
), preferred_width_(-1) {}
24 ProportionallySizedView::~ProportionallySizedView() {}
26 int ProportionallySizedView::GetHeightForWidth(int w
) const {
30 gfx::Size
ProportionallySizedView::GetPreferredSize() const {
31 if (preferred_width_
>= 0)
32 return gfx::Size(preferred_width_
, GetHeightForWidth(preferred_width_
));
33 return View::GetPreferredSize();
36 CloseWidgetView::CloseWidgetView(ui::EventType event_type
)
37 : event_type_(event_type
) {
40 void CloseWidgetView::OnEvent(ui::Event
* event
) {
41 if (event
->type() == event_type_
) {
42 // Go through NativeWidgetPrivate to simulate what happens if the OS
43 // deletes the NativeWindow out from under us.
44 // TODO(tapted): Change this to WidgetTest::SimulateNativeDestroy for a more
45 // authentic test on Mac.
46 GetWidget()->native_widget_private()->CloseNow();
49 if (!event
->IsTouchEvent())