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.
5 #ifndef CHROME_FRAME_INFOBARS_INTERNAL_INFOBAR_WINDOW_H_
6 #define CHROME_FRAME_INFOBARS_INTERNAL_INFOBAR_WINDOW_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time.h"
12 #include "chrome_frame/infobars/infobar_content.h"
13 #include "chrome_frame/infobars/infobar_manager.h"
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
23 // Integrates the InfobarWindow with its environment.
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;
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;
39 explicit InfobarWindow(InfobarType type
);
42 void SetHost(Host
* host
);
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.
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
);
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
);
61 // Provides InfobarContent with access to this InfobarWindow.
62 class FrameImpl
: public InfobarContent::Frame
{
64 explicit FrameImpl(InfobarWindow
* infobar_window
);
66 // InfobarContent::Frame implementation
67 virtual HWND
GetFrameWindow();
68 virtual void CloseInfobar();
71 InfobarWindow
* infobar_window_
;
72 DISALLOW_COPY_AND_ASSIGN(FrameImpl
);
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
);
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();
83 // Manage a timer that repeatedly calls Host::UpdateLayout
87 scoped_ptr
<InfobarContent
> content_
;
89 FrameImpl frame_impl_
;
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
98 int initial_height_
; // Where we started sliding from
99 int target_height_
; // Where we are sliding to
101 // ID and thunk for the slide-effect timer
103 FunctionStub
* timer_stub_
;
105 DISALLOW_COPY_AND_ASSIGN(InfobarWindow
);
106 }; // class InfobarWindow
108 #endif // CHROME_FRAME_INFOBARS_INTERNAL_INFOBAR_WINDOW_H_