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