Home | History | Annotate | Download | only in views
      1 // Copyright 2013 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_MESSAGE_CENTER_VIEWS_PADDED_BUTTON_H_
      6 #define UI_MESSAGE_CENTER_VIEWS_PADDED_BUTTON_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "ui/views/controls/button/image_button.h"
     11 
     12 namespace message_center {
     13 
     14 // PaddedButtons are ImageButtons whose image can be padded within the button.
     15 // This allows the creation of buttons like the notification close and expand
     16 // buttons whose clickable areas extends beyond their image areas
     17 // (<http://crbug.com/168822>) without the need to create and maintain
     18 // corresponding resource images with alpha padding. In the future, this class
     19 // will also allow for buttons whose touch areas extend beyond their clickable
     20 // area (<http://crbug.com/168856>).
     21 class PaddedButton : public views::ImageButton {
     22  public:
     23   PaddedButton(views::ButtonListener* listener);
     24   virtual ~PaddedButton();
     25 
     26   // Overridden from views::ImageButton:
     27   virtual gfx::Size GetPreferredSize() OVERRIDE;
     28   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     29   virtual void OnFocus() OVERRIDE;
     30 
     31   // The SetPadding() method also sets the button's image alignment (positive
     32   // values yield left/top alignments, negative values yield right/bottom ones,
     33   // and zero values center/middle ones). ImageButton::SetImageAlignment() calls
     34   // will not affect PaddedButton image alignments.
     35   void SetPadding(int horizontal_padding, int vertical_padding);
     36 
     37   void SetNormalImage(int resource_id);
     38   void SetHoveredImage(int resource_id);
     39   void SetPressedImage(int resource_id);
     40 
     41  protected:
     42   gfx::Point ComputePaddedImagePaintPosition(const gfx::ImageSkia& image);
     43 
     44  private:
     45   gfx::Insets padding_;
     46 
     47   DISALLOW_COPY_AND_ASSIGN(PaddedButton);
     48 };
     49 
     50 }  // namespace message_center
     51 
     52 #endif  // UI_MESSAGE_CENTER_VIEWS_PADDED_BUTTON_H_