Home | History | Annotate | Download | only in location_bar
      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 CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUTTON_DECORATION_H_
      6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUTTON_DECORATION_H_
      7 
      8 #import "base/mac/scoped_nsobject.h"
      9 #include "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h"
     10 
     11 // |LocationBarDecoration| which looks and acts like a button.
     12 
     13 class ButtonDecoration : public LocationBarDecoration {
     14  public:
     15   enum ButtonState {
     16     kButtonStateNormal,
     17     kButtonStateHover,
     18     kButtonStatePressed
     19   };
     20 
     21   ButtonDecoration();
     22   virtual ~ButtonDecoration();
     23 
     24   void SetButtonState(ButtonState state);
     25   ButtonState GetButtonState() const;
     26 
     27   // To be called when a mouse click occurs within the decoration, which will
     28   // set and reset the button's state as necessary before calling into
     29   // |OnMousePressed| below.
     30   bool OnMousePressedWithView(NSRect frame, NSView* control_view);
     31 
     32   // Implement |LocationBarDecoration|.
     33   virtual CGFloat GetWidthForSpace(CGFloat width) OVERRIDE;
     34   virtual void DrawInFrame(NSRect frame, NSView* control_view) OVERRIDE;
     35   virtual bool OnMousePressed(NSRect frame) OVERRIDE;
     36   virtual ButtonDecoration* AsButtonDecoration() OVERRIDE;
     37 
     38  protected:
     39   // Setters for the images for different states.
     40   void SetNormalImage(NSImage* normal_image);
     41   void SetHoverImage(NSImage* hover_image);
     42   void SetPressedImage(NSImage* pressed_image);
     43 
     44  private:
     45   base::scoped_nsobject<NSImage> normal_image_;
     46   base::scoped_nsobject<NSImage> hover_image_;
     47   base::scoped_nsobject<NSImage> pressed_image_;
     48   ButtonState state_;
     49 
     50   NSImage* GetImage();
     51 
     52   DISALLOW_COPY_AND_ASSIGN(ButtonDecoration);
     53 };
     54 
     55 #endif  // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUTTON_DECORATION_H_
     56