OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "athena/home/minimized_home.h" |
| 6 |
| 7 #include "ui/views/background.h" |
| 8 #include "ui/views/layout/box_layout.h" |
| 9 #include "ui/views/view.h" |
| 10 #include "ui/views/widget/widget.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 const SkColor kDragHandleColorNormal = SK_ColorGRAY; |
| 15 const SkColor kDragHandleColorHot = SK_ColorWHITE; |
| 16 |
| 17 class MinimizedHomeView : public views::View { |
| 18 public: |
| 19 explicit MinimizedHomeView(athena::MinimizedHomeDragDelegate* delegate) |
| 20 : delegate_(delegate), |
| 21 color_(SK_ColorTRANSPARENT) { |
| 22 SetColor(kDragHandleColorNormal); |
| 23 } |
| 24 virtual ~MinimizedHomeView() {} |
| 25 |
| 26 private: |
| 27 void SetColor(SkColor color) { |
| 28 if (color_ == color) |
| 29 return; |
| 30 color_ = color; |
| 31 set_background(views::Background::CreateSolidBackground(color_)); |
| 32 SchedulePaint(); |
| 33 } |
| 34 |
| 35 // views::View: |
| 36 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
| 37 const int kDragHandleWidth = 80; |
| 38 const int kDragHandleHeight = 4; |
| 39 return gfx::Size(kDragHandleWidth, kDragHandleHeight); |
| 40 } |
| 41 |
| 42 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
| 43 SkColor change_color = SK_ColorTRANSPARENT; |
| 44 if (event->type() == ui::ET_GESTURE_BEGIN && |
| 45 event->details().touch_points() == 1) { |
| 46 change_color = kDragHandleColorHot; |
| 47 } else if (event->type() == ui::ET_GESTURE_END && |
| 48 event->details().touch_points() == 1) { |
| 49 change_color = kDragHandleColorNormal; |
| 50 } |
| 51 |
| 52 if (change_color != SK_ColorTRANSPARENT) { |
| 53 SetColor(change_color); |
| 54 event->SetHandled(); |
| 55 return; |
| 56 } |
| 57 |
| 58 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { |
| 59 event->SetHandled(); |
| 60 } else if (event->type() == ui::ET_SCROLL_FLING_START) { |
| 61 const ui::GestureEventDetails& details = event->details(); |
| 62 const float kFlingCompletionVelocity = -100.f; |
| 63 if (details.velocity_y() < kFlingCompletionVelocity) |
| 64 delegate_->OnDragUpCompleted(); |
| 65 SetColor(kDragHandleColorNormal); |
| 66 } |
| 67 } |
| 68 |
| 69 athena::MinimizedHomeDragDelegate* delegate_; |
| 70 SkColor color_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(MinimizedHomeView); |
| 73 }; |
| 74 |
| 75 } // namespace |
| 76 |
| 77 namespace athena { |
| 78 |
| 79 views::Widget* CreateMinimizedHome(aura::Window* container, |
| 80 MinimizedHomeDragDelegate* delegate) { |
| 81 views::Widget* widget = new views::Widget; |
| 82 views::Widget::InitParams params( |
| 83 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 84 params.parent = container; |
| 85 params.delegate = NULL; |
| 86 widget->Init(params); |
| 87 |
| 88 views::View* content_view = new views::View; |
| 89 widget->SetContentsView(content_view); |
| 90 views::BoxLayout* layout = |
| 91 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 2, 0); |
| 92 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
| 93 content_view->SetLayoutManager(layout); |
| 94 |
| 95 views::View* view = new MinimizedHomeView(delegate); |
| 96 content_view->AddChildView(view); |
| 97 return widget; |
| 98 } |
| 99 |
| 100 } // namespace athena |
OLD | NEW |