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_FRAME_INFOBARS_INTERNAL_INFOBAR_WINDOW_H_ 6 #define CHROME_FRAME_INFOBARS_INTERNAL_INFOBAR_WINDOW_H_ 7 8 #include "base/basictypes.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "base/time/time.h" 11 12 #include "chrome_frame/infobars/infobar_content.h" 13 #include "chrome_frame/infobars/infobar_manager.h" 14 15 struct FunctionStub; 16 17 // Manages the display of an InfobarContent instance within a container window. 18 // Positions the infobar content by displacing other "natural" content of the 19 // window (see ReserveSpace). Allows positioning either above or below the 20 // natural content. 21 class InfobarWindow { 22 public: 23 // Integrates the InfobarWindow with its environment. 24 class Host { 25 public: ~Host()26 virtual ~Host() {} 27 28 // Returns a handle to the window within which infobar content should be 29 // created. All windows associated with the infobar content should be 30 // descendants of the container window. 31 virtual HWND GetContainerWindow() = 0; 32 33 // Triggers an immediate re-evaluation of the dimensions of the displaced 34 // content. InfobarWindow::ReserveSpace will be called with the natural 35 // dimensions of the displaced content. 36 virtual void UpdateLayout() = 0; 37 }; // class Host 38 39 explicit InfobarWindow(InfobarType type); 40 ~InfobarWindow(); 41 42 void SetHost(Host* host); 43 44 // Shows the supplied content in this InfobarWindow. Normally, 45 // InfobarContent::InstallInFrame will be called with an InfobarContent::Frame 46 // instance the content may use to interact with the InfobarWindow. 47 // 48 // InfobarContent is deleted when the InfobarWindow is finished with the 49 // content (either through failure or when successfully hidden). 50 bool Show(InfobarContent* content); 51 52 // Hides the infobar. 53 void Hide(); 54 55 // Receives the total space requested by the displaced content and subtracts 56 // any space required by this infobar. Passes the reserved dimensions to 57 // InfobarContent::SetDimensions. 58 void ReserveSpace(RECT* rect); 59 60 private: 61 // Provides InfobarContent with access to this InfobarWindow. 62 class FrameImpl : public InfobarContent::Frame { 63 public: 64 explicit FrameImpl(InfobarWindow* infobar_window); 65 66 // InfobarContent::Frame implementation 67 virtual HWND GetFrameWindow(); 68 virtual void CloseInfobar(); 69 70 private: 71 InfobarWindow* infobar_window_; 72 DISALLOW_COPY_AND_ASSIGN(FrameImpl); 73 }; // class FrameImpl 74 75 // Sets up our state to show or hide and calls Host::UpdateLayout to cause a 76 // call to ReserveSpace. Sets up a timer to periodically call UpdateLayout. 77 void StartSlidingTowards(int height); 78 79 // Based on the initial height, how long (and if) we have been sliding, and 80 // the target height, decides what the current height should be. 81 int CalculateHeight(); 82 83 // Manage a timer that repeatedly calls Host::UpdateLayout 84 bool StartTimer(); 85 bool StopTimer(); 86 87 scoped_ptr<InfobarContent> content_; 88 Host* host_; 89 FrameImpl frame_impl_; 90 InfobarType type_; 91 int current_width_; 92 int current_height_; 93 94 // These variables control our state for sliding and are used to calculate 95 // the desired height at any given time. 96 base::Time slide_start_; // When we started sliding, or the null time if we 97 // are not sliding. 98 int initial_height_; // Where we started sliding from 99 int target_height_; // Where we are sliding to 100 101 // ID and thunk for the slide-effect timer 102 int timer_id_; 103 FunctionStub* timer_stub_; 104 105 DISALLOW_COPY_AND_ASSIGN(InfobarWindow); 106 }; // class InfobarWindow 107 108 #endif // CHROME_FRAME_INFOBARS_INTERNAL_INFOBAR_WINDOW_H_ 109