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_LOCATION_BAR_CONTENT_SETTING_IMAGE_VIEW_H_ 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CONTENT_SETTING_IMAGE_VIEW_H_ 7 8 #include "base/memory/scoped_ptr.h" 9 #include "chrome/common/content_settings_types.h" 10 #include "ui/base/animation/animation_delegate.h" 11 #include "ui/base/animation/slide_animation.h" 12 #include "ui/gfx/font.h" 13 #include "ui/views/painter.h" 14 #include "ui/views/view.h" 15 #include "ui/views/widget/widget_observer.h" 16 17 class ContentSettingImageModel; 18 class LocationBarView; 19 20 namespace content { 21 class WebContents; 22 } 23 24 namespace views { 25 class ImageView; 26 class Label; 27 } 28 29 // The ContentSettingImageView displays an icon and optional text label for 30 // various content settings affordances in the location bar (i.e. plugin 31 // blocking, geolocation). 32 class ContentSettingImageView : public ui::AnimationDelegate, 33 public views::View, 34 public views::WidgetObserver { 35 public: 36 ContentSettingImageView(ContentSettingsType content_type, 37 LocationBarView* parent, 38 const gfx::Font& font, 39 int font_y_offset, 40 SkColor text_color, 41 SkColor parent_background_color); 42 virtual ~ContentSettingImageView(); 43 44 // Update the decoration from the shown WebContents. 45 void Update(content::WebContents* web_contents); 46 47 private: 48 // Number of milliseconds spent animating open; also the time spent animating 49 // closed. 50 static const int kOpenTimeMS; 51 52 // The total animation time, including open and close as well as an 53 // intervening "stay open" period. 54 static const int kAnimationDurationMS; 55 56 // Amount of padding at the edges of the bubble. If |by_icon| is true, this 57 // is the padding next to the icon; otherwise it's the padding next to the 58 // label. (We increase padding next to the label by the amount of padding 59 // "built in" to the icon in order to make the bubble appear to have 60 // symmetrical padding.) 61 static int GetBubbleOuterPadding(bool by_icon); 62 63 // ui::AnimationDelegate: 64 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; 65 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; 66 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE; 67 68 // views::View: 69 virtual gfx::Size GetPreferredSize() OVERRIDE; 70 virtual void Layout() OVERRIDE; 71 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; 72 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; 73 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 74 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; 75 76 // views::WidgetObserver: 77 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 78 79 bool background_showing() const { 80 return slide_animator_.is_animating() || pause_animation_; 81 } 82 83 int GetTotalSpacingWhileAnimating() const; 84 void OnClick(); 85 86 LocationBarView* parent_; // Weak, owns us. 87 scoped_ptr<ContentSettingImageModel> content_setting_image_model_; 88 scoped_ptr<views::Painter> background_painter_; 89 views::ImageView* icon_; 90 views::Label* text_label_; 91 ui::SlideAnimation slide_animator_; 92 bool pause_animation_; 93 double pause_animation_state_; 94 views::Widget* bubble_widget_; 95 96 DISALLOW_COPY_AND_ASSIGN(ContentSettingImageView); 97 }; 98 99 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CONTENT_SETTING_IMAGE_VIEW_H_ 100