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_VIEWS_FRAME_CONTENTS_CONTAINER_H_ 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_CONTENTS_CONTAINER_H_ 7 #pragma once 8 9 #include "base/memory/scoped_ptr.h" 10 #include "ui/base/animation/animation_delegate.h" 11 #include "views/view.h" 12 13 class TabContents; 14 15 namespace ui { 16 class SlideAnimation; 17 } 18 19 namespace views { 20 class Widget; 21 } 22 23 // ContentsContainer is responsible for managing the TabContents views. 24 // ContentsContainer has up to two children: one for the currently active 25 // TabContents and one for instant's TabContents. 26 class ContentsContainer : public views::View, public ui::AnimationDelegate { 27 public: 28 explicit ContentsContainer(views::View* active); 29 virtual ~ContentsContainer(); 30 31 // Makes the preview view the active view and nulls out the old active view. 32 // It's assumed the caller will delete or remove the old active view 33 // separately. 34 void MakePreviewContentsActiveContents(); 35 36 // Sets the preview view. This does not delete the old. 37 void SetPreview(views::View* preview, TabContents* preview_tab_contents); 38 39 TabContents* preview_tab_contents() const { return preview_tab_contents_; } 40 41 // Sets the active top margin. 42 void SetActiveTopMargin(int margin); 43 44 // Returns the bounds of the preview. If the preview isn't active this 45 // retuns the bounds the preview would be shown at. 46 gfx::Rect GetPreviewBounds(); 47 48 // Fades out the active contents. 49 void FadeActiveContents(); 50 51 // Shows the fade. This is similiar to |FadeActiveContents|, but is immediate. 52 void ShowFade(); 53 54 // Removes the fade. This is done implicitly when the preview is made active. 55 void RemoveFade(); 56 57 // View overrides: 58 virtual void Layout(); 59 60 // ui::AnimationDelegate overrides: 61 virtual void AnimationProgressed(const ui::Animation* animation); 62 63 private: 64 class OverlayContentView; 65 66 // Creates the overlay widget. The opacity is set at |initial_opacity|. 67 void CreateOverlay(int initial_opacity); 68 69 // Invoked when the contents view of the overlay is destroyed. 70 void OverlayViewDestroyed(); 71 72 views::View* active_; 73 74 views::View* preview_; 75 76 TabContents* preview_tab_contents_; 77 78 // Translucent Widget positioned right above the active view that is used to 79 // make the active view appear faded out. 80 views::Widget* active_overlay_; 81 82 // Content view of active_overlay. Used to track when the widget is destroyed. 83 OverlayContentView* overlay_view_; 84 85 // Animation used to vary the opacity of active_overlay. 86 scoped_ptr<ui::SlideAnimation> overlay_animation_; 87 88 // The margin between the top and the active view. This is used to make the 89 // preview overlap the bookmark bar on the new tab page. 90 int active_top_margin_; 91 92 DISALLOW_COPY_AND_ASSIGN(ContentsContainer); 93 }; 94 95 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_CONTENTS_CONTAINER_H_ 96