Commit f6f9c1d3 authored by backer@chromium.org's avatar backer@chromium.org

Revert 98434 - Adding a Views scrollbar implementation.

BUG=none
TEST=Verified basic functionality using views_examples.

Review URL: http://codereview.chromium.org/7669028
Patch from Daniel Nicoara <dnicoara@chromium.org>.

TBR=backer@chromium.org,dnicoara@chromium.org
Review URL: http://codereview.chromium.org/7767002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98467 0039d316-1c4b-4281-b951-d872f2087c98
parent e5a3cdcf
This diff is collapsed.
// Copyright (c) 2011 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 VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_H_
#define VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_H_
#pragma once
#include "views/context_menu_controller.h"
#include "views/controls/button/image_button.h"
#include "views/controls/menu/menu.h"
#include "views/controls/scrollbar/scroll_bar.h"
#include "views/repeat_controller.h"
namespace views {
class BaseScrollBarThumb;
///////////////////////////////////////////////////////////////////////////////
//
// BaseScrollBar
//
///////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT BaseScrollBar : public ScrollBar,
public ContextMenuController,
public Menu::Delegate {
public:
BaseScrollBar(bool horizontal, BaseScrollBarThumb* thumb);
virtual ~BaseScrollBar() { }
// Get the bounds of the "track" area that the thumb is free to slide within.
virtual gfx::Rect GetTrackBounds() const = 0;
// An enumeration of different amounts of incremental scroll, representing
// events sent from different parts of the UI/keyboard.
enum ScrollAmount {
SCROLL_NONE = 0,
SCROLL_START,
SCROLL_END,
SCROLL_PREV_LINE,
SCROLL_NEXT_LINE,
SCROLL_PREV_PAGE,
SCROLL_NEXT_PAGE,
};
// Scroll the contents by the specified type (see ScrollAmount above).
void ScrollByAmount(ScrollAmount amount);
// Scroll the contents to the appropriate position given the supplied
// position of the thumb (thumb track coordinates). If |scroll_to_middle| is
// true, then the conversion assumes |thumb_position| is in the middle of the
// thumb rather than the top.
void ScrollToThumbPosition(int thumb_position, bool scroll_to_middle);
// Scroll the contents by the specified offset (contents coordinates).
void ScrollByContentsOffset(int contents_offset);
// View overrides:
virtual gfx::Size GetPreferredSize() OVERRIDE = 0;
virtual void Layout() OVERRIDE = 0;
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE;
virtual void OnMouseCaptureLost() OVERRIDE;
virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE;
virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE;
// ScrollBar overrides:
virtual void Update(int viewport_size,
int content_size,
int contents_scroll_offset) OVERRIDE;
virtual int GetLayoutSize() const OVERRIDE = 0;
virtual int GetPosition() const OVERRIDE;
// ContextMenuController overrides.
virtual void ShowContextMenuForView(View* source,
const gfx::Point& p,
bool is_mouse_gesture) OVERRIDE;
// Menu::Delegate overrides:
virtual std::wstring GetLabel(int id) const OVERRIDE;
virtual bool IsCommandEnabled(int id) const OVERRIDE;
virtual void ExecuteCommand(int id) OVERRIDE;
protected:
// View overrides:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE = 0;
BaseScrollBarThumb* GetThumb() const;
CustomButton::ButtonState GetThumbTrackState() const;
// Wrapper functions that calls the controller. We need this since native
// scrollbars wrap around a different scrollbar. When calling the controller
// we need to pass in the appropriate scrollbar. For normal scrollbars it's
// the |this| scrollbar, for native scrollbars it's the native scrollbar used
// to create this.
virtual void ScrollToPosition(int position);
virtual int GetScrollIncrement(bool is_page, bool is_positive);
private:
// Called when the mouse is pressed down in the track area.
void TrackClicked();
// Responsible for scrolling the contents and also updating the UI to the
// current value of the Scroll Offset.
void ScrollContentsToOffset();
// Returns the size (width or height) of the track area of the ScrollBar.
int GetTrackSize() const;
// Calculate the position of the thumb within the track based on the
// specified scroll offset of the contents.
int CalculateThumbPosition(int contents_scroll_offset) const;
// Calculates the current value of the contents offset (contents coordinates)
// based on the current thumb position (thumb track coordinates). See
// |ScrollToThumbPosition| for an explanation of |scroll_to_middle|.
int CalculateContentsOffset(int thumb_position,
bool scroll_to_middle) const;
// Called when the state of the thumb track changes (e.g. by the user
// pressing the mouse button down in it).
void SetThumbTrackState(CustomButton::ButtonState state);
BaseScrollBarThumb* thumb_;
// The size of the scrolled contents, in pixels.
int contents_size_;
// The current amount the contents is offset by in the viewport.
int contents_scroll_offset_;
// The state of the scrollbar track. Typically, the track will highlight when
// the user presses the mouse on them (during page scrolling).
CustomButton::ButtonState thumb_track_state_;
// The last amount of incremental scroll that this scrollbar performed. This
// is accessed by the callbacks for the auto-repeat up/down buttons to know
// what direction to repeatedly scroll in.
ScrollAmount last_scroll_amount_;
// An instance of a RepeatController which scrolls the scrollbar continuously
// as the user presses the mouse button down on the up/down buttons or the
// track.
RepeatController repeater_;
// The position of the mouse within the scroll bar when the context menu
// was invoked.
int context_menu_mouse_position_;
DISALLOW_COPY_AND_ASSIGN(BaseScrollBar);
};
} // namespace views
#endif // VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_H_
// Copyright (c) 2011 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 "views/controls/scrollbar/base_scroll_bar_button.h"
namespace views {
BaseScrollBarButton::BaseScrollBarButton(ButtonListener* listener)
: CustomButton(listener),
ALLOW_THIS_IN_INITIALIZER_LIST(repeater_(
NewCallback<BaseScrollBarButton>(this,
&BaseScrollBarButton::RepeaterNotifyClick))) {
}
BaseScrollBarButton::~BaseScrollBarButton() {
}
bool BaseScrollBarButton::OnMousePressed(const MouseEvent& event) {
Button::NotifyClick(event);
repeater_.Start();
return true;
}
void BaseScrollBarButton::OnMouseReleased(const MouseEvent& event) {
OnMouseCaptureLost();
}
void BaseScrollBarButton::OnMouseCaptureLost() {
repeater_.Stop();
}
void BaseScrollBarButton::RepeaterNotifyClick() {
#if defined(OS_WIN)
DWORD pos = GetMessagePos();
POINTS points = MAKEPOINTS(pos);
gfx::Point cursor_point(points.x, points.y);
#elif defined(OS_LINUX)
gfx::Point cursor_point = gfx::Screen::GetCursorScreenPoint();
#endif
views::MouseEvent event(ui::ET_MOUSE_RELEASED,
cursor_point.x(), cursor_point.y(),
ui::EF_LEFT_BUTTON_DOWN);
Button::NotifyClick(event);
}
} // namespace views
// Copyright (c) 2011 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 VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_BUTTON_H_
#define VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_BUTTON_H_
#pragma once
#include "views/controls/button/custom_button.h"
#include "views/repeat_controller.h"
#if defined(OS_LINUX)
#include "ui/gfx/screen.h"
#endif
namespace views {
///////////////////////////////////////////////////////////////////////////////
//
// ScrollBarButton
//
// A button that activates on mouse pressed rather than released, and that
// continues to fire the clicked action as the mouse button remains pressed
// down on the button.
//
///////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT BaseScrollBarButton : public CustomButton {
public:
explicit BaseScrollBarButton(ButtonListener* listener);
virtual ~BaseScrollBarButton();
protected:
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE;
virtual void OnMouseCaptureLost() OVERRIDE;
private:
void RepeaterNotifyClick();
// The repeat controller that we use to repeatedly click the button when the
// mouse button is down.
RepeatController repeater_;
DISALLOW_COPY_AND_ASSIGN(BaseScrollBarButton);
};
} // namespace views
#endif // VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_BUTTON_H_
// Copyright (c) 2011 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 "views/controls/scrollbar/base_scroll_bar_thumb.h"
#include "views/controls/scrollbar/base_scroll_bar.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/rect.h"
namespace {
// The distance the mouse can be dragged outside the bounds of the thumb during
// dragging before the scrollbar will snap back to its regular position.
static const int kScrollThumbDragOutSnap = 100;
}
namespace views {
BaseScrollBarThumb::BaseScrollBarThumb(BaseScrollBar* scroll_bar)
: scroll_bar_(scroll_bar),
drag_start_position_(-1),
mouse_offset_(-1),
state_(CustomButton::BS_NORMAL) {
}
BaseScrollBarThumb::~BaseScrollBarThumb() {
}
void BaseScrollBarThumb::SetSize(int size) {
// Make sure the thumb is never sized smaller than its minimum possible
// display size.
gfx::Size prefsize = GetPreferredSize();
size = std::max(size, scroll_bar_->IsHorizontal() ? prefsize.width() :
prefsize.height());
gfx::Rect thumb_bounds = bounds();
if (scroll_bar_->IsHorizontal()) {
thumb_bounds.set_width(size);
} else {
thumb_bounds.set_height(size);
}
SetBoundsRect(thumb_bounds);
}
int BaseScrollBarThumb::GetSize() const {
if (scroll_bar_->IsHorizontal())
return width();
return height();
}
void BaseScrollBarThumb::SetPosition(int position) {
gfx::Rect thumb_bounds = bounds();
gfx::Rect track_bounds = scroll_bar_->GetTrackBounds();
if (scroll_bar_->IsHorizontal()) {
thumb_bounds.set_x(track_bounds.x() + position);
} else {
thumb_bounds.set_y(track_bounds.y() + position);
}
SetBoundsRect(thumb_bounds);
}
int BaseScrollBarThumb::GetPosition() const {
gfx::Rect track_bounds = scroll_bar_->GetTrackBounds();
if (scroll_bar_->IsHorizontal())
return x() - track_bounds.x();
return y() - track_bounds.y();
}
void BaseScrollBarThumb::OnMouseEntered(const MouseEvent& event) {
SetState(CustomButton::BS_HOT);
}
void BaseScrollBarThumb::OnMouseExited(const MouseEvent& event) {
SetState(CustomButton::BS_NORMAL);
}
bool BaseScrollBarThumb::OnMousePressed(const MouseEvent& event) {
mouse_offset_ = scroll_bar_->IsHorizontal() ? event.x() : event.y();
drag_start_position_ = GetPosition();
SetState(CustomButton::BS_PUSHED);
return true;
}
bool BaseScrollBarThumb::OnMouseDragged(const MouseEvent& event) {
// If the user moves the mouse more than |kScrollThumbDragOutSnap| outside
// the bounds of the thumb, the scrollbar will snap the scroll back to the
// point it was at before the drag began.
if (scroll_bar_->IsHorizontal()) {
if ((event.y() < y() - kScrollThumbDragOutSnap) ||
(event.y() > (y() + height() + kScrollThumbDragOutSnap))) {
scroll_bar_->ScrollToThumbPosition(drag_start_position_, false);
return true;
}
} else {
if ((event.x() < x() - kScrollThumbDragOutSnap) ||
(event.x() > (x() + width() + kScrollThumbDragOutSnap))) {
scroll_bar_->ScrollToThumbPosition(drag_start_position_, false);
return true;
}
}
if (scroll_bar_->IsHorizontal()) {
int thumb_x = event.x() - mouse_offset_;
scroll_bar_->ScrollToThumbPosition(GetPosition() + thumb_x, false);
} else {
int thumb_y = event.y() - mouse_offset_;
scroll_bar_->ScrollToThumbPosition(GetPosition() + thumb_y, false);
}
return true;
}
void BaseScrollBarThumb::OnMouseReleased(const MouseEvent& event) {
OnMouseCaptureLost();
}
void BaseScrollBarThumb::OnMouseCaptureLost() {
SetState(CustomButton::BS_HOT);
}
CustomButton::ButtonState BaseScrollBarThumb::GetState() const {
return state_;
}
void BaseScrollBarThumb::SetState(CustomButton::ButtonState state) {
state_ = state;
SchedulePaint();
}
} // namespace views
// Copyright (c) 2011 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 VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_THUMB_H_
#define VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_THUMB_H_
#pragma once
#include "ui/gfx/size.h"
#include "views/controls/button/custom_button.h"
#include "views/controls/scrollbar/scroll_bar.h"
#include "views/view.h"
namespace gfx {
class Canvas;
}
namespace views {
class BaseScrollBar;
///////////////////////////////////////////////////////////////////////////////
//
// BaseScrollBarThumb
//
// A view that acts as the thumb in the scroll bar track that the user can
// drag to scroll the associated contents view within the viewport.
//
///////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT BaseScrollBarThumb : public View {
public:
explicit BaseScrollBarThumb(BaseScrollBar* scroll_bar);
virtual ~BaseScrollBarThumb();
// Sets the size (width or height) of the thumb to the specified value.
void SetSize(int size);
// Retrieves the size (width or height) of the thumb.
int GetSize() const;
// Sets the position of the thumb on the x or y axis.
void SetPosition(int position);
// Gets the position of the thumb on the x or y axis.
int GetPosition() const;
// View overrides:
virtual gfx::Size GetPreferredSize() OVERRIDE = 0;
protected:
// View overrides:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE = 0;
virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE;
virtual void OnMouseCaptureLost() OVERRIDE;
CustomButton::ButtonState GetState() const;
// Update our state and schedule a repaint when the mouse moves over us.
void SetState(CustomButton::ButtonState state);
private:
// The BaseScrollBar that owns us.
BaseScrollBar* scroll_bar_;
int drag_start_position_;
// The position of the mouse on the scroll axis relative to the top of this
// View when the drag started.
int mouse_offset_;
// The current state of the thumb button.
CustomButton::ButtonState state_;
DISALLOW_COPY_AND_ASSIGN(BaseScrollBarThumb);
};
} // namespace views
#endif // VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_THUMB_H_
......@@ -6,7 +6,11 @@
#define VIEWS_CONTROLS_SCROLLBAR_BITMAP_SCROLL_BAR_H_
#pragma once
#include "views/controls/scrollbar/base_scroll_bar.h"
#include "views/context_menu_controller.h"
#include "views/controls/button/image_button.h"
#include "views/controls/menu/menu.h"
#include "views/controls/scrollbar/scroll_bar.h"
#include "views/repeat_controller.h"
namespace views {
......@@ -23,13 +27,24 @@ class BitmapScrollBarThumb;
// well as for the thumb and track. This is intended for creating UIs that
// have customized, non-native appearances, like floating HUDs etc.
//
// Maybe TODO(beng): (Cleanup) If we need to, we may want to factor rendering
// out of this altogether and have the user supply
// Background impls for each component, and just use those
// to render, so that for example we get native theme
// rendering.
//
///////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT BitmapScrollBar : public BaseScrollBar,
public ButtonListener {
class BitmapScrollBar : public ScrollBar,
public ButtonListener,
public ContextMenuController,
public Menu::Delegate {
public:
BitmapScrollBar(bool horizontal, bool show_scroll_buttons);
virtual ~BitmapScrollBar() { }
// Get the bounds of the "track" area that the thumb is free to slide within.
gfx::Rect GetTrackBounds() const;
// A list of parts that the user may supply bitmaps for.
enum ScrollBarPart {
// The button used to represent scrolling up/left by 1 line.
......@@ -56,31 +71,122 @@ class VIEWS_EXPORT BitmapScrollBar : public BaseScrollBar,
CustomButton::ButtonState state,
SkBitmap* bitmap);
// An enumeration of different amounts of incremental scroll, representing
// events sent from different parts of the UI/keyboard.
enum ScrollAmount {
SCROLL_NONE = 0,
SCROLL_START,
SCROLL_END,
SCROLL_PREV_LINE,
SCROLL_NEXT_LINE,
SCROLL_PREV_PAGE,
SCROLL_NEXT_PAGE,
};
gfx::Rect GetTrackBounds() const;
// Scroll the contents by the specified type (see ScrollAmount above).
void ScrollByAmount(ScrollAmount amount);
// Scroll the contents to the appropriate position given the supplied
// position of the thumb (thumb track coordinates). If |scroll_to_middle| is
// true, then the conversion assumes |thumb_position| is in the middle of the
// thumb rather than the top.
void ScrollToThumbPosition(int thumb_position, bool scroll_to_middle);
// Scroll the contents by the specified offset (contents coordinates).
void ScrollByContentsOffset(int contents_offset);
protected:
// View overrides:
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual void Layout() OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
// ScrollBar overrides:
virtual int GetLayoutSize() const OVERRIDE;
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE;
virtual void OnMouseCaptureLost() OVERRIDE;
virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE;
virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE;
// BaseButton::ButtonListener overrides:
virtual void ButtonPressed(Button* sender,
const views::Event& event) OVERRIDE;
// ScrollBar overrides:
virtual void Update(int viewport_size,
int content_size,
int contents_scroll_offset) OVERRIDE;
virtual int GetLayoutSize() const OVERRIDE;
virtual int GetPosition() const OVERRIDE;
// ContextMenuController overrides.
virtual void ShowContextMenuForView(View* source,
const gfx::Point& p,
bool is_mouse_gesture) OVERRIDE;
// Menu::Delegate overrides:
virtual std::wstring GetLabel(int id) const OVERRIDE;
virtual bool IsCommandEnabled(int id) const OVERRIDE;
virtual void ExecuteCommand(int id) OVERRIDE;
protected:
// View overrides:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
private:
// Up/Down/Left/Right buttons.
ImageButton* prev_button_;
ImageButton* next_button_;
// Called when the mouse is pressed down in the track area.
void TrackClicked();
// Responsible for scrolling the contents and also updating the UI to the
// current value of the Scroll Offset.
void ScrollContentsToOffset();
// Returns the size (width or height) of the track area of the ScrollBar.
int GetTrackSize() const;
// Calculate the position of the thumb within the track based on the
// specified scroll offset of the contents.
int CalculateThumbPosition(int contents_scroll_offset) const;
// Calculates the current value of the contents offset (contents coordinates)
// based on the current thumb position (thumb track coordinates). See
// |ScrollToThumbPosition| for an explanation of |scroll_to_middle|.
int CalculateContentsOffset(int thumb_position,
bool scroll_to_middle) const;
// Called when the state of the thumb track changes (e.g. by the user
// pressing the mouse button down in it).
void SetThumbTrackState(CustomButton::ButtonState state);
// The thumb needs to be able to access the part images.
friend BitmapScrollBarThumb;
SkBitmap* images_[PART_COUNT][CustomButton::BS_COUNT];
// The size of the scrolled contents, in pixels.
int contents_size_;
// The current amount the contents is offset by in the viewport.
int contents_scroll_offset_;
// Up/Down/Left/Right buttons and the Thumb.
ImageButton* prev_button_;
ImageButton* next_button_;
BitmapScrollBarThumb* thumb_;
// The state of the scrollbar track. Typically, the track will highlight when
// the user presses the mouse on them (during page scrolling).
CustomButton::ButtonState thumb_track_state_;
// The last amount of incremental scroll that this scrollbar performed. This
// is accessed by the callbacks for the auto-repeat up/down buttons to know
// what direction to repeatedly scroll in.
ScrollAmount last_scroll_amount_;
// An instance of a RepeatController which scrolls the scrollbar continuously
// as the user presses the mouse button down on the up/down buttons or the
// track.
RepeatController repeater_;
// The position of the mouse within the scroll bar when the context menu
// was invoked.
int context_menu_mouse_position_;
// True if the scroll buttons at each end of the scroll bar should be shown.
bool show_scroll_buttons_;
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2009 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.
......@@ -8,9 +8,7 @@
#include "ui/base/keycodes/keyboard_codes_posix.h"
#include "views/controls/scrollbar/native_scroll_bar.h"
#include "views/controls/scrollbar/native_scroll_bar_views.h"
#include "views/controls/scrollbar/scroll_bar.h"
#include "views/widget/widget.h"
namespace views {
......@@ -201,8 +199,6 @@ void NativeScrollBarGtk::MoveToBottom() {
// static
NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper(
NativeScrollBar* scroll_bar) {
if (Widget::IsPureViews())
return new NativeScrollBarViews(scroll_bar);
return new NativeScrollBarGtk(scroll_bar);
}
......
This diff is collapsed.
// Copyright (c) 2011 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 VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_VIEWS_H_
#define VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_VIEWS_H_
#pragma once
#include "ui/gfx/native_theme.h"
#include "ui/gfx/point.h"
#include "views/controls/button/button.h"
#include "views/controls/scrollbar/base_scroll_bar.h"
#include "views/controls/scrollbar/native_scroll_bar_wrapper.h"
#include "views/view.h"
namespace gfx {
class Canvas;
}
namespace views {
class NativeScrollBar;
// Views implementation for the scrollbar.
class VIEWS_EXPORT NativeScrollBarViews : public BaseScrollBar,
public ButtonListener,
public NativeScrollBarWrapper {
public:
// Creates new scrollbar, either horizontal or vertical.
explicit NativeScrollBarViews(NativeScrollBar* native_scroll_bar);
virtual ~NativeScrollBarViews();
private:
// View overrides:
virtual void Layout();
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual gfx::Size GetPreferredSize();
// ScrollBar overrides:
virtual int GetLayoutSize() const OVERRIDE;
// BaseScrollBar overrides:
virtual void ScrollToPosition(int position);
virtual int GetScrollIncrement(bool is_page, bool is_positive);
// BaseButton::ButtonListener overrides:
virtual void ButtonPressed(Button* sender,
const views::Event& event) OVERRIDE;
// NativeScrollBarWrapper overrides:
virtual int GetPosition() const;
virtual View* GetView();
virtual void Update(int viewport_size, int content_size, int current_pos);
// Returns the area for the track. This is the area of the scrollbar minus
// the size of the arrow buttons.
virtual gfx::Rect GetTrackBounds() const OVERRIDE;
// The NativeScrollBar we are bound to.
NativeScrollBar* native_scroll_bar_;
// The scroll bar buttons (Up/Down, Left/Right).
Button* prev_button_;
Button* next_button_;
gfx::NativeTheme::ExtraParams params_;
gfx::NativeTheme::Part part_;
gfx::NativeTheme::State state_;
DISALLOW_COPY_AND_ASSIGN(NativeScrollBarViews);
};
} // namespace views
#endif // VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_VIEWS_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 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.
......@@ -13,7 +13,7 @@ class View;
// A specialization of NativeControlWrapper that hosts a platform-native
// scroll bar.
class VIEWS_EXPORT NativeScrollBarWrapper {
class NativeScrollBarWrapper {
public:
virtual ~NativeScrollBarWrapper() {}
......
// Copyright (c) 2011 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 "views/controls/scrollbar/scroll_bar.h"
#include "views/controls/scrollbar/native_scroll_bar.h"
#include "views/controls/scrollbar/native_scroll_bar_views.h"
#include "views/test/views_test_base.h"
#include "views/widget/widget.h"
namespace {
// The Scrollbar controller. This is the widget that should do the real
// scrolling of contents.
class TestScrollBarController : public views::ScrollBarController {
public:
virtual ~TestScrollBarController() {}
virtual void ScrollToPosition(views::ScrollBar* source,
int position) OVERRIDE {
last_source = source;
last_position = position;
}
virtual int GetScrollIncrement(views::ScrollBar* source,
bool is_page,
bool is_positive) OVERRIDE {
last_source = source;
last_is_page = is_page;
last_is_positive = is_positive;
if (is_page)
return 20;
return 10;
}
// We save the last values in order to assert the corectness of the scroll
// operation.
views::ScrollBar* last_source;
bool last_is_positive;
bool last_is_page;
int last_position;
};
} // namespace
namespace views {
class NativeScrollBarTest : public ViewsTestBase {
public:
NativeScrollBarTest()
: widget_(NULL),
scrollbar_(NULL),
controller_(NULL) {
}
virtual void SetUp() {
ViewsTestBase::SetUp();
Widget::SetPureViews(true);
}
virtual void TearDown() {
Widget::SetPureViews(false);
if (widget_)
widget_->Close();
ViewsTestBase::TearDown();
}
void InitScrollBar() {
controller_.reset(new TestScrollBarController());
ASSERT_FALSE(scrollbar_);
native_scrollbar_ = new NativeScrollBar(true);
native_scrollbar_->SetBounds(0, 0, 100, 100);
scrollbar_ = new NativeScrollBarViews(native_scrollbar_);
scrollbar_->SetController(controller_.get());
widget_ = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
params.bounds = gfx::Rect(0, 0, 100, 100);
widget_->Init(params);
View* container = new View();
widget_->SetContentsView(container);
container->AddChildView(scrollbar_);
scrollbar_->SetBounds(0, 0, 100, 100);
scrollbar_->Update(100, 200, 0);
track_size_ = scrollbar_->GetTrackBounds().width();
}
protected:
Widget* widget_;
// This is the native scrollbar the Views one wraps around.
NativeScrollBar* native_scrollbar_;
// This is the Views scrollbar.
BaseScrollBar* scrollbar_;
// Keep track of the size of the track. This is how we can tell when we
// scroll to the middle.
int track_size_;
scoped_ptr<TestScrollBarController> controller_;
};
// TODO(dnicoara) Can't run the test on Windows since the scrollbar |Part|
// isn't handled in NativeTheme.
#if defined(OS_WIN)
TEST_F(NativeScrollBarTest, DISABLED_Scrolling) {
#else
TEST_F(NativeScrollBarTest, Scrolling) {
#endif
InitScrollBar();
EXPECT_EQ(scrollbar_->GetPosition(), 0);
EXPECT_EQ(scrollbar_->GetMaxPosition(), 100);
EXPECT_EQ(scrollbar_->GetMinPosition(), 0);
// Scroll to middle.
scrollbar_->ScrollToThumbPosition(track_size_ / 4, false);
EXPECT_EQ(controller_->last_position, 50);
EXPECT_EQ(controller_->last_source, native_scrollbar_);
// Scroll to the end.
scrollbar_->ScrollToThumbPosition(track_size_ / 2, false);
EXPECT_EQ(controller_->last_position, 100);
// Overscroll. Last position should be the maximum position.
scrollbar_->ScrollToThumbPosition(track_size_, false);
EXPECT_EQ(controller_->last_position, 100);
// Underscroll. Last position should be the minimum position.
scrollbar_->ScrollToThumbPosition(-10, false);
EXPECT_EQ(controller_->last_position, 0);
// Test the different fixed scrolling amounts. Generally used by buttons,
// or click on track.
scrollbar_->ScrollToThumbPosition(0, false);
scrollbar_->ScrollByAmount(BaseScrollBar::SCROLL_NEXT_LINE);
EXPECT_EQ(controller_->last_position, 10);
scrollbar_->ScrollByAmount(BaseScrollBar::SCROLL_PREV_LINE);
EXPECT_EQ(controller_->last_position, 0);
scrollbar_->ScrollByAmount(BaseScrollBar::SCROLL_NEXT_PAGE);
EXPECT_EQ(controller_->last_position, 20);
scrollbar_->ScrollByAmount(BaseScrollBar::SCROLL_PREV_PAGE);
EXPECT_EQ(controller_->last_position, 0);
}
} // namespace views
......@@ -173,18 +173,10 @@
'controls/resize_area.h',
'controls/scroll_view.cc',
'controls/scroll_view.h',
'controls/scrollbar/base_scroll_bar.cc',
'controls/scrollbar/base_scroll_bar.h',
'controls/scrollbar/base_scroll_bar_button.cc',
'controls/scrollbar/base_scroll_bar_button.h',
'controls/scrollbar/base_scroll_bar_thumb.cc',
'controls/scrollbar/base_scroll_bar_thumb.h',
'controls/scrollbar/bitmap_scroll_bar.cc',
'controls/scrollbar/bitmap_scroll_bar.h',
'controls/scrollbar/native_scroll_bar_gtk.cc',
'controls/scrollbar/native_scroll_bar_gtk.h',
'controls/scrollbar/native_scroll_bar_views.cc',
'controls/scrollbar/native_scroll_bar_views.h',
'controls/scrollbar/native_scroll_bar_wayland.cc',
'controls/scrollbar/native_scroll_bar_win.cc',
'controls/scrollbar/native_scroll_bar_win.h',
......@@ -538,7 +530,6 @@
'controls/menu/menu_model_adapter_unittest.cc',
'controls/textfield/native_textfield_views_unittest.cc',
'controls/textfield/textfield_views_model_unittest.cc',
'controls/scrollbar/scrollbar_unittest.cc',
'events/event_unittest.cc',
'focus/accelerator_handler_gtk_unittest.cc',
'focus/focus_manager_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment