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