Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: athena/home/minimized_home.cc

Issue 416963002: athena: Make the entire minimized home-card draggable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/views/background.h" 7 #include "ui/views/background.h"
8 #include "ui/views/layout/box_layout.h" 8 #include "ui/views/layout/box_layout.h"
9 #include "ui/views/view.h" 9 #include "ui/views/view.h"
10 #include "ui/views/widget/widget.h" 10 #include "ui/views/widget/widget.h"
11 11
12 namespace { 12 namespace {
13 13
14 const SkColor kDragHandleColorNormal = SK_ColorGRAY; 14 const SkColor kDragHandleColorNormal = SK_ColorGRAY;
15 const SkColor kDragHandleColorHot = SK_ColorWHITE; 15 const SkColor kDragHandleColorHot = SK_ColorWHITE;
16 16
17 class MinimizedHomeView : public views::View { 17 // The small white bar in the middle of the minimized view. Does not reach to
18 // events.
19 class SmallBarView : public views::View {
18 public: 20 public:
19 explicit MinimizedHomeView(athena::MinimizedHomeDragDelegate* delegate) 21 SmallBarView() : color_(SK_ColorTRANSPARENT) {
20 : delegate_(delegate),
21 color_(SK_ColorTRANSPARENT) {
22 SetColor(kDragHandleColorNormal); 22 SetColor(kDragHandleColorNormal);
23 } 23 }
24 virtual ~MinimizedHomeView() {} 24
25 virtual ~SmallBarView() {}
26
27 void SetActive(bool active) {
28 SetColor(active ? kDragHandleColorHot : kDragHandleColorNormal);
29 }
25 30
26 private: 31 private:
27 void SetColor(SkColor color) { 32 void SetColor(SkColor color) {
28 if (color_ == color) 33 if (color_ == color)
29 return; 34 return;
30 color_ = color; 35 color_ = color;
31 set_background(views::Background::CreateSolidBackground(color_)); 36 set_background(views::Background::CreateSolidBackground(color_));
32 SchedulePaint(); 37 SchedulePaint();
33 } 38 }
34 39
35 // views::View: 40 // views::View
36 virtual gfx::Size GetPreferredSize() const OVERRIDE { 41 virtual gfx::Size GetPreferredSize() const OVERRIDE {
37 const int kDragHandleWidth = 80; 42 const int kDragHandleWidth = 80;
38 const int kDragHandleHeight = 4; 43 const int kDragHandleHeight = 4;
39 return gfx::Size(kDragHandleWidth, kDragHandleHeight); 44 return gfx::Size(kDragHandleWidth, kDragHandleHeight);
40 } 45 }
41 46
47 SkColor color_;
48
49 DISALLOW_COPY_AND_ASSIGN(SmallBarView);
50 };
51
52 // This View shows an instance of SmallBarView in the middle, and reacts to
53 // mouse and touch-gesture events.
54 class MinimizedHomeView : public views::View {
55 public:
56 explicit MinimizedHomeView(athena::MinimizedHomeDragDelegate* delegate)
57 : delegate_(delegate),
58 bar_(new SmallBarView) {
59 set_background(views::Background::CreateSolidBackground(SK_ColorBLACK));
60 views::BoxLayout* layout =
61 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 2, 0);
62 layout->set_main_axis_alignment(
63 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
64 SetLayoutManager(layout);
65
66 AddChildView(bar_);
67 }
68 virtual ~MinimizedHomeView() {}
69
70 private:
71 // views::View:
42 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { 72 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
43 if (event.IsLeftMouseButton() && event.GetClickCount() == 1) { 73 if (event.IsLeftMouseButton() && event.GetClickCount() == 1) {
44 delegate_->OnDragUpCompleted(); 74 delegate_->OnDragUpCompleted();
45 SetColor(kDragHandleColorNormal); 75 bar_->SetActive(false);
46 return true; 76 return true;
47 } 77 }
48 return false; 78 return false;
49 } 79 }
50 80
51 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { 81 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE {
52 SetColor(kDragHandleColorHot); 82 bar_->SetActive(true);
53 } 83 }
54 84
55 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE { 85 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE {
56 SetColor(kDragHandleColorNormal); 86 bar_->SetActive(false);
57 } 87 }
58 88
59 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 89 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
60 SkColor change_color = SK_ColorTRANSPARENT;
61 if (event->type() == ui::ET_GESTURE_BEGIN && 90 if (event->type() == ui::ET_GESTURE_BEGIN &&
62 event->details().touch_points() == 1) { 91 event->details().touch_points() == 1) {
63 change_color = kDragHandleColorHot; 92 bar_->SetActive(true);
93 event->SetHandled();
94 return;
64 } else if (event->type() == ui::ET_GESTURE_END && 95 } else if (event->type() == ui::ET_GESTURE_END &&
65 event->details().touch_points() == 1) { 96 event->details().touch_points() == 1) {
66 change_color = kDragHandleColorNormal; 97 bar_->SetActive(false);
67 }
68
69 if (change_color != SK_ColorTRANSPARENT) {
70 SetColor(change_color);
71 event->SetHandled(); 98 event->SetHandled();
72 return; 99 return;
73 } 100 }
74 101
75 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { 102 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
76 event->SetHandled(); 103 event->SetHandled();
77 } else if (event->type() == ui::ET_SCROLL_FLING_START) { 104 } else if (event->type() == ui::ET_SCROLL_FLING_START) {
78 const ui::GestureEventDetails& details = event->details(); 105 const ui::GestureEventDetails& details = event->details();
79 const float kFlingCompletionVelocity = -100.f; 106 const float kFlingCompletionVelocity = -100.f;
80 if (details.velocity_y() < kFlingCompletionVelocity) 107 if (details.velocity_y() < kFlingCompletionVelocity)
81 delegate_->OnDragUpCompleted(); 108 delegate_->OnDragUpCompleted();
82 SetColor(kDragHandleColorNormal); 109 bar_->SetActive(false);
83 } 110 }
84 } 111 }
85 112
86 athena::MinimizedHomeDragDelegate* delegate_; 113 athena::MinimizedHomeDragDelegate* delegate_;
87 SkColor color_; 114 SmallBarView* bar_;
88 115
89 DISALLOW_COPY_AND_ASSIGN(MinimizedHomeView); 116 DISALLOW_COPY_AND_ASSIGN(MinimizedHomeView);
90 }; 117 };
91 118
92 } // namespace 119 } // namespace
93 120
94 namespace athena { 121 namespace athena {
95 122
96 views::View* CreateMinimizedHome(MinimizedHomeDragDelegate* delegate) { 123 views::View* CreateMinimizedHome(MinimizedHomeDragDelegate* delegate) {
97 views::View* content_view = new views::View; 124 return new MinimizedHomeView(delegate);
98 content_view->set_background(
99 views::Background::CreateSolidBackground(SK_ColorBLACK));
100 views::BoxLayout* layout =
101 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 2, 0);
102 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
103 content_view->SetLayoutManager(layout);
104
105 views::View* view = new MinimizedHomeView(delegate);
106 content_view->AddChildView(view);
107 return content_view;
108 } 125 }
109 126
110 } // namespace athena 127 } // namespace athena
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698