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

Side by Side Diff: athena/common/drag_handle.cc

Issue 545393002: Adding split view divider widget. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl format Created 6 years, 3 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
OLDNEW
(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/common/drag_handle.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 athena {
13 namespace {
14
15 const SkColor kDragHandleColorNormal = SK_ColorGRAY;
16 const SkColor kDragHandleColorHot = SK_ColorWHITE;
17
18 class DragHandleView : public views::View {
19 public:
20 explicit DragHandleView(DragHandle::ScrollDirection scroll_direction,
21 DragHandle::ScrollDelegate* delegate,
22 int preferred_width,
23 int preferred_height);
24 virtual ~DragHandleView();
25
26 private:
27 enum State {
28 DEFAULT,
29 SCROLLING,
30 };
31
32 void SetColor(SkColor color);
33
34 void SetState(State state);
35
36 // views::View:
37 virtual gfx::Size GetPreferredSize() const OVERRIDE;
38 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
39 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
40 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
41
42 State state_;
43 DragHandle::ScrollDelegate* delegate_;
44 DragHandle::ScrollDirection scroll_direction_;
45 SkColor color_;
46 float scroll_start_location_;
47 const int preferred_width_;
48 const int preferred_height_;
49
50 DISALLOW_COPY_AND_ASSIGN(DragHandleView);
51 };
52
53 DragHandleView::DragHandleView(DragHandle::ScrollDirection scroll_direction,
54 DragHandle::ScrollDelegate* delegate,
55 int preferred_width,
56 int preferred_height)
57 : state_(DEFAULT),
58 delegate_(delegate),
59 scroll_direction_(scroll_direction),
60 color_(SK_ColorTRANSPARENT),
61 preferred_width_(preferred_width),
62 preferred_height_(preferred_height) {
63 SetColor(kDragHandleColorNormal);
64 }
65
66 DragHandleView::~DragHandleView() {
67 }
68
69 void DragHandleView::SetColor(SkColor color) {
70 if (color_ == color)
71 return;
72 color_ = color;
73 set_background(views::Background::CreateSolidBackground(color_));
74 SchedulePaint();
75 }
76
77 void DragHandleView::SetState(State state) {
78 if (state_ == state)
79 return;
80 state_ = state;
81 if (state == DEFAULT)
82 scroll_start_location_ = 0;
83 }
84
85 // views::View:
86 gfx::Size DragHandleView::GetPreferredSize() const {
87 return gfx::Size(preferred_width_, preferred_height_);
88 }
89
90 void DragHandleView::OnMouseEntered(const ui::MouseEvent& event) {
91 SetColor(kDragHandleColorHot);
92 }
93
94 void DragHandleView::OnMouseExited(const ui::MouseEvent& event) {
95 SetColor(kDragHandleColorNormal);
96 }
97
98 void DragHandleView::OnGestureEvent(ui::GestureEvent* event) {
99 SkColor change_color = SK_ColorTRANSPARENT;
100 if (event->type() == ui::ET_GESTURE_BEGIN &&
101 event->details().touch_points() == 1) {
102 change_color = kDragHandleColorHot;
103 } else if (event->type() == ui::ET_GESTURE_END &&
104 event->details().touch_points() == 1) {
105 change_color = kDragHandleColorNormal;
106 }
107 if (change_color != SK_ColorTRANSPARENT) {
108 SetColor(change_color);
109 event->SetHandled();
110 return;
111 }
112
113 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
114 if (!delegate_->HandleCanScroll() || state_ != DEFAULT)
115 return;
116 float delta;
117 if (scroll_direction_ == DragHandle::VERTICAL) {
118 delta = event->details().scroll_y_hint();
119 scroll_start_location_ = event->root_location().y();
120 } else {
121 delta = event->details().scroll_x_hint();
122 scroll_start_location_ = event->root_location().x();
123 }
124 delegate_->HandleScrollBegin(delta);
125 SetState(SCROLLING);
126 event->SetHandled();
127 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) {
128 if (state_ != SCROLLING)
129 return;
130 delegate_->HandleScrollEnd();
131 SetColor(kDragHandleColorNormal);
132 SetState(DEFAULT);
133 event->SetHandled();
134 } else if (event->type() == ui::ET_SCROLL_FLING_START) {
135 if (state_ != SCROLLING)
136 return;
137 delegate_->HandleScrollEnd();
sadrul 2014/09/12 04:30:36 Do we not want to take the velocity into considera
mfomitchev 2014/09/12 20:49:07 That sounds like a good idea. I was thinking of do
138 SetColor(kDragHandleColorNormal);
139 SetState(DEFAULT);
140 event->SetHandled();
141 } else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
142 if (state_ != SCROLLING)
143 return;
144 float delta = scroll_direction_ == DragHandle::VERTICAL
145 ? event->root_location().y() - scroll_start_location_
146 : event->root_location().x() - scroll_start_location_;
147 delegate_->HandleScrollUpdate(delta);
148 event->SetHandled();
149 }
150 }
151
152 } // namespace
153
154 views::View* CreateDragHandleView(DragHandle::ScrollDirection scroll_direction,
155 DragHandle::ScrollDelegate* delegate,
156 int preferred_width,
157 int preferred_height,
158 int margin) {
159 views::View* content_view = new views::View;
160 content_view->set_background(
161 views::Background::CreateSolidBackground(SK_ColorBLACK));
162 views::BoxLayout* layout =
163 new views::BoxLayout(views::BoxLayout::kHorizontal, margin, margin, 0);
164 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
165 layout->set_cross_axis_alignment(
166 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
167 content_view->SetLayoutManager(layout);
168
169 views::View* view = new DragHandleView(
170 scroll_direction, delegate, preferred_width, preferred_height);
171 content_view->AddChildView(view);
172 return content_view;
173 }
174
175 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698