1 // Copyright (c) 2011 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 #pragma once 8 9 #include "base/task.h" 10 #include "chrome/browser/ui/views/infobars/infobar.h" 11 #include "chrome/browser/ui/views/infobars/infobar_background.h" 12 #include "chrome/browser/ui/views/infobars/infobar_container.h" 13 #include "views/controls/button/button.h" 14 #include "views/focus/focus_manager.h" 15 16 class SkPath; 17 18 namespace views { 19 class ExternalFocusTracker; 20 class ImageButton; 21 class ImageView; 22 class Label; 23 class Link; 24 class LinkController; 25 class MenuButton; 26 class TextButton; 27 class ViewMenuDelegate; 28 } 29 30 class InfoBarView : public InfoBar, 31 public views::View, 32 public views::ButtonListener, 33 public views::FocusChangeListener { 34 public: 35 explicit InfoBarView(InfoBarDelegate* delegate); 36 37 SkPath* fill_path() const { return fill_path_.get(); } 38 SkPath* stroke_path() const { return stroke_path_.get(); } 39 40 protected: 41 static const int kButtonButtonSpacing; 42 static const int kEndOfLabelSpacing; 43 44 virtual ~InfoBarView(); 45 46 // Creates a label with the appropriate font and color for an infobar. 47 static views::Label* CreateLabel(const string16& text); 48 49 // Creates a link with the appropriate font and color for an infobar. 50 static views::Link* CreateLink(const string16& text, 51 views::LinkController* controller, 52 const SkColor& background_color); 53 54 // Creates a menu button with an infobar-specific appearance. 55 static views::MenuButton* CreateMenuButton( 56 const string16& text, 57 bool normal_has_border, 58 views::ViewMenuDelegate* menu_delegate); 59 60 // Creates a text button with an infobar-specific appearance. 61 static views::TextButton* CreateTextButton(views::ButtonListener* listener, 62 const string16& text, 63 bool needs_elevation); 64 65 // views::View: 66 virtual void Layout() OVERRIDE; 67 virtual void ViewHierarchyChanged(bool is_add, 68 View* parent, 69 View* child) OVERRIDE; 70 71 // views::ButtonListener: 72 virtual void ButtonPressed(views::Button* sender, 73 const views::Event& event) OVERRIDE; 74 75 // Returns the minimum width the content (that is, everything between the icon 76 // and the close button) can be shrunk to. This is used to prevent the close 77 // button from overlapping views that cannot be shrunk any further. 78 virtual int ContentMinimumWidth() const; 79 80 // These return x coordinates delimiting the usable area for subclasses to lay 81 // out their controls. 82 int StartX() const; 83 int EndX() const; 84 85 // Convenience getter. 86 const InfoBarContainer::Delegate* container_delegate() const; 87 88 private: 89 static const int kHorizontalPadding; 90 91 // InfoBar: 92 virtual void PlatformSpecificHide(bool animate) OVERRIDE; 93 virtual void PlatformSpecificOnHeightsRecalculated() OVERRIDE; 94 95 // views::View: 96 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 97 virtual gfx::Size GetPreferredSize() OVERRIDE; 98 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; 99 100 // views::FocusChangeListener: 101 virtual void FocusWillChange(View* focused_before, 102 View* focused_now) OVERRIDE; 103 104 // Destroys the external focus tracker, if present. If |restore_focus| is 105 // true, restores focus to the view tracked by the focus tracker before doing 106 // so. 107 void DestroyFocusTracker(bool restore_focus); 108 109 // Deletes this object (called after a return to the message loop to allow 110 // the stack in ViewHierarchyChanged to unwind). 111 void DeleteSelf(); 112 113 // The optional icon at the left edge of the InfoBar. 114 views::ImageView* icon_; 115 116 // The close button at the right edge of the InfoBar. 117 views::ImageButton* close_button_; 118 119 // Tracks and stores the last focused view which is not the InfoBar or any of 120 // its children. Used to restore focus once the InfoBar is closed. 121 scoped_ptr<views::ExternalFocusTracker> focus_tracker_; 122 123 // Used to delete this object after a return to the message loop. 124 ScopedRunnableMethodFactory<InfoBarView> delete_factory_; 125 126 // The paths for the InfoBarBackground to draw, sized according to the heights 127 // above. 128 scoped_ptr<SkPath> fill_path_; 129 scoped_ptr<SkPath> stroke_path_; 130 131 DISALLOW_COPY_AND_ASSIGN(InfoBarView); 132 }; 133 134 #endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ 135