Chromium Code Reviews| Index: chrome_frame/infobar_window.h |
| =================================================================== |
| --- chrome_frame/infobar_window.h (revision 0) |
| +++ chrome_frame/infobar_window.h (revision 0) |
| @@ -0,0 +1,125 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_FRAME_INFOBAR_WINDOW_H_ |
| +#define CHROME_FRAME_INFOBAR_WINDOW_H_ |
| + |
| +#include "base/singleton.h" |
| +#include "base/scoped_ptr.h" |
| +#include "base/time.h" |
| + |
| +#include <atlbase.h> |
| +#include <atlapp.h> // Must be included AFTER base. |
| +#include <atlcrack.h> |
| +#include <atlframe.h> |
| +#include <atlmisc.h> |
| +#include <atlgdi.h> |
| +#include <atlwin.h> |
| + |
| +#include "chrome_frame/resource1.h" |
| +#include "chrome_frame/infobar_content.h" |
| + |
| +enum InfobarType { |
| + FIRST_INFOBAR_TYPE = 0, |
| + TOP_INFOBAR = 0, // Infobar at the top. |
| + BOTTOM_INFOBAR = 1, // Infobar at the bottom. |
| + END_OF_INFOBAR_TYPE = 2 |
|
grt (UTC plus 2)
2010/11/10 17:59:29
The way this value is used, I would find it more n
erikwright (departed)
2010/11/24 06:24:56
Hope to get rid of it altogether.
|
| +}; |
| + |
| +// InfobarWindow is the window created on the top or bottom of the browser tab |
| +// window that contains the web browser window. |
| +class InfobarWindow |
| + : public CWindowImpl<InfobarWindow, CWindow> { |
| + public: |
| + BEGIN_MSG_MAP(InfobarWindow) |
| + MSG_WM_TIMER(OnTimer) |
| + MSG_WM_DESTROY(OnDestroy) |
| + END_MSG_MAP() |
| + |
| + // Implementations of InfobarHost manage the integration of an InfobarWindow |
| + // with its environment. |
| + class InfobarHost { |
| + public: |
| + virtual ~InfobarHost() {} |
| + // Returns a handle to the window in which this InfobarWindow should be |
| + // created. |
| + virtual HWND GetContainerWindow() = 0; |
| + // Requests that the host update the layout of all infobars. Returns true |
| + // if the request is successful. |
| + virtual bool UpdateLayout() = 0; |
| + }; |
| + |
| + InfobarWindow(InfobarType type, InfobarHost* host); |
| + ~InfobarWindow(); |
| + |
| + // Shows the infobar. |
| + // The height of the infobar is calculated to fit the content (limited to |
| + // max_height if the content is too high; no limit if max_height is set to 0). |
| + // slide indicates whether to show sliding effect. |
| + // Normally, content->InstallInFrame will be called before Show returns. |
| + // IFF successful, content->Reset is guaranteed to be called when the content |
| + // is no longer visible. The InfobarContent implementation is responsible for |
| + // freeing itself and its resources during or after the call to Reset. |
| + HRESULT Show(InfobarContent *content, int max_height); |
| + // Hides the infobar. |
| + HRESULT Hide(); |
| + // Receives the total space requested by the displaced window and reserves |
| + // any space required by this infobar. Resizes the InfobarWindow to fill the |
| + // reserved space. |
| + void ReserveSpace(RECT* rect); |
| + |
| + private: |
| + // An implementation of ContentFrame that connects the Content to this |
| + // InfobarWindow. |
| + class FrameImpl : public InfobarContent::ContentFrame { |
| + public: |
| + FrameImpl(InfobarWindow* infobar_window) |
|
grt (UTC plus 2)
2010/11/10 17:59:29
explicit
erikwright (departed)
2010/11/24 06:24:56
Thanks.
|
| + : infobar_window_(infobar_window) { } |
| + |
| + // ContentFrame implementation |
| + virtual HWND GetFrameWindow() { return *infobar_window_; } |
| + virtual void CloseInfobar() { infobar_window_->Hide(); } |
| + |
| + private: |
| + InfobarWindow* infobar_window_; |
|
grt (UTC plus 2)
2010/11/10 17:59:29
DISALLOW_COPY_AND_ASSIGN?
erikwright (departed)
2010/11/24 06:24:56
Thanks.
|
| + }; |
| + |
| + // Sets up our state to show or hide and calls InfobarHost::UpdateLayout to |
| + // cause an eventual call to ReserveSpace. If sliding, also sets up a timer to |
| + // periodically call UpdateLayout. |
| + void StartUpdatingLayout(bool show, int max_height, bool slide); |
| + |
| + // Based on the initial height, how long (and if) we have been sliding, and |
| + // the target height, decides what the current height should be. |
| + int CalculateHeight(); |
| + |
| + // Implement a timer callback for sliding effect. |
| + LRESULT OnTimer(UINT_PTR nIDEvent); |
| + |
| + // Calls content_->Reset() when the InfobarWindow is destroyed (most likely |
| + // because the browser/tab is going away). |
| + void OnDestroy(); |
| + |
| + // Delegate for the InfobarContent to access us. |
| + FrameImpl frame_impl_; |
| + // Type of the infobar - whether it is displayed at the top or at the bottom |
| + // of the IE content window. |
| + InfobarType type_; |
| + // Our host environment |
| + InfobarHost* host_; |
| + // The content we are displaying |
| + InfobarContent* content_; |
| + // Whether the infobar is shown or not. |
| + bool show_; |
| + // When we started sliding, or the NULL time if we are not sliding. |
| + base::Time slide_start_; |
| + // Where we started sliding from |
| + int initial_height_; |
| + // Where we are sliding to |
| + int target_height_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(InfobarWindow); |
| +}; |
| + |
| +#endif // CHROME_FRAME_INFOBAR_WINDOW_H_ |