content_setting_image_view.h revision 58537e28ecd584eab876aee8be7156509866d23a
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 17class ContentSettingImageModel; 18class LocationBarView; 19 20namespace content { 21class WebContents; 22} 23 24namespace views { 25class ImageView; 26class 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). 32class 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 // Updates the decoration from the shown WebContents. 45 void UpdatePreLayout(content::WebContents* web_contents); 46 47 // Performs any updates which depend on the image having already been laid out 48 // by the owning LocationBarView. 49 void UpdatePostLayout(content::WebContents* web_contents); 50 51 private: 52 // Number of milliseconds spent animating open; also the time spent animating 53 // closed. 54 static const int kOpenTimeMS; 55 56 // The total animation time, including open and close as well as an 57 // intervening "stay open" period. 58 static const int kAnimationDurationMS; 59 60 // Amount of padding at the edges of the bubble. If |by_icon| is true, this 61 // is the padding next to the icon; otherwise it's the padding next to the 62 // label. (We increase padding next to the label by the amount of padding 63 // "built in" to the icon in order to make the bubble appear to have 64 // symmetrical padding.) 65 static int GetBubbleOuterPadding(bool by_icon); 66 67 // ui::AnimationDelegate: 68 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; 69 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; 70 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE; 71 72 // views::View: 73 virtual gfx::Size GetPreferredSize() OVERRIDE; 74 virtual void Layout() OVERRIDE; 75 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; 76 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; 77 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 78 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; 79 80 // views::WidgetObserver: 81 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 82 83 bool background_showing() const { 84 return slide_animator_.is_animating() || pause_animation_; 85 } 86 87 int GetTotalSpacingWhileAnimating() const; 88 void OnClick(); 89 void CreateBubble(content::WebContents* web_contents); 90 91 LocationBarView* parent_; // Weak, owns us. 92 scoped_ptr<ContentSettingImageModel> content_setting_image_model_; 93 scoped_ptr<views::Painter> background_painter_; 94 views::ImageView* icon_; 95 views::Label* text_label_; 96 ui::SlideAnimation slide_animator_; 97 bool pause_animation_; 98 double pause_animation_state_; 99 views::Widget* bubble_widget_; 100 101 DISALLOW_COPY_AND_ASSIGN(ContentSettingImageView); 102}; 103 104#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CONTENT_SETTING_IMAGE_VIEW_H_ 105