blob: 7434c8f88c0cb6eaeac38e68ea71c977beda8b66 [file] [log] [blame]
// Copyright (c) 2012 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.
#pragma once
#include "ui/base/animation/animation_delegate.h"
#include "ui/views/view.h"
#include "ui/views/views_export.h"
typedef unsigned int SkColor;
namespace ui {
class SlideAnimation;
namespace views {
class Slider;
enum SliderChangeReason {
VALUE_CHANGED_BY_USER, // value was changed by the user (by clicking, e.g.)
VALUE_CHANGED_BY_API, // value was changed by a call to SetValue.
class VIEWS_EXPORT SliderListener {
virtual void SliderValueChanged(Slider* sender,
float value,
float old_value,
SliderChangeReason reason) = 0;
// Invoked when a drag starts or ends (more specifically, when the mouse
// button is pressed or released).
virtual void SliderDragStarted(Slider* sender) {}
virtual void SliderDragEnded(Slider* sender) {}
virtual ~SliderListener() {}
class VIEWS_EXPORT Slider : public View,
public ui::AnimationDelegate {
enum Orientation {
Slider(SliderListener* listener, Orientation orientation);
virtual ~Slider();
float value() const { return value_; }
void SetValue(float value);
// Set the delta used for changing the value via keyboard.
void SetKeyboardIncrement(float increment);
void SetAccessibleName(const string16& name);
void set_focus_border_color(SkColor color) { focus_border_color_ = color; }
void SetValueInternal(float value, SliderChangeReason reason);
// Moves the button to the specified point and updates the value accordingly.
void MoveButtonTo(const gfx::Point& point);
// views::View overrides:
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE;
virtual ui::GestureStatus OnGestureEvent(
const views::GestureEvent& event) OVERRIDE;
virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
// ui::AnimationDelegate overrides:
virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
SliderListener* listener_;
Orientation orientation_;
scoped_ptr<ui::SlideAnimation> move_animation_;
float value_;
float keyboard_increment_;
float animating_value_;
bool value_is_valid_;
string16 accessible_name_;
SkColor focus_border_color_;
} // namespace views