NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / views / infobars / infobar_view.h
blob3db74352ad8c2f3407162efa8b9987dd24998016
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"
17 namespace ui {
18 class MenuModel;
21 namespace views {
22 class ImageButton;
23 class ImageView;
24 class Label;
25 class LabelButton;
26 class Link;
27 class LinkListener;
28 class MenuButton;
29 class MenuButtonListener;
30 class MenuRunner;
31 } // namespace views
33 class InfoBarView : public InfoBar,
34 public views::View,
35 public views::ButtonListener,
36 public views::ExternalFocusTracker {
37 public:
38 explicit InfoBarView(scoped_ptr<InfoBarDelegate> delegate);
40 const SkPath& fill_path() const { return fill_path_; }
41 const SkPath& stroke_path() const { return stroke_path_; }
43 protected:
44 typedef std::vector<views::Label*> Labels;
46 static const int kButtonButtonSpacing;
47 static const int kEndOfLabelSpacing;
49 virtual ~InfoBarView();
51 // Creates a label with the appropriate font and color for an infobar.
52 views::Label* CreateLabel(const base::string16& text) const;
54 // Creates a link with the appropriate font and color for an infobar.
55 // NOTE: Subclasses must ignore link clicks if we're unowned.
56 views::Link* CreateLink(const base::string16& text,
57 views::LinkListener* listener) const;
59 // Creates a menu button with an infobar-specific appearance.
60 // NOTE: Subclasses must ignore button presses if we're unowned.
61 static views::MenuButton* CreateMenuButton(
62 const base::string16& text,
63 views::MenuButtonListener* menu_button_listener);
65 // Creates a button with an infobar-specific appearance.
66 // NOTE: Subclasses must ignore button presses if we're unowned.
67 static views::LabelButton* CreateLabelButton(views::ButtonListener* listener,
68 const base::string16& text,
69 bool needs_elevation);
71 // Given |labels| and the total |available_width| to display them in, sets
72 // each label's size so that the longest label shrinks until it reaches the
73 // length of the next-longest label, then both shrink until reaching the
74 // length of the next-longest, and so forth.
75 static void AssignWidths(Labels* labels, int available_width);
77 // views::View:
78 virtual void Layout() OVERRIDE;
79 virtual void ViewHierarchyChanged(
80 const ViewHierarchyChangedDetails& details) OVERRIDE;
82 // views::ButtonListener:
83 // NOTE: This must not be called if we're unowned. (Subclasses should ignore
84 // calls to ButtonPressed() in this case.)
85 virtual void ButtonPressed(views::Button* sender,
86 const ui::Event& event) OVERRIDE;
88 // Returns the minimum width the content (that is, everything between the icon
89 // and the close button) can be shrunk to. This is used to prevent the close
90 // button from overlapping views that cannot be shrunk any further.
91 virtual int ContentMinimumWidth();
93 // These return x coordinates delimiting the usable area for subclasses to lay
94 // out their controls.
95 int StartX() const;
96 int EndX() const;
98 // Given a |view|, returns the centered y position within us, taking into
99 // account animation so the control "slides in" (or out) as we animate open
100 // and closed.
101 int OffsetY(views::View* view) const;
103 // Convenience getter.
104 const InfoBarContainer::Delegate* container_delegate() const;
106 // Shows a menu at the specified position.
107 // NOTE: This must not be called if we're unowned. (Subclasses should ignore
108 // calls to RunMenu() in this case.)
109 void RunMenuAt(ui::MenuModel* menu_model,
110 views::MenuButton* button,
111 views::MenuItemView::AnchorPosition anchor);
113 private:
114 static const int kHorizontalPadding;
115 static const int kCloseButtonSpacing;
117 // Does the actual work for AssignWidths(). Assumes |labels| is sorted by
118 // decreasing preferred width.
119 static void AssignWidthsSorted(Labels* labels, int available_width);
121 // InfoBar:
122 virtual void PlatformSpecificShow(bool animate) OVERRIDE;
123 virtual void PlatformSpecificHide(bool animate) OVERRIDE;
124 virtual void PlatformSpecificOnHeightsRecalculated() OVERRIDE;
126 // views::View:
127 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
128 virtual gfx::Size GetPreferredSize() OVERRIDE;
129 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
131 // views::ExternalFocusTracker:
132 virtual void OnWillChangeFocus(View* focused_before,
133 View* focused_now) OVERRIDE;
135 // The optional icon at the left edge of the InfoBar.
136 views::ImageView* icon_;
138 // The close button at the right edge of the InfoBar.
139 views::ImageButton* close_button_;
141 // The paths for the InfoBarBackground to draw, sized according to the heights
142 // above.
143 SkPath fill_path_;
144 SkPath stroke_path_;
146 // Used to run the menu.
147 scoped_ptr<views::MenuRunner> menu_runner_;
149 DISALLOW_COPY_AND_ASSIGN(InfoBarView);
152 #endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_