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 #pragma once 8 9 #include "base/memory/scoped_ptr.h" 10 #import "chrome/browser/ui/cocoa/location_bar/image_decoration.h" 11 #include "chrome/common/content_settings_types.h" 12 13 // ContentSettingDecoration is used to display the content settings 14 // images on the current page. 15 16 @class ContentSettingAnimationState; 17 class ContentSettingImageModel; 18 class LocationBarViewMac; 19 class Profile; 20 class TabContents; 21 22 class ContentSettingDecoration : public ImageDecoration { 23 public: 24 ContentSettingDecoration(ContentSettingsType settings_type, 25 LocationBarViewMac* owner, 26 Profile* profile); 27 virtual ~ContentSettingDecoration(); 28 29 // Updates the image and visibility state based on the supplied TabContents. 30 // Returns true if the decoration's visible state changed. 31 bool UpdateFromTabContents(TabContents* tab_contents); 32 33 // Overridden from |LocationBarDecoration| 34 virtual bool AcceptsMousePress(); 35 virtual bool OnMousePressed(NSRect frame); 36 virtual NSString* GetToolTip(); 37 virtual CGFloat GetWidthForSpace(CGFloat width); 38 virtual void DrawInFrame(NSRect frame, NSView* control_view); 39 40 // Called from internal animator. Only public because ObjC objects can't 41 // be friends. 42 virtual void AnimationTimerFired(); 43 44 private: 45 // Helper to get where the bubble point should land. Similar to 46 // |PageActionDecoration| or |StarDecoration| (|LocationBarViewMac| 47 // calls those). 48 NSPoint GetBubblePointInFrame(NSRect frame); 49 50 void SetToolTip(NSString* tooltip); 51 52 // Returns an attributed string with the animated text. Caller is responsible 53 // for releasing. 54 NSAttributedString* CreateAnimatedText(); 55 56 // Measure the width of the animated text. 57 CGFloat MeasureTextWidth(); 58 59 scoped_ptr<ContentSettingImageModel> content_setting_image_model_; 60 61 LocationBarViewMac* owner_; // weak 62 Profile* profile_; // weak 63 64 scoped_nsobject<NSString> tooltip_; 65 66 // Used when the decoration has animated text. 67 scoped_nsobject<ContentSettingAnimationState> animation_; 68 CGFloat text_width_; 69 scoped_nsobject<NSAttributedString> animated_text_; 70 scoped_nsobject<NSGradient> gradient_; 71 72 DISALLOW_COPY_AND_ASSIGN(ContentSettingDecoration); 73 }; 74 75 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_CONTENT_SETTING_DECORATION_H_ 76