15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CONTENT_SETTING_IMAGE_VIEW_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CONTENT_SETTING_IMAGE_VIEW_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/content_settings/core/common/content_settings_types.h" 10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/animation/animation_delegate.h" 11d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/animation/slide_animation.h" 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/views/painter.h" 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/views/view.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget_observer.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ContentSettingImageModel; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LocationBarView; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace content { 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class WebContents; 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace gfx { 24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class FontList; 25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 26d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace views { 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class ImageView; 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class Label; 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The ContentSettingImageView displays an icon and optional text label for 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// various content settings affordances in the location bar (i.e. plugin 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// blocking, geolocation). 35d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class ContentSettingImageView : public gfx::AnimationDelegate, 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public views::View, 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public views::WidgetObserver { 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ContentSettingImageView(ContentSettingsType content_type, 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LocationBarView* parent, 41d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const gfx::FontList& font_list, 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SkColor text_color, 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SkColor parent_background_color); 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~ContentSettingImageView(); 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Updates the decoration from the shown WebContents. 47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void Update(content::WebContents* web_contents); 4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private: 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Number of milliseconds spent animating open; also the time spent animating 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // closed. 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) static const int kOpenTimeMS; 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // The total animation time, including open and close as well as an 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // intervening "stay open" period. 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) static const int kAnimationDurationMS; 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Amount of padding at the edges of the bubble. If |by_icon| is true, this 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // is the padding next to the icon; otherwise it's the padding next to the 60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // label. (We increase padding next to the label by the amount of padding 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // "built in" to the icon in order to make the bubble appear to have 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // symmetrical padding.) 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) static int GetBubbleOuterPadding(bool by_icon); 64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 65d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // gfx::AnimationDelegate: 66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; 67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE; 6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // views::View: 71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual gfx::Size GetPreferredSize() const OVERRIDE; 72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual void Layout() OVERRIDE; 7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; 7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; 75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // views::WidgetObserver: 79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool background_showing() const { 82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return slide_animator_.is_animating() || pause_animation_; 83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int GetTotalSpacingWhileAnimating() const; 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void OnClick(); 8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) LocationBarView* parent_; // Weak, owns us. 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<ContentSettingImageModel> content_setting_image_model_; 90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<views::Painter> background_painter_; 91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) views::ImageView* icon_; 92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) views::Label* text_label_; 93d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) gfx::SlideAnimation slide_animator_; 9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool pause_animation_; 9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) double pause_animation_state_; 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::Widget* bubble_widget_; 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ContentSettingImageView); 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CONTENT_SETTING_IMAGE_VIEW_H_ 102