Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / location_bar / content_setting_decoration.h
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_COCOA_LOCATION_BAR_CONTENT_SETTING_DECORATION_H_
6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_CONTENT_SETTING_DECORATION_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #import "chrome/browser/ui/cocoa/location_bar/image_decoration.h"
10 #include "components/content_settings/core/common/content_settings_types.h"
11
12 // ContentSettingDecoration is used to display the content settings
13 // images on the current page.
14
15 @class ContentSettingAnimationState;
16 class ContentSettingImageModel;
17 class LocationBarViewMac;
18 class Profile;
19
20 namespace content {
21 class WebContents;
22 }
23
24 class ContentSettingDecoration : public ImageDecoration {
25  public:
26   ContentSettingDecoration(ContentSettingsType settings_type,
27                            LocationBarViewMac* owner,
28                            Profile* profile);
29   virtual ~ContentSettingDecoration();
30
31   // Updates the image and visibility state based on the supplied WebContents.
32   // Returns true if the decoration's visible state changed.
33   bool UpdateFromWebContents(content::WebContents* web_contents);
34
35   // Overridden from |LocationBarDecoration|
36   virtual bool AcceptsMousePress() OVERRIDE;
37   virtual bool OnMousePressed(NSRect frame, NSPoint location) OVERRIDE;
38   virtual NSString* GetToolTip() OVERRIDE;
39   virtual CGFloat GetWidthForSpace(CGFloat width) OVERRIDE;
40   virtual void DrawInFrame(NSRect frame, NSView* control_view) OVERRIDE;
41   virtual NSPoint GetBubblePointInFrame(NSRect frame) OVERRIDE;
42
43   // Called from internal animator. Only public because ObjC objects can't
44   // be friends.
45   virtual void AnimationTimerFired();
46
47  private:
48
49   void SetToolTip(NSString* tooltip);
50
51   // Returns an attributed string with the animated text.
52   base::scoped_nsobject<NSAttributedString> CreateAnimatedText();
53
54   // Measure the width of the animated text.
55   CGFloat MeasureTextWidth();
56
57   scoped_ptr<ContentSettingImageModel> content_setting_image_model_;
58
59   LocationBarViewMac* owner_;  // weak
60   Profile* profile_;  // weak
61
62   base::scoped_nsobject<NSString> tooltip_;
63
64   // Used when the decoration has animated text.
65   base::scoped_nsobject<ContentSettingAnimationState> animation_;
66   CGFloat text_width_;
67   base::scoped_nsobject<NSAttributedString> animated_text_;
68
69   DISALLOW_COPY_AND_ASSIGN(ContentSettingDecoration);
70 };
71
72 #endif  // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_CONTENT_SETTING_DECORATION_H_