Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / views / test / test_views.cc
blob555d4c67a276ce6f347366108ff7982f6f9fe950
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 } // namespace views