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 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 32 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); 39 40 const SkPath& fill_path() const { return fill_path_; } 41 const SkPath& stroke_path() const { return stroke_path_; } 42 43 protected: 44 static const int kButtonButtonSpacing; 45 static const int kEndOfLabelSpacing; 46 47 virtual ~InfoBarView(); 48 49 // Creates a label with the appropriate font and color for an infobar. 50 views::Label* CreateLabel(const base::string16& text) const; 51 52 // Creates a link with the appropriate font and color for an infobar. 53 // NOTE: Subclasses must ignore link clicks if we're unowned. 54 views::Link* CreateLink(const base::string16& text, 55 views::LinkListener* listener) const; 56 57 // Creates a menu button with an infobar-specific appearance. 58 // NOTE: Subclasses must ignore button presses if we're unowned. 59 static views::MenuButton* CreateMenuButton( 60 const base::string16& text, 61 views::MenuButtonListener* menu_button_listener); 62 63 // Creates a button with an infobar-specific appearance. 64 // NOTE: Subclasses must ignore button presses if we're unowned. 65 static views::LabelButton* CreateLabelButton(views::ButtonListener* listener, 66 const base::string16& text, 67 bool needs_elevation); 68 69 // views::View: 70 virtual void Layout() OVERRIDE; 71 virtual void ViewHierarchyChanged( 72 const ViewHierarchyChangedDetails& details) OVERRIDE; 73 74 // views::ButtonListener: 75 // NOTE: This must not be called if we're unowned. (Subclasses should ignore 76 // calls to ButtonPressed() in this case.) 77 virtual void ButtonPressed(views::Button* sender, 78 const ui::Event& event) OVERRIDE; 79 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; 84 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; 89 90 // Given a control with size |prefsize|, returns the centered y position 91 // within us, taking into account animation so the control "slides in" (or 92 // out) as we animate open and closed. 93 int OffsetY(const gfx::Size& prefsize) const; 94 95 // Convenience getter. 96 const InfoBarContainer::Delegate* container_delegate() const; 97 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::MenuItemView::AnchorPosition anchor); 104 105 private: 106 static const int kHorizontalPadding; 107 static const int kCloseButtonSpacing; 108 109 // InfoBar: 110 virtual void PlatformSpecificShow(bool animate) OVERRIDE; 111 virtual void PlatformSpecificHide(bool animate) OVERRIDE; 112 virtual void PlatformSpecificOnHeightsRecalculated() OVERRIDE; 113 114 // views::View: 115 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 116 virtual gfx::Size GetPreferredSize() OVERRIDE; 117 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; 118 119 // views::ExternalFocusTracker: 120 virtual void OnWillChangeFocus(View* focused_before, 121 View* focused_now) OVERRIDE; 122 123 // The optional icon at the left edge of the InfoBar. 124 views::ImageView* icon_; 125 126 // The close button at the right edge of the InfoBar. 127 views::ImageButton* close_button_; 128 129 // The paths for the InfoBarBackground to draw, sized according to the heights 130 // above. 131 SkPath fill_path_; 132 SkPath stroke_path_; 133 134 // Used to run the menu. 135 scoped_ptr<views::MenuRunner> menu_runner_; 136 137 DISALLOW_COPY_AND_ASSIGN(InfoBarView); 138 }; 139 140 #endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ 141