Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/wm/frame_painter.h" | 5 #include "ash/wm/frame_painter.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/wm/property_util.h" | |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "grit/ui_resources.h" | 12 #include "grit/ui_resources.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 15 #include "ui/base/hit_test.h" | |
| 16 #include "ui/gfx/screen.h" | |
| 14 #include "ui/views/controls/button/image_button.h" | 17 #include "ui/views/controls/button/image_button.h" |
| 15 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 19 #include "ui/views/widget/widget_delegate.h" | |
| 20 #include "ui/views/window/non_client_view.h" | |
| 16 | 21 |
| 17 using views::Widget; | 22 using views::Widget; |
| 18 using views::ImageButton; | 23 using views::ImageButton; |
| 19 | 24 |
| 20 namespace { | 25 namespace { |
| 21 | 26 |
| 27 class ResizableWidgetDelegate : public views::WidgetDelegate { | |
| 28 public: | |
| 29 ResizableWidgetDelegate(views::Widget* widget) { | |
| 30 widget_ = widget; | |
| 31 } | |
| 32 | |
| 33 virtual bool CanResize() const OVERRIDE { return true; } | |
| 34 // Implementations of the widget class. | |
| 35 virtual views::Widget* GetWidget() {return widget_; } | |
|
sky
2012/09/06 19:45:11
OVERRIDE on these two lines, and space after {
Mr4D (OOO till 08-26)
2012/09/06 23:16:13
Done.
| |
| 36 virtual const views::Widget* GetWidget() const { return widget_; } | |
| 37 private: | |
|
sky
2012/09/06 19:45:11
newline bewteen 36/67.
Mr4D (OOO till 08-26)
2012/09/06 23:16:13
Done.
| |
| 38 views::Widget* widget_; | |
| 39 }; | |
|
sky
2012/09/06 19:45:11
DISALLOW_...
Mr4D (OOO till 08-26)
2012/09/06 23:16:13
Done.
| |
| 40 | |
| 22 // Creates a test widget that owns its native widget. | 41 // Creates a test widget that owns its native widget. |
| 23 Widget* CreateTestWidget() { | 42 Widget* CreateTestWidget() { |
| 24 Widget* widget = new Widget; | 43 Widget* widget = new Widget; |
| 25 Widget::InitParams params; | 44 Widget::InitParams params; |
| 26 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 45 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 27 widget->Init(params); | 46 widget->Init(params); |
| 28 return widget; | 47 return widget; |
| 29 } | 48 } |
| 30 | 49 |
| 31 Widget* CreateAlwaysOnTopWidget() { | 50 Widget* CreateAlwaysOnTopWidget() { |
| 32 Widget* widget = new Widget; | 51 Widget* widget = new Widget; |
| 33 Widget::InitParams params; | 52 Widget::InitParams params; |
| 34 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 53 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 35 params.keep_on_top = true; | 54 params.keep_on_top = true; |
| 36 widget->Init(params); | 55 widget->Init(params); |
| 37 return widget; | 56 return widget; |
| 38 } | 57 } |
| 39 | 58 |
| 59 Widget* CreateResizableWidget() { | |
| 60 Widget* widget = new Widget; | |
| 61 Widget::InitParams params; | |
| 62 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 63 params.keep_on_top = true; | |
| 64 params.delegate = new ResizableWidgetDelegate(widget); | |
| 65 params.type = Widget::InitParams::TYPE_WINDOW; | |
| 66 widget->Init(params); | |
| 67 return widget; | |
| 68 } | |
| 69 | |
| 40 } // namespace | 70 } // namespace |
| 41 | 71 |
| 42 namespace ash { | 72 namespace ash { |
| 43 | 73 |
| 44 typedef ash::test::AshTestBase FramePainterTest; | 74 typedef ash::test::AshTestBase FramePainterTest; |
| 45 | 75 |
| 46 TEST_F(FramePainterTest, Basics) { | 76 TEST_F(FramePainterTest, Basics) { |
| 47 // Other tests might have created a FramePainter, so we cannot assert that | 77 // Other tests might have created a FramePainter, so we cannot assert that |
| 48 // FramePainter::instances_ is NULL here. | 78 // FramePainter::instances_ is NULL here. |
| 49 | 79 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 NULL)); | 184 NULL)); |
| 155 | 185 |
| 156 // Custom overlay image is drawn completely opaque. | 186 // Custom overlay image is drawn completely opaque. |
| 157 gfx::ImageSkia custom_overlay; | 187 gfx::ImageSkia custom_overlay; |
| 158 EXPECT_EQ(255, | 188 EXPECT_EQ(255, |
| 159 p1.GetHeaderOpacity(FramePainter::ACTIVE, | 189 p1.GetHeaderOpacity(FramePainter::ACTIVE, |
| 160 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, | 190 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, |
| 161 &custom_overlay)); | 191 &custom_overlay)); |
| 162 } | 192 } |
| 163 | 193 |
| 194 // Test the hit test function with windows which are "partially maximized". | |
| 195 TEST_F(FramePainterTest, HitTestSpecialMaximizedModes) { | |
| 196 // Create a widget and a painter for it. | |
| 197 scoped_ptr<Widget> w1(CreateResizableWidget()); | |
| 198 views::NonClientFrameView* frame = w1->CreateNonClientFrameView(); | |
| 199 FramePainter p1; | |
| 200 ImageButton size1(NULL); | |
| 201 ImageButton close1(NULL); | |
| 202 p1.Init(w1.get(), NULL, &size1, &close1, FramePainter::SIZE_BUTTON_MAXIMIZES); | |
| 203 w1->Show(); | |
| 204 gfx::Rect any_rect = gfx::Rect(0, 0, 100, 100); | |
| 205 w1->SetBounds(any_rect); | |
| 206 frame->SetBounds(0, 0, 100, 100); | |
|
sky
2012/09/06 19:45:11
Why do you need this? w1->SetBounds should take ca
Mr4D (OOO till 08-26)
2012/09/06 23:16:13
You need both. I was puzzled by this myself when w
sky
2012/09/07 02:43:30
Please investigate this more deeply. Setting the f
Mr4D (OOO till 08-26)
2012/09/08 01:17:41
I have dumped already several hours on this and wi
| |
| 207 EXPECT_EQ(HTTOPLEFT, | |
| 208 p1.NonClientHitTest(frame, gfx::Point(0, 15))); | |
| 209 gfx::Rect screen = gfx::Screen::GetDisplayMatching(any_rect).work_area(); | |
| 210 w1->SetBounds(gfx::Rect( | |
| 211 screen.x(), screen.y(), screen.width() / 2, screen.height())); | |
| 212 frame->SetBounds( | |
| 213 screen.x(), screen.y(), screen.width() / 2, screen.height()); | |
| 214 // A hit without a set restore rect should produce a top left hit. | |
| 215 EXPECT_EQ(HTTOPLEFT, | |
| 216 p1.NonClientHitTest(frame, gfx::Point(0, 15))); | |
| 217 ash::SetRestoreBoundsInScreen(w1->GetNativeWindow(), any_rect); | |
| 218 // A hit into the corner should produce nowhere - not left. | |
| 219 EXPECT_EQ(HTCAPTION, | |
| 220 p1.NonClientHitTest(frame, gfx::Point(0, 15))); | |
| 221 // A hit into the middle upper area should generate right - not top&right. | |
| 222 EXPECT_EQ(HTRIGHT, | |
| 223 p1.NonClientHitTest(frame, gfx::Point(screen.width() / 2, 15))); | |
| 224 // A hit into the middle should generate right. | |
| 225 EXPECT_EQ(HTRIGHT, | |
| 226 p1.NonClientHitTest(frame, gfx::Point(screen.width() / 2, | |
| 227 screen.height() / 2))); | |
| 228 // A hit into the middle lower area should generate right - not bottom&right. | |
| 229 EXPECT_EQ(HTRIGHT, | |
| 230 p1.NonClientHitTest(frame, gfx::Point(screen.width() / 2, | |
| 231 screen.height() - 1))); | |
| 232 } | |
| 233 | |
| 164 } // namespace ash | 234 } // namespace ash |
| OLD | NEW |