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

Unified Diff: athena/util/drag_handle.cc

Issue 545393002: Adding split view divider widget. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing sadrul's feedback 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 side-by-side diff with in-line comments
Download patch
Index: athena/util/drag_handle.cc
diff --git a/athena/util/drag_handle.cc b/athena/util/drag_handle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b1f3df8fe422dd85ddd2d8e963bbc7d06e06da04
--- /dev/null
+++ b/athena/util/drag_handle.cc
@@ -0,0 +1,164 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "athena/util/drag_handle.h"
+
+#include "ui/views/background.h"
+#include "ui/views/layout/box_layout.h"
+#include "ui/views/view.h"
+#include "ui/views/widget/widget.h"
+
+namespace athena {
+namespace {
+
+const SkColor kDragHandleColorNormal = SK_ColorGRAY;
+const SkColor kDragHandleColorHot = SK_ColorWHITE;
+
+class DragHandleView : public views::View {
tdanderson 2014/09/15 17:48:19 nit: include brief class-level documentation.
mfomitchev 2014/09/15 21:43:47 Done.
+ public:
+ explicit DragHandleView(DragHandle::ScrollDirection scroll_direction,
+ DragHandle::ScrollDelegate* delegate,
+ int preferred_width,
+ int preferred_height);
+ virtual ~DragHandleView();
+
+ private:
+ enum State {
+ DEFAULT,
+ SCROLLING,
+ };
+
+ void SetColor(SkColor color);
+
+ void SetState(State state);
+
+ // views::View:
+ virtual gfx::Size GetPreferredSize() const OVERRIDE;
+ virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
+ virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
+ virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
+
+ State state_;
+ DragHandle::ScrollDelegate* delegate_;
+ DragHandle::ScrollDirection scroll_direction_;
+ SkColor color_;
+ float scroll_start_location_;
+ const int preferred_width_;
+ const int preferred_height_;
+
+ DISALLOW_COPY_AND_ASSIGN(DragHandleView);
+};
+
+DragHandleView::DragHandleView(DragHandle::ScrollDirection scroll_direction,
+ DragHandle::ScrollDelegate* delegate,
+ int preferred_width,
+ int preferred_height)
+ : state_(DEFAULT),
+ delegate_(delegate),
+ scroll_direction_(scroll_direction),
+ color_(SK_ColorTRANSPARENT),
+ preferred_width_(preferred_width),
+ preferred_height_(preferred_height) {
+ SetColor(kDragHandleColorNormal);
+}
+
+DragHandleView::~DragHandleView() {
+}
+
+void DragHandleView::SetColor(SkColor color) {
+ if (color_ == color)
+ return;
+ color_ = color;
+ set_background(views::Background::CreateSolidBackground(color_));
+ SchedulePaint();
+}
+
+void DragHandleView::SetState(State state) {
+ if (state_ == state)
+ return;
+ state_ = state;
+ if (state == DEFAULT)
+ scroll_start_location_ = 0;
+}
+
+// views::View:
+gfx::Size DragHandleView::GetPreferredSize() const {
+ return gfx::Size(preferred_width_, preferred_height_);
+}
+
+void DragHandleView::OnMouseEntered(const ui::MouseEvent& event) {
+ SetColor(kDragHandleColorHot);
+}
+
+void DragHandleView::OnMouseExited(const ui::MouseEvent& event) {
+ SetColor(kDragHandleColorNormal);
+}
+
+void DragHandleView::OnGestureEvent(ui::GestureEvent* event) {
+ SkColor change_color = SK_ColorTRANSPARENT;
+ if (event->type() == ui::ET_GESTURE_BEGIN &&
+ event->details().touch_points() == 1) {
+ change_color = kDragHandleColorHot;
+ } else if (event->type() == ui::ET_GESTURE_END &&
+ event->details().touch_points() == 1) {
+ change_color = kDragHandleColorNormal;
+ }
tdanderson 2014/09/15 17:48:19 nit: newline after 106
mfomitchev 2014/09/15 21:43:47 Done.
+ if (change_color != SK_ColorTRANSPARENT) {
+ SetColor(change_color);
+ event->SetHandled();
+ return;
+ }
+
+ if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
+ if (!delegate_->HandleCanScroll() || state_ != DEFAULT)
+ return;
+ float delta;
+ if (scroll_direction_ == DragHandle::VERTICAL) {
+ delta = event->details().scroll_y_hint();
+ scroll_start_location_ = event->root_location().y();
+ } else {
+ delta = event->details().scroll_x_hint();
+ scroll_start_location_ = event->root_location().x();
+ }
+ delegate_->HandleScrollBegin(delta);
+ SetState(SCROLLING);
+ event->SetHandled();
+ } else if (event->type() == ui::ET_GESTURE_SCROLL_END) {
+ if (state_ != SCROLLING)
+ return;
+ delegate_->HandleScrollEnd();
+ SetColor(kDragHandleColorNormal);
+ SetState(DEFAULT);
+ event->SetHandled();
+ } else if (event->type() == ui::ET_SCROLL_FLING_START) {
tdanderson 2014/09/15 17:48:19 nit: SCROLL_END || SCROLL_FLING_START can be combi
mfomitchev 2014/09/15 21:43:47 Done.
+ if (state_ != SCROLLING)
+ return;
+ delegate_->HandleScrollEnd();
+ SetColor(kDragHandleColorNormal);
+ SetState(DEFAULT);
+ event->SetHandled();
+ } else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
+ if (state_ != SCROLLING)
+ return;
+ float delta = scroll_direction_ == DragHandle::VERTICAL
+ ? event->root_location().y() - scroll_start_location_
+ : event->root_location().x() - scroll_start_location_;
+ delegate_->HandleScrollUpdate(delta);
+ event->SetHandled();
+ }
+}
+
+} // namespace
+
+views::View* CreateDragHandleView(DragHandle::ScrollDirection scroll_direction,
+ DragHandle::ScrollDelegate* delegate,
+ int preferred_width,
+ int preferred_height,
+ int margin) {
+ views::View* view = new DragHandleView(
+ scroll_direction, delegate, preferred_width, preferred_height);
+ return view;
+}
+
+} // namespace athena

Powered by Google App Engine
This is Rietveld 408576698