Home | History | Annotate | Download | only in scrollbar
      1 // Copyright (c) 2012 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 #ifndef UI_VIEWS_CONTROLS_SCROLLBAR_BITMAP_SCROLL_BAR_H_
      6 #define UI_VIEWS_CONTROLS_SCROLLBAR_BITMAP_SCROLL_BAR_H_
      7 
      8 #include "ui/views/controls/scrollbar/base_scroll_bar.h"
      9 
     10 namespace views {
     11 
     12 namespace {
     13 class BitmapScrollBarThumb;
     14 }
     15 
     16 ///////////////////////////////////////////////////////////////////////////////
     17 //
     18 // BitmapScrollBar
     19 //
     20 //  A ScrollBar subclass that implements a scroll bar rendered using images
     21 //  that the user provides. There are images for the up and down buttons, as
     22 //  well as for the thumb and track. This is intended for creating UIs that
     23 //  have customized, non-native appearances, like floating HUDs etc.
     24 //
     25 ///////////////////////////////////////////////////////////////////////////////
     26 class VIEWS_EXPORT BitmapScrollBar : public BaseScrollBar,
     27                                      public ButtonListener {
     28  public:
     29   BitmapScrollBar(bool horizontal, bool show_scroll_buttons);
     30   virtual ~BitmapScrollBar() { }
     31 
     32   // A list of parts that the user may supply images for.
     33   enum ScrollBarPart {
     34     // The button used to represent scrolling up/left by 1 line.
     35     PREV_BUTTON = 0,
     36     // The button used to represent scrolling down/right by 1 line.
     37     // IMPORTANT: The code assumes the prev and next
     38     // buttons have equal width and equal height.
     39     NEXT_BUTTON,
     40     // The top/left segment of the thumb on the scrollbar.
     41     THUMB_START_CAP,
     42     // The tiled background image of the thumb.
     43     THUMB_MIDDLE,
     44     // The bottom/right segment of the thumb on the scrollbar.
     45     THUMB_END_CAP,
     46     // The grippy that is rendered in the center of the thumb.
     47     THUMB_GRIPPY,
     48     // The tiled background image of the thumb track.
     49     THUMB_TRACK,
     50     PART_COUNT
     51   };
     52 
     53   // Sets the image to be rendered for the specified part and state.
     54   void SetImage(ScrollBarPart part,
     55                 CustomButton::ButtonState state,
     56                 gfx::ImageSkia* image_skia);
     57 
     58 
     59   gfx::Rect GetTrackBounds() const;
     60 
     61  protected:
     62   // View overrides:
     63   virtual gfx::Size GetPreferredSize() OVERRIDE;
     64   virtual void Layout() OVERRIDE;
     65   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     66 
     67   // ScrollBar overrides:
     68   virtual int GetLayoutSize() const OVERRIDE;
     69 
     70   // BaseButton::ButtonListener overrides:
     71   virtual void ButtonPressed(Button* sender,
     72                              const ui::Event& event) OVERRIDE;
     73 
     74  private:
     75   // Up/Down/Left/Right buttons.
     76   ImageButton* prev_button_;
     77   ImageButton* next_button_;
     78 
     79   // The thumb needs to be able to access the part images.
     80   friend BitmapScrollBarThumb;
     81   gfx::ImageSkia* images_[PART_COUNT][CustomButton::STATE_COUNT];
     82 
     83   // True if the scroll buttons at each end of the scroll bar should be shown.
     84   bool show_scroll_buttons_;
     85 
     86   DISALLOW_COPY_AND_ASSIGN(BitmapScrollBar);
     87 };
     88 
     89 }  // namespace views
     90 
     91 #endif  // UI_VIEWS_CONTROLS_SCROLLBAR_BITMAP_SCROLL_BAR_H_
     92