OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/home/minimized_home.h" | 5 #include "athena/home/minimized_home.h" |
6 | 6 |
7 #include "athena/wm/public/window_manager.h" | 7 #include "ui/compositor/layer.h" |
| 8 #include "ui/compositor/layer_owner.h" |
8 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
9 #include "ui/views/background.h" | |
10 #include "ui/views/view.h" | |
11 | 10 |
12 namespace { | 11 namespace { |
13 | 12 |
14 const int kDragHandleWidth = 112; | 13 const int kDragHandleWidth = 112; |
15 const int kDragHandleHeight = 2; | 14 const int kDragHandleHeight = 2; |
| 15 const char kMinimizedHomeLayerName[] = "MinimizedHome"; |
16 | 16 |
17 class MinimizedHomeBackground : public views::Background { | 17 class MinimizedHomePainter : public ui::LayerDelegate, |
| 18 public ui::LayerOwner { |
18 public: | 19 public: |
19 MinimizedHomeBackground() {} | 20 explicit MinimizedHomePainter(ui::Layer* layer) { |
20 virtual ~MinimizedHomeBackground() {} | 21 layer->set_name(kMinimizedHomeLayerName); |
| 22 layer->set_delegate(this); |
| 23 SetLayer(layer); |
| 24 } |
| 25 virtual ~MinimizedHomePainter() {} |
21 | 26 |
22 private: | 27 private: |
23 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | 28 // ui::LayerDelegate: |
24 gfx::Rect bounds = view->GetLocalBounds(); | 29 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
| 30 gfx::Rect bounds(layer()->GetTargetBounds().size()); |
25 canvas->FillRect(bounds, SK_ColorBLACK); | 31 canvas->FillRect(bounds, SK_ColorBLACK); |
26 canvas->FillRect(gfx::Rect((bounds.width() - kDragHandleWidth) / 2, | 32 canvas->FillRect(gfx::Rect((bounds.width() - kDragHandleWidth) / 2, |
27 bounds.bottom() - kDragHandleHeight, | 33 bounds.bottom() - kDragHandleHeight, |
28 kDragHandleWidth, | 34 kDragHandleWidth, |
29 kDragHandleHeight), | 35 kDragHandleHeight), |
30 SK_ColorWHITE); | 36 SK_ColorWHITE); |
31 } | 37 } |
32 | 38 |
33 DISALLOW_COPY_AND_ASSIGN(MinimizedHomeBackground); | 39 virtual void OnDelegatedFrameDamage( |
34 }; | 40 const gfx::Rect& damage_rect_in_dip) OVERRIDE { |
35 | |
36 // This View shows an instance of SmallBarView in the middle, and reacts to | |
37 // mouse and touch-gesture events. | |
38 class MinimizedHomeView : public views::View { | |
39 public: | |
40 MinimizedHomeView() { | |
41 set_background(new MinimizedHomeBackground()); | |
42 } | |
43 virtual ~MinimizedHomeView() {} | |
44 | |
45 private: | |
46 // views::View: | |
47 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { | |
48 if (event.IsLeftMouseButton() && event.GetClickCount() == 1) { | |
49 athena::WindowManager::GetInstance()->ToggleOverview(); | |
50 return true; | |
51 } | |
52 return false; | |
53 } | 41 } |
54 | 42 |
55 DISALLOW_COPY_AND_ASSIGN(MinimizedHomeView); | 43 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
| 44 } |
| 45 |
| 46 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { |
| 47 return base::Closure(); |
| 48 } |
| 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(MinimizedHomePainter); |
56 }; | 51 }; |
57 | 52 |
58 } // namespace | 53 } // namespace |
59 | 54 |
60 namespace athena { | 55 namespace athena { |
61 | 56 |
62 views::View* CreateMinimizedHome() { | 57 scoped_ptr<ui::LayerOwner> CreateMinimizedHome() { |
63 return new MinimizedHomeView(); | 58 return scoped_ptr<ui::LayerOwner>( |
| 59 new MinimizedHomePainter(new ui::Layer(ui::LAYER_TEXTURED))); |
64 } | 60 } |
65 | 61 |
66 } // namespace athena | 62 } // namespace athena |
OLD | NEW |