summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authordewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-11 14:46:59 +0000
committerdewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-11 14:46:59 +0000
commit474d6fd020de6b1a307d4d7dc3c56ac0ba89a0de (patch)
tree53c242c96eec968c162b37b4a15d64b4028e8ac9 /ui
parentf3e46eec24473908be945e564235eff004261260 (diff)
downloadchromium_src-474d6fd020de6b1a307d4d7dc3c56ac0ba89a0de.zip
chromium_src-474d6fd020de6b1a307d4d7dc3c56ac0ba89a0de.tar.gz
chromium_src-474d6fd020de6b1a307d4d7dc3c56ac0ba89a0de.tar.bz2
Reland 204146 - Introduces a new scrollbar for message_center.
The new one overlaps with the scroll contents. TBR=sadrul@chromium.org BUG=239559 R=mukai@chromium.org Review URL: https://chromiumcodereview.appspot.com/16670002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205545 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/message_center/views/message_center_view.cc4
-rw-r--r--ui/message_center/views/notifier_settings_view.cc4
-rw-r--r--ui/views/controls/scroll_view.cc26
-rw-r--r--ui/views/controls/scroll_view.h2
-rw-r--r--ui/views/controls/scrollbar/overlay_scroll_bar.cc142
-rw-r--r--ui/views/controls/scrollbar/overlay_scroll_bar.h41
-rw-r--r--ui/views/controls/scrollbar/scroll_bar.cc10
-rw-r--r--ui/views/controls/scrollbar/scroll_bar.h7
-rw-r--r--ui/views/views.gyp2
9 files changed, 230 insertions, 8 deletions
diff --git a/ui/message_center/views/message_center_view.cc b/ui/message_center/views/message_center_view.cc
index 8e87df5..2d72653 100644
--- a/ui/message_center/views/message_center_view.cc
+++ b/ui/message_center/views/message_center_view.cc
@@ -31,7 +31,7 @@
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/scroll_view.h"
-#include "ui/views/controls/scrollbar/kennedy_scroll_bar.h"
+#include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/painter.h"
@@ -304,7 +304,7 @@ BoundedScrollView::BoundedScrollView(int min_height, int max_height)
if (IsRichNotificationEnabled()) {
set_background(views::Background::CreateSolidBackground(
kMessageCenterBackgroundColor));
- SetVerticalScrollBar(new views::KennedyScrollBar(false));
+ SetVerticalScrollBar(new views::OverlayScrollBar(false));
}
}
diff --git a/ui/message_center/views/notifier_settings_view.cc b/ui/message_center/views/notifier_settings_view.cc
index eeef62d..ba8c50b 100644
--- a/ui/message_center/views/notifier_settings_view.cc
+++ b/ui/message_center/views/notifier_settings_view.cc
@@ -20,7 +20,7 @@
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/scroll_view.h"
-#include "ui/views/controls/scrollbar/kennedy_scroll_bar.h"
+#include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h"
@@ -290,7 +290,7 @@ NotifierSettingsView::NotifierSettingsView(
scroller_ = new views::ScrollView();
scroller_->set_border(new Separator());
- scroller_->SetVerticalScrollBar(new views::KennedyScrollBar(false));
+ scroller_->SetVerticalScrollBar(new views::OverlayScrollBar(false));
AddChildView(scroller_);
views::View* contents_view = new views::View();
diff --git a/ui/views/controls/scroll_view.cc b/ui/views/controls/scroll_view.cc
index 3659c35..11ffc02 100644
--- a/ui/views/controls/scroll_view.cc
+++ b/ui/views/controls/scroll_view.cc
@@ -117,6 +117,8 @@ ScrollView::ScrollView()
vert_sb_(new NativeScrollBar(false)),
resize_corner_(NULL),
hide_horizontal_scrollbar_(false) {
+ set_notify_enter_exit_on_child(true);
+
AddChildView(contents_viewport_);
AddChildView(header_viewport_);
@@ -252,15 +254,17 @@ void ScrollView::Layout() {
}
if (horiz_sb_required) {
+ int height_offset = horiz_sb_->GetContentOverlapSize();
horiz_sb_->SetBounds(0,
- viewport_bounds.bottom(),
+ viewport_bounds.bottom() - height_offset,
viewport_bounds.right(),
- horiz_sb_height);
+ horiz_sb_height + height_offset);
}
if (vert_sb_required) {
- vert_sb_->SetBounds(viewport_bounds.right(),
+ int width_offset = vert_sb_->GetContentOverlapSize();
+ vert_sb_->SetBounds(viewport_bounds.right() - width_offset,
0,
- vert_sb_width,
+ vert_sb_width + width_offset,
viewport_bounds.bottom());
}
if (resize_corner_required) {
@@ -312,6 +316,20 @@ bool ScrollView::OnMouseWheel(const ui::MouseWheelEvent& e) {
return processed;
}
+void ScrollView::OnMouseEntered(const ui::MouseEvent& event) {
+ if (horiz_sb_)
+ horiz_sb_->OnMouseEnteredScrollView(event);
+ if (vert_sb_)
+ vert_sb_->OnMouseEnteredScrollView(event);
+}
+
+void ScrollView::OnMouseExited(const ui::MouseEvent& event) {
+ if (horiz_sb_)
+ horiz_sb_->OnMouseExitedScrollView(event);
+ if (vert_sb_)
+ vert_sb_->OnMouseExitedScrollView(event);
+}
+
void ScrollView::OnGestureEvent(ui::GestureEvent* event) {
// If the event happened on one of the scrollbars, then those events are
// sent directly to the scrollbars. Otherwise, only scroll events are sent to
diff --git a/ui/views/controls/scroll_view.h b/ui/views/controls/scroll_view.h
index 857ddac..da87ffd 100644
--- a/ui/views/controls/scroll_view.h
+++ b/ui/views/controls/scroll_view.h
@@ -70,6 +70,8 @@ class VIEWS_EXPORT ScrollView : public View, public ScrollBarController {
virtual void Layout() OVERRIDE;
virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
virtual bool OnMouseWheel(const ui::MouseWheelEvent& e) OVERRIDE;
+ virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
+ virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
virtual const char* GetClassName() const OVERRIDE;
diff --git a/ui/views/controls/scrollbar/overlay_scroll_bar.cc b/ui/views/controls/scrollbar/overlay_scroll_bar.cc
new file mode 100644
index 0000000..c7e254a
--- /dev/null
+++ b/ui/views/controls/scrollbar/overlay_scroll_bar.cc
@@ -0,0 +1,142 @@
+// Copyright 2013 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 "ui/views/controls/scrollbar/overlay_scroll_bar.h"
+
+#include "third_party/skia/include/core/SkColor.h"
+#include "third_party/skia/include/core/SkXfermode.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/background.h"
+#include "ui/views/border.h"
+#include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h"
+
+namespace views {
+namespace {
+
+const int kScrollbarWidth = 10;
+const int kThumbInsetInside = 3;
+const int kThumbInsetFromEdge = 1;
+const int kThumbCornerRadius = 2;
+const int kThumbMinimumSize = kScrollbarWidth;
+const int kThumbHoverAlpha = 128;
+const int kThumbDefaultAlpha = 64;
+
+class OverlayScrollBarThumb : public BaseScrollBarThumb,
+ public ui::AnimationDelegate {
+ public:
+ explicit OverlayScrollBarThumb(BaseScrollBar* scroll_bar);
+ virtual ~OverlayScrollBarThumb();
+
+ protected:
+ // View overrides:
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
+
+ // ui::AnimationDelegate overrides:
+ virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
+
+ private:
+ double animation_opacity_;
+ DISALLOW_COPY_AND_ASSIGN(OverlayScrollBarThumb);
+};
+
+OverlayScrollBarThumb::OverlayScrollBarThumb(BaseScrollBar* scroll_bar)
+ : BaseScrollBarThumb(scroll_bar),
+ animation_opacity_(0.0) {
+ if (get_use_acceleration_when_possible()) {
+ // This is necessary, otherwise the thumb will be rendered below the views
+ // if those views paint to their own layers.
+ SetPaintToLayer(true);
+ SetFillsBoundsOpaquely(false);
+ }
+}
+
+OverlayScrollBarThumb::~OverlayScrollBarThumb() {
+}
+
+gfx::Size OverlayScrollBarThumb::GetPreferredSize() {
+ return gfx::Size(kThumbMinimumSize, kThumbMinimumSize);
+}
+
+void OverlayScrollBarThumb::OnPaint(gfx::Canvas* canvas) {
+ gfx::Rect local_bounds(GetLocalBounds());
+ SkPaint paint;
+ int alpha = (GetState() == CustomButton::STATE_HOVERED ||
+ GetState() == CustomButton::STATE_PRESSED) ?
+ kThumbHoverAlpha : kThumbDefaultAlpha;
+ alpha *= animation_opacity_;
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setColor(SkColorSetARGB(alpha, 0, 0, 0));
+ canvas->DrawRoundRect(local_bounds, kThumbCornerRadius, paint);
+}
+
+void OverlayScrollBarThumb::AnimationProgressed(
+ const ui::Animation* animation) {
+ animation_opacity_ = animation->GetCurrentValue();
+ SchedulePaint();
+}
+
+} // namespace
+
+OverlayScrollBar::OverlayScrollBar(bool horizontal)
+ : BaseScrollBar(horizontal, new OverlayScrollBarThumb(this)),
+ animation_(static_cast<OverlayScrollBarThumb*>(GetThumb())) {
+ set_notify_enter_exit_on_child(true);
+}
+
+OverlayScrollBar::~OverlayScrollBar() {
+}
+
+gfx::Rect OverlayScrollBar::GetTrackBounds() const {
+ gfx::Rect local_bounds(GetLocalBounds());
+ if (IsHorizontal()) {
+ local_bounds.Inset(kThumbInsetFromEdge, kThumbInsetInside,
+ kThumbInsetFromEdge, kThumbInsetFromEdge);
+ } else {
+ local_bounds.Inset(kThumbInsetInside, kThumbInsetFromEdge,
+ kThumbInsetFromEdge, kThumbInsetFromEdge);
+ }
+ gfx::Size track_size = local_bounds.size();
+ track_size.SetToMax(GetThumb()->size());
+ local_bounds.set_size(track_size);
+ return local_bounds;
+}
+
+int OverlayScrollBar::GetLayoutSize() const {
+ return 0;
+}
+
+int OverlayScrollBar::GetContentOverlapSize() const {
+ return kScrollbarWidth;
+}
+
+void OverlayScrollBar::OnMouseEnteredScrollView(const ui::MouseEvent& event) {
+ animation_.Show();
+}
+
+void OverlayScrollBar::OnMouseExitedScrollView(const ui::MouseEvent& event) {
+ animation_.Hide();
+}
+
+gfx::Size OverlayScrollBar::GetPreferredSize() {
+ return gfx::Size();
+}
+
+void OverlayScrollBar::Layout() {
+ gfx::Rect thumb_bounds = GetTrackBounds();
+ BaseScrollBarThumb* thumb = GetThumb();
+ if (IsHorizontal()) {
+ thumb_bounds.set_x(thumb->x());
+ thumb_bounds.set_width(thumb->width());
+ } else {
+ thumb_bounds.set_y(thumb->y());
+ thumb_bounds.set_height(thumb->height());
+ }
+ thumb->SetBoundsRect(thumb_bounds);
+}
+
+void OverlayScrollBar::OnPaint(gfx::Canvas* canvas) {
+}
+
+} // namespace views
diff --git a/ui/views/controls/scrollbar/overlay_scroll_bar.h b/ui/views/controls/scrollbar/overlay_scroll_bar.h
new file mode 100644
index 0000000..043f5f7
--- /dev/null
+++ b/ui/views/controls/scrollbar/overlay_scroll_bar.h
@@ -0,0 +1,41 @@
+// Copyright 2013 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.
+
+#ifndef UI_VIEWS_CONTROLS_SCROLLBAR_OVERLAY_SCROLL_BAR_H_
+#define UI_VIEWS_CONTROLS_SCROLLBAR_OVERLAY_SCROLL_BAR_H_
+
+#include "ui/base/animation/slide_animation.h"
+#include "ui/views/controls/scrollbar/base_scroll_bar.h"
+
+namespace views {
+
+// The transparent scrollbar which overlays its contents.
+class VIEWS_EXPORT OverlayScrollBar : public BaseScrollBar {
+ public:
+ explicit OverlayScrollBar(bool horizontal);
+ virtual ~OverlayScrollBar();
+
+ protected:
+ // BaseScrollBar overrides:
+ virtual gfx::Rect GetTrackBounds() const OVERRIDE;
+
+ // ScrollBar overrides:
+ virtual int GetLayoutSize() const OVERRIDE;
+ virtual int GetContentOverlapSize() const OVERRIDE;
+ virtual void OnMouseEnteredScrollView(const ui::MouseEvent& event) OVERRIDE;
+ virtual void OnMouseExitedScrollView(const ui::MouseEvent& event) OVERRIDE;
+
+ // View overrides:
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual void Layout() OVERRIDE;
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
+
+ private:
+ ui::SlideAnimation animation_;
+ DISALLOW_COPY_AND_ASSIGN(OverlayScrollBar);
+};
+
+} // namespace views
+
+#endif // UI_VIEWS_CONTROLS_SCROLLBAR_OVERLAY_SCROLL_BAR_H_
diff --git a/ui/views/controls/scrollbar/scroll_bar.cc b/ui/views/controls/scrollbar/scroll_bar.cc
index 7719d86..5374d32 100644
--- a/ui/views/controls/scrollbar/scroll_bar.cc
+++ b/ui/views/controls/scrollbar/scroll_bar.cc
@@ -31,6 +31,16 @@ int ScrollBar::GetMinPosition() const {
return 0;
}
+int ScrollBar::GetContentOverlapSize() const {
+ return 0;
+}
+
+void ScrollBar::OnMouseEnteredScrollView(const ui::MouseEvent& event) {
+}
+
+void ScrollBar::OnMouseExitedScrollView(const ui::MouseEvent& event) {
+}
+
ScrollBar::ScrollBar(bool is_horiz)
: is_horiz_(is_horiz),
controller_(NULL),
diff --git a/ui/views/controls/scrollbar/scroll_bar.h b/ui/views/controls/scrollbar/scroll_bar.h
index 5b534d6..aa3800e 100644
--- a/ui/views/controls/scrollbar/scroll_bar.h
+++ b/ui/views/controls/scrollbar/scroll_bar.h
@@ -86,6 +86,13 @@ class VIEWS_EXPORT ScrollBar : public View {
// is the height for a horizontal scrollbar.
virtual int GetLayoutSize() const = 0;
+ // Get the width or height for this scrollbar which overlaps with the content.
+ // Default is 0.
+ virtual int GetContentOverlapSize() const;
+
+ virtual void OnMouseEnteredScrollView(const ui::MouseEvent& event);
+ virtual void OnMouseExitedScrollView(const ui::MouseEvent& event);
+
protected:
// Create new scrollbar, either horizontal or vertical. These are protected
// since you need to be creating either a NativeScrollBar or a
diff --git a/ui/views/views.gyp b/ui/views/views.gyp
index 3acfcc6..3155021 100644
--- a/ui/views/views.gyp
+++ b/ui/views/views.gyp
@@ -188,6 +188,8 @@
'controls/scrollbar/native_scroll_bar_wrapper.h',
'controls/scrollbar/native_scroll_bar.cc',
'controls/scrollbar/native_scroll_bar.h',
+ 'controls/scrollbar/overlay_scroll_bar.cc',
+ 'controls/scrollbar/overlay_scroll_bar.h',
'controls/scrollbar/scroll_bar.cc',
'controls/scrollbar/scroll_bar.h',
'controls/separator.cc',