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 "ash/wm/property_util.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 window_ = NULL; | 95 window_ = NULL; |
96 window->RemoveObserver(this); | 96 window->RemoveObserver(this); |
97 } | 97 } |
98 | 98 |
99 aura::Window* window_; | 99 aura::Window* window_; |
100 bool is_paint_scheduled_; | 100 bool is_paint_scheduled_; |
101 | 101 |
102 DISALLOW_COPY_AND_ASSIGN(WindowRepaintChecker); | 102 DISALLOW_COPY_AND_ASSIGN(WindowRepaintChecker); |
103 }; | 103 }; |
104 | 104 |
105 // Modifies the values of kInactiveWindowOpacity, kActiveWindowOpacity, and | |
106 // kSoloWindowOpacity for the lifetime of the class. This is useful so that | |
107 // the constants each have different values. | |
108 class ScopedOpacityConstantModifier { | |
109 public: | |
110 ScopedOpacityConstantModifier() | |
111 : initial_active_window_opacity_( | |
112 ash::FramePainter::kActiveWindowOpacity), | |
113 initial_inactive_window_opacity_( | |
114 ash::FramePainter::kInactiveWindowOpacity), | |
115 initial_solo_window_opacity_(ash::FramePainter::kSoloWindowOpacity) { | |
116 ash::FramePainter::kActiveWindowOpacity = 100; | |
117 ash::FramePainter::kInactiveWindowOpacity = 120; | |
118 ash::FramePainter::kSoloWindowOpacity = 140; | |
119 } | |
120 ~ScopedOpacityConstantModifier() { | |
121 ash::FramePainter::kActiveWindowOpacity = initial_active_window_opacity_; | |
122 ash::FramePainter::kInactiveWindowOpacity = | |
123 initial_inactive_window_opacity_; | |
124 ash::FramePainter::kSoloWindowOpacity = initial_solo_window_opacity_; | |
125 } | |
126 | |
127 private: | |
128 int initial_active_window_opacity_; | |
129 int initial_inactive_window_opacity_; | |
130 int initial_solo_window_opacity_; | |
131 | |
132 DISALLOW_COPY_AND_ASSIGN(ScopedOpacityConstantModifier); | |
133 }; | |
134 | |
105 } // namespace | 135 } // namespace |
106 | 136 |
107 namespace ash { | 137 namespace ash { |
108 | 138 |
109 class FramePainterTest : public ash::test::AshTestBase { | 139 class FramePainterTest : public ash::test::AshTestBase { |
110 public: | 140 public: |
111 // Creates a test widget that owns its native widget. | 141 // Creates a test widget that owns its native widget. |
112 Widget* CreateTestWidget() { | 142 Widget* CreateTestWidget() { |
113 Widget* widget = new Widget; | 143 Widget* widget = new Widget; |
114 Widget::InitParams params; | 144 Widget::InitParams params; |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 | 466 |
437 TEST_F(FramePainterTest, GetHeaderOpacity) { | 467 TEST_F(FramePainterTest, GetHeaderOpacity) { |
438 // Create a widget and a painter for it. | 468 // Create a widget and a painter for it. |
439 scoped_ptr<Widget> w1(CreateTestWidget()); | 469 scoped_ptr<Widget> w1(CreateTestWidget()); |
440 FramePainter p1; | 470 FramePainter p1; |
441 ImageButton size1(NULL); | 471 ImageButton size1(NULL); |
442 ImageButton close1(NULL); | 472 ImageButton close1(NULL); |
443 p1.Init(w1.get(), NULL, &size1, &close1, FramePainter::SIZE_BUTTON_MAXIMIZES); | 473 p1.Init(w1.get(), NULL, &size1, &close1, FramePainter::SIZE_BUTTON_MAXIMIZES); |
444 w1->Show(); | 474 w1->Show(); |
445 | 475 |
476 // Modify the values of the opacity constants so that they each have a | |
477 // different value. | |
478 ScopedOpacityConstantModifier opacity_constant_modifier; | |
479 | |
446 // Solo active window has solo window opacity. | 480 // Solo active window has solo window opacity. |
447 EXPECT_EQ(FramePainter::kSoloWindowOpacity, | 481 EXPECT_EQ(FramePainter::kSoloWindowOpacity, |
448 p1.GetHeaderOpacity(FramePainter::ACTIVE, | 482 p1.GetHeaderOpacity(FramePainter::ACTIVE, |
449 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, | 483 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, |
450 NULL)); | 484 NULL)); |
451 | 485 |
452 // Create a second widget and painter. | 486 // Create a second widget and painter. |
453 scoped_ptr<Widget> w2(CreateTestWidget()); | 487 scoped_ptr<Widget> w2(CreateTestWidget()); |
454 FramePainter p2; | 488 FramePainter p2; |
455 ImageButton size2(NULL); | 489 ImageButton size2(NULL); |
(...skipping 12 matching lines...) Expand all Loading... | |
468 p2.GetHeaderOpacity(FramePainter::INACTIVE, | 502 p2.GetHeaderOpacity(FramePainter::INACTIVE, |
469 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE, | 503 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE, |
470 NULL)); | 504 NULL)); |
471 | 505 |
472 // Custom overlay image is drawn completely opaque. | 506 // Custom overlay image is drawn completely opaque. |
473 gfx::ImageSkia custom_overlay; | 507 gfx::ImageSkia custom_overlay; |
474 EXPECT_EQ(255, | 508 EXPECT_EQ(255, |
475 p1.GetHeaderOpacity(FramePainter::ACTIVE, | 509 p1.GetHeaderOpacity(FramePainter::ACTIVE, |
476 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, | 510 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, |
477 &custom_overlay)); | 511 &custom_overlay)); |
512 | |
513 // Regular maximized window is fully transparent. | |
James Cook
2013/03/06 23:45:39
Hooray for tests!
| |
514 ash::wm::MaximizeWindow(w1->GetNativeWindow()); | |
515 EXPECT_EQ(0, | |
516 p1.GetHeaderOpacity(FramePainter::ACTIVE, | |
517 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, | |
518 NULL)); | |
519 | |
520 // Windows with custom overlays are fully opaque when maximized. | |
521 EXPECT_EQ(255, | |
522 p1.GetHeaderOpacity(FramePainter::ACTIVE, | |
523 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, | |
524 &custom_overlay)); | |
525 | |
526 // The maximized window frame should take on the active/inactive opacity | |
527 // while the user is cycling through workspaces. | |
528 w1->GetNativeWindow()->GetRootWindow()->SetProperty( | |
529 ash::internal::kCyclingThroughWorkspacesKey, true); | |
530 EXPECT_EQ(FramePainter::kInactiveWindowOpacity, | |
531 p1.GetHeaderOpacity(FramePainter::INACTIVE, | |
532 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, | |
533 NULL)); | |
478 } | 534 } |
479 | 535 |
480 // Test the hit test function with windows which are "partially maximized". | 536 // Test the hit test function with windows which are "partially maximized". |
481 TEST_F(FramePainterTest, HitTestSpecialMaximizedModes) { | 537 TEST_F(FramePainterTest, HitTestSpecialMaximizedModes) { |
482 // Create a widget and a painter for it. | 538 // Create a widget and a painter for it. |
483 scoped_ptr<Widget> w1(CreateResizableWidget()); | 539 scoped_ptr<Widget> w1(CreateResizableWidget()); |
484 FramePainter p1; | 540 FramePainter p1; |
485 ImageButton size1(NULL); | 541 ImageButton size1(NULL); |
486 ImageButton close1(NULL); | 542 ImageButton close1(NULL); |
487 p1.Init(w1.get(), NULL, &size1, &close1, FramePainter::SIZE_BUTTON_MAXIMIZES); | 543 p1.Init(w1.get(), NULL, &size1, &close1, FramePainter::SIZE_BUTTON_MAXIMIZES); |
(...skipping 18 matching lines...) Expand all Loading... | |
506 EXPECT_EQ(HTRIGHT, | 562 EXPECT_EQ(HTRIGHT, |
507 p1.NonClientHitTest(frame, gfx::Point(screen.width() / 2, | 563 p1.NonClientHitTest(frame, gfx::Point(screen.width() / 2, |
508 screen.height() / 2))); | 564 screen.height() / 2))); |
509 // A hit into the middle lower area should generate right - not bottom&right. | 565 // A hit into the middle lower area should generate right - not bottom&right. |
510 EXPECT_EQ(HTRIGHT, | 566 EXPECT_EQ(HTRIGHT, |
511 p1.NonClientHitTest(frame, gfx::Point(screen.width() / 2, | 567 p1.NonClientHitTest(frame, gfx::Point(screen.width() / 2, |
512 screen.height() - 1))); | 568 screen.height() - 1))); |
513 } | 569 } |
514 | 570 |
515 } // namespace ash | 571 } // namespace ash |
OLD | NEW |