Home | History | Annotate | Download | only in infobars
      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_VIEWS_INFOBARS_INFOBAR_VIEW_H_
      6 #define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "chrome/browser/infobars/infobar.h"
     11 #include "chrome/browser/infobars/infobar_container.h"
     12 #include "third_party/skia/include/core/SkPath.h"
     13 #include "ui/views/controls/button/button.h"
     14 #include "ui/views/controls/menu/menu_item_view.h"
     15 #include "ui/views/focus/external_focus_tracker.h"
     16 
     17 namespace ui {
     18 class MenuModel;
     19 }
     20 namespace views {
     21 class ImageButton;
     22 class ImageView;
     23 class Label;
     24 class LabelButton;
     25 class Link;
     26 class LinkListener;
     27 class MenuButton;
     28 class MenuButtonListener;
     29 class MenuRunner;
     30 }
     31 
     32 class InfoBarView : public InfoBar,
     33                     public views::View,
     34                     public views::ButtonListener,
     35                     public views::ExternalFocusTracker {
     36  public:
     37   InfoBarView(InfoBarService* owner, InfoBarDelegate* delegate);
     38 
     39   const SkPath& fill_path() const { return fill_path_; }
     40   const SkPath& stroke_path() const { return stroke_path_; }
     41 
     42  protected:
     43   static const int kButtonButtonSpacing;
     44   static const int kEndOfLabelSpacing;
     45 
     46   virtual ~InfoBarView();
     47 
     48   // Creates a label with the appropriate font and color for an infobar.
     49   views::Label* CreateLabel(const string16& text) const;
     50 
     51   // Creates a link with the appropriate font and color for an infobar.
     52   // NOTE: Subclasses must ignore link clicks if we're unowned.
     53   views::Link* CreateLink(const string16& text,
     54                           views::LinkListener* listener) const;
     55 
     56   // Creates a menu button with an infobar-specific appearance.
     57   // NOTE: Subclasses must ignore button presses if we're unowned.
     58   static views::MenuButton* CreateMenuButton(
     59       const string16& text,
     60       views::MenuButtonListener* menu_button_listener);
     61 
     62   // Creates a button with an infobar-specific appearance.
     63   // NOTE: Subclasses must ignore button presses if we're unowned.
     64   static views::LabelButton* CreateLabelButton(views::ButtonListener* listener,
     65                                                const string16& text,
     66                                                bool needs_elevation);
     67 
     68   // views::View:
     69   virtual void Layout() OVERRIDE;
     70   virtual void ViewHierarchyChanged(
     71       const ViewHierarchyChangedDetails& details) OVERRIDE;
     72 
     73   // views::ButtonListener:
     74   // NOTE: This must not be called if we're unowned.  (Subclasses should ignore
     75   // calls to ButtonPressed() in this case.)
     76   virtual void ButtonPressed(views::Button* sender,
     77                              const ui::Event& event) OVERRIDE;
     78 
     79   // Returns the minimum width the content (that is, everything between the icon
     80   // and the close button) can be shrunk to.  This is used to prevent the close
     81   // button from overlapping views that cannot be shrunk any further.
     82   virtual int ContentMinimumWidth() const;
     83 
     84   // These return x coordinates delimiting the usable area for subclasses to lay
     85   // out their controls.
     86   int StartX() const;
     87   int EndX() const;
     88 
     89   // Convenience getter.
     90   const InfoBarContainer::Delegate* container_delegate() const;
     91 
     92   // Shows a menu at the specified position.
     93   // NOTE: This must not be called if we're unowned.  (Subclasses should ignore
     94   // calls to RunMenu() in this case.)
     95   void RunMenuAt(ui::MenuModel* menu_model,
     96                  views::MenuButton* button,
     97                  views::MenuItemView::AnchorPosition anchor);
     98 
     99  private:
    100   static const int kHorizontalPadding;
    101 
    102   // InfoBar:
    103   virtual void PlatformSpecificShow(bool animate) OVERRIDE;
    104   virtual void PlatformSpecificHide(bool animate) OVERRIDE;
    105   virtual void PlatformSpecificOnHeightsRecalculated() OVERRIDE;
    106 
    107   // views::View:
    108   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
    109   virtual gfx::Size GetPreferredSize() OVERRIDE;
    110   virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
    111 
    112   // views::ExternalFocusTracker:
    113   virtual void OnWillChangeFocus(View* focused_before,
    114                                  View* focused_now) OVERRIDE;
    115 
    116   // The optional icon at the left edge of the InfoBar.
    117   views::ImageView* icon_;
    118 
    119   // The close button at the right edge of the InfoBar.
    120   views::ImageButton* close_button_;
    121 
    122   // The paths for the InfoBarBackground to draw, sized according to the heights
    123   // above.
    124   SkPath fill_path_;
    125   SkPath stroke_path_;
    126 
    127   // Used to run the menu.
    128   scoped_ptr<views::MenuRunner> menu_runner_;
    129 
    130   DISALLOW_COPY_AND_ASSIGN(InfoBarView);
    131 };
    132 
    133 #endif  // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_
    134