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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_
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"
28 class MenuButtonListener;
32 class InfoBarView : public InfoBar,
34 public views::ButtonListener,
35 public views::ExternalFocusTracker {
37 InfoBarView(InfoBarService* owner, InfoBarDelegate* delegate);
39 const SkPath& fill_path() const { return fill_path_; }
40 const SkPath& stroke_path() const { return stroke_path_; }
43 static const int kButtonButtonSpacing;
44 static const int kEndOfLabelSpacing;
46 virtual ~InfoBarView();
48 // Creates a label with the appropriate font and color for an infobar.
49 views::Label* CreateLabel(const string16& text) const;
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;
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(
60 views::MenuButtonListener* menu_button_listener);
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,
66 bool needs_elevation);
69 virtual void Layout() OVERRIDE;
70 virtual void ViewHierarchyChanged(
71 const ViewHierarchyChangedDetails& details) OVERRIDE;
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;
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;
84 // These return x coordinates delimiting the usable area for subclasses to lay
85 // out their controls.
89 // Convenience getter.
90 const InfoBarContainer::Delegate* container_delegate() const;
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);
100 static const int kHorizontalPadding;
103 virtual void PlatformSpecificShow(bool animate) OVERRIDE;
104 virtual void PlatformSpecificHide(bool animate) OVERRIDE;
105 virtual void PlatformSpecificOnHeightsRecalculated() OVERRIDE;
108 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
109 virtual gfx::Size GetPreferredSize() OVERRIDE;
110 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
112 // views::ExternalFocusTracker:
113 virtual void OnWillChangeFocus(View* focused_before,
114 View* focused_now) OVERRIDE;
116 // The optional icon at the left edge of the InfoBar.
117 views::ImageView* icon_;
119 // The close button at the right edge of the InfoBar.
120 views::ImageButton* close_button_;
122 // The paths for the InfoBarBackground to draw, sized according to the heights
127 // Used to run the menu.
128 scoped_ptr<views::MenuRunner> menu_runner_;
130 DISALLOW_COPY_AND_ASSIGN(InfoBarView);
133 #endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_