Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / infobars / infobar_view.h
blob39085f2536d14a1ae52087ceb4eebd995189d07f
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 "components/infobars/core/infobar.h"
11 #include "components/infobars/core/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_types.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 MenuRunner;
30 } // namespace views
32 class InfoBarView : public infobars::InfoBar,
33 public views::View,
34 public views::ButtonListener,
35 public views::ExternalFocusTracker {
36 public:
37 explicit InfoBarView(scoped_ptr<infobars::InfoBarDelegate> delegate);
39 const SkPath& fill_path() const { return fill_path_; }
40 const SkPath& stroke_path() const { return stroke_path_; }
42 protected:
43 typedef std::vector<views::Label*> Labels;
45 static const int kButtonButtonSpacing;
46 static const int kEndOfLabelSpacing;
48 ~InfoBarView() override;
50 // Creates a label with the appropriate font and color for an infobar.
51 views::Label* CreateLabel(const base::string16& text) const;
53 // Creates a link with the appropriate font and color for an infobar.
54 // NOTE: Subclasses must ignore link clicks if we're unowned.
55 views::Link* CreateLink(const base::string16& text,
56 views::LinkListener* listener) const;
58 // Creates a focusable button for use on an infobar. The appearance is
59 // customized for infobars (except in Material mode).
60 // NOTE: Subclasses must ignore button presses if we're unowned.
61 static views::LabelButton* CreateLabelButton(views::ButtonListener* listener,
62 const base::string16& text);
64 // Given |labels| and the total |available_width| to display them in, sets
65 // each label's size so that the longest label shrinks until it reaches the
66 // length of the next-longest label, then both shrink until reaching the
67 // length of the next-longest, and so forth.
68 static void AssignWidths(Labels* labels, int available_width);
70 // views::View:
71 void Layout() override;
72 void ViewHierarchyChanged(
73 const ViewHierarchyChangedDetails& details) override;
75 // views::ButtonListener:
76 // NOTE: This must not be called if we're unowned. (Subclasses should ignore
77 // calls to ButtonPressed() in this case.)
78 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
80 // Returns the minimum width the content (that is, everything between the icon
81 // and the close button) can be shrunk to. This is used to prevent the close
82 // button from overlapping views that cannot be shrunk any further.
83 virtual int ContentMinimumWidth() const;
85 // These return x coordinates delimiting the usable area for subclasses to lay
86 // out their controls.
87 int StartX() const;
88 int EndX() const;
90 // Given a |view|, returns the centered y position within us, taking into
91 // account animation so the control "slides in" (or out) as we animate open
92 // and closed.
93 int OffsetY(views::View* view) const;
95 // Convenience getter.
96 const infobars::InfoBarContainer::Delegate* container_delegate() const;
98 // Shows a menu at the specified position.
99 // NOTE: This must not be called if we're unowned. (Subclasses should ignore
100 // calls to RunMenu() in this case.)
101 void RunMenuAt(ui::MenuModel* menu_model,
102 views::MenuButton* button,
103 views::MenuAnchorPosition anchor);
105 private:
106 // Does the actual work for AssignWidths(). Assumes |labels| is sorted by
107 // decreasing preferred width.
108 static void AssignWidthsSorted(Labels* labels, int available_width);
110 // InfoBar:
111 void PlatformSpecificShow(bool animate) override;
112 void PlatformSpecificHide(bool animate) override;
113 void PlatformSpecificOnHeightsRecalculated() override;
115 // views::View:
116 void GetAccessibleState(ui::AXViewState* state) override;
117 gfx::Size GetPreferredSize() const override;
118 void PaintChildren(const ui::PaintContext& context) override;
120 // views::ExternalFocusTracker:
121 void OnWillChangeFocus(View* focused_before, View* focused_now) override;
123 // The optional icon at the left edge of the InfoBar.
124 views::ImageView* icon_;
126 // The close button at the right edge of the InfoBar.
127 views::ImageButton* close_button_;
129 // The paths for the InfoBarBackground to draw, sized according to the heights
130 // above.
131 SkPath fill_path_;
132 SkPath stroke_path_;
134 // Used to run the menu.
135 scoped_ptr<views::MenuRunner> menu_runner_;
137 DISALLOW_COPY_AND_ASSIGN(InfoBarView);
140 #endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_