Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / views / test / test_views.cc
blob95b6b564ba3c3c2ebfb9a232aecdee0fe618e004
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) : size_(size) {}
15 StaticSizedView::~StaticSizedView() {}
17 gfx::Size StaticSizedView::GetPreferredSize() const {
18 return size_;
21 ProportionallySizedView::ProportionallySizedView(int factor)
22 : factor_(factor), preferred_width_(-1) {}
24 ProportionallySizedView::~ProportionallySizedView() {}
26 int ProportionallySizedView::GetHeightForWidth(int w) const {
27 return w * factor_;
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();
47 } else {
48 View::OnEvent(event);
49 if (!event->IsTouchEvent())
50 event->SetHandled();
54 } // namespace views